Skip to main content

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 causes DLL load failed errors 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 latest tick
uv run mt5-bridge client --url http://192.168.1.10:8000 tick 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 /health
  • GET /rates/{symbol}?timeframe=M1&count=1000
  • GET /rates_range/{symbol}?timeframe=M1&start=2026-01-01&end=2026-01-15 (Note: API still expects timestamps if using numeric values)
  • GET /tick/{symbol}
  • GET /account
  • GET /positions?symbols=XAUUSD,BTCUSD&magic=123456
  • POST /order
  • POST /close
  • POST /modify

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


Download files

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

Source Distribution

mt5_bridge-1.4.1.tar.gz (123.2 kB view details)

Uploaded Source

Built Distribution

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

mt5_bridge-1.4.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file mt5_bridge-1.4.1.tar.gz.

File metadata

  • Download URL: mt5_bridge-1.4.1.tar.gz
  • Upload date:
  • Size: 123.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mt5_bridge-1.4.1.tar.gz
Algorithm Hash digest
SHA256 2c6c99bdfe4f29b814db12fe8a384aba07c46f1e8514633210bcd4f2586d52cb
MD5 7a7703c1fa2f0360ecd10850135f9157
BLAKE2b-256 a10ec29650a23588bf21387b1df62f3645c3f43be12cffea1521d57b3db207fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for mt5_bridge-1.4.1.tar.gz:

Publisher: publish.yml on akivajp/mt5-bridge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mt5_bridge-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: mt5_bridge-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mt5_bridge-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c74d88a709a688e5c87c386c3269e0458225fea2dd79ad02c3a0e1690b003028
MD5 f5ca6d812994c2dd3f14b90b5810a3c4
BLAKE2b-256 e8e8aa38442a426c8b8b53b64e008f6e7175af811b5aee12d2cb0054e31dfcd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for mt5_bridge-1.4.1-py3-none-any.whl:

Publisher: publish.yml on akivajp/mt5-bridge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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