The Personal Finance API provides comprehensive RESTful endpoints for portfolio management, asset tracking, analytics, and performance monitoring. This API follows REST principles and includes OpenAPI/Swagger documentation.
/api/
All endpoints require authentication using Django's token authentication:
Authorization: Token your_api_token_hereGet your token via:
POST /api/auth-token/
Content-Type: application/json
{
"username": "your_username",
"password": "your_password"
}GET /api/portfolios/- List user's portfoliosPOST /api/portfolios/- Create new portfolioGET /api/portfolios/{id}/- Get portfolio detailsPUT /api/portfolios/{id}/- Update portfolioDELETE /api/portfolios/{id}/- Delete portfolio
Special Portfolio Endpoints:
GET /api/portfolios/{id}/performance_metrics/- Get performance metricsGET /api/portfolios/{id}/allocation/- Get allocation data for chartsGET /api/portfolios/{id}/historical_performance/- Get historical data
GET /api/positions/- List positions (filterable by portfolio)POST /api/positions/- Create new positionGET /api/positions/{id}/- Get position detailsPUT /api/positions/{id}/- Update positionDELETE /api/positions/{id}/- Delete position
GET /api/transactions/- List transactions (filterable)POST /api/transactions/- Create new transactionGET /api/transactions/{id}/- Get transaction detailsPUT /api/transactions/{id}/- Update transactionDELETE /api/transactions/{id}/- Delete transaction
GET /api/portfolio-snapshots/- List historical snapshotsGET /api/portfolio-snapshots/{id}/- Get snapshot details
GET /api/assets/- List assets (searchable and filterable)POST /api/assets/- Create new assetGET /api/assets/{id}/- Get asset detailsPUT /api/assets/{id}/- Update assetDELETE /api/assets/{id}/- Delete asset
Special Asset Endpoints:
GET /api/assets/search/- Search assets by symbol/nameGET /api/assets/{id}/performance_metrics/- Get asset performanceGET /api/assets/{id}/technical_indicators/- Get technical indicatorsGET /api/assets/{id}/price_history/- Get historical pricesPOST /api/assets/{id}/update_price/- Manually update pricePOST /api/assets/{id}/refresh_data/- Refresh from data sources
GET /api/price-history/- List price history (filterable)GET /api/price-history/{id}/- Get specific price record
GET /api/analytics/market_data/- Get market indices, sectors, currencies
GET /api/analytics/correlation_matrix/- Asset correlation matrixGET /api/analytics/risk_metrics/- Comprehensive risk metricsGET /api/analytics/asset_allocation_analysis/- Allocation analysisGET /api/analytics/scenario_analysis/- Scenario/stress testing
GET /api/users/- List users (admin only)GET /api/users/me/- Get current user profilePUT /api/users/me/- Update current user profile
Date Ranges:
?start_date=2024-01-01&end_date=2024-12-31
Portfolio Filtering:
?portfolio_id=1
Asset Filtering:
?asset_type=STOCK&exchange=NASDAQ§or=Technology
Search:
?search=AAPL
Pagination:
?page=1&page_size=50
GET /api/portfolios/1/performance_metrics/
?start_date=2024-01-01
&end_date=2024-12-31
&benchmark=SPY
GET /api/portfolios/1/allocation/
?group_by=asset_type|sector|individual
GET /api/assets/search/
?q=apple
&asset_type=STOCK
&exchange=NASDAQ
&limit=20
{
"count": 25,
"next": "http://api.example.com/api/portfolios/?page=2",
"previous": null,
"results": [...]
}{
"error": "Portfolio not found",
"details": {
"code": "not_found",
"message": "The requested portfolio does not exist or you don't have permission to access it."
}
}{
"id": 1,
"name": "Growth Portfolio",
"description": "Long-term growth focused investments",
"is_active": true,
"created": "2024-01-15T10:30:00Z",
"modified": "2024-01-20T15:45:00Z",
"total_value": "125000.00",
"total_cost_basis": "100000.00",
"total_return": "25000.00",
"total_return_percentage": "25.0000",
"position_count": 8
}{
"id": 1,
"portfolio": 1,
"portfolio_name": "Growth Portfolio",
"asset": {
"id": 1,
"symbol": "AAPL",
"name": "Apple Inc.",
"asset_type": "STOCK",
"current_price": "175.50",
"price_change": "2.50",
"price_change_percentage": "1.44"
},
"quantity": "100.00000000",
"average_cost": "150.00000000",
"first_purchase_date": "2024-01-15",
"total_cost_basis": "15000.00",
"current_value": "17550.00",
"unrealized_gain_loss": "2550.00",
"unrealized_return_percentage": "17.0000"
}{
"id": 1,
"symbol": "AAPL",
"name": "Apple Inc.",
"asset_type": "STOCK",
"currency": "USD",
"exchange": "NASDAQ",
"current_price": "175.50",
"previous_close": "173.00",
"price_change": "2.50",
"price_change_percentage": "1.44",
"day_high": "176.25",
"day_low": "174.80",
"volume": 52847392,
"market_cap": "2750000000000.00",
"sector": "Technology",
"industry": "Consumer Electronics",
"last_price_update": "2024-01-20T20:00:00Z"
}{
"total_return": "25.5500",
"total_return_percentage": "25.55",
"annualized_return": "18.75",
"volatility": "15.25",
"sharpe_ratio": "1.23",
"max_drawdown": "-8.45",
"var_95": "-2850.00",
"beta": "1.15",
"alpha": "3.25",
"sortino_ratio": "1.67",
"calmar_ratio": "2.22",
"start_date": "2024-01-01",
"end_date": "2024-12-31",
"days_analyzed": 365
}| Code | Status | Description |
|---|---|---|
| 400 | Bad Request | Invalid request parameters |
| 401 | Unauthorized | Missing or invalid authentication |
| 403 | Forbidden | Insufficient permissions |
| 404 | Not Found | Resource does not exist |
| 422 | Unprocessable Entity | Validation errors |
| 500 | Internal Server Error | Server error |
- Standard endpoints: 1000 requests per hour
- Analytics endpoints: 100 requests per hour
- Market data: 50 requests per hour
The API will support webhooks for real-time updates:
- Portfolio value changes
- Price alerts
- Risk threshold breaches
- Transaction notifications
import requests
# Authentication
response = requests.post('/api/auth-token/', {
'username': 'your_username',
'password': 'your_password'
})
token = response.json()['token']
headers = {'Authorization': f'Token {token}'}
# Get portfolios
portfolios = requests.get('/api/portfolios/', headers=headers)
# Get performance metrics
metrics = requests.get(
'/api/portfolios/1/performance_metrics/',
params={'start_date': '2024-01-01', 'benchmark': 'SPY'},
headers=headers
)// Authentication
const authResponse = await fetch('/api/auth-token/', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
username: 'your_username',
password: 'your_password'
})
});
const {token} = await authResponse.json();
// Get portfolios
const portfolios = await fetch('/api/portfolios/', {
headers: {'Authorization': `Token ${token}`}
});
// Create new position
const newPosition = await fetch('/api/positions/', {
method: 'POST',
headers: {
'Authorization': `Token ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
portfolio: 1,
asset: 5,
quantity: '100.0',
average_cost: '150.0',
first_purchase_date: '2024-01-15'
})
});Interactive API documentation is available at:
- Swagger UI:
/api/docs/ - OpenAPI Schema:
/api/schema/
The schema includes:
- Complete endpoint documentation
- Request/response examples
- Parameter validation rules
- Authentication requirements
- Model schemas with field descriptions
- Pagination: Always handle paginated responses for list endpoints
- Error Handling: Check response status codes and handle errors gracefully
- Rate Limiting: Implement exponential backoff for rate-limited requests
- Data Validation: Validate data before sending to avoid 422 errors
- Security: Never expose API tokens in client-side code
- Caching: Cache market data and analytics responses appropriately
- Bulk Operations: Use bulk endpoints when available for better performance
For API support and questions:
- Documentation:
/api/docs/ - GitHub Issues: Repository issue tracker
- Contact: API support team
This API follows semantic versioning. Current version: v1.0