Python / MT5 - no order possible - error message 'Unsupported filling mode'

PeterXY
41
PeterXY  
I have a Python program that accesses a CFD platform via the Python / MT5 interface. Everything actually works as it should (e.g. logging in, querying courses, etc.).

Only when I try to place an order on the CFD platform from the Python program via the Metatrader5 interface does it unfortunately not work. I keep getting the error message 'Unsupported filling mode', regardless of whether I set "type_filling": mt5.ORDER_FILLING_RETURN, "type_filling": mt5.ORDER_FILLING_FOK or "type_filling": mt5.RDER_FILLING_IOC.

Does anyone have any idea why this could be (I activated “Algo trading” in MT5).

 

Thanks in advance!

 

The full error message:

2. order_send failed, retcode=10030
   retcode=10030
   deal=0
   order=0
   volume=0.0
   price=0.0
   bid=0.0
   ask=0.0
   comment=Unsupported filling mode
   request_id=0
   retcode_external=0
   request=TradeRequest(action=1, magic=0, order=0, symbol='USDJPY', volume=0.1, price=108.891, stoplimit=0.0, sl=0.0, tp=0.0, deviation=0, type=0, type_filling=0, type_time=0, expiration=0, comment='python script open', position=0, position_by=0)
       traderequest: action=1
       traderequest: magic=0
       traderequest: order=0
       traderequest: symbol=USDJPY
       traderequest: volume=0.1
       traderequest: price=108.891
       traderequest: stoplimit=0.0
       traderequest: sl=0.0
       traderequest: tp=0.0
       traderequest: deviation=0
       traderequest: type=0
       traderequest: type_filling=0
       traderequest: type_time=0
       traderequest: expiration=0
       traderequest: comment=python script open
       traderequest: position=0
       traderequest: position_by=0

Dominik Egert
1582
Dominik Egert  
I suggest to check if you in fact have set the correct value in the send request. Print the structure before sending.

Then check the account in use, what are the supported fillings by your broker.

And maybe you could post your code around send order. This way others could provide more insight and support.


PeterXY
41
PeterXY  
Dominik Egert:
I suggest to check if you in fact have set the correct value in the send request. Print the structure before sending.

Then check the account in use, what are the supported fillings by your broker.

And maybe you could post your code around send order. This way others could provide more insight and support.


1. Thanks very much for answer!

2. I tried asking my broker's hotline about what are the supported fillings, but they had no idea. Is there a technical way to find out? 

3. My code for the order corresponds practically 100% to the example in the instructions (https://www.mql5.com/de/docs/integration/python_metatrader5/mt5ordersend_py):

# Vorbereitung der Struktur request für einen Kauf

symbol = "USDJPY"

symbol_info = mt5.symbol_info(symbol)

if symbol_info is None:

    print(symbol, "not found, can not call order_check()")

    mt5.shutdown()

    quit()

 

# Wenn das Symbol im MarketWatch nicht verfügbar ist, wird es hinzugefügt

if not symbol_info.visible:

    print(symbol, "is not visible, trying to switch on")

    if not mt5.symbol_select(symbol,True):

        print("symbol_select({}}) failed, exit",symbol)

        mt5.shutdown()

        quit()

 

lot = 0.1

point = mt5.symbol_info(symbol).point

price = mt5.symbol_info_tick(symbol).ask

deviation = 20 # Maximal akzeptierte Abweichung vom gewünschten Preis, angegeben in Punkten

request = {

    "action": mt5.TRADE_ACTION_DEAL,

    "symbol": symbol,

    "volume": lot,

    "type": mt5.ORDER_TYPE_BUY,

    "price": price,

    "sl": price - 100 * point, #Ein Preis, zu dem eine Stop-Loss-Order aktiviert wird, wenn sich der Preis in eine ungünstige Richtung bewegt.

    "tp": price + 100 * point, #Ein Preis, zu dem ein Take-Profit-Auftrag aktiviert wird, wenn sich der Preis in eine günstige Richtung bewegt.

    "deviation": deviation, #Maximal akzeptierte Abweichung vom gewünschten Preis, angegeben in Punkten

    "magic": 234000, # EA-ID. Ermöglicht das Erkennen von Handelsaufträgen für eine anlytische Behandlung. Jeder EA kann beim Senden einer Handelsanfrage eine eindeutige ID festlegen.

    "comment": "python script open",

    "type_time": mt5.ORDER_TIME_GTC,

    "type_filling": mt5.ORDER_FILLING_RETURN, 

}



# Senden eines Handelsauftrags

result = mt5.order_send(request)

# Prüfen des Ausführungsergebnisses

print("1. order_send(): by {} {} lots at {} with deviation={} points".format(symbol,lot,price,deviation));

if result.retcode != mt5.TRADE_RETCODE_DONE:

    print("2. order_send failed, retcode={}".format(result.retcode))

   # Abrufen des Ergebnisses als Liste und Darstellung Element für Element

    result_dict=result._asdict()

    for field in result_dict.keys():

        print("   {}={}".format(field,result_dict[field]))

        # Wenn es die Struktur eines Handelsauftrags ist, werden die Elemente auch einzeln angezeigt

        if field=="request":

            traderequest_dict=result_dict[field]._asdict()

            for tradereq_filed in traderequest_dict:

                print("       traderequest: {}={}".format(tradereq_filed,traderequest_dict[tradereq_filed]))

    print("shutdown() and quit")

    mt5.shutdown()

    #quit()

 

print("2. order_send done, ", result)

print("   opened position with POSITION_TICKET={}".format(result.order))

Dokumentation zu MQL5: Integration / MetaTrader für Python / order_send
Dokumentation zu MQL5: Integration / MetaTrader für Python / order_send
  • www.mql5.com
order_send - MetaTrader für Python - Integration - Nachschlagewerk MQL5 - Nachschlagewerk über die Sprache des algothitmischen/automatischen Handels für MetaTrader 5
Dominik Egert
1582
Dominik Egert  
PeterXY:

1. Thanks very much for answer!

2. I tried asking my broker's hotline about what are the supported fillings, but they had no idea. Is there a technical way to find out? 

3. My code for the order corresponds practically 100% to the example in the instructions (https://www.mql5.com/de/docs/integration/python_metatrader5/mt5ordersend_py):

What did the print out give you?

Did you try another broker, maybe? (demo account)

Print out the request structure to console before sending it to the function call:

# Senden eines Handelsauftrags

# Bitte die request-struct auf der Konsole ausgeben, die Werte gegenprüfen.

result = mt5.order_send(request)
PeterXY
41
PeterXY  
Dominik Egert:

What did the print out give you?

Did you try another broker, maybe? (demo account)

Print out the request structure to console before sending it to the function call:

So I got it working now :-)

The platform only accepts: "type_filling": mt5.ORDER_FILLING_IOC.

The mistake was also that you have to enter an explizit login for an order:

account=12345
authorized=mt5.login(account, password="XXXX")
if authorized:
    # Anzeige der Daten des Handelskontos 'as is'
    print("")
    print("account_info:\n", mt5.account_info())
    # Anzeige der Daten des Handelskontos als Liste
    print("")
    print("Show account_info()._asdict():")
    account_info_dict = mt5.account_info()._asdict()
    for prop in account_info_dict:
        print("  {}={}".format(prop, account_info_dict[prop]))
else:
    print("failed to connect at account #{}, error code: {}".format(account, mt5.last_error()))

If you do it that way, you also get the individual specifics of the access back as an additional benefit, especially important for me that the ordering option is activated.