Complete API reference for the Advanced Multi-Asset Trading System v2.0
- Base URL:
http://localhost:8000 - API Version: v2.0.0
- Authentication: Bearer Token (for protected endpoints)
- Content-Type:
application/json - Documentation: Available at
/docs(Swagger UI) and/redoc(ReDoc)
Most endpoints require authentication using Bearer tokens:
curl -H "Authorization: Bearer YOUR_TOKEN" http://localhost:8000/api/v1/endpointDescription: System health check with service status
Authentication: None required
Response Model: HealthResponse
curl http://localhost:8000/healthResponse:
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00Z",
"version": "2.0.0",
"environment": "production",
"services": {
"database": {
"status": "healthy",
"response_time": "< 10ms"
},
"redis": {
"status": "healthy",
"response_time": "< 5ms"
}
}
}Description: Detailed trading system status
Authentication: None required
Response Model: SystemStatusResponse
curl http://localhost:8000/api/v1/statusResponse:
{
"trading_active": false,
"market_hours": {
"us_market_open": false,
"crypto_market_open": true,
"forex_market_open": true
},
"connected_exchanges": ["alpaca", "binance"],
"active_strategies": ["momentum", "mean_reversion", "covered_calls"],
"system_metrics": {
"uptime": "16h 42m",
"memory_usage": "45%",
"cpu_usage": "12%"
}
}Description: Get system configuration (non-sensitive data only) Authentication: None required
curl http://localhost:8000/api/v1/configResponse:
{
"environment": "production",
"trading_mode": "paper",
"demo_mode": "true",
"version": "2.0.0"
}Description: Get current portfolio overview Authentication: Required
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/api/v1/portfolioResponse:
{
"total_value": 97052.34,
"cash": 50000.00,
"positions_value": 47052.34,
"day_pnl": 1234.56,
"total_pnl": -2947.66,
"positions": [
{
"symbol": "AAPL",
"quantity": 100,
"avg_price": 150.00,
"market_value": 15500.00,
"unrealized_pnl": 500.00,
"updated_at": "2024-01-15T10:30:00Z"
}
]
}Description: Get detailed position information
Authentication: Required
Response Model: List[PositionResponse]
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/api/v1/positionsDescription: Place a new trading order
Authentication: Required
Request Model: TradeRequest
curl -X POST \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"symbol": "AAPL",
"side": "buy",
"quantity": 100,
"order_type": "market",
"strategy": "momentum"
}' \
http://localhost:8000/api/v1/ordersRequest Body:
{
"symbol": "AAPL",
"side": "buy",
"quantity": 100,
"order_type": "market",
"price": 150.00,
"strategy": "momentum"
}Response:
{
"order_id": "ord_123456789",
"status": "submitted",
"symbol": "AAPL",
"side": "buy",
"quantity": 100,
"order_type": "market",
"submitted_at": "2024-01-15T10:30:00Z"
}Description: Get order details by ID Authentication: Required
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/api/v1/orders/ord_123456789Description: Cancel an open order Authentication: Required
curl -X DELETE \
-H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/api/v1/orders/ord_123456789Description: List all available trading strategies Authentication: Required
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/api/v1/strategiesResponse:
{
"strategies": [
{
"id": "momentum",
"name": "Momentum Strategy",
"status": "active",
"allocation": 0.33,
"performance": {
"total_return": 0.0523,
"sharpe_ratio": 1.42,
"max_drawdown": 0.0234
}
}
]
}Description: Enable a trading strategy Authentication: Required
curl -X POST \
-H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/api/v1/strategies/momentum/enableDescription: Disable a trading strategy Authentication: Required
curl -X POST \
-H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/api/v1/strategies/momentum/disableDescription: Get detailed strategy performance metrics Authentication: Required
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/api/v1/strategies/momentum/performanceDescription: Get current risk metrics Authentication: Required
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/api/v1/risk/metricsResponse:
{
"portfolio_var": 0.0234,
"max_position_size": 0.05,
"current_leverage": 1.2,
"risk_score": 3.2,
"correlation_risk": 0.15
}Description: Get current risk limits Authentication: Required
Description: Update risk limits Authentication: Required
Description: Get active risk alerts Authentication: Required
Description: Get performance summary Authentication: Required
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/api/v1/performance/summaryDescription: Get daily performance data Authentication: Required
Description: Get trade history and performance Authentication: Required
Description: Get performance attribution by strategy Authentication: Required
Connect to real-time data streams via WebSocket:
const ws = new WebSocket('ws://localhost:8000/ws');ws.send(JSON.stringify({
"action": "subscribe",
"channels": ["portfolio", "orders", "market_data"]
}));ws.send(JSON.stringify({
"action": "unsubscribe",
"channels": ["market_data"]
}));// Send ping
ws.send(JSON.stringify({
"action": "ping"
}));
// Receive pong
{
"type": "pong",
"timestamp": "2024-01-15T10:30:00Z"
}{
"type": "portfolio_update",
"data": {
"total_value": 97052.34,
"day_pnl": 1234.56,
"timestamp": "2024-01-15T10:30:00Z"
}
}{
"type": "order_update",
"data": {
"order_id": "ord_123456789",
"status": "filled",
"fill_price": 150.25,
"timestamp": "2024-01-15T10:30:00Z"
}
}{
"type": "market_data",
"data": {
"symbol": "AAPL",
"price": 150.25,
"volume": 1000000,
"timestamp": "2024-01-15T10:30:00Z"
}
}{
"status": str, # "healthy", "degraded", "unhealthy"
"timestamp": datetime,
"version": str,
"environment": str,
"services": Dict[str, Any]
}{
"trading_active": bool,
"market_hours": Dict[str, Any],
"connected_exchanges": List[str],
"active_strategies": List[str],
"system_metrics": Dict[str, Any]
}{
"symbol": str, # Required
"side": str, # "buy" or "sell"
"quantity": float, # Required
"order_type": str, # "market", "limit", "stop"
"price": Optional[float], # Required for limit orders
"strategy": str # Strategy identifier
}{
"symbol": str,
"quantity": float,
"avg_price": float,
"market_value": float,
"unrealized_pnl": float,
"updated_at": datetime
}200: Success400: Bad Request (invalid parameters)401: Unauthorized (missing/invalid token)404: Not Found (endpoint/resource not found)429: Too Many Requests (rate limited)500: Internal Server Error
{
"detail": "Error description",
"timestamp": "2024-01-15T10:30:00Z"
}- Default Rate Limit: 100 requests per minute per IP
- Authenticated Rate Limit: 1000 requests per minute per token
- WebSocket Connections: 10 concurrent connections per IP
- Check System Status
curl http://localhost:8000/api/v1/status- Get Portfolio Overview
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/api/v1/portfolio- Place Market Order
curl -X POST \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"symbol": "AAPL",
"side": "buy",
"quantity": 100,
"order_type": "market",
"strategy": "momentum"
}' \
http://localhost:8000/api/v1/orders- Monitor Order Status
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/api/v1/orders/ord_123456789- Check Updated Portfolio
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8000/api/v1/portfolio- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Use the interactive documentation or tools like Postman, curl, or HTTPie to test endpoints.
Configure API behavior using environment variables:
TRADING_MODE: "paper" or "live"API_RATE_LIMIT: Requests per minuteLOG_LEVEL: "DEBUG", "INFO", "WARNING", "ERROR"
📚 This API documentation provides comprehensive coverage of all available endpoints. For implementation details and advanced usage, refer to the main README.md and system architecture documentation.