Created
July 6, 2025 04:40
-
-
Save databento-bot/113b55b43eefb9a4ac8205e2d33c5532 to your computer and use it in GitHub Desktop.
Get trade counts on all listed NG outrights
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
import databento as db | |
import pandas as pd | |
client = db.Historical() | |
def print_ng_summary_by_date(date_str: str): | |
date = pd.to_datetime(date_str) | |
weekday = date.weekday() | |
if weekday == 5: | |
raise ValueError("Provided date is a Saturday. Please choose a date from Sunday to Friday.") | |
next_day = date + pd.Timedelta(days=1) | |
end_str = next_day.strftime("%Y-%m-%d") | |
pattern = r"^NG.\d{1,2}$" | |
defn = client.timeseries.get_range( | |
dataset="GLBX.MDP3", | |
schema="definition", | |
stype_in="parent", | |
symbols=["NG.FUT"], | |
start=date_str, | |
end=end_str, | |
).to_df() | |
defn = defn[defn["symbol"].str.match(pattern)].copy() | |
defn["expiration"] = pd.to_datetime(defn["expiration"]).dt.strftime("%Y-%m") | |
defn = defn[["symbol", "expiration"]].sort_values(by="expiration") | |
trades = client.timeseries.get_range( | |
dataset="GLBX.MDP3", | |
schema="trades", | |
stype_in="parent", | |
symbols=["NG.FUT"], | |
start=date_str, | |
end=end_str, | |
).to_df() | |
trade_counts = ( | |
trades[trades["symbol"].str.match(pattern)]["symbol"] | |
.value_counts() | |
.sort_index() | |
.rename("trade_count") | |
.reset_index() | |
.rename(columns={"index": "symbol"}) | |
) | |
summary = pd.merge(defn, trade_counts, on="symbol", how="left").fillna(0) | |
summary["trade_count"] = summary["trade_count"].astype(int) | |
print(f"\nSummary on {date_str}:") | |
print(summary.to_string(index=False)) | |
print_ng_summary_by_date("2019-04-09") | |
print_ng_summary_by_date("2021-04-09") | |
print_ng_summary_by_date("2025-04-09") |
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
Summary on 2019-04-09: | |
symbol expiration trade_count | |
NGK9 2019-04 17545 | |
NGM9 2019-05 6027 | |
NGN9 2019-06 2664 | |
NGQ9 2019-07 852 | |
NGU9 2019-08 1047 | |
NGV9 2019-09 1292 | |
NGX9 2019-10 782 | |
NGZ9 2019-11 340 | |
NGF0 2019-12 519 | |
NGG0 2020-01 123 | |
NGH0 2020-02 223 | |
NGJ0 2020-03 516 | |
NGK0 2020-04 166 | |
NGM0 2020-05 145 | |
NGN0 2020-06 144 | |
NGQ0 2020-07 128 | |
NGU0 2020-08 305 | |
NGV0 2020-09 228 | |
NGX0 2020-10 27 | |
NGZ0 2020-11 22 | |
NGF1 2020-12 4 | |
NGG1 2021-01 2 | |
NGH1 2021-02 3 | |
NGJ1 2021-03 5 | |
NGK1 2021-04 9 | |
NGM1 2021-05 0 | |
NGN1 2021-06 0 | |
NGQ1 2021-07 0 | |
NGU1 2021-08 0 | |
NGV1 2021-09 0 | |
NGX1 2021-10 1 | |
NGZ1 2021-11 1 | |
NGF2 2021-12 0 | |
NGG2 2022-01 0 | |
NGH2 2022-02 0 | |
NGJ2 2022-03 0 | |
NGK2 2022-04 1 | |
NGM2 2022-05 0 | |
NGN2 2022-06 0 | |
NGQ2 2022-07 0 | |
NGU2 2022-08 0 | |
NGV2 2022-09 0 | |
NGX2 2022-10 0 | |
NGZ2 2022-11 0 | |
NGF3 2022-12 0 | |
NGG3 2023-01 0 | |
NGH3 2023-02 0 | |
NGJ3 2023-03 0 | |
NGK3 2023-04 0 | |
NGM3 2023-05 0 | |
NGN3 2023-06 0 | |
NGQ3 2023-07 0 | |
NGU3 2023-08 0 | |
NGV3 2023-09 0 | |
NGX3 2023-10 0 | |
NGZ3 2023-11 0 | |
NGF4 2023-12 0 | |
NGG4 2024-01 0 | |
NGH4 2024-02 0 | |
NGJ4 2024-03 0 | |
NGK4 2024-04 0 | |
NGM4 2024-05 0 | |
NGN4 2024-06 0 | |
NGQ4 2024-07 0 | |
NGU4 2024-08 0 | |
NGV4 2024-09 0 | |
NGX4 2024-10 0 | |
NGZ4 2024-11 0 | |
NGF5 2024-12 0 | |
NGG5 2025-01 0 | |
NGH5 2025-02 0 | |
NGJ5 2025-03 0 | |
NGK5 2025-04 0 | |
NGM5 2025-05 0 | |
NGN25 2025-06 0 | |
NGQ25 2025-07 0 | |
NGU25 2025-08 0 | |
NGV25 2025-09 0 | |
NGX25 2025-10 0 | |
NGZ25 2025-11 0 | |
NGF26 2025-12 0 | |
NGG26 2026-01 0 | |
NGH26 2026-02 0 | |
NGJ26 2026-03 0 | |
NGK26 2026-04 0 | |
NGM26 2026-05 0 | |
NGN26 2026-06 0 | |
NGQ26 2026-07 0 | |
NGU26 2026-08 0 | |
NGV26 2026-09 0 | |
NGX26 2026-10 0 | |
NGZ26 2026-11 0 | |
NGF27 2026-12 0 | |
NGG27 2027-01 0 | |
NGH27 2027-02 0 | |
NGJ27 2027-03 0 | |
NGK27 2027-04 0 | |
NGM27 2027-05 0 | |
NGN27 2027-06 0 | |
NGQ27 2027-07 0 | |
NGU27 2027-08 0 | |
NGV27 2027-09 0 | |
NGX27 2027-10 0 | |
NGZ27 2027-11 0 | |
NGF28 2027-12 0 | |
NGG28 2028-01 0 | |
NGH28 2028-02 0 | |
NGJ28 2028-03 0 | |
NGK28 2028-04 0 | |
NGM28 2028-05 0 | |
NGN28 2028-06 0 | |
NGQ28 2028-07 0 | |
NGU28 2028-08 0 | |
NGV28 2028-09 0 | |
NGX28 2028-10 0 | |
NGZ28 2028-11 0 | |
NGF29 2028-12 0 | |
NGG29 2029-01 0 | |
NGH29 2029-02 0 | |
NGJ29 2029-03 0 | |
NGK29 2029-04 0 | |
NGM29 2029-05 0 | |
NGN29 2029-06 0 | |
NGQ29 2029-07 0 | |
NGU29 2029-08 0 | |
NGV29 2029-09 0 | |
NGX29 2029-10 0 | |
NGZ29 2029-11 0 | |
NGF30 2029-12 0 | |
NGG30 2030-01 0 | |
NGH30 2030-02 0 | |
NGJ30 2030-03 0 | |
NGK30 2030-04 0 | |
NGM30 2030-05 0 | |
NGN30 2030-06 0 | |
NGQ30 2030-07 0 | |
NGU30 2030-08 0 | |
NGV30 2030-09 0 | |
NGX30 2030-10 0 | |
NGZ30 2030-11 0 | |
NGF31 2030-12 0 | |
NGG31 2031-01 0 | |
NGH31 2031-02 0 | |
NGJ31 2031-03 0 | |
NGK31 2031-04 0 | |
NGM31 2031-05 0 | |
NGN31 2031-06 0 | |
NGQ31 2031-07 0 | |
NGU31 2031-08 0 | |
NGV31 2031-09 0 | |
NGX31 2031-10 0 | |
NGZ31 2031-11 0 |
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
Summary on 2021-04-09: | |
symbol expiration trade_count | |
NGK1 2021-04 16923 | |
NGM1 2021-05 5418 | |
NGN1 2021-06 4841 | |
NGQ1 2021-07 815 | |
NGU1 2021-08 600 | |
NGV1 2021-09 1286 | |
NGX1 2021-10 546 | |
NGZ1 2021-11 470 | |
NGF2 2021-12 1128 | |
NGG2 2022-01 327 | |
NGH2 2022-02 378 | |
NGJ2 2022-03 518 | |
NGK2 2022-04 318 | |
NGM2 2022-05 91 | |
NGN2 2022-06 45 | |
NGQ2 2022-07 50 | |
NGU2 2022-08 54 | |
NGV2 2022-09 238 | |
NGX2 2022-10 21 | |
NGZ2 2022-11 55 | |
NGF3 2022-12 14 | |
NGG3 2023-01 6 | |
NGH3 2023-02 22 | |
NGJ3 2023-03 17 | |
NGK3 2023-04 2 | |
NGM3 2023-05 1 | |
NGN3 2023-06 0 | |
NGQ3 2023-07 0 | |
NGU3 2023-08 0 | |
NGV3 2023-09 1 | |
NGX3 2023-10 1 | |
NGZ3 2023-11 3 | |
NGF4 2023-12 0 | |
NGG4 2024-01 0 | |
NGH4 2024-02 0 | |
NGJ4 2024-03 1 | |
NGK4 2024-04 0 | |
NGM4 2024-05 0 | |
NGN4 2024-06 0 | |
NGQ4 2024-07 0 | |
NGU4 2024-08 0 | |
NGV4 2024-09 1 | |
NGX4 2024-10 0 | |
NGZ4 2024-11 0 | |
NGF5 2024-12 0 | |
NGG5 2025-01 0 | |
NGH5 2025-02 0 | |
NGJ5 2025-03 0 | |
NGK5 2025-04 0 | |
NGM5 2025-05 0 | |
NGN25 2025-06 0 | |
NGQ25 2025-07 0 | |
NGU25 2025-08 0 | |
NGV25 2025-09 0 | |
NGX25 2025-10 0 | |
NGZ25 2025-11 0 | |
NGF26 2025-12 0 | |
NGG26 2026-01 0 | |
NGH26 2026-02 0 | |
NGJ26 2026-03 0 | |
NGK26 2026-04 0 | |
NGM26 2026-05 0 | |
NGN26 2026-06 0 | |
NGQ26 2026-07 0 | |
NGU26 2026-08 0 | |
NGV26 2026-09 0 | |
NGX26 2026-10 0 | |
NGZ26 2026-11 0 | |
NGF27 2026-12 0 | |
NGG27 2027-01 0 | |
NGH27 2027-02 0 | |
NGJ27 2027-03 0 | |
NGK27 2027-04 0 | |
NGM27 2027-05 0 | |
NGN27 2027-06 0 | |
NGQ27 2027-07 0 | |
NGU27 2027-08 0 | |
NGV27 2027-09 0 | |
NGX27 2027-10 0 | |
NGZ27 2027-11 0 | |
NGF28 2027-12 0 | |
NGG28 2028-01 0 | |
NGH28 2028-02 0 | |
NGJ28 2028-03 0 | |
NGK28 2028-04 0 | |
NGM28 2028-05 0 | |
NGN28 2028-06 0 | |
NGQ28 2028-07 0 | |
NGU28 2028-08 0 | |
NGV28 2028-09 0 | |
NGX28 2028-10 0 | |
NGZ28 2028-11 0 | |
NGF29 2028-12 0 | |
NGG29 2029-01 0 | |
NGH29 2029-02 0 | |
NGJ29 2029-03 0 | |
NGK29 2029-04 0 | |
NGM29 2029-05 0 | |
NGN29 2029-06 0 | |
NGQ29 2029-07 0 | |
NGU29 2029-08 0 | |
NGV29 2029-09 0 | |
NGX29 2029-10 0 | |
NGZ29 2029-11 0 | |
NGF30 2029-12 0 | |
NGG30 2030-01 0 | |
NGH30 2030-02 0 | |
NGJ30 2030-03 0 | |
NGK30 2030-04 0 | |
NGM30 2030-05 0 | |
NGN30 2030-06 0 | |
NGQ30 2030-07 0 | |
NGU30 2030-08 0 | |
NGV30 2030-09 0 | |
NGX30 2030-10 0 | |
NGZ30 2030-11 0 | |
NGF31 2030-12 0 | |
NGG31 2031-01 0 | |
NGH31 2031-02 0 | |
NGJ31 2031-03 0 | |
NGK31 2031-04 0 | |
NGM31 2031-05 0 | |
NGN31 2031-06 0 | |
NGQ31 2031-07 0 | |
NGU31 2031-08 0 | |
NGV31 2031-09 0 | |
NGX31 2031-10 0 | |
NGZ31 2031-11 0 | |
NGF32 2031-12 0 | |
NGG32 2032-01 0 | |
NGH32 2032-02 0 | |
NGJ32 2032-03 0 | |
NGK32 2032-04 0 | |
NGM32 2032-05 0 | |
NGN32 2032-06 0 | |
NGQ32 2032-07 0 | |
NGU32 2032-08 0 | |
NGV32 2032-09 0 | |
NGX32 2032-10 0 | |
NGZ32 2032-11 0 | |
NGF33 2032-12 0 | |
NGG33 2033-01 0 | |
NGH33 2033-02 0 | |
NGJ33 2033-03 0 | |
NGK33 2033-04 0 | |
NGM33 2033-05 0 | |
NGN33 2033-06 0 | |
NGQ33 2033-07 0 | |
NGU33 2033-08 0 | |
NGV33 2033-09 0 | |
NGX33 2033-10 0 | |
NGZ33 2033-11 0 |
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
Summary on 2025-04-09: | |
symbol expiration trade_count | |
NGK5 2025-04 103669 | |
NGM5 2025-05 32130 | |
NGN25 2025-06 14087 | |
NGQ25 2025-07 10327 | |
NGU25 2025-08 6069 | |
NGV25 2025-09 11255 | |
NGX25 2025-10 3239 | |
NGZ25 2025-11 3969 | |
NGF26 2025-12 9088 | |
NGG26 2026-01 3066 | |
NGH26 2026-02 3978 | |
NGJ26 2026-03 8066 | |
NGK26 2026-04 2257 | |
NGM26 2026-05 2020 | |
NGN26 2026-06 1405 | |
NGQ26 2026-07 1335 | |
NGU26 2026-08 785 | |
NGV26 2026-09 1548 | |
NGX26 2026-10 368 | |
NGZ26 2026-11 258 | |
NGF27 2026-12 523 | |
NGG27 2027-01 35 | |
NGH27 2027-02 67 | |
NGJ27 2027-03 93 | |
NGK27 2027-04 0 | |
NGM27 2027-05 0 | |
NGN27 2027-06 0 | |
NGQ27 2027-07 0 | |
NGU27 2027-08 0 | |
NGV27 2027-09 2 | |
NGX27 2027-10 1 | |
NGZ27 2027-11 2 | |
NGF28 2027-12 1 | |
NGG28 2028-01 1 | |
NGH28 2028-02 0 | |
NGJ28 2028-03 1 | |
NGK28 2028-04 1 | |
NGM28 2028-05 0 | |
NGN28 2028-06 1 | |
NGQ28 2028-07 2 | |
NGU28 2028-08 0 | |
NGV28 2028-09 1 | |
NGX28 2028-10 0 | |
NGZ28 2028-11 0 | |
NGF29 2028-12 1 | |
NGG29 2029-01 1 | |
NGH29 2029-02 0 | |
NGJ29 2029-03 1 | |
NGK29 2029-04 0 | |
NGM29 2029-05 0 | |
NGN29 2029-06 1 | |
NGQ29 2029-07 1 | |
NGU29 2029-08 1 | |
NGV29 2029-09 2 | |
NGX29 2029-10 1 | |
NGZ29 2029-11 1 | |
NGF30 2029-12 0 | |
NGG30 2030-01 2 | |
NGH30 2030-02 0 | |
NGJ30 2030-03 0 | |
NGK30 2030-04 0 | |
NGM30 2030-05 0 | |
NGN30 2030-06 0 | |
NGQ30 2030-07 0 | |
NGU30 2030-08 0 | |
NGV30 2030-09 0 | |
NGX30 2030-10 0 | |
NGZ30 2030-11 0 | |
NGF31 2030-12 0 | |
NGG31 2031-01 0 | |
NGH31 2031-02 0 | |
NGJ31 2031-03 0 | |
NGK31 2031-04 0 | |
NGM31 2031-05 0 | |
NGN31 2031-06 0 | |
NGQ31 2031-07 0 | |
NGU31 2031-08 0 | |
NGV31 2031-09 0 | |
NGX31 2031-10 0 | |
NGZ31 2031-11 0 | |
NGF32 2031-12 0 | |
NGG32 2032-01 0 | |
NGH32 2032-02 0 | |
NGJ32 2032-03 0 | |
NGK32 2032-04 0 | |
NGM32 2032-05 0 | |
NGN32 2032-06 0 | |
NGQ32 2032-07 0 | |
NGU32 2032-08 0 | |
NGV32 2032-09 0 | |
NGX32 2032-10 0 | |
NGZ32 2032-11 0 | |
NGF33 2032-12 0 | |
NGG33 2033-01 0 | |
NGH33 2033-02 0 | |
NGJ33 2033-03 0 | |
NGK33 2033-04 0 | |
NGM33 2033-05 0 | |
NGN33 2033-06 0 | |
NGQ33 2033-07 0 | |
NGU33 2033-08 0 | |
NGV33 2033-09 0 | |
NGX33 2033-10 0 | |
NGZ33 2033-11 0 | |
NGF34 2033-12 0 | |
NGG34 2034-01 0 | |
NGH34 2034-02 0 | |
NGJ34 2034-03 0 | |
NGK34 2034-04 0 | |
NGM34 2034-05 0 | |
NGN34 2034-06 0 | |
NGQ34 2034-07 0 | |
NGU34 2034-08 0 | |
NGV34 2034-09 0 | |
NGX34 2034-10 0 | |
NGZ34 2034-11 0 | |
NGF35 2034-12 0 | |
NGG35 2035-01 0 | |
NGH35 2035-02 0 | |
NGJ35 2035-03 0 | |
NGK35 2035-04 0 | |
NGM35 2035-05 0 | |
NGN35 2035-06 0 | |
NGQ35 2035-07 0 | |
NGU35 2035-08 0 | |
NGV35 2035-09 0 | |
NGX35 2035-10 0 | |
NGZ35 2035-11 0 | |
NGF36 2035-12 0 | |
NGG36 2036-01 0 | |
NGH36 2036-02 0 | |
NGJ36 2036-03 0 | |
NGK36 2036-04 0 | |
NGM36 2036-05 0 | |
NGN36 2036-06 0 | |
NGQ36 2036-07 0 | |
NGU36 2036-08 0 | |
NGV36 2036-09 0 | |
NGX36 2036-10 0 | |
NGZ36 2036-11 0 | |
NGF37 2036-12 0 | |
NGG37 2037-01 0 | |
NGH37 2037-02 0 | |
NGJ37 2037-03 0 | |
NGK37 2037-04 0 | |
NGM37 2037-05 0 | |
NGN37 2037-06 0 | |
NGQ37 2037-07 0 | |
NGU37 2037-08 0 | |
NGV37 2037-09 0 | |
NGX37 2037-10 0 | |
NGZ37 2037-11 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment