Skip to content

Multi Leg Detector

Family: Flow surveillance

What it computes

Emits MultiLegDetectorTick ticks carrying structure_kind, legs[], aggressor_lean off trade tape.

Available on the live, historical, and replay drives.

Methodology

Synchronized-fill structure detection.

See the methodology overview for the citation index.

Inputs

Trade tape.

Key outputs

Structure_kind, legs[], aggressor_lean. The full field set is in the tick table below.

Output schema (MultiLegDetectorTick)

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

FieldTypeDescription
rootArc<str>Underlying symbol.
datei32Trading session date (YYYYMMDD).
ms_of_dayi32ms_of_day of the earliest leg in the structure.
structure_kindStructureKindClassified structure kind — see [StructureKind].
aggressor_leanAggressorLeanAggregate directional lean derived from the constructed payoff — see [AggressorLean].
legsVec<MultiLegLeg>Per-leg breakdown. Ordered by ascending (expiration, right, strike) so verticals / iron condors / butterflies arrive in a deterministic sequence the classifier can be inverted against.
total_contractsi32Number of distinct contracts in the structure — same as legs.len(), carried as a separate field for downstream columnar filtering.
total_premium_usdf64Total premium across the structure (USD: sum of size × price × 100 per leg, unsigned).
confidencef64Confidence in the classification, in [0.0, 1.0]. 1.0 is reserved for exact-size, exact-spacing, exact-leg-count matches; the classifier downgrades on inexact size matches, irregular strike spacing, or partial leg sets.

Configuration (MultiLegDetectorParams)

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

FieldTypeDescription
contractsSecurityFilterUnderlyings the subscription tracks. The detector expands a SecurityFilter::Symbols(["AAPL"]) over every option contract on the underlying chain — leg correlation runs per-symbol.
conditionsConditionPolicyTrade-condition admission policy. Default [ConditionPolicy::OpraRegular] — cancels, openings, late, and halt-rule prints are excluded.
window_msi32Rolling window in milliseconds. Synchronised fills are correlated within this window — the institutional convention for the complex-order book on options is the 50 ms human-tick horizon (CBOE COB latency floor) used by the public flow- surveillance feeds. Default 50.
min_total_premium_usdf64Minimum total premium (USD) summed across legs for a structure to emit. Default 0.0 — emit every detected structure. Production-grade flow surveillance typically raises this to 25_000.0 so single-contract retail combinations stay off the wire.
min_confidencef64Lower bound on the per-structure confidence for emission. The classifier downgrades confidence on inexact size matches, irregular strike spacing, or partial leg sets. Default 0.5 — emit when the structure is at least equiprobable with a noise-pair coincidence.
max_window_legsusizeMaximum entries kept in the active per-symbol window. Bounds memory growth on a busy underlying. Default 16 — covers every 2-, 3-, and 4-leg structure with headroom for interleaved single-leg flow.

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().multi_leg_detector(["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()
  .multiLegDetector(["QQQ"])
  .onEvent((tick) => {
    console.log(tick);
  });

Rust

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

use kairos::{Client, MultiLegDetectorRow};

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

let sub = client
    .live()
    .multi_leg_detector(["QQQ"])
    .on_event(|row: &MultiLegDetectorRow| println!("structure={:?}", row.structure_kind))?;

// ... later, to stop delivery ...
sub.unsubscribe();
# Ok(())
# }

Proprietary. All rights reserved.