Tech/FastAPI Server

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.

GET /markets — all active weather markets with prices
GET /signals — current trading signals with Kelly sizing
GET /portfolio — open positions and P&L
POST /trade — execute a trade (paper or live mode)
GET /forecast/{station} — model prediction for a station

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.