FastAPI Server
REST API serving real-time market data, signals, and trade execution
API Architecture
The FastAPI server runs on Uvicorn with async request handling. It serves as the central hub connecting the prediction model, market data, and client applications. All endpoints return JSON with consistent error handling and CORS support for the web frontend.
Key Endpoints
The API exposes endpoints for market data retrieval, signal generation, portfolio management, and trade execution. Real-time data is cached with a 30-second TTL to balance freshness with API rate limits.
Real-Time Data Serving
The server maintains an in-memory cache of the latest market prices, model predictions, and trading signals. A background task refreshes this cache every 30 seconds by querying the Polymarket API and running the prediction model. Clients receive near-real-time data without triggering redundant model evaluations.