Skip to content

Instantly share code, notes, and snippets.

@databento-bot
Created February 21, 2024 11:05
Show Gist options
  • Save databento-bot/827ea1695d405bb0def617028a5e38c4 to your computer and use it in GitHub Desktop.
Save databento-bot/827ea1695d405bb0def617028a5e38c4 to your computer and use it in GitHub Desktop.
Example of getting largest premarket moves in US stocks with Databento
import databento as db
client = db.Historical()
data = client.timeseries.get_range(
dataset='XNAS.ITCH',
schema='ohlcv-1m',
symbols='ALL_SYMBOLS',
start='20230606T00:00',
end='20230606T14:30',
)
# Low-level way to get the symbology quickly
sym = data.request_symbology(client)
data._instrument_map.insert_json(sym)
# Generalize this for dates with daylight savings
df = data.to_df(tz='US/Eastern').between_time('00:00', '09:30')
# Get first and last prices for each symbol
df = df.groupby(['symbol']).agg({'open': 'first', 'close': 'last'})
df['change'] = (df['close'] - df['open'])/df['open']
df.sort_values(by='change', inplace=True)
print(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment