dingmaotu / mt4-server

Turn MetaTrader Terminal into a Redis compatible server with ZMQ sockets
Apache License 2.0
163 stars 94 forks source link

ZMQ Response error #8

Open venzen opened 1 year ago

venzen commented 1 year ago

In MT4 this Script compiles and all the tests pass when running the test script included with mql-zmq. I can connect to the ZMQ server, however when I send a command I get the following error in the "Experts" panel of the Terminal:

2023.01.22 17:25:43.968 Mt4ServerZMQ XAUUSD.i,H1: >>> Error parsing command: RespParseErrorInvalidPrefix

I connect from Python using a textbook REQ socket:

context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:6666")

socket.send(b"ORDERS")

I have tried encoding the command as "utf-16-le" (WIN32 unicode) but this crashes the server. I have also tried the alternate libraries provided in VC2010 folder of mql-zmq. Installed version of ZMQ is 4.3.2. Any ideas?

venzen commented 1 year ago

Progress report about this issue. I have familiarized myself with the mt4-server code (not yet mql-lib or mql-zmq) and have placed some Print() statements to see where the code is choking on my command.

      ArrayResize(m_commandBuffer,request.size(),100);
      Print(">>>  Receiving a client request. size: ",request.size());
      request.getData(m_commandBuffer);
      Print(">>>  Parsing client request: ", request.getData());

Up to here I can see that MT4serverZMQ is receiving my command via ZMQ.

Here it is in the Terminal:

Screenshot from 2023-01-25 14-27-57

Parsing the ORDERS command yields NULL:

      RespValue *command=m_parser.parse(m_commandBuffer);
      Print(">>>  entering reply processing for command: ",command);
      RespValue *reply;
      if(command==NULL)
        {
         string error=EnumToString(m_parser.getError());
         Print(">>> Error parsing command: ",error);
         reply=new RespError(error);
        }

So, it receives the command but does not like the bytestream? Or is the response being incorrectly parsed? Apparently the response suffix (+, -, $, etc) is missing or incorrect... I must also mention that this behavior is not replicated when I connect via Redis which returns an array of orders as expected.