Skip to content

REST API Server

FastAPI-powered HTTP API with 35+ endpoints, Swagger docs, and CORS support.

Quick Start

pip install financelib[api]

# Start server
uvicorn financelib.api.server:app --reload --port 8000

# Or from Python
python -c "from financelib.api import run_server; run_server(port=8000)"

Open http://localhost:8000/docs for interactive Swagger UI.

Endpoint Groups

Group Endpoints Description
/health 1 Health check + version
/api/stock/ 4 Price, search, indicators, risk
/api/options/ 2 Black-Scholes pricing, implied vol
/api/bonds/ 1 Bond pricing + duration
/api/valuation/ 2 DCF, Gordon Growth Model
/api/fundamental/ 3 Ratios, screening, sectors
/api/forex/ 3 Rates, conversion, pair list
/api/commodities/ 2 Prices, listing
/api/economic/ 2 FRED/TCMB series lists
/api/portfolio/ 3 Summary, buy, sell
/api/users/ 3 Multi-user portfolios, leaderboard
/api/enterprise/ 5 Order routing, audit, RBAC

Examples

# Stock price
curl http://localhost:8000/api/stock/THYAO.IS

# Technical indicators
curl http://localhost:8000/api/stock/THYAO.IS/indicators?period=6mo

# Options pricing
curl "http://localhost:8000/api/options/price?S=100&K=100&T=1&r=0.05&sigma=0.2"

# Forex
curl http://localhost:8000/api/forex/USD/TRY

# Portfolio
curl -X POST http://localhost:8000/api/portfolio/buy \
  -H "Content-Type: application/json" \
  -d '{"symbol": "THYAO.IS", "amount": 100, "price": 175}'

# Enterprise order routing
curl -X POST http://localhost:8000/api/enterprise/route \
  -H "Content-Type: application/json" \
  -d '{"symbol": "BTC/USDT", "side": "buy", "quantity": 0.1, "asset_class": "crypto"}'

Docker Deployment

docker-compose up -d
# API: http://localhost:8000
# Swagger: http://localhost:8000/docs