Subscription
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:
| Property | Type | Description |
|---|---|---|
| id | number | Event 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 |
| ex | number | Index of the account in the exchanges array |
| channel | string | Channel: ticker, bbo, depth, trade, kline, tickers, private |
| symbol | string | Symbol code. Empty string for tickers and private subscriptions |
| depth | number | Number of order book levels for a depth subscription (0 means the exchange's default number of levels). 0 for other subscriptions |
| interval | number | Period (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
| Name | Description |
| Subscription.book | Reads the order book maintained by this depth subscription itself. |
| Subscription.positions | Reads the latest positions that a private subscription maintains from pushed updates. |
| Subscription.balances | Reads the latest balances that a private subscription keeps up to date from pushed events. |
| Subscription.unsubscribe | Unsubscribe: releases the reference held by this subscription object; the actual unsubscribe request is sent to the exchange only when the last reference is rel… |