You will need a live license for OPRA.PILLAR to run this example. See our plans and live data page for more information.
Get symbols for 0DTE options
Overview
In this example we will show how to get symbols for 0DTE options for a product. 0DTE (Zero Days To Expiration) options are contracts that expire at the end of the current session.
Definition schema
The definition schema contains instrument definitions and properties. In these examples, we are primarily interested in the raw_symbol and expiration fields. We will retrieve definition data for all options that trade under a parent symbol. We will then filter for 0DTE contracts based on expiration. We can then use raw_symbol to pass a list of symbols into another data query.
Historical example
First, we'll take a look at how to do this with the Historical client. We'll use a pandas DataFrame to filter for this example.
import datetime
import databento as db
# Create a historical client
client = db.Historical("$YOUR_API_KEY")
# Set parameters
dataset = "OPRA.PILLAR"
parent_symbol = "SPXW" # SPX Weekly Options
date = datetime.date(2025, 9, 10)
# Download definition data for a parent symbol
def_data = client.timeseries.get_range(
dataset=dataset,
schema="definition",
symbols=f"{parent_symbol}.OPT",
stype_in="parent",
start=date,
)
# Convert to DataFrame and filter for 0DTE
def_df = def_data.to_df()
def_df = def_df[def_df["expiration"].dt.date == date]
# Print out raw_symbols, expiration, and strike price
print(def_df[["raw_symbol", "expiration", "strike_price"]])
# Download some TCBBO data with these symbols
tcbbo_data = client.timeseries.get_range(
dataset=dataset,
schema="tcbbo",
symbols=def_df["raw_symbol"].to_list(),
start=date,
limit=10000,
)
# Convert to DataFrame
tcbbo_df = tcbbo_data.to_df()
# Print TCBBO DataFrame
print(tcbbo_df)
Result
raw_symbol expiration strike_price
ts_recv
2025-09-10 10:30:02.624717419+00:00 SPXW 250910P04000000 2025-09-10 00:00:00+00:00 4000.0
2025-09-10 10:30:02.634731457+00:00 SPXW 250910P06700000 2025-09-10 00:00:00+00:00 6700.0
2025-09-10 10:30:02.644740147+00:00 SPXW 250910P06200000 2025-09-10 00:00:00+00:00 6200.0
2025-09-10 10:30:02.644740147+00:00 SPXW 250910C05775000 2025-09-10 00:00:00+00:00 5775.0
2025-09-10 10:30:02.662006482+00:00 SPXW 250910P06450000 2025-09-10 00:00:00+00:00 6450.0
... ... ... ...
2025-09-10 10:30:29.833577055+00:00 SPXW 250910C05970000 2025-09-10 00:00:00+00:00 5970.0
2025-09-10 10:30:29.844558808+00:00 SPXW 250910C06145000 2025-09-10 00:00:00+00:00 6145.0
2025-09-10 10:30:29.869477754+00:00 SPXW 250910C06065000 2025-09-10 00:00:00+00:00 6065.0
2025-09-10 10:30:29.883667299+00:00 SPXW 250910C05960000 2025-09-10 00:00:00+00:00 5960.0
2025-09-10 10:30:29.994986746+00:00 SPXW 250910P06710000 2025-09-10 00:00:00+00:00 6710.0
[406 rows x 3 columns]
ts_event rtype publisher_id instrument_id side ... bid_sz_00 ask_sz_00 bid_pb_00 ask_pb_00 symbol
ts_recv ...
2025-09-10 13:30:02.764440257+00:00 2025-09-10 13:30:02.764236273+00:00 194 22 1241523583 N ... 0 0 0 0 SPXW 250910P06350000
2025-09-10 13:30:02.764443670+00:00 2025-09-10 13:30:02.764240780+00:00 194 22 1241523583 N ... 0 0 0 0 SPXW 250910P06350000
2025-09-10 13:30:02.764725051+00:00 2025-09-10 13:30:02.764522162+00:00 194 22 1241515705 N ... 0 0 0 0 SPXW 250910P06400000
2025-09-10 13:30:02.764725051+00:00 2025-09-10 13:30:02.764522162+00:00 194 22 1241515705 N ... 0 0 0 0 SPXW 250910P06400000
2025-09-10 13:30:02.764734633+00:00 2025-09-10 13:30:02.764531350+00:00 194 22 1241515705 N ... 0 0 0 0 SPXW 250910P06400000
... ... ... ... ... ... ... ... ... ... ... ...
2025-09-10 13:31:50.928232746+00:00 2025-09-10 13:31:50.928030554+00:00 194 22 1241531922 N ... 385 364 22 22 SPXW 250910C06610000
2025-09-10 13:31:50.956014355+00:00 2025-09-10 13:31:50.955812019+00:00 194 22 1241520104 N ... 134 200 22 22 SPXW 250910P06495000
2025-09-10 13:31:50.961115681+00:00 2025-09-10 13:31:50.960913601+00:00 194 22 1241528118 N ... 234 200 22 22 SPXW 250910C06555000
2025-09-10 13:31:50.962087120+00:00 2025-09-10 13:31:50.961883488+00:00 194 22 1241516275 N ... 136 60 22 22 SPXW 250910C06545000
2025-09-10 13:31:50.962087120+00:00 2025-09-10 13:31:50.961883488+00:00 194 22 1241519790 N ... 54 188 22 22 SPXW 250910C06550000
[10000 rows x 15 columns]
Live example
Next, we'll take a look at how to do this with the Live client. We'll use the pretty_expiration attribute which converts expiration into a datetime object to filter.
Info
import datetime
import databento as db
# Create a live client
live_client = db.Live("$YOUR_API_KEY")
# Set parameters
dataset = "OPRA.PILLAR"
parent_symbol = "SPXW" # SPX Weekly Options
date = datetime.datetime.now(tz=datetime.timezone.utc).date()
# Subscribe to the definition schema for the parent symbol for this session
live_client.subscribe(
dataset=dataset,
schema="definition",
symbols=f"{parent_symbol}.OPT",
stype_in="parent",
start=0,
)
# Create a list of 0DTE symbols
symbols = []
def append_symbol_list(msg):
if isinstance(msg, db.InstrumentDefMsg):
# Filter for 0DTE
if msg.pretty_expiration.date() == date:
symbols.append(msg.raw_symbol)
# Add the callback and start the stream
live_client.add_callback(append_symbol_list)
live_client.start()
# Listen to the stream for 15 seconds to get all messages
live_client.block_for_close(timeout=15)
# Print out the symbol count and the first 5 symbols
print(f"Total symbol count for {dataset} = {len(symbols)}\nFirst 5 symbols...{symbols[:5]}")
# Re-subscribe to the TCBBO schema with 0DTE symbols
live_client.subscribe(
dataset=dataset,
schema="tcbbo",
symbols=symbols,
)
# Add a print callback and start the stream
live_client.add_callback(print)
live_client.start()
# Listen to the stream for 10 seconds
live_client.block_for_close(timeout=10)
Result
Total symbol count for OPRA.PILLAR = 888
First 5 symbols...['SPXW 250919P06500000', 'SPXW 250919P05950000', 'SPXW 250919P06000000', 'SPXW 250919C05675000', 'SPXW 250919P07000000']
SystemMsg { hd: RecordHeader { length: 80, rtype: System, publisher_id: 0, instrument_id: 0, ts_event: 1758291634420399209 }, msg: "Subscription request 2 for tcbbo data succeeded", code: 255 }
SymbolMappingMsg { hd: RecordHeader { length: 44, rtype: SymbolMapping, publisher_id: 0, instrument_id: 1224738072, ts_event: 1758291634420402085 }, stype_in: 255, stype_in_symbol: "SPXW 250919P06500000", stype_out: 255, stype_out_symbol: "SPXW 250919P06500000", start_ts: 18446744073709551615, end_ts: 18446744073709551615 }
SymbolMappingMsg { hd: RecordHeader { length: 44, rtype: SymbolMapping, publisher_id: 0, instrument_id: 1224738073, ts_event: 1758291634420403577 }, stype_in: 255, stype_in_symbol: "SPXW 250919P05950000", stype_out: 255, stype_out_symbol: "SPXW 250919P05950000", start_ts: 18446744073709551615, end_ts: 18446744073709551615 }
SymbolMappingMsg { hd: RecordHeader { length: 44, rtype: SymbolMapping, publisher_id: 0, instrument_id: 1224738074, ts_event: 1758291634420404890 }, stype_in: 255, stype_in_symbol: "SPXW 250919P06000000", stype_out: 255, stype_out_symbol: "SPXW 250919P06000000", start_ts: 18446744073709551615, end_ts: 18446744073709551615 }
...
SymbolMappingMsg { hd: RecordHeader { length: 44, rtype: SymbolMapping, publisher_id: 0, instrument_id: 1224772029, ts_event: 1758291634421293512 }, stype_in: 255, stype_in_symbol: "SPXW 250919P07110000", stype_out: 255, stype_out_symbol: "SPXW 250919P07110000", start_ts: 18446744073709551615, end_ts: 18446744073709551615 }
SymbolMappingMsg { hd: RecordHeader { length: 44, rtype: SymbolMapping, publisher_id: 0, instrument_id: 1224772044, ts_event: 1758291634421294404 }, stype_in: 255, stype_in_symbol: "SPXW 250919P06835000", stype_out: 255, stype_out_symbol: "SPXW 250919P06835000", start_ts: 18446744073709551615, end_ts: 18446744073709551615 }
SymbolMappingMsg { hd: RecordHeader { length: 44, rtype: SymbolMapping, publisher_id: 0, instrument_id: 1224772045, ts_event: 1758291634421295296 }, stype_in: 255, stype_in_symbol: "SPXW 250919C07210000", stype_out: 255, stype_out_symbol: "SPXW 250919C07210000", start_ts: 18446744073709551615, end_ts: 18446744073709551615 }
Cmbp1Msg { hd: RecordHeader { length: 20, rtype: Tcbbo, publisher_id: OpraPillarXcbo, instrument_id: 1224739240, ts_event: 1758291634438859835 }, price: 1.600000000, size: 14, action: 'T', side: 'N', flags: LAST | TOB (194), ts_recv: 1758291634439062490, ts_in_delta: 0, levels: [ConsolidatedBidAskPair { bid_px: 1.550000000, ask_px: 1.650000000, bid_sz: 345, ask_sz: 327, bid_pb: OpraPillarXcbo, ask_pb: OpraPillarXcbo }] }
Cmbp1Msg { hd: RecordHeader { length: 20, rtype: Tcbbo, publisher_id: OpraPillarXcbo, instrument_id: 1224757001, ts_event: 1758291634456046495 }, price: 9.700000000, size: 1, action: 'T', side: 'N', flags: LAST | TOB (194), ts_recv: 1758291634456246979, ts_in_delta: 0, levels: [ConsolidatedBidAskPair { bid_px: 9.700000000, ask_px: 9.800000000, bid_sz: 1, ask_sz: 64, bid_pb: OpraPillarXcbo, ask_pb: OpraPillarXcbo }] }
Cmbp1Msg { hd: RecordHeader { length: 20, rtype: Tcbbo, publisher_id: OpraPillarXcbo, instrument_id: 1224757001, ts_event: 1758291634456055545 }, price: 9.700000000, size: 1, action: 'T', side: 'N', flags: LAST | TOB (194), ts_recv: 1758291634456255965, ts_in_delta: 0, levels: [ConsolidatedBidAskPair { bid_px: 9.600000000, ask_px: 9.800000000, bid_sz: 56, ask_sz: 64, bid_pb: OpraPillarXcbo, ask_pb: OpraPillarXcbo }] }
...
Cmbp1Msg { hd: RecordHeader { length: 20, rtype: Tcbbo, publisher_id: OpraPillarXcbo, instrument_id: 1224767719, ts_event: 1758291643450137783 }, price: 6.300000000, size: 1, action: 'T', side: 'N', flags: LAST | TOB (194), ts_recv: 1758291643450338446, ts_in_delta: 0, levels: [ConsolidatedBidAskPair { bid_px: 6.200000000, ask_px: 6.400000000, bid_sz: 120, ask_sz: 163, bid_pb: OpraPillarXcbo, ask_pb: OpraPillarXcbo }] }
Cmbp1Msg { hd: RecordHeader { length: 20, rtype: Tcbbo, publisher_id: OpraPillarXcbo, instrument_id: 1224744795, ts_event: 1758291643611958220 }, price: 1.120000000, size: 1, action: 'T', side: 'N', flags: LAST | TOB (194), ts_recv: 1758291643612159427, ts_in_delta: 0, levels: [ConsolidatedBidAskPair { bid_px: 1.050000000, ask_px: 1.150000000, bid_sz: 471, ask_sz: 319, bid_pb: OpraPillarXcbo, ask_pb: OpraPillarXcbo }] }
Cmbp1Msg { hd: RecordHeader { length: 20, rtype: Tcbbo, publisher_id: OpraPillarXcbo, instrument_id: 1224738847, ts_event: 1758291643611963284 }, price: 0.470000000, size: 1, action: 'T', side: 'N', flags: LAST | TOB (194), ts_recv: 1758291643612163868, ts_in_delta: 0, levels: [ConsolidatedBidAskPair { bid_px: 0.450000000, ask_px: 0.500000000, bid_sz: 427, ask_sz: 178, bid_pb: OpraPillarXcbo, ask_pb: OpraPillarXcbo }] }