Broker API HubMenu

MQL5 OrderSendAsync()

functionOrderSendAsync()MQL5Sending orders

Sends a trade request to the trade server without waiting for its answer. The page describes it as made for high frequency trading, where waiting for the server is not acceptable.

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

Independent and unofficialmql5.comchecked

This is an MQL5 function, not an HTTP endpoint. It has no method, no path and no address to send a request to: it runs inside the MetaTrader 5 terminal, in a program written in MQL5.

The outcome of the request arrives later, through the OnTradeTransaction and OnTrade handlers. The page says OnTradeTransaction is called several times for one request.

Signature

The form of the call on the vendor's page, with the vendor's comments taken out.

bool OrderSendAsync(
  MqlTradeRequest& request,
  MqlTradeResult& result
)

Arguments

NameTypeDescription
requestrequiredMqlTradeRequest&The trade request, an MqlTradeRequest structure passed by reference.
resultrequiredMqlTradeResult&An MqlTradeResult structure passed by reference. After a successful send its return code holds TRADE_RETCODE_PLACED, which is 10008.

Return value

Type
bool
What comes back
True when the request was sent, false when it was not. The page says true means only that it was sent: it is no guarantee the request reached the server or was accepted.

Sample

Written by this site from the signature and arguments recorded on this page. It has not been run against a terminal, a server or an account, and the values in it are placeholders. It holds no credential and needs none: the program runs inside a terminal that is already logged in to an account. Nothing is entered on this site.

// Expert Advisor fragment. Run it only on a demo account.
void SendBuy()
  {
   MqlTradeRequest request={};
   MqlTradeResult  result={};
   request.action=TRADE_ACTION_DEAL;
   request.symbol=_Symbol;
   request.volume=0.1;
   request.type  =ORDER_TYPE_BUY;
   request.price =SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   if(!OrderSendAsync(request,result))
      PrintFormat("OrderSendAsync error %d, retcode=%u",GetLastError(),result.retcode);
  }

// The server's answer arrives here, more than once for one request.
void OnTradeTransaction(const MqlTradeTransaction &trans,const MqlTradeRequest &request,const MqlTradeResult &result)
  {
   Print(EnumToString(trans.type));
  }

Return codes documented for this function

The page says that after a successful send the response code in the result variable holds TRADE_RETCODE_PLACED, code 10008, and its example prints result.retcode. That field holds a trade server return code, and each one recorded here is below. mql5.comchecked