Skip to content

Instantly share code, notes, and snippets.

@databento-bot
Created February 21, 2024 12:06
Show Gist options
  • Save databento-bot/86af3afa7e279815099f950f28104096 to your computer and use it in GitHub Desktop.
Save databento-bot/86af3afa7e279815099f950f28104096 to your computer and use it in GitHub Desktop.
Example of fetching CME and ICE energy futures data on Databento
import databento as db
client = db.Historical()
# Heating oil, gasoline and crude futures on CME and ICE
# .FUT parent symbology notation fetches all expirations across
# all outrights and multi-legged spreads etc.
CME_SYMBOLS = ['HO.FUT', 'RB.FUT', 'CL.FUT']
ICE_SYMBOLS = ['UHO.FUT', 'UHU.FUT', 'BRN.FUT']
data = client.timeseries.get_range(
dataset='GLBX.MDP3',
schema='ohlcv-1m', # 1-min OHLCV
stype_in='parent', # fetch all expirations, spreads, etc.
symbols=CME_SYMBOLS,
start='2024-02-12',
end='2024-02-13',
)
df_cme_1m = data.to_df(tz='US/Eastern')
data = client.timeseries.get_range(
dataset='GLBX.MDP3',
schema='trades', # tick-by-tick trades i.e. last sale
stype_in='parent',
symbols=CME_SYMBOLS,
start='2024-02-12',
end='2024-02-13',
)
df_cme_trades = data.to_df(tz='US/Eastern')
data = client.timeseries.get_range(
dataset='IFEU.IMPACT',
schema='ohlcv-1m',
stype_in='parent',
symbols=ICE_SYMBOLS,
start='2024-02-12',
end='2024-02-13',
)
df_ice_1m = data.to_df(tz='US/Eastern')
data = client.timeseries.get_range(
dataset='IFEU.IMPACT',
schema='trades',
stype_in='parent',
symbols=ICE_SYMBOLS,
start='2024-02-12',
end='2024-02-13',
)
df_ice_trades = data.to_df(tz='US/Eastern')
df_cme_1m.to_csv('databento-cme-energies-2024-02-12.ohlcv-1m.csv.gz', compression='gzip')
df_cme_trades.to_csv('databento-cme-energies-2024-02-12.trades.csv.gz', compression='gzip')
df_ice_1m.to_csv('databento-ice-energies-2024-02-12.ohlcv-1m.csv.gz', compression='gzip')
df_ice_trades.to_csv('databento-ice-energies-2024-02-12.trades.csv.gz', compression='gzip')
df_cme_1m.to_parquet('databento-cme-energies-2024-02-12.ohlcv-1m.parquet.gz', compression='gzip')
df_cme_trades.to_parquet('databento-cme-energies-2024-02-12.trades.parquet.gz', compression='gzip')
df_ice_1m.to_parquet('databento-ice-energies-2024-02-12.ohlcv-1m.parquet.gz', compression='gzip')
df_ice_trades.to_parquet('databento-ice-energies-2024-02-12.trades.parquet.gz', compression='gzip')
print(df_cme_1m)
print(df_ice_1m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment