Invalid request on order_send [resolved]

 

Hello,


I'm using python. On my code i want to do sell order like this :

mt5.order_send(request)
request variable contain:

{'action': 1, 'symbol': 'GBPCAD', 'volume': 0.01, 'type': 1, 'price': 1.5594, 'sl': 1.57441, 'tp': 1.53441, 'deviation': 20, 'magic': 234000, 'comment': 'python script', 'type_time': 0, 'type_filling': 2}

But i go "Invalid request" with retcode : 10013

In MT5 :


I can't find what is wrong with my request ... Any idea ? i probably miss a parameter, but i don't see it in example i used.

Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
  • www.mql5.com
Trade Server Return Codes - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Valentin Garreau:

Hello,


I'm using python. On my code i want to do sell order like this :

request variable contain:

But i go "Invalid request" with retcode : 10013

In MT5 :


I can't find what is wrong with my request ... Any idea ? i probably miss a parameter, but i don't see it in example i used.

I don't use Python for MetaTrader, but looking at the documentation, your usage does not look like the examples:

request = {
    "action": mt5.TRADE_ACTION_DEAL,
    "symbol": symbol,
    "volume": lot,
    "type": mt5.ORDER_TYPE_BUY,
    "price": price,
    "sl": price - 100 * point,
    "tp": price + 100 * point,
    "deviation": deviation,
    "magic": 234000,
    "comment": "python script open",
    "type_time": mt5.ORDER_TIME_GTC,
    "type_filling": mt5.ORDER_FILLING_RETURN,
}

https://www.mql5.com/en/docs/integration/python_metatrader5/mt5ordersend_py

Documentation on MQL5: Integration / MetaTrader for Python / order_send
Documentation on MQL5: Integration / MetaTrader for Python / order_send
  • www.mql5.com
order_send - MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
R4tna C #:

I don't use Python for MetaTrader, but looking at the documentation, your usage does not look like the examples:

https://www.mql5.com/en/docs/integration/python_metatrader5/mt5ordersend_py

Hello,


thank for the reply.

Wich parameter is missing. From my print i got all of them with good data. If you talk about SL & TP that don't have 100 * points it's because i calculate them before, but they are valid because if i try manually it's working on MT5.

 
Valentin Garreau #:

Hello,


thank for the reply.

Wich parameter is missing. From my print i got all of them with good data. If you talk about SL & TP that don't have 100 * points it's because i calculate them before, but they are valid because if i try manually it's working on MT5.

The action, type, type_filling look different - you have used numbers rather than what is shown in the examples.

Maybe it should work (I know not as I use MQL5 rather than Python), but why would you deviate from the official examples provided? 

I suggest using the example code to get a working example

 
R4tna C #:

The action, type, type_filling look different - you have used numbers rather than what is shown in the examples.

Maybe it should work (I know not as I use MQL5 rather than Python), but why would you deviate from the official examples provided? 

I suggest using the example code to get a working example

They are constant variable used in the MT5 library of python. In my code i have write "mt5.TRADE_ACTION_DEAL", but in the request in process it into a number. 


 

Ok for those who got same problem as me.

I don't know if it's from my broker or not (vantage), but i have to add '.' at the end of the symbol. For example : "GBPCAD." and not "GBPCAD"

 
Valentin Garreau #:

They are constant variable used in the MT5 library of python. In my code i have write "mt5.TRADE_ACTION_DEAL", but in the request in process it into a number. 


Yes I saw that these are constants - I have seen many situations when the software is patched/upgraded and no longer compatible if the vendor's best practices/guidelines have not been followed exactly. If they happen to change the constants numbering in a future release, there could be problems so why take the risk?

But I am glad you found the solution
Reason: