2

I was following the 7 video tutorials on how to interface python with a MetaTrader Terminal 4 and got no problem running them on iPython kernel just as instructed in this video

By no problem I mean a trade was sent to the server with ease and client (my laptop) received proper response after each action is executed. When I call zmq._get_response_() I can get access to server response.

The problem starts to arise when I want to compile the DWX_ZeroMQ_Connector class within a program. So I start with a simple program just like this :

def main():  
    zmq = DWX_ZeroMQ_Connector()
    my_trade = { '_action':       'OPEN',
                 '_type':         0,
                 '_symbol':       'USOIL',
                 '_price':        0.0,
                 '_SL':           0,
                 '_TP':           0,
                 '_comment':      'dwx-zeromq',
                 '_lots':         0.01,
                 '_magic':   123456,
                 '_ticket':       0
                 }
    #
    zmq._DWX_MTX_NEW_TRADE_(_order=my_trade)
    #
    reply     = zmq._get_response_()  
    all_trade = zmq._DWX_MTX_GET_ALL_OPEN_TRADES_()
    #
    print( "reply" + str( reply ) )
    print( "----------------------" )
    print( "alltrade" + str( all_trade ) )

main()

The weird part is this script STILL SENDS ORDERS SUCCESSFULLY, BUT DID NOT PROMPT ANY RESPONSE BACK as the reply turned out to be null. Was struggling with this for a week.

Some additional information :

  • I found the problem of not receiving response only when using Anaconda prompt to execute the compiled file, but I received proper response on iPython kernel so I presumed it could not be my dependencies. Both was running on local host

  • the github page I was cloning is the latest v2.0.1 RC8 version

  • Here is the printed version of zmq._get_response_() enter image description here

  • Here are my parameters for MQL4 code enter image description here

  • Here is a picture of MT4 actively pushing quote enter image description here

  • Here is a picture of Console when I tried to set _monitor = True in the initialization process of DWX_ZeroMQ_Connector object. Now it even failed to send trades to MetaTrader Terminal 4 ( a Terminal-side DWX-code service-server ) and of course still failed to get any response back. enter image description here

  • Here is the copy of both Terminal Log and Expert Log examples when I tried getting a response from MT4 Terminal (server). As it was weekend, I had to experiment with bitcoin trade.


TERMINAL LOG

0   16:33:17.600    MetaTrader build 1260 started (Exness Ltd.)
0   16:33:17.600    Windows 10 Pro x64, IE 11, UAC, 4 x Intel Core i7-5500U  @ 2.40GHz, Memory: 4899 / 8103 Mb, Disk: 73 / 99 Gb, GMT+7
0   16:33:17.600    Data Folder: C:\Users\Admin\AppData\Roaming\MetaQuotes\Terminal\F5C18A2156882613427FB4ACF0892997
2   16:33:20.664    Expert DWX_ZeroMQ_Server_v2.0.1_RC8 USOIL,H1: loaded successfully
2   16:33:20.767    Expert DWX_ZeroMQ_Server_v2.0.1_RC8 GBPJPY,H1: loaded successfully
0   16:33:22.258    '36006969': login on Exness-Trial4 through DC00 (ping: 235.09 ms)
0   16:33:24.299    '36006969': login datacenter on Exness-Trial4 through DC00 (ping: 235.09 ms)
0   16:33:24.933    '36006969': previous successful authorization performed from 171.255.70.226
2   16:33:31.235    Expert DWX_ZeroMQ_Server_v2.0.1_RC8 GBPJPY,H1: removed
2   16:33:31.247    Expert DWX_ZeroMQ_Server_v2.0.1_RC8 GBPJPY,H1: loaded successfully
0   16:33:42.019    '36006969': order buy market 0.01 BTCUSD sl: 0.00 tp: 0.00
0   16:33:42.514    Trades: use hosting service to speed up the execution - 0.33 ms via 'MQL5 Amsterdam 01 (MQL5.community)' instead of 235.09 ms
0   16:33:42.514    '36006969': order was opened : #2991084 buy 0.01 BTCUSD at 7110.21 sl: 0.00 tp: 0.00
2   16:35:11.850    Expert DWX_ZeroMQ_Server_v2.0.1_RC8 USOIL,H1: removed
2   16:35:11.866    Expert DWX_ZeroMQ_Server_v2.0.1_RC8 GBPJPY,H1: removed
0   16:35:12.081    MetaTrader build 1260 stopped

EXPERT LOG :

0   16:33:20.269    Expert DWX_ZeroMQ_Server_v2.0.1_RC8 EURUSDm,H1: loaded successfully
0   16:33:20.270    DWX_ZeroMQ_Server_v2.0.1_RC8 EURUSDm,H1 inputs: PROJECT_NAME=DWX_ZeroMQ_MT4_Server; ZEROMQ_PROTOCOL=tcp; HOSTNAME=*; PUSH_PORT=32768; PULL_PORT=32769; PUB_PORT=32770; MILLISECOND_TIMER=1; t0=--- Trading Parameters ---; MagicNumber=123456; MaximumOrders=1; MaximumLotSize=0.01; MaximumSlippage=3; DMA_MODE=true; t1=--- ZeroMQ Configuration ---; Publish_MarketData=false; 
0   16:33:20.664    Expert DWX_ZeroMQ_Server_v2.0.1_RC8 USOIL,H1: loaded successfully
0   16:33:20.664    DWX_ZeroMQ_Server_v2.0.1_RC8 USOIL,H1 inputs: PROJECT_NAME=DWX_ZeroMQ_MT4_Server; ZEROMQ_PROTOCOL=tcp; HOSTNAME=*; PUSH_PORT=32768; PULL_PORT=32769; PUB_PORT=32770; MILLISECOND_TIMER=1; t0=--- Trading Parameters ---; MagicNumber=123456; MaximumOrders=1; MaximumLotSize=0.01; MaximumSlippage=3; DMA_MODE=true; t1=--- ZeroMQ Configuration ---; Publish_MarketData=false; 
00  16:33:20.767    Expert DWX_ZeroMQ_Server_v2.0.1_RC8 GBPJPY,H1: loaded successfully
0   16:33:20.767    DWX_ZeroMQ_Server_v2.0.1_RC8 GBPJPY,H1 inputs: PROJECT_NAME=DWX_ZeroMQ_MT4_Server; ZEROMQ_PROTOCOL=tcp; HOSTNAME=*; PUSH_PORT=32768; PULL_PORT=32769; PUB_PORT=32770; MILLISECOND_TIMER=1; t0=--- Trading Parameters ---; MagicNumber=123456; MaximumOrders=1; MaximumLotSize=0.01; MaximumSlippage=3; DMA_MODE=true; t1=--- ZeroMQ Configuration ---; Publish_MarketData=true; 

halfer
  • 19,824
  • 17
  • 99
  • 186
tiensison
  • 21
  • 3
  • 1
    Would be fair to also post a complete copy of all the **`print`-ed responses from a launched `DWX_ZeroMQ_Connector()`** + a copy of the MetaTrader Terminal log, where connections from python node were made to the MetaTrader Terminal node. – user3666197 Apr 16 '20 at 08:54
  • @user3666197 Hi, i have updated more information to the question as it might help you understand my issues better. Also thanks for editing my post to follow the guideline better, I am new to stackoverflow and your comment is much appreciated :) – tiensison Apr 16 '20 at 11:19
  • Always welcome, @tiensison – user3666197 Apr 16 '20 at 12:27
  • Did you correct the -3- principal errors documented below? You owe me a beer for each one ... & Happy **and *safe*** Trading! – user3666197 Apr 20 '20 at 19:25

1 Answers1

2

The DWX_ZeroMQ_Connector() source code provided as-is suffers from several ZeroMQ deficiencies in self-protecting the communicating node from deadlocking and lacks a few touches to achieve a professional-grade software robustness.

