MT5 Bridge API - REST API and CLI for MetaTrader5
Project description
MT5 Bridge API
Overview
mt5-bridge is a FastAPI service and CLI tool that mediates market data access and order execution between a MetaTrader 5 terminal and external applications.
- Server: Runs on Windows (where MT5 is installed) and exposes a REST API.
- Client: Runs on any platform (Windows, Linux, macOS) and communicates with the Server to fetch data or execute trades.
Prerequisites
- Python 3.11+
- Server Mode: Windows environment with MetaTrader 5 terminal installed.
- Client Mode: Any OS.
Installation
From PyPI (Recommended)
You can install mt5-bridge directly from PyPI:
pip install mt5-bridge
Once installed, you can run the mt5-bridge command directly.
From Source (Development)
This project uses uv for package management.
# Install dependencies
uv sync
On Linux/macOS, the MetaTrader5 package will be skipped automatically, allowing you to use the client functionality without issues.
Usage
The package installs a CLI command mt5-bridge.
1. Start the Server (Windows Only)
On your Windows machine with MT5:
# Default (localhost:8000)
uv run mt5-bridge server
# Custom host/port
uv run mt5-bridge server --host 0.0.0.0 --port 8000
Note: If you are using WSL, please checkout this repository on the Windows file system (e.g.,
C:\Work\mt5-bridge) and run the command from PowerShell/Command Prompt. Running Windows Python directly against a directory inside WSL (UNC path like\\wsl.localhost\Ubuntu\...) often causesDLL load failederrors with libraries like NumPy.
Additional options:
--mt5-path "C:\Path\To\terminal64.exe": proper initialization--no-utc: Disable Server Time -> UTC conversion
2. Use the Client (Any Platform)
From another machine (or the same one), use the client command to interact with the server.
# Check connection health
uv run mt5-bridge client --url http://192.168.1.10:8000 health
# Get historical rates (M1, last 1000 bars) for XAUUSD
uv run mt5-bridge client --url http://192.168.1.10:8000 rates XAUUSD
# Get historical rates by date range (M1, 2026-01-01 to 2026-01-15)
uv run mt5-bridge client --url http://192.168.1.10:8000 rates_range XAUUSD --timeframe M1 --start 2026-01-01 --end 2026-01-15
# Get historical tick data from a specific date (count-based)
uv run mt5-bridge client --url http://192.168.1.10:8000 ticks_from XAUUSD --start 2026-01-01 --count 1000 --flags ALL
# Get historical tick data within a date range
uv run mt5-bridge client --url http://192.168.1.10:8000 ticks_range XAUUSD --start "2026-01-01 10:00:00" --end "2026-01-01 10:05:00" --flags TRADE
# Get latest tick
uv run mt5-bridge client --url http://192.168.1.10:8000 tick XAUUSD
# Get market depth (Level 2)
uv run mt5-bridge client --url http://192.168.1.10:8000 book XAUUSD
# Get account information
uv run mt5-bridge client --url http://192.168.1.10:8000 account
# List open positions (optional filters: --symbols XAUUSD,BTCUSD --magic 123456)
uv run mt5-bridge client --url http://192.168.1.10:8000 positions
# Send order
uv run mt5-bridge client --url http://192.168.1.10:8000 order XAUUSD BUY 0.01 --sl 2000.0 --tp 2050.0
# Close position
uv run mt5-bridge client --url http://192.168.1.10:8000 close 12345678
# Modify position
uv run mt5-bridge client --url http://192.168.1.10:8000 modify 12345678 --sl 2005.0
JSON API
You can also access the API directly via generic HTTP clients (curl, Postman, specific libraries).
GET /healthGET /rates/{symbol}?timeframe=M1&count=1000GET /rates_range/{symbol}?timeframe=M1&start=2026-01-01&end=2026-01-15GET /tick/{symbol}GET /book/{symbol}(v1.6.0+)GET /ticks_from/{symbol}?start=2026-01-01&count=1000&flags=ALL(v1.5.0+)GET /ticks_range/{symbol}?start=2026-01-01&end=2026-01-02&flags=ALL(v1.5.0+)GET /accountGET /positions?symbols=XAUUSD,BTCUSD&magic=123456POST /orderPOST /closePOST /modify
Historical Tick Data (v1.5.0+)
The tick data endpoints support the following tick type flags:
| Flag | Description |
|---|---|
ALL |
All ticks |
INFO |
Ticks with Bid/Ask changes |
TRADE |
Ticks with Last/Volume changes (actual trades) |
The response includes:
time: Timestamp in seconds (UTC)time_msc: Millisecond-precision timestampbid,ask,last,volume: Price and volume informationflags: Tick change flags
Architecture
mt5_bridge/main.py: CLI entry point and FastAPI server definition.mt5_bridge/mt5_handler.py: Wrapper for MetaTrader5 package (guarded imports).mt5_bridge/client.py: HTTP client implementation.
MCP (Copilot CLI) Integration
- Purpose: expose the MT5 Bridge API to Copilot CLI (MCP).
- Run MCP server:
python mt5_bridge/mcp_server.py --api-base http://localhost:8000
License
MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mt5_bridge-1.6.2.tar.gz.
File metadata
- Download URL: mt5_bridge-1.6.2.tar.gz
- Upload date:
- Size: 126.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5306fa733f5a6b2bf6a2b6afe6f2d53f41973e378051f257e6d31815d10130ff
|
|
| MD5 |
0991f4eb1935e2be8b9a82628602a2f9
|
|
| BLAKE2b-256 |
cd51f2fdbb350d7bbd9b6bbfad81e4668c8d200fa85d0d0616817263d5b7d460
|
Provenance
The following attestation bundles were made for mt5_bridge-1.6.2.tar.gz:
Publisher:
publish.yml on akivajp/mt5-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mt5_bridge-1.6.2.tar.gz -
Subject digest:
5306fa733f5a6b2bf6a2b6afe6f2d53f41973e378051f257e6d31815d10130ff - Sigstore transparency entry: 862977354
- Sigstore integration time:
-
Permalink:
akivajp/mt5-bridge@f8b2c56a9a2477e8ee66c2b2790dc3fdb75c9856 -
Branch / Tag:
refs/tags/v1.6.2 - Owner: https://github.com/akivajp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f8b2c56a9a2477e8ee66c2b2790dc3fdb75c9856 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mt5_bridge-1.6.2-py3-none-any.whl.
File metadata
- Download URL: mt5_bridge-1.6.2-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdb4c9556364176205995ea75a970bb360a896cb61c81f804dd1649f1741ea79
|
|
| MD5 |
fc5d42602a0c868c4c0fb86cb4296984
|
|
| BLAKE2b-256 |
5f81e0b8d0fde090b4d06a0a3af39af19822b87b1bc4bcc325b278e2e6c68ba4
|
Provenance
The following attestation bundles were made for mt5_bridge-1.6.2-py3-none-any.whl:
Publisher:
publish.yml on akivajp/mt5-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mt5_bridge-1.6.2-py3-none-any.whl -
Subject digest:
cdb4c9556364176205995ea75a970bb360a896cb61c81f804dd1649f1741ea79 - Sigstore transparency entry: 862977412
- Sigstore integration time:
-
Permalink:
akivajp/mt5-bridge@f8b2c56a9a2477e8ee66c2b2790dc3fdb75c9856 -
Branch / Tag:
refs/tags/v1.6.2 - Owner: https://github.com/akivajp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f8b2c56a9a2477e8ee66c2b2790dc3fdb75c9856 -
Trigger Event:
push
-
Statement type: