BUG report: Python order_send behavior is different than MQL5 OrderSend

 

I'm encountering unexpected behavior with the order_send function from the MetaTrader5 Python library. I believe this might be a bug.

Issue Description:

Python order_send function returns an OrderSendResult object analogous to the MQL5 MqlTradeResult structure, which includes the attributes:

  • retcode: Operation return code

  • comment: Broker comment related to the operation

The problem occurs specifically when the return code is 10006 (Request Rejected). In MQL5, when an order is rejected, the comment attribute correctly returns the broker-provided reason for rejection. However, in the Python version, the comment attribute erroneously replicates the original comment sent in the request, not the broker's rejection reason.

Here is the code to reproduce the issue:

//+------------------------------------------------------------------+
//| EXPECTED BEHAVIOR (FOR REFERENCE ONLY)                           |
//+------------------------------------------------------------------+
void OnStart()
  {
   string symbol = "PETR4";
   double price = 50.00;
   int volume = 100;

   // Create request
   MqlTradeRequest request;
   MqlTradeResult result;

   ZeroMemory(request);

   request.action   = TRADE_ACTION_PENDING;
   request.symbol   = symbol;
   request.volume   = volume;
   request.price    = price;
   request.type     = ORDER_TYPE_SELL_LIMIT;
   request.type_filling = ORDER_FILLING_RETURN;

   // Send order
   OrderSend(request, result);
   Print("OrderSend result: ", result.retcode, " | Comment: ", result.comment);
   }

The comment correctly indicates the reason for rejection provided by the broker:


Now the Python version (erroneous behavior):

import MetaTrader5 as mt5

# Initialize MT5 connection
mt5.initialize()

symbol = "PETR4"
price = 50.00
volume = 100.0

# Create request
request = {
    "action": mt5.TRADE_ACTION_PENDING,
    "symbol": symbol,
    "volume": volume,
    "price": price,
    "type": mt5.ORDER_TYPE_SELL_LIMIT,
    "type_filling": mt5.ORDER_FILLING_RETURN,
    "comment": "Python SELL_LIMIT order",
}

# Send the order
result = mt5.order_send(request)

# Print result
print(result)

# Shutdown MT5 connection
mt5.shutdown()

Python function return the OrderSendResult object containing the original request comment instead of the broker-provided rejection reason.


Could the MetaTrader development team investigate this discrepancy? Am I doing something wrong?