Broker API HubMenu

MT5 Python order_check()

functionorder_check()MetaTrader5 Python packageOrders

Checks whether the account has the funds for a trade request without sending it, and returns what the balance, equity and margin would be.

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 a Python function, not an HTTP endpoint. It has no method, no path and no address to send a request to: the package talks to a MetaTrader 5 terminal running on the same computer.

The page says a request that passes this check can still fail when it is sent.

Signature

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

order_check(
  request
)

Arguments

NameTypeDescription
requestrequiredMqlTradeRequest structureThe trade request to check, with the same fields order_send() takes. In Python it is written as a dictionary, as the page's example does.

Return value

Type
MqlTradeCheckResult structure
What comes back
The result of the check. Its request field holds the request that was passed in. The page's example prints it with retcode, balance, equity, profit, margin, margin_free, margin_level and comment.

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. No credential is typed into it: where one is needed it is read from an environment variable on your own machine. Nothing is entered on this site.

import MetaTrader5 as mt5

if not mt5.initialize():
    raise SystemExit(f"initialize() failed: {mt5.last_error()}")

symbol = "EURUSD"
tick = mt5.symbol_info_tick(symbol)
request = {
    "action": mt5.TRADE_ACTION_DEAL,
    "symbol": symbol,
    "volume": 0.1,
    "type": mt5.ORDER_TYPE_BUY,
    "price": tick.ask,
    "deviation": 20,
    "type_time": mt5.ORDER_TIME_GTC,
    "type_filling": mt5.ORDER_FILLING_RETURN,
}
# Nothing is sent to the trade server by this call.
check = mt5.order_check(request)
print(check)

mt5.shutdown()