1

Python code:

import zmq
import sys
   
port ="5555"
print("Connecting to hello world server…")

context = zmq.Context()
socket = context.socket(zmq.REQ)          #  Socket to talk to server
socket.connect("tcp://localhost:%s"%port)

while(1):                                 #  Do requests,
    try:                                  #     waiting each time for a response
        message = socket.recv()

        print(message)
    except:
        pass

MQL4 code:

#include <Zmq/Zmq.mqh>
Context context("helloworld");
Socket socket(context,ZMQ_REP);
socket.bind("tcp://*:5555");
ZmqMsg request;
ZmqMsg reply("Trade was executed");
socket.send(reply);
Print("Feedback: Trade was executed");

an infinite loop occurs when I want to send data from MQL4 to the Python programming language as above Python cannot receive message data through the port

user3666197
  • 1
  • 6
  • 50
  • 92

1 Answers1

1

Q : "How to transfer live data between python and mql4?"

Starting to use the REQ/REP Scalable Formal Communication Archetype is rather demanding. Your mock-up code ignores the mechanics of this archetype, having not received a REQ-side message ( which your code does not perform ), the REP-side will never get into a state ( REQ/REP is a dFSA - a distributed Finite State Automaton ), where a .send()-method can execute ( the native API would report an error state, that shows cases, where a dFSA state-rules are violated ).

Use PUSH/PULL instead and your demo-code will not fall into problems.

MQL4-side will PUSH, python-side will PULL.

I use this since ZeroMQ v2.11 was ported as a DLL for use with MQL4, and all my trading projects are working as charm.

user3666197
  • 1
  • 6
  • 50
  • 92
  • I couldn't find the Push feature in the socket class is there a chance to share the solution you said with the code example? – Kemal Bayram Oct 20 '20 at 08:03
  • 1
    Are you sure there is no ZMQ_PUSH socket archetype implemented in the ZeroMQ-binding for MQL4/5 that you use? I doubt it was excluded ... yet ... Anyway, I use ZeroMQ-binding from Austen Conrad ( source + pre-compiled binaries available from https://github.com/AustenConrad/mql4zmq ), which supports all ZeroMQ archetypes as were present in the native API v2.11 and works as charm. Feel free to use it too & enjoy the clarity of ZeroMQ signalling / messaging mezzosystem for [tag:distributed-computing] – user3666197 Oct 20 '20 at 12:18
  • 1
    M1: Error binding the speaker! I met his mistake – Kemal Bayram Oct 20 '20 at 14:38
  • 1
    What? Is that reproducible? Document a reproducible MCVE, use other port number or reboot every time you finish the crash-test, as your code has zero graceful resources' release & termination care ( and .bind()-s often stay hanging on ports ... not making them free until reboot ) – user3666197 Oct 21 '20 at 15:48