简体   繁体   中英

How to transfer live data between Python and MQL4?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM