dwx-zeromq-connector
dwx-zeromq-connector copied to clipboard
[Pending Resolution] GET_ALL_OPEN_TRADES_() Bug > 18 trades
Hi,
DWX_MTX_GET_ALL_OPEN_TRADES() doesnt return anything when there are more than 18 trades opened.
Any workaround ?
I have the same problem i do not know how to solve!!
Did you find the solution?
Thanks!
This is due to a mql string limitation. The return response is too long.
I simply created another DWX_GetOpenOrders function with a new InformPullClient and shrinked the "zmq_ret" response as much as possible. I can successfully pull around 130 opened trades.
I simply created another DWX_GetOpenOrders function with a new InformPullClient and shrinked the "zmq_ret" response as much as possible. I can successfully pull around 130 opened trades.
Could you share the new function that you developed? It would be very useful. Thanks.
Great stuff @kkhanh ! 🙂
We'd be super grateful if you could share your solution here? 🙏
It would be benefit the rest of the user community + we would of course patch the code and credit you with the solution!
Many thanks.
Finally I did something similar, creating a new function in mql and its counterpart in python to call it. Curiously I also reached the 130 open trades, but for that I had to replace the dictionary by a list, saving the space that the keys take, then when receiving the message python is responsible for displaying the list in a dictionary to maintain compatibility.
But to reach that limit I had to eliminate several fields of information, like magic number, comment, stop loss, take profit,... but only because in our system they are not necessary. So I think it's not an adequate general solution, and it raises the limit a lot, but the limit still exists.
Although I have not implemented it, I consider that a suitable general solution would be to divide the information in several messages, or even a message by trade, but for it a protocol must be established that allows the receiver to check the integrity of the information, that does not lose messages of trades. Perhaps with an initial message detailing the number of messages that follow it, and a defined numbering for each subsequent message.
I have a solution for this. I just paginate the trade collection. Here is the code example : ` string trades = "["; int totalTrades = OrdersTotal(); int pages = OrdersTotal() / ITEM_PER_PAGE + 1;
for (int p = 1; p <= pages; p++)
{
string trades = "[";
int groupOrderCount = totalTrades - (p - 1) * ITEM_PER_PAGE > ITEM_PER_PAGE ? ITEM_PER_PAGE : totalTrades - (p - 1) * ITEM_PER_PAGE;
for (int i = 0; i < groupOrderCount; i++)
{
int index = (p - 1) * 10 + i;
if (!OrderSelect(index, SELECT_BY_POS))
{
continue;
}
trades += StringFormat(TRADE_FORMAT,
OrderSymbol(),
OrderTicket(),
OrderLots(),
OrderType(),
OrderOpenPrice(),
(int)OrderOpenTime(),
OrderStopLoss(),
OrderTakeProfit(),
OrderProfit(),
OrderComment());
if (i < groupOrderCount - 1)
{
trades += ",";
}
}
trades += "]";
PublishMessage(StringFormat(MSG_FORMAT,
SYNC_TRADE,
StringFormat(SYNC_TRADE_FORMAT,
pages,
p,
trades)));
}
`
I had to change the mql code and the backend code to make this works.