Yet, the most warning is the explicit statement Win10 only + obey all DLLs dependencies + DO NOT USE in iPython + do not upgrade to v2.0.2, so rather follow it, until authors publish stable and robust version.


( v2.0.2 is currently in beta-testing, please do not upgrade to v2.0.2 )
...
5 ) This project and all accompanying source code should be run standalone (i.g. via a Python or IPython console, or batch process).

6 ) Please DO NOT run this code in Jupyter or IPython Notebooks.

7 ) The project's dependencies require MS VC++ Libraries. Without these installed, you are likely to run into "Resource Timeout" errors. The DLLs in the dependency projects (mql-zmq, libzmq, libsodium) require that you have the latest Visual C++ runtime (2015) libraries already installed.

8 ) This project has not been tested on emulated environments (e.g. WINE, VMWare, etc).

9 ) This project is intended for use solely in Windows 10 environments, at the present time.

To answer this question, it would be fair to also post:

  • a complete copy of all the print-ed responses from a launched DWX_ZeroMQ_Connector()
  • a copy of the MetaTrader Terminal log, where connections from python node were made to the MetaTrader Terminal node.
  • a copy of the MetaTrader Terminal MQL4-code parameters :

enter image description here

  • a copy of the proof of MetaTrader Terminal active work - receiving Trade Requests and pushing QUOTE-updates :

enter link description here


Best check all Darwinex published compatibility conditions above and review your compliance with there set rules.


EPILOGUE : "... failed to get responses from the MT4 ...", well not so ...

The problem ( not receiving MT4.PUSH-es ) is caused by not understanding the rules of the game and the steps needed for a working solution are hidden in -3- different places :

1 ) The API-publisher, Darwinex, might have documented this somewhere, yet the first headbang is in trying to use the very same TCP port# three times, which has no other chance but to crash any such late attempts to acquire an already acquired resource ( as the ZeroMQ-related code in v2.0.1 (as-is, as I had chances to review) does not use proper self-protecting settings, these crashes may block any other use-cases because of frozen Context()-instances, some might persist even until an O/S reboot.

2 ) The Expert initialisation explicitly disabled in 2 of 3 launch cases, to ever be notified about the MT4.PUSH-ed FxMarketEVENTs ( QUOTE-(tick)-data ), by honorable user her/him/x/fluid/*-self

3 ) You falsely expect the v2.0.1-RC8 code to do things, it was explicitly set in an imperative code setup not to do ( again, API-publisher, Darwinex, might have documented this weakness somewhere, yet given a Broker is free to name there traded instruments as free as the MetaQuotes' MT4-Server suite license conditions and configuration constraints permit, it is your headbang point, if you do not adapt the code to meet your Broker actual _Symbol names and headbang for the third time due to all these non-matching cases )

having happened to see a case, when one day our Broker has suddenly changed all the names, and it was I tell you a Hell like experience to see, what the trading infrastructure had to go through ... - the headbanging is a mild and pleasant experience, compared to that ...

0   16:33:20.270           DWX_ZeroMQ_Server_v2.0.1_RC8 EURUSDm,H1 inputs: PROJECT_NAME       =      DWX_ZeroMQ_MT4_Server;
                                                                           ZEROMQ_PROTOCOL    =      tcp;
                                                                           HOSTNAME           =      *;
                                                                           PUSH_PORT          =  32768;
                                                                           PULL_PORT          =  32769;
                                                                           PUB_PORT           =  32770;
                                                                           MILLISECOND_TIMER  =      1;
                                                                           t0                 =      --- Trading Parameters ---;
                                                                           MagicNumber        = 123456;
                                                                           MaximumOrders      =      1;
                                                                           MaximumLotSize     =      0.01;
                                                                           MaximumSlippage    =      3;
                                                                           DMA_MODE           =      true;
                                                                           t1                 =      --- ZeroMQ Configuration ---;
                                                                           Publish_MarketData =      false;
halfer
  • 19,824
  • 17
  • 99
  • 186
user3666197
  • 1
  • 6
  • 50
  • 92
  • the OP seems to be using v2.0.1 as instructed on the README page of the Github ("the github page I was cloning is the latest version" pointing to v2.0.1) – Pierre C. Apr 16 '20 at 08:55
  • your answer is harsh and unjustified tbh – Pierre C. Apr 16 '20 at 08:59
  • @SherloxTV With all respect, **(1)** the O/P did not follow the StackOverflow Policy how to Ask questions, did she/he? **(2)** the set of Darwinex conditions was not met, was it? **(3)** How would you improve taking more and more care of people, who do not follow the expressed public explicit conditions and then ask you to go and repair all the (all needless,ref.1)+2)) damages they have caused themselves, taking more and more of your sponsored time, without efficiently learning them, not to cause damages first? You can waste all your time to repair damages, yet better if damages were avoided – user3666197 Apr 16 '20 at 09:07
  • I totally agree with the latter reasoning (that wasn't present when I posted my comment since you edited the post, for which I thank you). All your points are totally correct, but I think there is always some way to say it in a more approriate manner :) thank you for your time – Pierre C. Apr 16 '20 at 10:48
  • Cheers guys @user3666197 could you kindly point out which part of Darwinex conditions I fail to meet ? I was following closely to the videos tutorial and successfully sent orders and get response using ipython console, so i guess you could eliminate dependencies as source of problem. I only failed to get response when compiling the class into a python program – tiensison Apr 16 '20 at 12:15
  • @tiensison Did I get it right, that console interpreted python code works error-free, whereas after ***"compiling"***-a-program the problems start to appear? **What sort of compilation** ( of the normally interpreted python source-code ) **do you try to use here?** – user3666197 Apr 16 '20 at 12:44
  • 1
    I just cloned the class .py file https://github.com/darwinex/dwx-zeromq-connector/blob/master/v2.0.1/python/api/DWX_ZeroMQ_Connector_v2_0_1_RC8.py, then add the piece of my code described in original post as a .py file, then tried running using Anaconda prompt. It managed to send orders to metatrader server but I could not any response using this .py file. Ah and yes you got it right – tiensison Apr 16 '20 at 16:14
  • The verb **compile** in C/S associates using a Compiler ( a program, that translates the code into a machine-executable (from python+DLLs into a machine-code), not a human-driven "compilate". **Anyway** -we see nothing going across the ZeroMQ signalling/messaging plane - **a )** Do you have the MQL4-code, which is responsible for the "opposit" side of the calls? **b )** Did you try the launch of the python side, using **`DWX_ZeroMQ_Connector( _monitor = True )`** to enforce the superposition of a socket-monitor layer, to inspect the sockets' actual flow of events as they run or fail to run...? – user3666197 Apr 16 '20 at 20:27
  • hi @user3666197 I have updated pictures of printed console when I set _monitor = True. Not only it could not get any response back but also failed to send orders. and for the MQL code at the opposite of the call, you can find in this repo https://github.com/darwinex/dwx-zeromq-connector/blob/master/v2.0.1/mql4/DWX_ZeroMQ_Server_v2.0.1_RC8.mq4 I did not make any change to this piece, just simply compile using MetaEditor to create an EA in MetaTrader :) – tiensison Apr 17 '20 at 07:58
  • **Still missing** : a full-copy of the **[Metatrader Terminal JOURNAL (log)]** since the first row: *2020.04.12 11:10:46.093 MetaTrader - {BrokerEntity} build 1090 started ({WhiteLabel})* till the end of experiment. – user3666197 Apr 17 '20 at 11:18
  • hi @user3666197 I have uploaded both Terminal Log and Expert Log in my github repo and also delete irrelevant info (indicators initialized,.etc) for your convenience :) – tiensison Apr 18 '20 at 09:45
  • StackOverflow strongly discourages to refer to off-site resources, the less with weak-links or missing links at all. Put all the problem-relevant data ( **not** for *my* convenience ) as the StackOverflow Policies state for the Community Best Practices. – user3666197 Apr 18 '20 at 10:36