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 (uv)

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 latest tick
uv run mt5-bridge client --url http://192.168.1.10:8000 tick XAUUSD

# List open positions
uv run mt5-bridge client --url http://192.168.1.10:8000 positions

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 /tick/{symbol}
  • GET /positions
  • 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.1.0.tar.gz (120.0 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.1.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mt5_bridge-1.1.0.tar.gz
  • Upload date:
  • Size: 120.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mt5_bridge-1.1.0.tar.gz
Algorithm Hash digest
SHA256 565fd1f438feb329a8a7cd42ee5e6fdfcee88dbe367d5f87d1bd9dacb6a364f0
MD5 3f85474220d34e9e7f78729783dd7336
BLAKE2b-256 8ba698a2b5abf2217a1a53346ef7fb9ade18dab1cf7aa9721a8f060fc9a40025

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mt5_bridge-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mt5_bridge-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2684891f70db3910dc5a989108e5a17fbc23f50fab01dde292f0f71879bda71
MD5 2b373ac1fe57408cca008a7674cfeace
BLAKE2b-256 d1a5950e3d93bc08ffe7354fa87c8d3295a03eaa615ee3d7ea12e09971d33d93

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