Appearance
Top Book Persistence
Family: Microstructure
What it computes
Emits TopBookPersistenceTick ticks carrying mean_lifetime_ms, last_lifetime_ms, change_count off stock NBBO quote tape.
Available on the live, historical, and replay drives.
Methodology
Hasbrouck-Saar (2013) running mean lifetime of the NBBO inside between consecutive L1 changes via Welford (1962) running-mean recursion — the canonical HFT market-quality gauge.
See the methodology overview for the citation index.
Inputs
Stock NBBO quote tape.
Key outputs
Mean_lifetime_ms, last_lifetime_ms, change_count. The full field set is in the tick table below.
Output schema (TopBookPersistenceTick)
The field / type / description table below is regenerated from the TopBookPersistenceTick Rust source by docs-site/scripts/inject-doc-tables.ts on every npm run docs:build. Do not hand-edit between the sentinels.
| Field | Type | Description |
|---|---|---|
symbol | Arc<str> | Underlying symbol (interned). Stock-only analytic. |
date | i32 | Trading-session date (YYYYMMDD). |
ms_of_day | i32 | Milliseconds since midnight at emission time. |
mean_lifetime_ms | f64 | Running per-session mean L1-quote lifetime in milliseconds. NaN until the first L1 change seals (a single snapshot has no lifetime by construction). |
last_lifetime_ms | i32 | Lifetime of the just-sealed L1 quote in milliseconds — the per-event reading every lifetime histogram consumes; pairs with mean_lifetime_ms so consumers can split the per-event reading from the cumulative mean. |
change_count | i32 | Number of sealed L1 changes inside the active session — the per-session change-count odometer. |
Configuration (TopBookPersistenceParams)
Regenerated from the TopBookPersistenceParams Rust source — see the note above.
| Field | Type | Description |
|---|---|---|
contracts | SecurityFilter | Contracts the subscription tracks. Stock-only NBBO stream — the filter must resolve to stock contracts. |
conditions | ConditionPolicy | Trade-condition admission policy applied to the NBBO bid-side condition byte. |
venues | ExchangeFilter | Exchange / venue admission policy. |
min_emit_interval_ms | i32 | Minimum interval between consecutive emissions per symbol, in milliseconds. Defaults to [DEFAULT_MIN_EMIT_INTERVAL_MS] (0 ms — every sealed change emits). |
Example
Python
python
import kairos_thetadata as kt
client = kt.Client.connect(kt.Credentials.from_env())
def on_event(row):
print(row)
sub = client.live().top_book_persistence(["QQQ"]).on_event(on_event)
sub.wait(timeout_seconds=60.0)TypeScript
typescript
import { Client, Credentials } from "kairos-thetadata";
const client = await Client.connect(Credentials.fromEnv());
await client
.live()
.topBookPersistence(["QQQ"])
.onEvent((tick) => {
console.log(tick);
});Rust
rust
// Cargo.toml:
// kairos = "0.1"
use kairos::{Client, TopBookPersistenceRow};
# fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::connect(("me@example.com", "secret"))?;
let sub = client
.live()
.top_book_persistence(["QQQ"])
.on_event(|row: &TopBookPersistenceRow| println!("mean_lifetime_ms={} change_count={}", row.mean_lifetime_ms, row.change_count))?;
// ... later ...
sub.unsubscribe();
# Ok(())
# }