darwinex / dwx-zeromq-connector

Wrapper library for algorithmic trading in Python 3, providing DMA/STP access to Darwinex liquidity via a ZeroMQ-enabled MetaTrader Bridge EA.
https://blog.darwinex.com/zeromq-interface-python-r-metatrader4/
BSD 3-Clause "New" or "Revised" License
346 stars 228 forks source link

how to use this command _DWX_MTX_SEND_HIST_REQUEST_? #129

Closed MashiePotato closed 2 years ago

MashiePotato commented 3 years ago

May I ask how do I retrieve historical data showing only 'close' data using the command _DWX_MTX_SEND_HISTREQUEST?

And how do I get it in a list similar to a CSV list.

{'EURUSD_D1': [{'time': '2021.06.01 00:00', 'open': 1.22297, 'high': 1.22411, 'low': 1.2213, 'close': 1.22247, 'tick_volume': 52193, 'spread': 0, 'real_volume': 0}]}

lorenzo522 commented 3 years ago

I'll tell you what I understood after spending a week of work, I also wrote on slack but there is no one who answers. If you send a HIST command from the connector, the server on MT throws the request because in the function that interprets the messages there is no one for the history. I tell you I did it to make it work. on the InterpretZmqMessage I add if(compArray[0] == "HIST") switch_action = 9; and in the switch(action) ` case 9: // history REQUEST

     zmq_ret = "{";

     DWX_GetHistory(compArray, zmq_ret);

     InformPullClient(pSocket, zmq_ret + "}");

     break; `

I created the DWX_GetHistory function `// Get history data for request datetime range void DWX_GetHistory(string& compArray[], string& zmq_ret) {

// Format: DATA|SYMBOL|TIMEFRAME|START_DATETIME|END_DATETIME

double price_array[]; datetime time_array[];

// Get prices int price_count = CopyClose(compArray[1], StrToInteger(compArray[2]), StrToTime(compArray[3]), StrToTime(compArray[4]), price_array);

// Get timestamps int time_count = CopyTime(compArray[1], StrToInteger(compArray[2]), StrToTime(compArray[3]), StrToTime(compArray[4]), time_array);

zmq_ret = zmq_ret + "'_action': 'HIST',"; zmq_ret = zmq_ret + "'_symbol': '"+compArray[1]+"'";

if (price_count > 0) {

  zmq_ret = zmq_ret + ", '_data': {";

  // Construct string of price|price|price|.. etc and send to PULL client.
  for(int i = 0; i < price_count; i++ ) {

     if(i == 0)
        zmq_ret = zmq_ret + "'" + TimeToString(time_array[i]) + "': " + DoubleToString(price_array[i]);
     else
        zmq_ret = zmq_ret + ", '" + TimeToString(time_array[i]) + "': " + DoubleToString(price_array[i]);

  }

  zmq_ret = zmq_ret + "}";

} else { zmq_ret = zmq_ret + ", " + "'_response': 'NOT_AVAILABLE'"; }

}` I don't know if it's the best way to face this problem, but it works for me. Anyway, if you want to add your data, you have to modify my function (it's almost copied from DWX_GetData) adding ohlc and the others values you need. hope this helps

MashiePotato commented 3 years ago

Hi Lorenzo,

Thank you for your reply. Unfortunately I have limited coding background.

I understand from Darwinex videos there is an easier method of extracting only close values but they haven't gone through yet. Hopefully @darwinex will be able to shed some light. Cheers!

elvinex commented 2 years ago

Hi, Maybe I am missing something. But in the current version the response from MT4 to _DWX_MTX_SEND_HIST_REQUEST_ should already include time, open, high, low, close, spread and tick_volume, which is stored in the _History_DB dict.

Btw. we published the DWX Connect package which is easier to use for people with less coding background. It is also probably better suited for most of the use cases.