Conversation
Co-authored-by: Nfectious <19631929+Nfectious@users.noreply.github.com>
Co-authored-by: Nfectious <19631929+Nfectious@users.noreply.github.com>
Co-authored-by: Nfectious <19631929+Nfectious@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Create FastAPI service for cryptocurrency OHLCV data
Add FastAPI service for cryptocurrency market data with technical indicators
Feb 7, 2026
Owner
|
Initial Upload |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Production-ready FastAPI service that fetches OHLCV data from cryptocurrency exchanges (via ccxt) and calculates technical indicators (EMA 20/50/200, RSI-14, ATR-14). Proper handling of NaN/infinity values in pandas calculations ensures valid JSON serialization.
Architecture
Layered design with clean separation:
api/v1/routes_live_data.py- FastAPI endpoints with validationservices/- Business logic (market data processing, indicator calculation)integrations/exchanges.py- ccxt wrapper for testabilityschemas/live_data.py- Pydantic models for request/responseKey implementation detail:
API
GET /api/v1/live_data- Query parameters:symbol,timeframe,limit,exchangeReturns last 20 candles with indicators + latest indicator values. Response includes
nullfor indicators where insufficient historical data exists (e.g., EMA-200 requires 200 candles).Error handling maps ccxt exceptions:
NetworkError→ 503ExchangeError→ 400Configuration
Environment-based via pydantic-settings. Default exchange: Binance spot market.
Development
Project Structure
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.binance.com/home/REDACTED/.local/bin/pytest pytest -v(dns block)/usr/local/bin/uvicorn uvicorn app.main:app --host 0.0.0.0 --port 8000(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Objective
Create a professional, production-ready FastAPI service for fetching cryptocurrency OHLCV data and technical indicators using ccxt.
Requirements
Repository Structure
Create a
src/-based package layout with the following structure:API Implementation
Main Endpoint:
GET /api/v1/live_dataQuery parameters:
symbol(string, default: "BTC/USDT", min: 3, max: 30 chars)timeframe(string, default: "1h", min: 1, max: 10 chars)limit(integer, default: 250, range: 20-2000)exchange(string, default from config, min: 2, max: 40 chars)Response Model (LiveDataResponse):
{ "symbol": str, "timeframe": str, "exchange": str, "last_price": float, "last_timestamp": datetime, "candles_count": int, "recent_candles": List[Candle], # last 20 candles "latest_indicators": LatestIndicators, "meta": dict }Candle Model:
{ "timestamp": datetime, "open": float, "high": float, "low": float, "close": float, "volume": float, "ema_20": Optional[float], "ema_50": Optional[float], "ema_200": Optional[float], "rsi_14": Optional[float], "atr_14": Optional[float] }LatestIndicators Model:
{ "ema_20": Optional[float], "ema_50": Optional[float], "ema_200": Optional[float], "rsi_14": Optional[float], "atr_14": Optional[float] }Technical Indicators
Implement using the
talibrary:Important: Handle NaN values properly by converting them to
None(null in JSON) instead of returning invalid JSON.Configuration
Use
pydantic-settingsfor environment-based configuration:Load from
.envfile (provide.env.exampletemplate).Exchange Integration
ExchangeClientwrapper class for testabilityccxt.NetworkError→ 503 HTTP errorccxt.ExchangeError→ 400 HTTP errorError Handling
HTTPExceptionwith appropriate status codesDevelopment Tools
pyproject.toml should include:
Dependencies:
Dev dependencies:
Tool configuration:
Docker Support
Dockerfile:
uvicorn app.main:app --host 0.0.0.0 --port 8000docker-compose.yml:
CI/CD
GitHub Actions workflow (.github/workflows/ci.yml):
Tests
test_health.py:
GET /health endpointtest_live_data.py:
GET /api/v1/live_dataDocumentation
README.md should include:
Additional Files
.gitignore: Ignore .venv/, pycache, .pytest_cache, .mypy_cache, .ruff_cache, dist/, build/, .env.env.example: Template with all configuration variablesImplementation Notes
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.