UNPKG

kestrel.markets

Version:

A typed, token-efficient language + runtime for agentic trading: agents author bounded plans, the runtime fires them at the tick. CLI + typed library + MCP server.

72 lines 5.44 kB
/** * # session/market-pane — the acting frame's market pane + its `@fair` chain column * * The date-blind MARKET half of every frame the Simulate driver ({@link import("./simulate.ts")}) serves: * spot/levels/tape + the option chain, with the chain's `fair` column priced through the SAME pure * {@link import("../fair/index.ts").executionFair} the fill engine prices `@fair` with. Extracted from the * driver so the pane projection lives beside its own small interface. * * - {@link marketPaneOf} — `(AuthorFrame, instrument, options?, fairCtx?) → MarketPane`; * - {@link chainLegFair} / {@link ChainFairContext} — ExecutionFair for ONE near-money chain leg; * - {@link buildFrameOptions} / {@link OptionsOverlayConfig} — the perception arm's live `market.options`, * folded causally to a frame cutoff and relabeled date-blind ({@link dateBlindOptions}). * * PURE + injected-time: no wall clock, no RNG. Every projection is a byte-identical function of its * inputs; the `fair` column is intrinsic-floored with a receipt or `—` (fail-closed — NEVER a fabricated * fair, a silent mid is forbidden, RUNTIME §4), and the options fold reads only the causal ≤-cutoff * prefix (no look-ahead) and relabels expiry DATE labels to relative-day tags before any token reaches * the date-blind agent frame. */ import type { BusEvent } from "../bus/index.ts"; import type { MarketPane } from "../frame/types.ts"; import { type OptionsAnalytics } from "../frame/options-analytics.ts"; import type { AuthorFrame } from "./day.ts"; import type { FairTauProvider } from "./clock.ts"; /** The perception arm's options-analytics overlay input (kestrel-4gl.13.13). Its presence is the * config gate that populates `market.options` in the live frame; absent ⇒ the minimal arm (no * options panes, no fold). The projection is a PURE function of the overlay events folded to the * frame cutoff (no wall clock, no RNG), with the MODEL honesty (stale-spot → UNKNOWN taint) intact. */ export interface OptionsOverlayConfig { /** A RE-READABLE source of the OPRA options-overlay tape (SPOT + BOOK events). The driver folds it * ONCE per frame cutoff (a lazy generator that breaks at the cutoff reads only the causal prefix), * so this MUST be re-iterable — pass a thunk (e.g. `() => readBusFile(path)`), not a spent iterator. */ readonly events: () => Iterable<BusEvent>; /** `${expiry}:${strike}:${right}` → open interest, from the OI sidecar via `openInterestMap`. */ readonly openInterest: ReadonlyMap<string, number>; /** Expiry label → close epoch-ms (the caller computes it from the session's calendar; the projection * only ever diffs it vs the cutoff to derive tau/dte durations, and the label never reaches the * agent — it is relabeled to a relative-day tag at the frame boundary). */ readonly expiryCloseTs: ReadonlyMap<string, number>; /** Per-contract multiplier (default 100). */ readonly multiplier?: number; /** Staleness backstop in ms: a spot older than this at the cutoff taints the GEX pane (default 120_000). */ readonly staleMs?: number; } /** The fair-pricing context {@link marketPaneOf} anchors the chain `fair` column on (kestrel-121): the * injected time-to-expiry resolver (`fairTauYears`) + the frame cutoff `nowTs` it is evaluated at — the * SAME `(fairTauYears, cutoffTs)` the fill engine prices `@fair` through (`sim.ts` `fairFor`). Absent ⇒ * the chain `fair` stays `—` (byte-identical to a pre-fair frame). */ export interface ChainFairContext { readonly tauYears: FairTauProvider; readonly nowTs: number; /** kestrel-wcnd: the chain's OWN expiry token (`BookState.expiry` — an ISO date or `0dte`), the * 2nd argument τ is resolved against. Sourced from the RAW snapshot's chain, NOT from the frame * (the frame is date-blind by construction and carries only a relative `dte`), and it never * reaches the author — it feeds the pricer, and the chain header still renders the relative tag. * Absent / unresolvable ⇒ τ is `null` ⇒ `fair` renders `—` (fail-closed, never a same-day guess). */ readonly expiry?: string; } /** The width (minutes) this driver's market pane serves tape rows at — CONSTANT for a session (each * `af.tape` sample is one 1-minute single-sample bucket). Named ONCE so `marketPaneOf` (which stamps it * onto every frame's `market.tapeBucketMin`) and the schedule-time View validator (`scheduleTimeViewDefect`, * which checks a `tape <window>` arg against it via `windowServableBy`) read the SAME width — the two can * never drift (kestrel-wa0j.19 §1). */ export declare const SERVED_TAPE_BUCKET_MIN = 1; export declare function marketPaneOf(af: AuthorFrame, instrument: string, options?: OptionsAnalytics, fairCtx?: ChainFairContext): MarketPane; /** Fold the options overlay to `cutoffTs` (causal, no look-ahead) and build the date-blind * options-analytics projection for one live frame. Returns `undefined` when nothing folds (an empty / * pre-open cutoff) — the pane then fails closed on its own. Pure over (overlay events ≤ cutoffTs, * config): no wall clock, no RNG, and the MODEL honesty (stale-spot → UNKNOWN) rides in * {@link buildOptionsAnalytics}. */ export declare function buildFrameOptions(cfg: OptionsOverlayConfig, cutoffTs: number): OptionsAnalytics | undefined; //# sourceMappingURL=market-pane.d.ts.map