MT5Account ¡ Subscriptions Streaming â Overview¶
Quick map of the live streaming APIs: ticks, trade deltas, transactions, position P/L, and IDs-only snapshots. Use this to pick the right stream fast.
đ What lives here¶
- on_symbol_tick â live tick stream per symbol (Bid/Ask/Last, volumes, flags, time).
- on_trade â highâlevel order/position/deal deltas + account P/L snapshot per event.
- on_trade_transaction â lowâlevel transaction feed: transaction + request + result.
- on_position_profit â periodic P/L snapshots for positions (new/updated/deleted) + account info.
- on_positions_and_pending_orders_tickets â periodic IDsâonly snapshot of position and pending order tickets.
đ§ Plain English¶
- on_symbol_tick â your price heartbeat (perâsymbol ticks for UI/algos).
- on_trade â state deltas (orders/positions/deals) bundled for easy UI sync.
- on_trade_transaction â auditâlevel stream with request/result pairing.
- on_position_profit â P/L ticker for positions on a timer.
- on_positions_and_pending_orders_tickets â cheap setâdiff source (IDs only).
Rule of thumb: need prices â
on_symbol_tick
; need deltas âon_trade
; need audit âon_trade_transaction
; need P/L âon_position_profit
; need change detection â IDsâonly stream.
Quick choose¶
If you need⌠| Use | Returns | Key inputs |
---|---|---|---|
Live ticks (Bid/Ask/Last/flags/time) | on_symbol_tick |
stream OnSymbolTickData |
symbols: list[str] , cancellation_event? |
Deltas of orders/positions/deals + account | on_trade |
stream OnTradeData |
cancellation_event? |
Raw transactions with request+result | on_trade_transaction |
stream OnTradeTransactionData |
cancellation_event? |
Timed position P/L snapshots | on_position_profit |
stream OnPositionProfitData |
interval_ms:int , ignore_empty:bool , cancel? |
IDsâonly snapshot (positions & pendings) | on_positions_and_pending_orders_tickets |
stream OnPositionsAndPendingOrdersTicketsData |
interval_ms:int , cancellation_event? |
â Crossârefs & gotchas¶
- Longâlived streams â always support a
cancellation_event
and stop cleanly on page change/shutdown. - UTC times â
Timestamp
/time_msc
are UTC; convert once for UI. - Backâpressure â keep perâevent handlers light; push to queues if you do heavy work.
- Cold start â use
OpenedOrders
(or other snapshot RPCs) once, then rely on streams. - IDs vs full objects â tickets stream is for setâdiff; fetch details only on change.
đ˘ Minimal snippets¶
# on_symbol_tick â print Bid/Ask
async for ev in acct.on_symbol_tick(["EURUSD", "XAUUSD"]):
t = ev.symbol_tick
print(t.symbol, t.bid, t.ask)
# on_trade â count changed objects per event
async for ev in acct.on_trade():
d = ev.event_data
print(len(d.new_orders), len(d.updated_positions), len(d.new_history_deals))
# on_trade_transaction â show type and ids
async for ev in acct.on_trade_transaction():
tr = ev.trade_transaction
print(tr.type, tr.order_ticket, tr.deal_ticket)
# on_position_profit â sum current P/L in the batch
async for ev in acct.on_position_profit(1000, True):
print(sum(p.profit for p in (ev.updated_positions or [])))
# on_positions_and_pending_orders_tickets â diff detector
prev_pos, prev_ord = set(), set()
async for ev in acct.on_positions_and_pending_orders_tickets(750):
pos, ords = set(ev.opened_position_tickets), set(ev.opened_orders_tickets)
if (pos != prev_pos) or (ords != prev_ord):
print("changed")
prev_pos, prev_ord = pos, ords