Appearance
OFI
Family: Microstructure
What it computes
Emits OfiTick ticks carrying ofi_window, ofi_session, bid / ask pressure off quote tape.
Available on the live, historical, and replay drives.
Methodology
Cont-Kukanov-Stoikov (2014) NBBO-event imbalance.
See the methodology overview for the citation index.
Inputs
Quote tape.
Key outputs
Ofi_window, ofi_session, bid / ask pressure. The full field set is in the tick table below.
Output schema (OfiTick)
The field / type / description table below is regenerated from the OfiTick 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 — the symbol is the full user-facing identity. |
date | i32 | Trading-session date (YYYYMMDD). |
ms_of_day | i32 | Milliseconds since midnight at emission time. |
ofi_window | f64 | Cont-Stoikov OFI summed across every admitted NBBO update inside the trailing window_ms horizon. Positive = net buying pressure; negative = net selling pressure. |
ofi_session_cumulative | f64 | Session-cumulative OFI since the first admitted NBBO update of the active trading session. Resets on date rollover. |
bid_pressure | f64 | Bid-side contribution summed across the rolling window — the positive Cont-Stoikov leg before the mirror subtraction. |
ask_pressure | f64 | Ask-side contribution summed across the rolling window under the mirrored sign convention (positive = sellers pulled). |
n_events_in_window | i32 | Number of admitted NBBO events currently inside the window. |
Configuration (OfiParams)
Regenerated from the OfiParams Rust source — see the note above.
| Field | Type | Description |
|---|---|---|
contracts | SecurityFilter | Contracts the subscription tracks. OFI runs off the stock NBBO stream — the filter must resolve to stock contracts. |
conditions | ConditionPolicy | Trade-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. |
venues | ExchangeFilter | Exchange / venue admission policy. |
window_ms | i32 | Rolling-window length in milliseconds. Defaults to [DEFAULT_WINDOW_MS] (60_000 ms). |
min_emit_interval_ms | i32 | Minimum interval between consecutive emissions per symbol, in milliseconds. Defaults to [DEFAULT_MIN_EMIT_INTERVAL_MS] (1_000 ms). Set to 0 to surface every NBBO admission. |
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().ofi(["SPX"]).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()
.ofi(["SPX"])
.onEvent((tick) => {
console.log(tick);
});Rust
rust
// Cargo.toml:
// kairos = "0.1"
use kairos::{Client, OfiRow};
# fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::connect(("me@example.com", "secret"))?;
let sub = client
.live()
.ofi(["SPX"])
.on_event(|row: &OfiRow| println!("ofi_window={} session={}", row.ofi_window, row.ofi_session_cumulative))?;
// ... later, to stop delivery ...
sub.unsubscribe();
# Ok(())
# }