vdemydiuk / mtapi

MetaTrader API (terminal bridge)
http://mtapi4.net/
MIT License
523 stars 282 forks source link

about order's comment is null #167

Open zhao0876 opened 5 years ago

zhao0876 commented 5 years ago

This is the problem I encountered today. When I get an order update from TradeMonitor I try to pass the changed orders through the event for processing one by one. One of the processing steps is to check the order ‘s comment. I found it is null which will trigger .net to generate a null Exception I think it should be a empty string. I modified the mq4 file. But it’s still null I don't clear the message build process, I think you can fix this problem faster.

This problem also made me discover another place for improvement. The code in the TimerTradeMonitor line 82 looks like this:             _timer.Elapsed -= _timer_Elapsed; //unregister from events to prevent rise condition during work with orders             Check();             _timer.Elapsed += _timer_Elapsed; //register again

There is event passing in Check() on TradeMonitor line 153 AvailabilityOrdersChanged?.Invoke(this, new AvailabilityOrdersEventArgs(openedOrders, closedOrders));

This null error is included in my processing event The result is that Check() has an error. Then _timer.Elapsed += _timer_Elapsed is not executed So the TradeMonitor was interrupted. At the same time, the upper order processing event was handled by my try catch. The result is nothing happens, as if the TimerTradeMonitor did not start running.

I spent a lot of time to find the root cause of this problem.

I think adding and subtracting _timer.Elapsed is not a particularly good method. You can consider another way to control the switch of the order check event. Also consider whether to do exception handling when sending events

zhao0876 commented 5 years ago

I just thought of it, that is the problem I found before. Set comment to "" instead of null when I send a order After the order is executed, the real comment is not "", but the request type I think there are some problems in the serialization of json. At that time, I didn't think it was a big problem. maybe the current problem is related to this.

vdemydiuk commented 5 years ago

Hi. Thank you for report of this problem. I will check it soon and try to fix.

payam-alexander commented 4 years ago

Hi, This bug is still there. When I try to get an order, a wrong magic number is being returned, although I had opened the order with null and "" comment. There seems to be a bug in json serialization/deserialization, which causes this issue

eabase commented 3 years ago

I think we should put another more obvious default. Perhaps MTAPI?