Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
exchange.Go
EventLoop
ctx.subscribe
ctx.poll
Subscription
Subscription.book
Subscription.positions
Subscription.balances
Subscription.unsubscribe
threading
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Server
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

A subscription object, returned by ctx.subscribe, represents a single push subscription. It can be passed directly to ctx.poll to receive events from this subscription only. A subscription object belongs to the thread that created it: events from the subscription are delivered only to that thread, and only that thread can unsubscribe it. For a batch subscription (an array passed as symbol), an array of subscription objects is returned. Calling unsubscribe() on the array unsubscribes all of its elements at once. The array can also be passed directly to ctx.poll().
A subscription object has the following read-only properties. The result of JSON.stringify(sub) contains only these properties:

PropertyTypeDescription
idnumberEvent stream ID. The ev.stream of events produced by this subscription equals this value. Subscriptions with the same identity in the same thread have the same id
exnumberIndex of the account in the exchanges array
channelstringChannel: ticker, bbo, depth, trade, kline, tickers, private
symbolstringSymbol code. Empty string for tickers and private subscriptions
depthnumberNumber of order book levels for a depth subscription (0 means the exchange's default number of levels). 0 for other subscriptions
intervalnumberPeriod (in seconds) of a kline subscription. 0 for other subscriptions

Methods: book reads the order book of this depth subscription. positions and balances read the latest positions and balances maintained by a private subscription. unsubscribe unsubscribes.
In Python, it is a Subscription object with the same read-only properties, and info() returns a dictionary made up of these properties. A batch subscription returns a SubscriptionList (a subclass of list), whose unsubscribe() unsubscribes all of its elements. In Rust, the equivalent is the ctx::Sub returned by ctx::subscribe() (ctx::subscribe_many() for batch subscriptions), and its properties are provided as methods: id(), ex(), channel(), depth(), interval().

In this sectionRead the whole section

NameDescription
Subscription.bookReads the order book maintained by this depth subscription itself.
Subscription.positionsReads the latest positions that a private subscription maintains from pushed updates.
Subscription.balancesReads the latest balances that a private subscription keeps up to date from pushed events.
Subscription.unsubscribeUnsubscribe: releases the reference held by this subscription object; the actual unsubscribe request is sent to the exchange only when the last reference is rel…