Live.unsubscribe
Remove the specified symbols from the session's subscriptions for a schema.
The symbols don't need to match an earlier Live.subscribe call: any subset of the subscribed symbols can be removed, and 'ALL_SYMBOLS' removes every symbol for the schema.
The gateway acknowledges the request with a SystemMsg with system code UNSUBSCRIBE_ACK. Symbols that aren't subscribed, or that can't be removed with the given stype_in, are left in place and reported in an ErrorMsg.
The unsubscribe's stype_in must be compatible with the subscription's stype_in.
| Subscribed with | Can unsubscribe with |
|---|---|
'raw_symbol', 'instrument_id', or 'continuous' | 'raw_symbol' or 'instrument_id' |
'parent' | 'parent' |
To remove a continuous symbol, unsubscribe the raw symbol or instrument ID that it resolved to at subscription time.
A client can only unsubscribe after a successful connection is made by calling Live.subscribe. When the Live client reconnects with a reconnect_policy of 'reconnect', subscriptions and unsubscriptions are replayed in the order they were sent.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
schema | Schema or str | required | The data record schema to unsubscribe from. |
symbols | Iterable[str | int] or str or int | required | The product symbols to unsubscribe from. 'ALL_SYMBOLS' removes every symbol for the schema. |
stype_in | SType or str, default 'raw_symbol' | optional | The symbology type of input symbols. Must be one of 'raw_symbol', 'parent', or 'instrument_id'. |
Live.unsubscribe(
schema: Schema | str,
symbols: Iterable[str | int] | str | int,
stype_in: SType | str = "raw_symbol",
) -> None 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
import databento as db
# Create a live client
client = db.Live(key="$YOUR_API_KEY")
# Subscribe to the trades schema for ES and NQ futures
client.subscribe(
dataset="GLBX.MDP3",
schema="trades",
stype_in="parent",
symbols=["ES.FUT", "NQ.FUT"],
)
# Start the streaming session
client.start()
# Stop receiving trades for NQ futures
client.unsubscribe(
schema="trades",
stype_in="parent",
symbols="NQ.FUT",
)
# Terminate the streaming session
client.terminate()