trading-platform-data-service/main.py
rckrdmrd 01683a850f feat: Initial Data Service implementation
- FastAPI service for market data synchronization from Polygon.io
- Async PostgreSQL integration with SQLAlchemy
- API endpoints for tickers, OHLCV data, and sync operations
- Rate-limited Polygon.io API client
- Background task support for historical data sync
- Support for 6 assets: XAUUSD, EURUSD, BTCUSD, GBPUSD, USDJPY, AUDUSD

Endpoints:
- GET /api/v1/tickers - List all tickers
- GET /api/v1/tickers/{symbol}/ohlcv - Get OHLCV data
- GET /api/v1/tickers/{symbol}/latest - Get latest price
- POST /api/v1/sync/historical - Start historical sync
- POST /api/v1/sync/ticker/{symbol} - Sync single ticker

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-13 13:28:18 -06:00

91 lines
2.1 KiB
Python

"""
Data Service - Market Data Synchronization API
FastAPI service for fetching and synchronizing market data from Polygon.io
to the trading platform database.
"""
import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from src.config import get_settings
from src.routers import tickers_router, sync_router
# Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger(__name__)
settings = get_settings()
@asynccontextmanager
async def lifespan(app: FastAPI):
"""Application lifespan handler."""
logger.info("Data Service starting up...")
logger.info(f"Environment: {settings.environment}")
logger.info(f"Database: {settings.database_url.split('@')[1] if '@' in settings.database_url else 'configured'}")
yield
logger.info("Data Service shutting down...")
app = FastAPI(
title="Trading Platform - Data Service",
description="Market data synchronization service using Polygon.io API",
version="1.0.0",
lifespan=lifespan,
docs_url="/docs",
redoc_url="/redoc"
)
# CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include routers
app.include_router(tickers_router)
app.include_router(sync_router)
@app.get("/")
async def root():
"""Root endpoint with service info."""
return {
"service": "data-service",
"version": "1.0.0",
"description": "Market data synchronization from Polygon.io",
"endpoints": {
"tickers": "/api/v1/tickers",
"sync": "/api/v1/sync",
"docs": "/docs"
}
}
@app.get("/health")
async def health_check():
"""Health check endpoint."""
return {
"status": "healthy",
"service": "data-service"
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"main:app",
host="0.0.0.0",
port=settings.port,
reload=settings.environment == "development"
)