Skip to content

Instantly share code, notes, and snippets.

@databento-bot
Created July 6, 2025 06:26
Show Gist options
  • Save databento-bot/64b88bb3cd9d7d7f9b67a4eccd3b788c to your computer and use it in GitHub Desktop.
Save databento-bot/64b88bb3cd9d7d7f9b67a4eccd3b788c to your computer and use it in GitHub Desktop.
Resample 1-minute OHLCV bars to 5-minute OHLCV bars on Databento
import pandas as pd
import databento as db
client = db.Historical()
data = client.timeseries.get_range(
dataset="XNAS.ITCH",
schema="ohlcv-1m",
symbols="AAPL",
start="2021-04-09",
end="2021-04-10",
)
df = data.to_df()
# Resample to 5-minute bars
resampled_df = df.resample('5min').agg({
'open': 'first', # First value in the 5-minute window
'high': 'max', # Maximum high in the 5-minute window
'low': 'min', # Minimum low in the 5-minute window
'close': 'last', # Last value in the 5-minute window
'volume': 'sum', # Sum of volume in the 5-minute window
'symbol': 'last', # Last symbol value (should be consistent)
'instrument_id': 'last', # Last instrument_id value (should be consistent)
'publisher_id': 'last', # Last publisher_id value (should be consistent except for aggregated datasets)
'rtype': 'last' # Last rtype value (should be consistent)
}).dropna()
print(resampled_df.head(10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment