pymt5 Documentation
pymt5 is a Python client for the MT5 Web Terminal via reverse-engineered WebSocket binary protocol.
It provides full access to account data, market data, real-time streaming, and trading operations through a clean async Python API.
Contents
- Quick Start
- API Reference
- Trading
- Push Notifications
- Protocol Reference
- MT5 Web Terminal Command Coverage
- Official Python API Compatibility
- Detailed Comparison With Official MetaTrader5 Python API
- Iteration Plan
- Project Status Summary
- Phase 1: Code Quality & Internal Cleanup (v0.9.0)
- Phase 2: Transport & Reliability (v1.0.0)
- Phase 3: Observability & Diagnostics (v1.1.0)
- Phase 4: API & Usability (v1.2.0)
- Phase 5: Protocol & Codec (v1.3.0)
- Phase 6: Testing & CI (v1.4.0)
- Phase 7: Documentation & Ecosystem (v1.5.0)
- Priority Matrix
- Risk Assessment
- Iteration Plan v2
- Iteration Plan v3
- Iteration Plan v4
- Project Status Summary
- Gap Analysis
- Phase 15: Coverage & Code Health (v0.9.0)
- Phase 16: Resilience & Typed Events (v0.10.0)
- Phase 17: Testing Infrastructure (v1.0.0)
- Phase 18: Documentation & Release (v1.0.0)
- Phase 19: Advanced Features (v1.1.0)
- Implementation Roadmap
- Priority Summary
- Verification Checklist
- Iteration Plan v5
- Project Status Summary
- Deep Analysis Findings
- Phase 20: Critical Bug Fixes (v0.9.1)
- Phase 21: Concurrency & Data Integrity (v0.9.2)
- Phase 22: API Consistency & Ergonomics (v0.10.0)
- Phase 23: Testing Infrastructure (v1.0.0-rc)
- Phase 24: Documentation & v1.0.0 Release (v1.0.0)
- Implementation Roadmap
- Priority Summary
- Verification Checklist
- Changelog
Features
WebSocket transport to
wss://web.metatrader.app/terminalAES-CBC encryption with zero IV and PKCS7 padding
Bootstrap handshake with automatic key exchange
Login with UTF-16LE encoded fields
Full account information (balance, equity, margin, leverage)
Open positions, pending orders, and trade history
Symbol cache with fast name-to-ID lookup
Historical OHLCV bars (M1 to MN1)
Real-time tick streaming with callbacks
Order book (depth-of-market) subscription
All 9 order types: market buy/sell, limit, stop, stop-limit
Position close, modify SL/TP, cancel pending orders
9 push notification types for real-time updates
Auto heartbeat and auto reconnect with exponential backoff
Async context manager support
Requirements
Python 3.11+
websockets >= 12.0cryptography >= 42.0.0
Installation
pip install pymt5
Or install from source:
git clone https://github.com/cloudQuant/pymt5.git
cd pymt5
pip install -e .