Connect to MetaTrader5 on a networked device?


I have MetaTrader5 running on Wine on Arch Linux and can connect to it just fine from that machine using the following python script:

from mt5linux import MetaTrader5

mt5 = MetaTrader5('localhost', 18812)

However, I want to be able to run my script on a Windows 10 machine on the same network but still connect to the MetaTrader5 instance on the Arch Linux server. I attempted this little code:

if == 'nt':
    import MetaTrader5
    mt5 = MetaTrader5('', 18812)
elif == 'posix':
    from mt5linux import MetaTrader5
    mt5 = MetaTrader5('localhost', 18812)
    print('Unknown OS')

If I run this on Windows 10 it gives this error:

Traceback (most recent call last):
  File "C:\Users\me\TradeTester\TradeTester.pyw", line 11, in <module>
    mt5 = MetaTrader5('', 18812)
TypeError: 'module' object is not callable

According to the docs, on Windows you connect as so:

import MetaTrader5 as mt5

And then you can just do the:


Whereas on Linux you have to run a server that listens on port 18812 and then do this:

mt5 = MetaTrader5('localhost', 18812)

So when I'm on Windows and attempt to connect it throws the error above. Is there a way on Windows to connect to a remote MetaTrader5 instance?

Documentation on MQL5: Integration / MetaTrader for Python
Documentation on MQL5: Integration / MetaTrader for Python
MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
I also encountered the same problem
I don't think that will be possible. As far as I know, the Python API cannot connect across the network, only on the same machine (it uses named pipes).
Most probably that port is binded to localhost so it can only be accessed from local machine.
You may try to forward that port using socat.

Actually this is possible. There is a Python library called mt5linux that implements a RPyC server to allow calling local Metatrader Python functions from remote.

Library name does not describe what it can do as it may run in windows too.

I'm developing a docker image that runs MetaTrader5 and mt5linux server on a container, exposing rpyc port so that a Python script may be run from anywhere.