dingmaotu / mql4-lib

MQL4/5 Foundation Library For Professional Developers
Apache License 2.0
544 stars 251 forks source link

OrderManager error handling #22

Closed yerden closed 6 years ago

yerden commented 6 years ago

When the OrderSend() returns -1 and sets _LastError, OrderManager::send() uses GetLastError(), sends Alert() and returns -1. This leaves no clue about the error to the caller. For example, I may want to repeat send() in case of context lock, or maybe I should abort due to server problems. Since GetLastError() effectively resets _LastError, this deprives the calling function of knowing the error.

The reason is this. Say we have two experts on different charts. If they try to issue orders simultaneously one of them would receive ERR_TRADE_CONTEXT_BUSY error and would have to retry. But if the expert gets ERR_ACCOUNT_DISABLED error, it would have to stop trading at all. Using OrderManager as is doesn't allow to distinguish the trading behavour.

The proposed solutions: 1) Mql::getLastError() should memorize the last error, or; 2) return the error code with negative sign as the output of send(), modify() etc., or 3) introduce own error handling with similar to GetLastError() semantics.

Any thoughts?

yerden commented 6 years ago

please see PR #24.

dingmaotu commented 6 years ago

Hi, thanks for the pull request, it clearly solves the problem without breaking existing interface.