PyTrader Python MT4/MT5 Trading API Connector

repository·master·Indexed 21 days ago

https://github.com/thesnowguru/pytrader-python-mt4-mt5-trading-api-connector-drag-n-drop

A WebSocket-based bridge connecting Python scripts to MetaTrader 4 and 5. It uses a client-server architecture where a MetaTrader Expert Advisor (EA) acts as the server and the Python script as the client. Key capabilities include account and terminal management, order and position management (open, change, close), and retrieval of market data such as tick and bar data. Supports remote deployment and provides specific API documentation for both MT4 and MT5.

Tokens
1.1K
Snippets
0
Records
8
Agent score
75%

What's inside PyTrader

  1. What is PyTrader

    master

    PyTrader is a drag-and-drop connector designed to link Python scripts with MetaTrader 4 (MT4) and MetaTrader 5 (MT5).

    Architecture Model:

    • Server: The Expert Advisor (EA) running within MT4/MT5 acts as the server.
    • Client: The Python script acts as the client.
    • Communication: Uses WebSockets for fast and efficient data transfer.
    • Deployment: The EA can run on a different computer than the Python script.

    Capabilities:

    • Python login to MT5.
    • Connection persistence (keep connection alive).
    • Retrieve account information and open orders.
    • Manage orders (open, change, close) directly from Python.
    • Retrieve last tick and bar data.
    • Get instrument information (e.g., pip value, tick size).
  2. How the PyTrader ecosystem works

    master

    PyTrader uses a client-server architecture to connect Python trading strategies to MetaTrader 4 or 5.

    • Server: The MetaTrader Expert Advisor (EA) acts as the server.
    • Client: The Python script acts as the client.
    • Communication: Data is exchanged via Websockets.
    • Workflow: The Python client sends a query (function call), and the EA (server) provides the output (data).

    Because it uses websockets, the EA does not need to be running on the same computer as the Python script.

    Note on Versions: Ensure compatibility between versions (e.g., Pytrader version _06 requires EA version .06).

    Demo Limitations: The demo version (without the licensing indicator) provides full functionality but is restricted to a limited number of instruments: EURUSD, AUDCHF, NZDCHF, GBPNZD, and USDCAD.

  3. Available PyTrader features and capabilities

    master

    PyTrader provides a wide range of capabilities for interacting with MT4/MT5 via Python, including:

    Account & Terminal Management

    • Python login to Metatrader5 Terminal
    • Python Connection keep alive function
    • Get MT5 Account Info (via Python client)
    • Get static account information (from MT5 to Python)
    • Get dynamic account info (balance, equity, margin, free margins)

    Order & Position Management

    • Open New Orders (Python client to MT5) with verification of sending and receiving
    • Change (Take Profit, Stop Loss), Cancel, or Open Orders
    • Close or Partly Close Positions
    • Get all Open orders & Positions (from MT5 to Python)
    • MT5 Execution info (to Python client)

    Market Data & Instrument Info

    • Get instrument information (pip value, max lot, tick size, tick value)
    • Get last tick data (date, bid, ask, vol)
    • Get last X ticks array (date, bid, ask, last, vol)
    • Get bar data (date, open, low, high, close, vol)
    • Get last X bars array (date, open, low, high, close, vol)

    Note: 'Get indicator data from MT5 to your script' is listed as a coming soon feature.