REST API¶
The pdmt5 REST API exposes read-only MetaTrader 5 data via FastAPI. It supports JSON and Apache Parquet responses for efficient analytics workflows.
Installation¶
Install pdmt5 with API dependencies:
Configuration¶
Set the API key and optional limits via environment variables:
export MT5_API_KEY="your-secret-api-key"
export API_LOG_LEVEL="INFO"
export API_RATE_LIMIT="100"
export API_CORS_ORIGINS="*"
Running the API¶
Access the docs at:
- Swagger UI:
http://localhost:8000/docs - OpenAPI JSON:
http://localhost:8000/openapi.json
Authentication¶
All endpoints except /api/v1/health require an API key header:
Format Negotiation¶
Use Accept header or format query parameter:
curl -H "X-API-Key: your-secret-api-key" \
-H "Accept: application/parquet" \
"http://localhost:8000/api/v1/rates/from?symbol=EURUSD&timeframe=1&date_from=2024-01-01T00:00:00Z&count=100"
Example Requests¶
Health Check (No Auth)¶
MT5 Version¶
Symbols¶
Symbol Details¶
Rates (OHLCV)¶
curl -H "X-API-Key: your-secret-api-key" \
"http://localhost:8000/api/v1/rates/from?symbol=EURUSD&timeframe=1&date_from=2024-01-01T00:00:00Z&count=100"
Account Info¶
History Orders¶
curl -H "X-API-Key: your-secret-api-key" \
"http://localhost:8000/api/v1/history/orders?date_from=2024-01-01T00:00:00Z&date_to=2024-01-02T00:00:00Z"
Error Responses¶
Errors follow RFC 7807 Problem Details:
{
"type": "/errors/validation-error",
"title": "Request Validation Failed",
"status": 400,
"detail": "count must be positive (got: -10)",
"instance": "/api/v1/rates/from"
}
Performance Benchmarks¶
Target benchmarks for production readiness:
- Health check latency < 500ms under normal load
- Market data queries < 2s for typical datasets (<1000 records)
- 100 concurrent requests without significant degradation
Security Checklist¶
Minimum security posture for deployments:
- API key authentication enabled (
MT5_API_KEY) - Rate limiting enabled (
API_RATE_LIMIT) - Run behind HTTPS in production
- Restrict CORS origins (
API_CORS_ORIGINS) for public deployments