MT5Account ¡ Trading Operations â Overview¶
Quick map of the trading ops APIs: send/modify/close orders, preâflight checks, and margin calc. Use this page to pick the right call fast.
đ What lives here¶
- order_send â place market or pending orders; returns deal/order IDs & return code.
- order_modify â edit SL/TP, pending price, expiration, stopâlimit trigger.
- order_close â close a position (full/partial) or cancel a pending order.
- order_check â dryârun a trade request â return code + projected margins.
- order_calc_margin â compute required margin for a hypothetical order.
đ§ Plain English¶
- order_send â the âplace itâ button.
- order_modify â the âedit ticketâ wrench.
- order_close â the âexit/cancelâ switch.
- order_check â the âpreflightâ: will it pass? how much margin after?
- order_calc_margin â the âwhatâif marginâ calculator for a single order.
Rule of thumb: need to know before you place â
order_check
/order_calc_margin
. Ready to act âorder_send
/order_modify
/order_close
.
Quick choose¶
If you need⌠| Use | Returns | Key inputs (enums) |
---|---|---|---|
Place market/pending order | order_send |
OrderSendData |
symbol , operation:TMT5_ENUM_ORDER_TYPE , volume , price , slippage , SL/TP , expiration_time_type:TMT5_ENUM_ORDER_TYPE_TIME , expiration |
Edit SL/TP, price, expiration, stopâlimit | order_modify |
OrderModifyData |
ticket , stop_loss , take_profit , price , stop_limit , expiration_time_type , expiration |
Close position / cancel pending | order_close |
OrderCloseData |
ticket , volume (optional), price (0.0 â market), slippage , comment |
Preâflight: return code & margins | order_check |
OrderCheckData |
MrpcMqlTradeRequest{ action:MRPC_ENUM_TRADE_REQUEST_ACTIONS, order_type:ENUM_ORDER_TYPE_TF, symbol, volume, price, deviation, type_filling, type_time, expiration } |
Required margin for a hypothetical order | order_calc_margin |
OrderCalcMarginData |
order_type:ENUM_ORDER_TYPE_TF , symbol , volume , price |
â Crossârefs & gotchas¶
- Market vs pending. Market ops usually use
price=0.0
+slippage
. Pending ops require a price (andstop_limit
for *_STOP_LIMIT). - UTC timestamps for expirations. Choose
*_TIME_*
enums deliberately (GTC/DAY/SPECIFIED/SPECIFIED_DAY). - Filling modes matter (FOK/IOC/RETURN/BOC) in
order_send
andorder_check
â brokers differ. - Return codes. All trading ops return numeric + string codes; render userâfriendly messages in UI.
- For partial closes, ensure lot step/min via symbol params before calling
order_close
.
đ˘ Minimal snippets¶
# order_send â market BUY 0.10 with slippage
from MetaRpcMT5 import mt5_term_api_trading_helper_pb2 as th_pb2
req = th_pb2.OrderSendRequest(symbol="EURUSD", operation=th_pb2.TMT5_ENUM_ORDER_TYPE.TMT5_ORDER_TYPE_BUY, volume=0.10, price=0.0, slippage=20, expiration_time_type=th_pb2.TMT5_ENUM_ORDER_TYPE_TIME.TMT5_ORDER_TIME_GTC)
res = await acct.order_send(req); print(res.deal, res.returned_string_code)
# order_modify â adjust SL/TP
from MetaRpcMT5 import mt5_term_api_trading_helper_pb2 as th_pb2
req = th_pb2.OrderModifyRequest(ticket=1234567890, stop_loss=1.07200, take_profit=1.07800, expiration_time_type=th_pb2.TMT5_ENUM_ORDER_TYPE_TIME.TMT5_ORDER_TIME_GTC)
print((await acct.order_modify(req)).returned_string_code)
# order_close â partial close at market
from MetaRpcMT5 import mt5_term_api_trading_helper_pb2 as th_pb2
req = th_pb2.OrderCloseRequest(ticket=1234567890, volume=0.05, price=0.0, slippage=15)
print((await acct.order_close(req)).deal)
# order_check â preflight for BUY_LIMIT
from MetaRpcMT5 import mt5_term_api_trade_functions_pb2 as tf_pb2
rq = tf_pb2.MrpcMqlTradeRequest(action=tf_pb2.MRPC_ENUM_TRADE_REQUEST_ACTIONS.TRADE_ACTION_PENDING, order_type=tf_pb2.ENUM_ORDER_TYPE_TF.ORDER_TYPE_TF_BUY_LIMIT, symbol="XAUUSD", volume=0.10, price=2300.0)
print((await acct.order_check(tf_pb2.OrderCheckRequest(mql_trade_request=rq))).mql_trade_check_result.margin)
# order_calc_margin â what-if margin for SELL @ market
from MetaRpcMT5 import mt5_term_api_trade_functions_pb2 as tf_pb2
req = tf_pb2.OrderCalcMarginRequest(order_type=tf_pb2.ENUM_ORDER_TYPE_TF.ORDER_TYPE_TF_SELL, symbol="BTCUSD", volume=0.02, price=0.0)
print((await acct.order_calc_margin(req)).margin)