Skip to content

Instantly share code, notes, and snippets.

ts_event rtype publisher_id instrument_id action side price size channel_id order_id flags ts_in_delta sequence symbol
ts_recv
2025-04-25 13:30:00.002415517+00:00 2025-04-25 13:30:00.000435143+00:00 160 1 42003627 F A 5510.25 2 8 6863196218407 0 14070 333790855 MESM5
2025-04-25 13:30:00.002415517+00:00 2025-04-25 13:30:00.000435143+00:00 160 1 42003627 F A 5510.25 1 8 6863196218557 0 14070 333790855 MESM5
2025-04-25 13:30:00.002415517+00:00 2025-04-25 13:30:00.000435143+00:00 160 1 42003627 F A 5510.50 1 8 6863196218273 0 14070 333790855 MESM5
2025-04-25 13:30:00.002495446+00:00 2025-04-25 13:30:00.000756343+00:00 160 1 42003627 F A 5510.50 1 8 6863196218273 0 12976 333790857 MESM5
2025-04-25 13:30
@databento-bot
databento-bot / scanner.py
Last active April 25, 2025 22:11
Real-time scanner for detecting large price movements in all US stocks and ETFs
"""
This script demonstrates how to build a real-time scanner that detects significant
price movements across all US stocks and ETFs using Databento's market data APIs.
Features:
- Handles entire US equities universe of ~9,000 symbols efficiently
- Median sub-ms feed delay to NY4/5 (WAN-shaped) and ~5s to start scanning
- Monitors all US stocks and ETFs for price movements exceeding a configurable threshold
- Compares current prices against previous day's closing prices
- Displays alerts when significant moves are detected
@databento-bot
databento-bot / resample.py
Created April 23, 2025 01:15
Resample OHLCV-1s with uniform
"""
OHLCV-1s data follows standard convention of most vendors and doesn't print on intervals
when there's no trade. This is the typical approach as there's no way to infer the type
of price interpolation or forward fill preferred. If you need prices printed uniformly
with forward filling or price interpolation, you can follow this example to do it on
client side.
See also: https://databento.com/docs/examples/basics-historical/tick-resampling/example
"""
// Condenses MEMX notices on https://info.memxtrading.com/category/alerts-notices/
const s=document.createElement("style");s.innerHTML="*{margin:0!important;padding:0!important;line-height:1!important;font-size:10px!important;letter-spacing:0!important}div,p,span,a,li,td,th{line-height:1!important;font-size:10px!important}table{border-spacing:0!important;border-collapse:collapse!important}",document.head.appendChild(s),(async()=>{const e=document.querySelector("main");if(!e)return void console.error("No <main> element found.");document.querySelectorAll("div.nav-links").forEach(t=>t.remove());for(let t=2;t<=91;t++){const n=`https://info.memxtrading.com/category/alerts-notices/page/${t}/`;try{const t=await fetch(n),o=await t.text(),i=new DOMParser().parseFromString(o,"text/html");i.querySelectorAll("hr, article").forEach(t=>e.appendChild(t.cloneNode(!0))),console.log(`Appended page ${t}`)}catch(a){console.error(`Error fetching page ${t}:`,a)}}})();
@databento-bot
databento-bot / compare_cme_eod.py
Created March 3, 2025 05:18
Compare Databento vs. CME end-of-day settlement volumes
from enum import Enum
import databento as db
import pandas as pd
class Stat(Enum):
SETTLEMENT_VOLUME = 6
client = db.Historical()
@databento-bot
databento-bot / live_ohlcv.py
Created October 10, 2024 21:36
Basic example of using live OHLCV data from Databento
import databento as db
@singledispatch
def dbn_handler(_: db.DBNRecord):
pass
@dbn_handler.register
def _(sym: db.SymbolMappingMsg):
instrument_id = sym.instrument_id
@databento-bot
databento-bot / pairs_trading.py
Last active April 24, 2025 09:28
A cross-venue pairs trading strategy between WTI (CME) and Brent (ICE) crude oil
import databento as db
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.stattools import coint
from sklearn.linear_model import LinearRegression
plt.style.use("ggplot")
# Instrument-specific configuration
@databento-bot
databento-bot / x2522.20240813.log
Last active October 1, 2024 14:08
X2522 benchmark, 2024-08-13
# One-way, overall
#
# 0.973/1.093/3.042us (0/50/99p, 256 byte packets)
# Port-to-port (switch hop)
#
# 680+/-20ns
#
# - Mellanox Spectrum SN2700 w/ Cumulus 5.7
@databento-bot
databento-bot / get_xnas_ohlcv1h_20240501.py
Created June 8, 2024 17:42
Extracts 1 day of OHLCV-1h data for XNAS.ITCH
# Extracts 1 day of OHLCV-1h data for XNAS.ITCH
import databento as db
client = db.Historical()
data = client.timeseries.get_range(
dataset='XNAS.ITCH',
schema='ohlcv-1h',
symbols='ALL_SYMBOLS',
@databento-bot
databento-bot / replay_snapshot.py
Last active March 6, 2025 15:20
Use intraday replay to synthetically generate a snapshot
#!/usr/bin/env python
#
# replay_snapshot.py
#
# As of Databento's Python client v0.33.0, intraday snapshots are not available via
# the historical (HTTP) API, so you can use intraday replay to generate those snapshots
# on client side. This is the recommended method until these two features are released:
#
# If no bar for a symbol is received in the first second, there will be no entry in the
# DataFrame for that symbol.