Skip to content

Book Depth At Top

Family: Microstructure

What it computes

Emits BookDepthAtTopTick ticks carrying bid_size, ask_size, book_depth off stock NBBO quote tape.

Available on the live, historical, and replay drives.

Methodology

Foucault / Pagano / Röell (2013) §5 total displayed top-of-book size bid_size + ask_size aggregated over admitted NBBO updates — the textbook level-1 liquidity gauge alongside the bid-ask spread.

See the methodology overview for the citation index.

Inputs

Stock NBBO quote tape.

Key outputs

Bid_size, ask_size, book_depth. The full field set is in the tick table below.

Output schema (BookDepthAtTopTick)

The field / type / description table below is regenerated from the BookDepthAtTopTick Rust source by docs-site/scripts/inject-doc-tables.ts on every npm run docs:build. Do not hand-edit between the sentinels.

FieldTypeDescription
symbolArc<str>Underlying symbol (interned). Stock-only analytic.
datei32Trading-session date (YYYYMMDD).
ms_of_dayi32Milliseconds since midnight at emission time.
bid_sizei32Bid size at emission time (resting shares on the best bid).
ask_sizei32Ask size at emission time (resting shares on the best ask).
book_depthi32Total displayed size at the NBBO — bid_size + ask_size. Saturating-add is used so the published reading is finite even when both legs sit close to i32::MAX.

Configuration (BookDepthAtTopParams)

Regenerated from the BookDepthAtTopParams Rust source — see the note above.

FieldTypeDescription
contractsSecurityFilterContracts the subscription tracks. Stock-only NBBO stream — the filter must resolve to stock contracts.
conditionsConditionPolicyTrade-condition admission policy applied to the NBBO bid-side condition byte; the same policy gates trade prints on related analytics so the filtered universe is consistent.
venuesExchangeFilterExchange / venue admission policy.
min_emit_interval_msi32Minimum interval between consecutive emissions per symbol, in milliseconds. Defaults to [DEFAULT_MIN_EMIT_INTERVAL_MS] (0 ms — every admission 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().book_depth_at_top(["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()
  .bookDepthAtTop(["QQQ"])
  .onEvent((tick) => {
    console.log(tick);
  });

Rust

rust
// Cargo.toml:
//   kairos = "0.1"

use kairos::{Client, BookDepthAtTopRow};

# fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::connect(("me@example.com", "secret"))?;

let sub = client
    .live()
    .book_depth_at_top(["QQQ"])
    .on_event(|row: &BookDepthAtTopRow| {
        println!("book_depth={} bid_size={}", row.book_depth, row.bid_size)
    })?;
// ... later ...
sub.unsubscribe();
# Ok(())
# }

Proprietary. All rights reserved.