Skip to main content

MetaTrader 5 REST API

Project description

mt5api

MetaTrader 5 REST API using FastAPI

CI/CD

mt5api exposes read-only MT5 market data, account info, and trading history over HTTP. It uses the pdmt5 client internally and adds optional API-key auth, rate limiting, and JSON/Parquet response formatting.

The API server must run on Windows. The MetaTrader5 Python package used by pdmt5 is supported only on Windows, so you must host mt5api on a Windows machine with a logged-in MetaTrader 5 terminal. HTTP clients can connect from any operating system.

Features

  • Read-only REST endpoints for symbols, market data, account info, orders, and history
  • JSON and Apache Parquet responses (content negotiation)
  • Optional API key authentication with per-minute rate limiting
  • Structured JSON logging and configurable CORS
  • OpenAPI/Swagger docs built into the API

Requirements

  • Python 3.11+
  • Windows host with MetaTrader 5 terminal installed and logged in
  • Linux and macOS are not supported for the API server runtime, but they work for HTTP clients

Installation

Install and run the API on the Windows machine where MetaTrader 5 is installed.

git clone https://github.com/dceoy/mt5api.git
cd mt5api
uv sync

Running the API on Windows

$env:MT5_API_KEY = "your-secret-api-key"  # Optional: omit to disable auth
uv run uvicorn mt5api.main:app --host 0.0.0.0 --port 8000

Docs:

  • Swagger UI: http://localhost:8000/docs
  • OpenAPI JSON: http://localhost:8000/openapi.json

Example Requests with curl

Replace windows-host with the DNS name or IP address of the Windows machine running mt5api. If you run the request on that Windows host, localhost also works. In PowerShell, use curl.exe if curl resolves to Invoke-WebRequest.

curl "http://windows-host:8000/api/v1/health"
# Include X-API-Key only when MT5_API_KEY is configured on the server.
curl -H "X-API-Key: your-secret-api-key" "http://windows-host:8000/api/v1/symbols?group=*USD*"
curl -H "X-API-Key: your-secret-api-key" -H "Accept: application/parquet" "http://windows-host:8000/api/v1/rates/from?symbol=EURUSD&timeframe=1&date_from=2024-01-01T00:00:00Z&count=100"

Endpoints (Read-Only)

  • Health: /api/v1/health, /api/v1/version
  • Symbols: /api/v1/symbols, /api/v1/symbols/{symbol}, /api/v1/symbols/{symbol}/tick
  • Market data: /api/v1/rates/from, /api/v1/rates/from-pos, /api/v1/rates/range, /api/v1/ticks/from, /api/v1/ticks/range, /api/v1/market-book/{symbol}
  • Account: /api/v1/account, /api/v1/terminal
  • Trading state: /api/v1/positions, /api/v1/orders
  • History: /api/v1/history/orders, /api/v1/history/deals

License

MIT License - see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mt5api-0.0.2.tar.gz (241.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mt5api-0.0.2-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file mt5api-0.0.2.tar.gz.

File metadata

  • Download URL: mt5api-0.0.2.tar.gz
  • Upload date:
  • Size: 241.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mt5api-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e57692a080dd2f0cf07535b63410230015764f3eb569b63d413a5195593645b9
MD5 c0d3fc0cd7f969a38338bd3e0647354e
BLAKE2b-256 45543c386406e0f626c099f1374b71c17e0101abd875e09ba08109a4e5e3b45e

See more details on using hashes here.

File details

Details for the file mt5api-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: mt5api-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mt5api-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ad5f388c031b2f771a34d10be0fa57a9c5165140fe57caaab348679f88c0ddd2
MD5 85cb12fe04d7b105e7ab344b12e71104
BLAKE2b-256 41a1aac65dd6f4f92116d2d918c98ebad2a961ebafc9c3b5dec811e7d8a14121

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page