Skip to main content

MetaTrader 5 REST API using FastAPI

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

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

$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

curl.exe http://localhost:8000/api/v1/health
# Include X-API-Key only when MT5_API_KEY is configured on the server.
curl.exe -H "X-API-Key: your-secret-api-key" "http://localhost:8000/api/v1/symbols?group=*USD*"
curl.exe -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"

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.1.tar.gz (241.4 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.1-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mt5api-0.0.1.tar.gz
  • Upload date:
  • Size: 241.4 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.1.tar.gz
Algorithm Hash digest
SHA256 13e97b6468c1c2a8625ce584664a47c6d43d07faa81bdaf0030d3455e642107f
MD5 f8f0273bfe445e6e6d83afd192e84817
BLAKE2b-256 65c84e8aacdcb271631a0c839ae9c86d8c80fc8379d81cb28158d43ee033690a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mt5api-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 20.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 acdddf37e36f08def336506682ad40709aa48a7f1b658f71ae67a160b7edda2c
MD5 3b6663d887d0a7e56e2900e41aa61060
BLAKE2b-256 fc20c6374aecaa25c66e44d3d85f09e09e832e7fe3afd1718b775570910ac4e1

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