[英]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: MQL4 代码:
#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当我想将数据从 MQL4 发送到 Python 编程语言时发生无限循环,如上所述 Python 无法通过端口接收消息数据
Q : "How to transfer live data between python and mql4?"
问: “如何在python和mql4之间传输实时数据?”
Starting to use the REQ/REP
Scalable Formal Communication Archetype is rather demanding.开始使用
REQ/REP
可扩展的正式通信原型是相当苛刻的。 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 ).你的模型代码忽略了这个原型的机制,没有收到
REQ
端的消息(你的代码没有执行), REP
端永远不会进入一个状态( REQ/REP
是一个 dFSA - 一个分布式有限状态自动机),其中.send()
方法可以执行(本机 API 会报告错误状态,显示违反 dFSA 状态规则的情况)。
Use PUSH/PULL
instead and your demo-code will not fall into problems.使用
PUSH/PULL
代替,您的演示代码不会出现问题。
MQL4-side will PUSH
, python-side will PULL
. MQL4 端将
PUSH
,python 端将PULL
。
I use this since ZeroMQ v2.11 was ported as a DLL for use with MQL4, and all my distributed-computing trading projects are working as charm.我使用它是因为 ZeroMQ v2.11 被移植为一个 DLL 以与 MQL4 一起使用,并且我所有的分布式计算交易项目都非常有魅力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.