Request: subscribe to raw trade transactions (like MQL5 OnTradeTransaction): each event carries the transaction, the original request, and the result returned by the trade server.
# Minimal: print transaction type and idsfromMetaRpcMT5importmt5_term_api_subscriptions_pb2assub_pb2asyncforevinacct.on_trade_transaction():tr=ev.trade_transactionprint(tr.type,tr.order_ticket,tr.deal_ticket)
# Cooperative cancellation after the first DEAL‑ADDfromMetaRpcMT5importmt5_term_api_subscriptions_pb2assub_pb2importasynciocancel=asyncio.Event()asyncforevinacct.on_trade_transaction(cancellation_event=cancel):tr=ev.trade_transactioniftr.type==sub_pb2.SUB_ENUM_TRADE_TRANSACTION_TYPE.TRADE_TRANSACTION_DEAL_ADD:print("deal added:",tr.deal_ticket,"price:",tr.price)cancel.set()
asyncdefon_trade_transaction(self,cancellation_event:asyncio.Event|None=None,)->subscription_client.OnTradeTransaction# async iterable of OnTradeTransactionData
What it is. A low‑level event stream: every trade server transaction as it happens — order add/update/delete, deal add, history add/update/delete, etc.
Why. Perfect for accurate audit logs, reconciliation, and state machines that need request+result context per change.
Be careful.
Stream is infinite until canceled via cancellation_event.
Timestamps are UTC; many structs have both time (Timestamp) and time_msc (ms since epoch).
Some transactions include only ids (e.g., order delete) — don’t assume full bodies are always present.