Symbology mapping for live data
Overview
In this example we will use the Live client to create symbology mappings using the SymbolMappingMsg. This message is sent at the start of every session and when a subscribed symbol mapping is updated. These messages allow us to map between the instrument ID on every record and more human-readable STypes like raw and continuous contract symbologies.
Example
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 26 27 28 29 30 31 32
import databento as db
# First, create a live client and connect
live_client = db.Live(key="$YOUR_API_KEY")
# Next, we will subscribe to a few symbols
live_client.subscribe(
dataset="GLBX.MDP3",
schema="ohlcv-1s",
symbols=["ES.c.0", "ES.c.1", "ES.c.2", "ES.c.3"],
stype_in="continuous",
)
# Finally, we will iterate over the incoming records.
# The SymbolMappingMsgs will be sent at the start.
for record in live_client:
if isinstance(record, db.SymbolMappingMsg):
instrument_id = record.instrument_id
# The stype_in_symbol contains the continuous symbology we requested
continuous_symbol = record.stype_in_symbol
# The stype_out_symbol contains the raw symbol for smart symbology
raw_symbol = record.stype_out_symbol
print(
f"{continuous_symbol} ({raw_symbol}) has an instrument ID of {instrument_id}",
)
# Close the connection
# We will still process all received data
live_client.stop() Result
1 2 3 4
ES.c.0 (ESM4) has an instrument ID of 5602 ES.c.1 (ESU4) has an instrument ID of 118 ES.c.2 (ESZ4) has an instrument ID of 183748 ES.c.3 (ESH5) has an instrument ID of 5002
See also
Symbology for further details.