Created
February 28, 2024 09:20
-
-
Save databento-bot/f99a3adc08233b1bfe3f3c1b8aee8913 to your computer and use it in GitHub Desktop.
Example of getting largest moves in US stocks during extended hours with Databento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import databento as db | |
import pandas as pd | |
def get_df_move(date: str = '2023-06-06'): | |
end_dt = datetime.datetime.strptime(date+'T16:00', '%Y-%m-%dT%H:%M') | |
start_dt = end_dt - datetime.timedelta(days=1) | |
start = pd.Timestamp(start_dt, tz='US/Eastern') | |
end = pd.Timestamp(date+'T09:30:00', tz='US/Eastern') | |
data = client.timeseries.get_range( | |
dataset='XNAS.ITCH', | |
schema='ohlcv-1m', | |
symbols='ALL_SYMBOLS', | |
start=start, | |
end=end, | |
) | |
# Low-level way to get the symbology quickly | |
sym = data.request_symbology(client) | |
data._instrument_map.insert_json(sym) | |
# Get first and last prices for each symbol | |
df = data.to_df(tz='US/Eastern') | |
df = df.groupby(['symbol']).agg({'open': 'first', 'close': 'last'}) | |
df['change'] = (df['close'] - df['open'])/df['open'] | |
return df.sort_values(by='change') | |
df_move = get_df_move('2023-06-06') | |
print(df_move) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment