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, 2, 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,
end=date + datetime.timedelta(days=1),
)
# 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 TBBO data with these symbols
tbbo_data = client.timeseries.get_range(
dataset=dataset,
schema="tbbo",
symbols=def_df["raw_symbol"].to_list(),
start=date,
end=date + datetime.timedelta(days=1),
limit=10000,
)
# Convert to DataFrame
tbbo_df = tbbo_data.to_df()
# Print tbbo DataFrame
print(tbbo_df)
Result
raw_symbol expiration strike_price
ts_recv
2025-02-10 11:30:02.370919887+00:00 SPXW 250210C03600000 2025-02-10 00:00:00+00:00 3600.0
2025-02-10 11:30:02.375993765+00:00 SPXW 250210P07600000 2025-02-10 00:00:00+00:00 7600.0
2025-02-10 11:30:02.395560084+00:00 SPXW 250210P06700000 2025-02-10 00:00:00+00:00 6700.0
2025-02-10 11:30:02.566456600+00:00 SPXW 250210C05675000 2025-02-10 00:00:00+00:00 5675.0
2025-02-10 11:30:02.761757958+00:00 SPXW 250210C05690000 2025-02-10 00:00:00+00:00 5690.0
... ... ... ...
2025-02-10 11:30:36.531956878+00:00 SPXW 250210P05705000 2025-02-10 00:00:00+00:00 5705.0
2025-02-10 11:30:36.561991638+00:00 SPXW 250210P05540000 2025-02-10 00:00:00+00:00 5540.0
2025-02-10 11:30:36.578621281+00:00 SPXW 250210P05175000 2025-02-10 00:00:00+00:00 5175.0
2025-02-10 11:30:36.582044414+00:00 SPXW 250210P05645000 2025-02-10 00:00:00+00:00 5645.0
2025-02-10 11:30:36.692232388+00:00 SPXW 250210C06310000 2025-02-10 00:00:00+00:00 6310.0
[402 rows x 3 columns]
ts_event rtype publisher_id instrument_id action ... bid_sz_00 ask_sz_00 bid_ct_00 ask_ct_00 symbol
ts_recv ...
2025-02-10 14:30:03.011453892+00:00 2025-02-10 14:30:03.011244800+00:00 1 22 1275071930 T ... 0 0 0 0 SPXW 250210P05925000
2025-02-10 14:30:03.012396776+00:00 2025-02-10 14:30:03.012187648+00:00 1 22 1275076777 T ... 0 0 0 0 SPXW 250210P05600000
2025-02-10 14:30:03.012412036+00:00 2025-02-10 14:30:03.012202496+00:00 1 22 1275076777 T ... 0 0 0 0 SPXW 250210P05600000
2025-02-10 14:30:03.012421813+00:00 2025-02-10 14:30:03.012212736+00:00 1 22 1275076777 T ... 0 0 0 0 SPXW 250210P05600000
2025-02-10 14:30:03.013676681+00:00 2025-02-10 14:30:03.013467136+00:00 1 22 1275086387 T ... 0 0 0 0 SPXW 250210P05800000
... ... ... ... ... ... ... ... ... ... ... ...
2025-02-10 14:32:54.687648326+00:00 2025-02-10 14:32:54.687438592+00:00 1 22 1275087183 T ... 0 764 0 0 SPXW 250210C06140000
2025-02-10 14:32:54.906877893+00:00 2025-02-10 14:32:54.906667008+00:00 1 22 1275072671 T ... 52 24 0 0 SPXW 250210C06055000
2025-02-10 14:32:54.963909467+00:00 2025-02-10 14:32:54.963698432+00:00 1 22 1275072671 T ... 38 48 0 0 SPXW 250210C06055000
2025-02-10 14:32:54.963909467+00:00 2025-02-10 14:32:54.963698432+00:00 1 22 1275081924 T ... 104 20 0 0 SPXW 250210C06060000
2025-02-10 14:32:54.966379446+00:00 2025-02-10 14:32:54.966169600+00:00 1 22 1275081924 T ... 104 20 0 0 SPXW 250210C06060000
[10000 rows x 19 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 TBBO schema with 0DTE symbols
live_client.subscribe(
dataset=dataset,
schema="tbbo",
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 = 450
First 5 symbols...['SPXW 250304P06060000', 'SPXW 250304C05785000', 'SPXW 250304P05895000', 'SPXW 250304P03000000', 'SPXW 250304C05985000']
SymbolMappingMsg { hd: RecordHeader { length: 44, rtype: SymbolMapping, publisher_id: 0, instrument_id: 1275068440, ts_event: 1741118375219986733 }, stype_in: 255, stype_in_symbol: "SPXW 250304P06060000", stype_out: 255, stype_out_symbol: "SPXW 250304P06060000", start_ts: 18446744073709551615, end_ts: 18446744073709551615 }
SymbolMappingMsg { hd: RecordHeader { length: 44, rtype: SymbolMapping, publisher_id: 0, instrument_id: 1275068543, ts_event: 1741118375219988867 }, stype_in: 255, stype_in_symbol: "SPXW 250304C05785000", stype_out: 255, stype_out_symbol: "SPXW 250304C05785000", start_ts: 18446744073709551615, end_ts: 18446744073709551615 }
SymbolMappingMsg { hd: RecordHeader { length: 44, rtype: SymbolMapping, publisher_id: 0, instrument_id: 1275068571, ts_event: 1741118375219989879 }, stype_in: 255, stype_in_symbol: "SPXW 250304P05895000", stype_out: 255, stype_out_symbol: "SPXW 250304P05895000", start_ts: 18446744073709551615, end_ts: 18446744073709551615 }
...
SymbolMappingMsg { hd: RecordHeader { length: 44, rtype: SymbolMapping, publisher_id: 0, instrument_id: 1275100574, ts_event: 1741118375220394029 }, stype_in: 255, stype_in_symbol: "SPXW 250304C05390000", stype_out: 255, stype_out_symbol: "SPXW 250304C05390000", start_ts: 18446744073709551615, end_ts: 18446744073709551615 }
SymbolMappingMsg { hd: RecordHeader { length: 44, rtype: SymbolMapping, publisher_id: 0, instrument_id: 1275100661, ts_event: 1741118375220394910 }, stype_in: 255, stype_in_symbol: "SPXW 250304P05505000", stype_out: 255, stype_out_symbol: "SPXW 250304P05505000", start_ts: 18446744073709551615, end_ts: 18446744073709551615 }
SymbolMappingMsg { hd: RecordHeader { length: 44, rtype: SymbolMapping, publisher_id: 0, instrument_id: 1275100710, ts_event: 1741118375220395782 }, stype_in: 255, stype_in_symbol: "SPXW 250304P05390000", stype_out: 255, stype_out_symbol: "SPXW 250304P05390000", start_ts: 18446744073709551615, end_ts: 18446744073709551615 }
Mbp1Msg { hd: RecordHeader { length: 20, rtype: Mbp1, publisher_id: OpraPillarXcbo, instrument_id: 1275085553, ts_event: 1741118375655598336 }, price: 1.250000000, size: 1, action: 'T', side: 'N', flags: LAST | TOB (194), depth: 0, ts_recv: 1741118375655810197, ts_in_delta: 0, sequence: 3692436456, levels: [BidAskPair { bid_px: 1.250000000, ask_px: 1.300000000, bid_sz: 1, ask_sz: 315, bid_ct: 22, ask_ct: 22 }] }
Mbp1Msg { hd: RecordHeader { length: 20, rtype: Mbp1, publisher_id: OpraPillarXcbo, instrument_id: 1275071745, ts_event: 1741118375761044736 }, price: 9.600000000, size: 1, action: 'T', side: 'N', flags: LAST | TOB (194), depth: 0, ts_recv: 1741118375761256828, ts_in_delta: 0, sequence: 3692444981, levels: [BidAskPair { bid_px: 9.400000000, ask_px: 9.700000000, bid_sz: 75, ask_sz: 94, bid_ct: 22, ask_ct: 22 }] }
Mbp1Msg { hd: RecordHeader { length: 20, rtype: Mbp1, publisher_id: OpraPillarXcbo, instrument_id: 1275072355, ts_event: 1741118375894849280 }, price: 0.360000000, size: 10, action: 'T', side: 'N', flags: LAST | TOB (194), depth: 0, ts_recv: 1741118375895061420, ts_in_delta: 0, sequence: 3692453147, levels: [BidAskPair { bid_px: 0.300000000, ask_px: 0.400000000, bid_sz: 663, ask_sz: 922, bid_ct: 22, ask_ct: 22 }] }
...
Mbp1Msg { hd: RecordHeader { length: 20, rtype: Mbp1, publisher_id: OpraPillarXcbo, instrument_id: 1275084705, ts_event: 1741118377693027584 }, price: 4.200000000, size: 10, action: 'T', side: 'N', flags: LAST | TOB (194), depth: 0, ts_recv: 1741118377693238423, ts_in_delta: 0, sequence: 3692663217, levels: [BidAskPair { bid_px: 4.100000000, ask_px: 4.300000000, bid_sz: 114, ask_sz: 76, bid_ct: 22, ask_ct: 22 }] }
Mbp1Msg { hd: RecordHeader { length: 20, rtype: Mbp1, publisher_id: OpraPillarXcbo, instrument_id: 1275072823, ts_event: 1741118377829208576 }, price: 3.700000000, size: 1, action: 'T', side: 'N', flags: LAST | TOB (194), depth: 0, ts_recv: 1741118377829419088, ts_in_delta: 0, sequence: 3692675779, levels: [BidAskPair { bid_px: 3.600000000, ask_px: 3.700000000, bid_sz: 54, ask_sz: 15, bid_ct: 22, ask_ct: 22 }] }
Mbp1Msg { hd: RecordHeader { length: 20, rtype: Mbp1, publisher_id: OpraPillarXcbo, instrument_id: 1275085553, ts_event: 1741118377887346176 }, price: 1.250000000, size: 1, action: 'T', side: 'N', flags: LAST | TOB (194), depth: 0, ts_recv: 1741118377887557200, ts_in_delta: 0, sequence: 3692679613, levels: [BidAskPair { bid_px: 1.250000000, ask_px: 1.300000000, bid_sz: 10, ask_sz: 33, bid_ct: 22, ask_ct: 22 }] }