Backend API Reference
The backend API is built with FastAPI and provides RESTful endpoints for all platform functionality.
Base URL
http://localhost:8000/api/v1
API Categories
Authentication API
POST /auth/register- Register new userPOST /auth/login- User loginPOST /auth/logout- User logoutPOST /auth/refresh- Refresh access token
Stock Data API
GET /stocks- List all stocksGET /stocks/{code}- Get stock detailsGET /stocks/{code}/price- Get current priceGET /stocks/{code}/history- Get price historyGET /stocks/{code}/financials- Get financial statements
Screening API
POST /screen- Screen stocks with filtersGET /screen/presets- Get saved screen presetsPOST /screen/presets- Save screen presetDELETE /screen/presets/{id}- Delete screen preset
Portfolio API
GET /portfolio- Get user portfolioPOST /portfolio/holdings- Add holdingPUT /portfolio/holdings/{id}- Update holdingDELETE /portfolio/holdings/{id}- Remove holdingGET /portfolio/performance- Get performance metrics
Alerts API
GET /alerts- List user alertsPOST /alerts- Create price alertPUT /alerts/{id}- Update alertDELETE /alerts/{id}- Delete alert
Interactive API Documentation
FastAPI provides automatic interactive API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- OpenAPI Spec: http://localhost:8000/openapi.json
Example: Stock Screening
import requests
# Screen for stocks with specific criteria
response = requests.post(
'http://localhost:8000/api/v1/screen',
headers={'Authorization': 'Bearer YOUR_TOKEN'},
json={
'filters': {
'market': 'KOSPI',
'per': {'min': 0, 'max': 20},
'pbr': {'min': 0, 'max': 1.5},
'roe': {'min': 10},
'market_cap': {'min': 100000000000} # 100B KRW
},
'sort': [
{'field': 'roe', 'direction': 'desc'}
],
'limit': 50
}
)
stocks = response.json()['data']
for stock in stocks:
print(f"{stock['code']}: {stock['name']} - ROE: {stock['roe']}%")
Error Handling
The API uses standard HTTP status codes:
200 OK- Request successful201 Created- Resource created400 Bad Request- Invalid request parameters401 Unauthorized- Authentication required403 Forbidden- Insufficient permissions404 Not Found- Resource not found429 Too Many Requests- Rate limit exceeded500 Internal Server Error- Server error