Last active
November 8, 2025 05:56
-
-
Save databento-bot/8c437c0c79380ec67299dfa67819f013 to your computer and use it in GitHub Desktop.
Get daily high/low values and times they occurred for ES futures outside regular US cash session hours
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| """ | |
| eth_high_low.py | |
| ============== | |
| Calculates daily high/low occurrences for ES futures outside regular US cash session hours | |
| using Databento API. | |
| Fetches second-by-second OHLCV data for ES continuous futures from Databento, | |
| filters to exclude regular US cash session (9:30 AM - 4:00 PM ET), then computes | |
| the max high and min low for each day along with their timestamps. | |
| This approach relying on OHLCV data is the fastest down to 1-second resolution. If you need | |
| sub-second resolution for the event times, you should use `trades` instead. If you need to | |
| incorporate highest bid or lowest ask - which is useful for instruments with inactive | |
| trading - you can use `bbo-1s` or `mbp-1`. | |
| Note that CME futures trade nearly 24h from Sun-Fri without explicit pre-market/after-hours | |
| sessions, so the time range exclusion is user-defined. | |
| """ | |
| import datetime as dt | |
| import databento as db | |
| client = db.Historical() | |
| data = client.timeseries.get_range( | |
| dataset="GLBX.MDP3", | |
| schema="ohlcv-1s", | |
| stype_in="continuous", | |
| symbols=["ES.n.0"], | |
| start="2024-11-01", | |
| end="2024-12-01", | |
| ) | |
| df = data.to_df(tz="US/Eastern") | |
| # Exclude US cash session (9:30 AM - 4:00 PM ET) | |
| df_filtered = df[(df.index.time < dt.time(9, 30)) | (df.index.time >= dt.time(16, 0))] | |
| daily_extremes = df_filtered.groupby(df_filtered.index.date).agg({ | |
| 'high': ['max', 'idxmax'], | |
| 'low': ['min', 'idxmin'] | |
| }) | |
| # Flatten the column names | |
| daily_extremes.columns = ['max_high', 'ts_max_high', 'min_low', 'ts_min_low'] | |
| daily_extremes = daily_extremes.reset_index() | |
| daily_extremes.rename(columns={'ts_event': 'date'}, inplace=True) | |
| print(daily_extremes) | |
| """ | |
| index max_high ts_max_high min_low ts_min_low | |
| 0 2024-10-31 5749.75 2024-10-31 23:46:20-04:00 5732.50 2024-10-31 22:13:10-04:00 | |
| 1 2024-11-01 5769.50 2024-11-01 08:42:03-04:00 5740.50 2024-11-01 03:27:50-04:00 | |
| 2 2024-11-03 5774.75 2024-11-03 23:45:42-05:00 5740.00 2024-11-03 18:00:00-05:00 | |
| 3 2024-11-04 5776.50 2024-11-04 01:43:09-05:00 5735.00 2024-11-04 20:27:32-05:00 | |
| 4 2024-11-05 5894.75 2024-11-05 22:04:27-05:00 5743.00 2024-11-05 00:00:00-05:00 | |
| 5 2024-11-06 5968.75 2024-11-06 23:54:10-05:00 5866.25 2024-11-06 00:10:49-05:00 | |
| 6 2024-11-07 6009.50 2024-11-07 16:21:16-05:00 5959.25 2024-11-07 02:29:00-05:00 | |
| 7 2024-11-08 6029.00 2024-11-08 16:23:56-05:00 5990.25 2024-11-08 06:07:12-05:00 | |
| 8 2024-11-10 6038.50 2024-11-10 18:21:04-05:00 6029.50 2024-11-10 18:01:13-05:00 | |
| 9 2024-11-11 6053.25 2024-11-11 07:48:03-05:00 6022.00 2024-11-11 21:51:31-05:00 | |
| 10 2024-11-12 6031.75 2024-11-12 03:54:04-05:00 6002.00 2024-11-12 21:32:33-05:00 | |
| 11 2024-11-13 6030.25 2024-11-13 08:42:18-05:00 5993.00 2024-11-13 01:35:39-05:00 | |
| 12 2024-11-14 6025.25 2024-11-14 07:00:42-05:00 5954.75 2024-11-14 21:06:31-05:00 | |
| 13 2024-11-15 5963.00 2024-11-15 00:18:00-05:00 5896.50 2024-11-15 16:00:00-05:00 | |
| 14 2024-11-17 5915.50 2024-11-17 23:53:20-05:00 5891.75 2024-11-17 18:01:48-05:00 | |
| 15 2024-11-18 5933.75 2024-11-18 23:30:04-05:00 5886.50 2024-11-18 08:23:43-05:00 | |
| 16 2024-11-19 5954.00 2024-11-19 19:22:43-05:00 5855.00 2024-11-19 09:01:22-05:00 | |
| 17 2024-11-20 5957.75 2024-11-20 03:21:09-05:00 5911.00 2024-11-20 16:20:41-05:00 | |
| 18 2024-11-21 5977.00 2024-11-21 22:17:00-05:00 5905.25 2024-11-21 04:28:17-05:00 | |
| 19 2024-11-22 5991.25 2024-11-22 16:48:06-05:00 5940.75 2024-11-22 05:10:34-05:00 | |
| 20 2024-11-24 6015.25 2024-11-24 20:38:30-05:00 6005.50 2024-11-24 18:00:02-05:00 | |
| 21 2024-11-25 6033.75 2024-11-25 09:17:00-05:00 5976.25 2024-11-25 20:03:05-05:00 | |
| 22 2024-11-26 6047.00 2024-11-26 21:28:45-05:00 5997.00 2024-11-26 03:38:05-05:00 | |
| 23 2024-11-27 6041.50 2024-11-27 02:33:37-05:00 6013.75 2024-11-27 16:07:50-05:00 | |
| 24 2024-11-28 6035.00 2024-11-28 23:16:37-05:00 6018.00 2024-11-28 19:51:17-05:00 | |
| 25 2024-11-29 6035.50 2024-11-29 00:01:27-05:00 6018.75 2024-11-29 08:45:05-05:00 | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment