OrderSendAsync() function

 

The description says thatthe OrderSendAsync() function is designed to perform asynchronous operations without waiting for the server to respond to the sent request. On successful execution the response code in the result variable contains the value TRADE_RETCODE_PLACED ( code 10008) - "order placed". Successful execution of . does not give us any guarantee that the request has reached the trade server and been accepted for processing.

On the one hand, we know that the retcode field contains the trade server's return code - i.e. it is assumed that this code is generated by the server, not the user terminal. On the other hand, the Reference Manual states that forOrderSendAsync() function one of the codes to be generated by the server (code 10008) can be returned, even if the trade request itself has not reached the trade server.

Question 1: Where exactly (at what stage) is code 10008 generated forthe OrderSendAsync function? [Assuming this code can be returned without the trade server being involved.]

Question 2: Is code 10008 the trade server code or is this code generated on the client terminal side before the trade request is received by the server?

Документация по MQL5: Стандартные константы, перечисления и структуры / Структуры данных / Структура торгового запроса
Документация по MQL5: Стандартные константы, перечисления и структуры / Структуры данных / Структура торгового запроса
  • www.mql5.com
Стандартные константы, перечисления и структуры / Структуры данных / Структура торгового запроса - Документация по MQL5
 

1. terminal, on successful dispatch operation (order successfully dropped from the aircraft, but we don't know what's next)

2. Apologies for the tautology, but I will answer the same way: Yes, code 10008 is the response code of the trade server. Yes, this code is set by the terminal at the moment of... next point 1.

Why are you trying to find between lines what is already written explicitly?

 

The asynchronous trade order model assumes multiple events and order states:

Market Order States Diagram

Conditional Order States Diagram

Currently in MT5:

  1. CREATED - the very fact of OrderSendAsync and OrderSend being called (this order state in MT5 cannot be identified in any way from the outside).
  2. If the order is CANCELLED (the terminal itself has cut it off through its filters. For example, the limit price is worse than the current price), the response is negative from OrderSend and OrderSendAsync.
  3. OPENED is the result of TRADE_RETCODE_PLACED (your order successfully passes through internal filters of the terminal and is sent to the server) for OrderSendAsync.
  4. SUBMIT_OK - the server has accepted your trade order. If it is a pending order, OrderSend will complete its execution. If Market - continue to wait.
  5. FILLED - your order is in execution state (for example, you have sent it through STP and are waiting for a response). Continue to wait.
  6. FILL_OK - your order has executed. If Market - OrderSend will complete its execution.

Please see the diagrams above for more details.

 
Rosh:

1. terminal, on successful dispatch operation (order successfully dropped from the aircraft, but we don't know what's next)

2. Apologies for the tautology, but I will answer the same way: Yes, code 10008 is the response code of the trade server. Yes, this code is set by the terminal at the moment of... next point 1.

Why are you trying to find between the lines of what is already written explicitly?

I'm not looking for "between the lines", but again, I'm trying to understand the stages of two (now) trade functions.

In your comment to the OrderSendAsync function, you say that "the function is similar to OrderSend() in purpose and parameters". But, judging by your answer, the OrderSendAsync function is not quite the same as the OrderSend function. The latter is intended for checking the trade request on the server, so the codes returned by OrderSend() are the codes generated by the server itself, not some other substance. In the case of OrderSendAsync() the return code is generated by the terminal, so this code (code 10008) cannot be considered as server return code. This is "code generated by the terminal" even if you formally include it into server's code list.

In other words, the two functions are two approaches: "Server-generated code" vs "Terminal-generated code". In this respect, the functions are not the same. Knowing this subtlety is necessary to correctly understand whether the "return code" is coming from the server or the terminal.

 
hrenfx:

OPENED is the result of TRADE_RETCODE_PLACED for OrderSendAsync.

    Can we conclude that TRADE_RETCODE_PLACED (10008) is useless at all in terms of its expectation when using the original OrderSend function?

    Gracias for the diagram!

    How do you correctly translate "Order condition gets met"?

     
    Yedelkin:

    Can we conclude that TRADE_RETCODE_PLACED (10008) is useless at all in terms of its expectation when using the original OrderSend function?

    TRADE_RETCODE_PLACED has nothing to do with sequential OrderSend.

    How do you correctly translate "Order condition gets met"?

    The current price satisfies the order condition. Instead of FILLED it can be CANCELLED, for example if there is not enough margin to execute the order.

    Again, in order to work asynchronously, we need a powerful event system, where on arrival there is an option to receive:

    • The text message of the event.
    • The time of its creation.
    • Which order it relates to.
    • The type of message (news, order, communication status, etc.)

    The architecture of the platform itself should be very well thought out. If there are gaps at the architecture design stage, it is extremely difficult to circumvent them in order to achieve universality.

    IMessage (JForex API 2.9.6.1 API)
    • www.dukascopy.com
    FRAMES    NO FRAMES
     

    hrenfx:

    Yedelkin:

    Can we conclude that TRADE_RETCODE_PLACED (10008) is useless at all in terms of its expectation when using the original OrderSend function?

    TRADE_RETCODE_PLACED has nothing to do with sequential OrderSend.

    There! I came to this intuitively about half a year ago, and you kind of confirm it:) Already good :)
     
    hrenfx:

    Again, to work asynchronously, you need a powerful event system where there is an option to receive on arrival:

    • The text message of the event.
    • The time of its creation.
    • What order it refers to.
    • Message type (news, order, communication status, etc.)
    Is this about, among other things, the need to detail the OnTrade event?
     
    Yedelkin:
    There! I came to this intuitively about half a year ago, and you kind of confirm it:) Already good :)
    A man is always happy when someone confirms the correctness of his reasoning. No matter how much it corresponds to reality.
     
    Rosh:
    A person is always happy when someone confirms the correctness of their reasoning. No matter how true it is.
    Well, in the past eight months no one has ever refuted the man's public conclusion. Neither theoretically nor by test results. But thanks for sowing doubt :)
     

    It should be clarified:

    TRADE_RETCODE_PLACED for OrderSend is the server response.

    TRADE_RETCODE_PLACED for OrderSendAsync is a terminal response.

    Although the codes are identical, they have quite a different meaning. The developers will most likely fix this ambiguity.

    That's why you should understand it:

    TRADE_RETCODE_PLACED к последовательной OrderSend не имеет никакого отношения.

    must be understood in the appropriate context.

    Reason: