@orangecharts/wrun-chart-host 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +13 -5
  2. package/dist/constants/marketCapabilities.constants.d.ts +5 -0
  3. package/dist/constants/marketCapabilities.constants.js +16 -0
  4. package/dist/host-ports.types.d.ts +35 -3
  5. package/dist/index.d.ts +11 -1
  6. package/dist/index.js +11 -1
  7. package/dist/indicators/controls/tpo-session.util.js +42 -18
  8. package/dist/market-data/billing.interface.d.ts +2 -1
  9. package/dist/settings-templates/indicator-fields.js +10 -0
  10. package/dist/utility/chart/crypto-index.leaf.d.ts +16 -0
  11. package/dist/utility/chart/crypto-index.leaf.js +19 -0
  12. package/dist/utility/chart/index-mode-admission.util.js +9 -1
  13. package/dist/utility/chart/index-mode.util.d.ts +11 -5
  14. package/dist/utility/chart/index-mode.util.js +22 -10
  15. package/dist/utility/chart/kscript-source-answer-budget.leaf.d.ts +36 -0
  16. package/dist/utility/chart/kscript-source-answer-budget.leaf.js +39 -0
  17. package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +38 -1
  18. package/dist/utility/chart/kscript-source-degrade.leaf.js +39 -1
  19. package/dist/utility/chart/live-bucket.util.d.ts +2 -1
  20. package/dist/utility/chart/live-bucket.util.js +47 -15
  21. package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +15 -1
  22. package/dist/utility/chart/local-kscript-warmup-depth.util.js +9 -0
  23. package/dist/utility/chart/market-session-schedule.util.d.ts +3 -1
  24. package/dist/utility/chart/market-session-schedule.util.js +24 -2
  25. package/dist/utility/chart/marketKind.util.d.ts +12 -7
  26. package/dist/utility/chart/marketKind.util.js +15 -5
  27. package/dist/utility/chart/ny-calendar.util.d.ts +104 -0
  28. package/dist/utility/chart/ny-calendar.util.js +346 -0
  29. package/dist/utility/chart/om-panel.util.d.ts +14 -2
  30. package/dist/utility/chart/om-panel.util.js +108 -40
  31. package/dist/utility/chart/rth-session.util.d.ts +10 -7
  32. package/dist/utility/chart/rth-session.util.js +17 -22
  33. package/dist/utility/chart/trading-day.util.js +90 -18
  34. package/dist/utility/chart/us-equities-session.util.js +20 -67
  35. package/dist/utility/chart/wrun-bar-session-facts.util.js +14 -1
  36. package/dist/utility/common/time.util.d.ts +7 -1
  37. package/dist/utility/common/time.util.js +11 -41
  38. package/dist/utility/number-format.util.d.ts +17 -7
  39. package/dist/utility/number-format.util.js +18 -8
  40. package/dist/utility/options/option-symbol.util.js +13 -2
  41. package/dist/utility/symbol-selection/contract-expiry.util.js +9 -1
  42. package/dist/utility/watchlist/import/import-request.leaf.d.ts +4 -1
  43. package/dist/utility/watchlist/import/import-request.leaf.js +5 -2
  44. package/dist/utility/watchlist/import/tradingview-symbols.leaf.d.ts +25 -4
  45. package/dist/utility/watchlist/import/tradingview-symbols.leaf.js +62 -4
  46. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +19 -0
  47. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +57 -0
  48. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +23 -0
  49. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +90 -0
  50. package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.d.ts +39 -0
  51. package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.js +60 -0
  52. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +77 -0
  53. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +195 -0
  54. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +56 -0
  55. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +70 -0
  56. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +53 -0
  57. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +239 -0
  58. package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +16 -0
  59. package/dist/utility/wrun/sources/lanes/option_stats_10m.js +14 -0
  60. package/dist/utility/wrun/sources/lanes/options_flow.d.ts +43 -18
  61. package/dist/utility/wrun/sources/lanes/options_flow.js +209 -72
  62. package/dist/utility/wrun/sources/lanes/token_supply.js +5 -31
  63. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +3 -18
  64. package/dist/utility/wrun/sources/opra-option-lanes.util.js +12 -57
  65. package/dist/utility/wrun/sources/row-lane-registry.d.ts +1 -1
  66. package/dist/utility/wrun/sources/row-lane-registry.js +22 -8
  67. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +61 -0
  68. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +103 -8
  69. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +5 -0
  70. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +24 -12
  71. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +55 -0
  72. package/dist/utility/wrun/sources/row-lanes/option_prints.js +95 -18
  73. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +15 -1
  74. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +23 -8
  75. package/dist/utility/wrun/sources/row-lanes/option_surface.js +11 -11
  76. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +14 -2
  77. package/dist/utility/wrun/sources/wrun-poll-lane.types.js +6 -3
  78. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +43 -8
  79. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +77 -11
  80. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +31 -16
  81. package/dist/utility/wrun/sources/wrun-row-lane.types.js +2 -0
  82. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +52 -12
  83. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +110 -46
  84. package/dist/utility/wrun/wrun-browser-sources.leaf.d.ts +10 -0
  85. package/dist/utility/wrun/wrun-browser-sources.leaf.js +12 -0
  86. package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +3 -3
  87. package/dist/utility/wrun/wrun-coin-lane-live.util.js +53 -18
  88. package/dist/utility/wrun/wrun-color-settings.util.d.ts +6 -0
  89. package/dist/utility/wrun/wrun-color-settings.util.js +45 -0
  90. package/dist/utility/wrun/wrun-draft-overlay.util.js +14 -8
  91. package/dist/utility/wrun/wrun-failure-cause.d.ts +1 -1
  92. package/dist/utility/wrun/wrun-failure-cause.js +14 -0
  93. package/dist/utility/wrun/wrun-frames.js +6 -2
  94. package/dist/utility/wrun/wrun-host.service.d.ts +26 -18
  95. package/dist/utility/wrun/wrun-host.service.js +49 -52
  96. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +1 -1
  97. package/dist/utility/wrun/wrun-hosted-wire-caps.js +2 -0
  98. package/dist/utility/wrun/wrun-input-requirements.leaf.js +7 -4
  99. package/dist/utility/wrun/wrun-kit-run-tables.util.d.ts +24 -0
  100. package/dist/utility/wrun/wrun-kit-run-tables.util.js +87 -0
  101. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +2 -1
  102. package/dist/utility/wrun/wrun-live-tick.util.d.ts +8 -2
  103. package/dist/utility/wrun/wrun-live-tick.util.js +35 -16
  104. package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +40 -13
  105. package/dist/utility/wrun/wrun-opra-flow.leaf.js +39 -12
  106. package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +70 -21
  107. package/dist/utility/wrun/wrun-option-contract-flow.util.js +257 -112
  108. package/dist/utility/wrun/wrun-option-prints.util.d.ts +62 -22
  109. package/dist/utility/wrun/wrun-option-prints.util.js +148 -46
  110. package/dist/utility/wrun/wrun-option-views.util.d.ts +262 -0
  111. package/dist/utility/wrun/wrun-option-views.util.js +356 -0
  112. package/dist/utility/wrun/wrun-options-chain.util.d.ts +23 -2
  113. package/dist/utility/wrun/wrun-options-chain.util.js +37 -3
  114. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +18 -3
  115. package/dist/utility/wrun/wrun-overlay-drivers.util.js +32 -7
  116. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +9 -3
  117. package/dist/utility/wrun/wrun-overlay-recovery.util.js +146 -18
  118. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +50 -6
  119. package/dist/utility/wrun/wrun-overlay-run.util.js +816 -243
  120. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +5 -0
  121. package/dist/utility/wrun/wrun-pin-spelling.util.js +28 -12
  122. package/dist/utility/wrun/wrun-pin-venues.util.js +4 -6
  123. package/dist/utility/wrun/wrun-present-bits.util.d.ts +9 -0
  124. package/dist/utility/wrun/wrun-present-bits.util.js +39 -0
  125. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +3 -2
  126. package/dist/utility/wrun/wrun-refusal-surface.util.js +5 -4
  127. package/dist/utility/wrun/wrun-refusal.util.d.ts +66 -6
  128. package/dist/utility/wrun/wrun-refusal.util.js +335 -40
  129. package/dist/utility/wrun/wrun-source-rows.util.js +11 -0
  130. package/dist/utility/wrun/wrun-tier-grid.util.d.ts +28 -3
  131. package/dist/utility/wrun/wrun-tier-grid.util.js +79 -19
  132. package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +14 -3
  133. package/dist/utility/wrun/wrun-transient-rerun.util.js +33 -8
  134. package/package.json +5 -5
  135. package/dist/utility/wrun/wrun-opra-underlying.util.d.ts +0 -12
  136. package/dist/utility/wrun/wrun-opra-underlying.util.js +0 -1
@@ -1,4 +1,4 @@
1
- import type { WrunRowLaneHorizon } from './sources/wrun-row-lane.types.js';
1
+ import { type WrunRowLaneHorizon } from './sources/wrun-row-lane.types.js';
2
2
  /** The gateway type the class reads, by name (the protocol package names it from its release). */
3
3
  export declare const WRUN_OPTION_PRINT_TYPE = "OPTION_PRINT";
4
4
  /** f64s per tuple, the `present` mask included. */
@@ -30,6 +30,14 @@ export declare const WRUN_OPTION_PRINT_BIT: Readonly<{
30
30
  readonly quote: 3;
31
31
  readonly forward: 4;
32
32
  }>;
33
+ /**
34
+ * The payload fields an instance names its chain in (the lane's acquisition, and the K control's request to the worker
35
+ * twin under the same names): the exchange the chain lists on (its plane follows it), the ONE book when it is not the
36
+ * underlying's own series, and the continuous alias a CME chain was read off (its lead contract is `coin`).
37
+ */
38
+ export declare const WRUN_OPTION_PRINTS_EXCHANGE_FIELD = "printExchange";
39
+ export declare const WRUN_OPTION_PRINTS_BOOK_FIELD = "printBook";
40
+ export declare const WRUN_OPTION_PRINTS_CONTINUOUS_FIELD = "printContinuous";
33
41
  /** The large-print floors the gateway copies prints into `option_print_large` by (its write and read charts). */
34
42
  export declare const WRUN_OPTION_PRINT_LARGE_MIN_PREMIUM = 25000;
35
43
  export declare const WRUN_OPTION_PRINT_LARGE_MIN_CONTRACTS = 150;
@@ -46,9 +54,15 @@ export declare const WRUN_OPTION_PRINTS_HISTORY: readonly ["live", "3d", "90d"];
46
54
  export type WrunOptionPrintsHistory = (typeof WRUN_OPTION_PRINTS_HISTORY)[number];
47
55
  export declare const WRUN_OPTION_PRINTS_OVERFLOW: readonly ["refuse", "largest"];
48
56
  export type WrunOptionPrintsOverflow = (typeof WRUN_OPTION_PRINTS_OVERFLOW)[number];
49
- /** The acquisition an `option_prints` instance asks with (its payload's facets and identity). */
57
+ /** The acquisition an `option_prints` instance asks with (its payload's facets and its chain). */
50
58
  export interface WrunOptionPrintsAcquisition {
59
+ /** The chain's underlying, upper case: the key its plane files the prints under (the OPRA ticker, a crypto venue's
60
+ * root coin, the CME futures contract). */
51
61
  coin: string;
62
+ /** The exchange the chain lists on, upper case ('' when the payload names none: no read is served then). */
63
+ exchange: string;
64
+ /** The ONE book read, upper case: the payload's book, else the underlying's own series. */
65
+ book: string;
52
66
  minPremium: number;
53
67
  history: WrunOptionPrintsHistory;
54
68
  overflow: WrunOptionPrintsOverflow;
@@ -57,8 +71,15 @@ export interface WrunOptionPrintsAcquisition {
57
71
  }
58
72
  /** An instance's payload as the acquisition it carries, or undefined when it names no valid floor or history. */
59
73
  export declare function wrunOptionPrintsAcquisitionOf(extras: Readonly<Record<string, unknown>> | null | undefined): WrunOptionPrintsAcquisition | undefined;
60
- /** Whether a payload is an `option_prints` lane ask the K control serves: it names the OPRA plane and an
61
- * acquisition with a coin (a source asked any other way is declined, fail closed). */
74
+ /**
75
+ * Whether a payload's OPRA stamp agrees with the chain it names, the print classes' one rule for a K control: the
76
+ * payload names its chain's exchange, and it carries the stamp (`wrunPlane: 'opra'`, which Door C judged) exactly when
77
+ * that exchange rides the OPRA plane. An OPRA chain asked without the stamp, or a stamp on another plane's chain, is
78
+ * declined (fail closed).
79
+ */
80
+ export declare function wrunOptionChainAskStampHolds(payload: Readonly<Record<string, unknown>> | null | undefined, exchange: string): boolean;
81
+ /** Whether a payload is an `option_prints` lane ask the K control serves: an acquisition with a coin and a chain whose
82
+ * OPRA stamp holds (`wrunOptionChainAskStampHolds`); any other is declined, fail closed. */
62
83
  export declare function isWrunOptionPrintsAsk(payload: Readonly<Record<string, unknown>> | null | undefined): boolean;
63
84
  /** Whether the reader serves this floor from the large-print table (and so reaches back as far as it). */
64
85
  export declare function wrunOptionPrintsReadsLargeTable(minPremium: number): boolean;
@@ -78,10 +99,11 @@ export interface WrunOptionPrintRead {
78
99
  minAmount?: number;
79
100
  }
80
101
  /**
81
- * The reads a window needs at an acquisition's floor: one read at the floor (the reader picks the table), except a
82
- * "90d" floor below the large floor, whose part older than the raw table's 3 days reads `option_print_large` twice,
83
- * the large premiums (`minQuoteAmount` 25,000) and the large sizes at the floor (`minAmount` 150 with the floor), so
84
- * the two together are every large print at or above the floor (a print in both is merged by its id).
102
+ * The reads a window needs at an acquisition's floor on its chain's plane (`exchange`): one read at the floor (the
103
+ * reader picks the table), except a "90d" floor below the large floor, whose part older than the raw table's 3 days
104
+ * reads `option_print_large`: the large premiums (`minQuoteAmount` 25,000) and, on a plane whose large table also
105
+ * keeps large sizes (OPRA and CME), those at the floor (`minAmount` 150 with the floor), so the reads together are every
106
+ * large print at or above the floor (a print in both is merged by its id).
85
107
  */
86
108
  export declare function wrunOptionPrintReads(args: {
87
109
  fromMs: number;
@@ -89,6 +111,7 @@ export declare function wrunOptionPrintReads(args: {
89
111
  minPremium: number;
90
112
  history: WrunOptionPrintsHistory;
91
113
  nowMs: number;
114
+ exchange: string;
92
115
  }): WrunOptionPrintRead[];
93
116
  /** The print key of an id: its FNV-1a 64 hash, cut to the low 53 bits (an exact f64). Two 32-bit words, every
94
117
  * product below 2^42, so the arithmetic is exact in doubles. */
@@ -101,35 +124,52 @@ export declare function wrunOptionPrintDrops(): Readonly<Record<WrunOptionPrintD
101
124
  export declare function __resetWrunOptionPrintDropsForTest(): void;
102
125
  /** The print's time in ms off its Timestamp (whole seconds plus the milliseconds of its nanoseconds). */
103
126
  export declare function wrunOptionPrintTimeMs(timestamp: unknown): number;
104
- /** OptionPrintSide (NONE 0, ASK 1, BID 2, MID 3; a JSON reading names it) as the tuple's aggressor. */
127
+ /** OptionPrintSide (NONE 0, ASK 1, BID 2, MID 3; a JSON reading names it) as the tuple's aggressor: on a crypto venue
128
+ * and CME the taker side rides ASK (a taker buy) and BID (a taker sell), never MID. */
105
129
  export declare function wrunOptionPrintAggressor(side: unknown): 1 | -1 | 0 | 2;
106
- /** A contract's OSI symbol read once (a chain's prints repeat a few thousand symbols): its root's code (undefined
107
- * for a root the codec refuses) and its side. Bounded: cleared whole past `CONTRACT_CACHE_MAX` symbols. */
130
+ /** A contract's raw symbol read once (a chain's prints repeat a few thousand symbols, a read up to 500,000 rows): its
131
+ * root's code (undefined for a root the codec refuses) and its side, by venue then symbol. Bounded: cleared whole
132
+ * past `CONTRACT_CACHE_MAX` symbols. */
108
133
  interface WrunOptionContract {
109
134
  rootCode: number | undefined;
110
135
  side: 'call' | 'put';
111
136
  }
112
- /** The contract an OSI symbol names (its root's code and side), or null for no OPRA contract symbol. */
113
- export declare function wrunOptionContractOf(symbol: string): WrunOptionContract | null;
114
- /** One print, tupled: its time and the knob facts the filters read beside the tuple (`offset_ms` 0 until landed). */
137
+ /**
138
+ * The contract a raw symbol names on an exchange (its root's code and side), parsed by the venue of the exchange (the
139
+ * pane options-flow worker's parse: `optionVenueForExchange`, then the venue's own symbol shape), or null for a symbol
140
+ * that venue does not spell, and for an exchange that is no options venue.
141
+ */
142
+ export declare function wrunOptionContractOf(exchange: string, symbol: string): WrunOptionContract | null;
143
+ /** One print, tupled: its time, its contract's exchange and raw symbol (its book), and the knob facts the filters read
144
+ * beside the tuple (`offset_ms` 0 until landed). */
115
145
  export interface WrunOptionPrint {
116
146
  id: string;
117
147
  tsMs: number;
118
- /** The expiry's New York date minus the print's (0 on expiration day; the feed's JSON omits a zero). */
148
+ /** The exchange the print's series names, upper case. */
149
+ exchange: string;
150
+ /** The contract's raw symbol, as the series names it (its book is the series it spells). */
151
+ symbol: string;
152
+ /** The expiry's trade date minus the print's, on the market's own clock (the producer's: 0 on expiration day; the
153
+ * feed's JSON omits a zero). */
119
154
  dteDays: number | undefined;
120
155
  premium: number;
121
156
  tuple: number[];
122
157
  }
123
158
  /**
124
- * One OPRA print as the class's tuple, from the history shape (a reshaped protobuf-es message: int64 as bigint,
125
- * enums as ids, unset optionals undefined) or the live shape (the feed's JSON: int64 as strings, enums as names,
126
- * unset optionals omitted), so the two paths build the same tuple for the same print. `series` is the point's
127
- * series (the contract: its OSI symbol, the underlying as coin, the option type). A print missing its id, time or
128
- * contract, or whose root the codec refuses, is dropped and counted.
159
+ * One print as the class's tuple, from the history shape (a reshaped protobuf-es message: int64 as bigint, enums as
160
+ * ids, unset optionals undefined) or the live shape (the feed's JSON: int64 as strings, enums as names, unset optionals
161
+ * omitted), so the two paths build the same tuple for the same print. `series` is the point's series (the contract:
162
+ * its exchange, by name or pb-common id, its raw symbol, the option type). A print missing its id, time or contract (a
163
+ * series naming no exchange, or a symbol its venue does not spell), or whose root the codec refuses, is dropped and
164
+ * counted.
129
165
  */
130
166
  export declare function wrunOptionPrintOf(print: Readonly<Record<string, unknown>> | null | undefined, series: Readonly<Record<string, unknown>> | null | undefined): WrunOptionPrint | WrunOptionPrintDrop;
131
- /** Whether a print passes an acquisition's own filters: its floor, and "0dte" (expiring on the print's trade date). */
132
- export declare function wrunOptionPrintKept(print: WrunOptionPrint, acquisition: WrunOptionPrintsAcquisition): boolean;
167
+ /**
168
+ * Whether a print passes an acquisition's own filters, on history and live alike: its chain (the print's exchange is
169
+ * the chain's, and its book, the series its raw symbol spells, is the ONE book the acquisition reads: two books of one
170
+ * coin never merge), its floor, and "0dte" (expiring on the print's trade date, the producer's `dte_days`).
171
+ */
172
+ export declare function wrunOptionPrintKept(print: WrunOptionPrint, acquisition: Pick<WrunOptionPrintsAcquisition, 'coin' | 'exchange' | 'book' | 'minPremium' | 'expiries'>): boolean;
133
173
  /** Whether a cell is a print tuple of the class: exactly 16 finite numbers. */
134
174
  export declare function isWrunOptionPrintTuple(cell: unknown): cell is number[];
135
175
  /** A bar's print tuples in the order they printed: by offset, then by key (two prints in one millisecond). */
@@ -1,37 +1,54 @@
1
1
  /**
2
- * The `option_prints` class (UW-PARITY source contract v2, S3): one 16-value tuple per OPRA print of the chart's
3
- * underlying at or above `min_premium`, on the bar it printed in, history plus live. Pure and light: the row lane
4
- * (`sources/row-lanes/option_prints.ts`), its K control (`K_OPTION_PRINT`) and the worker twin read the same rules
5
- * from here, so history and live build the same tuple for the same print.
2
+ * The `option_prints` class (UW-PARITY source contract v2, S3; on every chain since OPTIONS-PORT P7): one 16-value
3
+ * tuple per print of the chain's ONE book at or above `min_premium`, on the bar it printed in, history plus live. Pure
4
+ * and light: the row lane (`sources/row-lanes/option_prints.ts`), its K control (`K_OPTION_PRINT`) and the worker twin
5
+ * read the same rules from here, so history and live build the same tuple for the same print.
6
6
  *
7
7
  * The tuple: `[offset_ms, print_key, root_code, expiry_ms, side_cp, strike, price, size, premium, aggressor, outside,
8
- * underlying, iv, delta, venue, present]`.
8
+ * underlying, iv, delta, venue, present]`, in the units the producer stores on the chain's plane (OPTIONS-PORT C7-3; no
9
+ * conversion here):
9
10
  * - `offset_ms`: the print's time minus the host bar's open (the landing re-bases it; the worker keys a print by its
10
11
  * second, its offset the milliseconds inside it).
11
12
  * - `print_key`: the print id's FNV-1a 64 hash cut to its low 53 bits, the same on history and live (the reconcile
12
- * merges by it). The id is `<publisher>-<ts_event ns>-<symbol>-<price>-<size>-<k>` (the OptionPrint proto).
13
- * - `root_code`: `encodeSymbol(root)` of the contract's OSI root; a root the codec refuses drops the print and is
14
- * counted (`wrunOptionPrintDrops`), never a made-up code.
15
- * - `side_cp` +1 call, -1 put; `aggressor` +1 ask, -1 bid, 0 mid, 2 none (the print against the NBBO midpoint);
16
- * `outside` +1 above the ask, -1 below the bid, 0 inside (0 with no quote); `venue` the publisher id.
17
- * - `present` bits: 0 iv, 1 delta, 2 underlying, 3 the quote was valid (bid and ask set, above 0, not crossed: the
18
- * producer's own rule, so the side is not NONE), 4 the underlying is a forward, 14 the bar is partial.
13
+ * merges by it). The id is `<publisher>-<ts_event ns>-<symbol>-<price>-<size>-<k>` on OPRA and
14
+ * `<EXCHANGE>-<venue trade id>` on every other plane (the OptionPrint proto, contract C2).
15
+ * - `root_code`: `encodeSymbol(root)` of the contract's root, its raw symbol parsed by the venue of the print's exchange
16
+ * (an OSI root on OPRA, a crypto venue's root coin, a CME futures root); a symbol its venue does not spell and a root
17
+ * the codec refuses drop the print and are counted (`wrunOptionPrintDrops`), never a made-up code.
18
+ * - `price` in USD per unit of the underlying (a share on OPRA, a coin on a crypto chain, an index point on CME),
19
+ * `size` in contracts on OPRA and CME and in coin on a crypto chain, `premium` in USD on every plane.
20
+ * - `side_cp` +1 call, -1 put; `aggressor` +1 buyer, -1 seller, 0 mid, 2 none (on OPRA the print against the NBBO
21
+ * midpoint; on a crypto venue and CME the venue's taker side, never mid); `outside` +1 above the ask, -1 below the
22
+ * bid, 0 inside (0 with no quote, so 0 off OPRA); `underlying` the price the print was made against (OPRA's
23
+ * underlying, a crypto venue's index, the CME future); `venue` the Databento publisher id on OPRA, and off it one id
24
+ * per chain, the pb-common `Exchange` id of the print's exchange (the wire's `venue` reads 0 there, contract C7).
25
+ * - `present` bits: 0 iv, 1 delta, 2 underlying, 3 the side is known (on OPRA the quote was valid: bid and ask set,
26
+ * above 0, not crossed, the producer's own rule; elsewhere the venue named the taker), 4 the underlying is a forward,
27
+ * 14 the bar is partial.
19
28
  *
20
- * The backend (tsdb-gateway `pkg/tsdb/selects/option_print.go`): OPTION_PRINT is read by underlying (`coin`) from
21
- * `option_print` (every print, kept 3 days) or, when the read's own floor reaches a large-print floor (premium
22
- * >= 25,000 USD as `minQuoteAmount`, or size >= 150 contracts as `minAmount`), from `option_print_large` (those
23
- * prints, kept 90 days). The floors AND. An unaggregated read is held to the gateway's bar limit (one point a minute,
24
- * 15,000 on every tier: about 10.4 days back), trimmed without a word.
29
+ * The backend (tsdb-gateway `pkg/tsdb/selects/option_print.go`): OPTION_PRINT is read by the chain's exchange and its
30
+ * underlying (`coin`), every book of the underlying in one answer, so the ONE book is kept here (a print's book is the
31
+ * series its raw symbol spells, opra-option-lanes.util `wrunOptionSeriesOf`), from `option_print` (every print, kept 3
32
+ * days) or, when the read's own floor reaches a large-print floor of its plane, from `option_print_large` (those
33
+ * prints, kept 90 days): premium >= 25,000 USD (`minQuoteAmount`) on every plane, or size >= 150 contracts
34
+ * (`minAmount`) on OPRA and CME; a crypto chain has no size floor (its sizes are in coin, decision D-P7). The floors
35
+ * AND. An unaggregated read is held to the gateway's bar limit (one point a minute, 15,000 on every tier: about 10.4
36
+ * days back), trimmed without a word.
25
37
  *
26
38
  * `history` (om's words): "live" (the default) the live channel plus the history the run needs for the visible bars,
27
39
  * read at the input's floor from whichever table the reader picks for it; "3d" every print of the last three days;
28
- * "90d" up to 90 days of the large prints (premium 25,000 or size 150 and up): below the large floor an older bar
29
- * holds only those and is partial.
40
+ * "90d" up to 90 days of the large prints (premium 25,000, or size 150 on OPRA and CME, and up): below the large floor
41
+ * an older bar holds only those and is partial.
30
42
  */
43
+ import { Exchange } from '@orangecharts/orange-v2-pb-common';
31
44
  import { parseOptionSymbol } from '../options/option-symbol.util.js';
45
+ import { optionVenueForExchange } from '../options/option-venue.util.js';
32
46
  import { WRUN_PLANE_PAYLOAD_KEY } from '../chart/opra-read-access.leaf.js';
47
+ import { exchangeCodeOf } from '../v2/gate-plane.util.js';
33
48
  import { wrunPresentMaskOf, wrunPresentWithPartial } from './wrun-present-bits.util.js';
34
49
  import { encodeSymbol } from './wrun-symbol-code.util.js';
50
+ import { wrunOptionSeriesOf } from './sources/opra-option-lanes.util.js';
51
+ import { wrunLaneChainPlaneOf } from './sources/wrun-row-lane.types.js';
35
52
  /** The gateway type the class reads, by name (the protocol package names it from its release). */
36
53
  export const WRUN_OPTION_PRINT_TYPE = 'OPTION_PRINT';
37
54
  /** f64s per tuple, the `present` mask included. */
@@ -57,9 +74,24 @@ export const WRUN_OPTION_PRINT_COLUMN = Object.freeze({
57
74
  });
58
75
  /** The `present` bits by name (14, the partial bar, is the shared one). */
59
76
  export const WRUN_OPTION_PRINT_BIT = Object.freeze({ iv: 0, delta: 1, underlying: 2, quote: 3, forward: 4 });
77
+ /**
78
+ * The payload fields an instance names its chain in (the lane's acquisition, and the K control's request to the worker
79
+ * twin under the same names): the exchange the chain lists on (its plane follows it), the ONE book when it is not the
80
+ * underlying's own series, and the continuous alias a CME chain was read off (its lead contract is `coin`).
81
+ */
82
+ export const WRUN_OPTION_PRINTS_EXCHANGE_FIELD = 'printExchange';
83
+ export const WRUN_OPTION_PRINTS_BOOK_FIELD = 'printBook';
84
+ export const WRUN_OPTION_PRINTS_CONTINUOUS_FIELD = 'printContinuous';
60
85
  /** The large-print floors the gateway copies prints into `option_print_large` by (its write and read charts). */
61
86
  export const WRUN_OPTION_PRINT_LARGE_MIN_PREMIUM = 25_000;
62
87
  export const WRUN_OPTION_PRINT_LARGE_MIN_CONTRACTS = 150;
88
+ /** The size floor of the large-print table on each plane: the contracts floor on the cme deployment (OPRA and CME),
89
+ * none on ore, whose crypto sizes are in coin (a contract count means nothing across coins: decision D-P7). */
90
+ const WRUN_OPTION_PRINT_LARGE_MIN_SIZE = Object.freeze({
91
+ opra: WRUN_OPTION_PRINT_LARGE_MIN_CONTRACTS,
92
+ cme: WRUN_OPTION_PRINT_LARGE_MIN_CONTRACTS,
93
+ plain: undefined,
94
+ });
63
95
  const DAY_MS = 86_400_000;
64
96
  /** `option_print` keeps every print 3 days; `option_print_large` the large ones 90. */
65
97
  export const WRUN_OPTION_PRINT_RAW_RETENTION_MS = 3 * DAY_MS;
@@ -72,6 +104,10 @@ export const WRUN_OPTION_PRINT_BAR_LIMIT_MS = 15_000 * 60_000;
72
104
  export const WRUN_OPTION_PRINT_CLOCK_MARGIN_MS = 10 * 60_000;
73
105
  export const WRUN_OPTION_PRINTS_HISTORY = Object.freeze(['live', '3d', '90d']);
74
106
  export const WRUN_OPTION_PRINTS_OVERFLOW = Object.freeze(['refuse', 'largest']);
107
+ /** A payload field's text, trimmed and upper case ('' for anything else). */
108
+ function upperTextOf(value) {
109
+ return typeof value === 'string' ? value.trim().toUpperCase() : '';
110
+ }
75
111
  /** An instance's payload as the acquisition it carries, or undefined when it names no valid floor or history. */
76
112
  export function wrunOptionPrintsAcquisitionOf(extras) {
77
113
  if (!extras)
@@ -85,20 +121,34 @@ export function wrunOptionPrintsAcquisitionOf(extras) {
85
121
  return undefined;
86
122
  if (!WRUN_OPTION_PRINTS_OVERFLOW.includes(overflow))
87
123
  return undefined;
88
- const coin = typeof extras.coin === 'string' ? extras.coin : '';
124
+ const coin = upperTextOf(extras.coin);
125
+ const book = upperTextOf(extras[WRUN_OPTION_PRINTS_BOOK_FIELD]);
89
126
  return {
90
127
  coin,
128
+ exchange: upperTextOf(extras[WRUN_OPTION_PRINTS_EXCHANGE_FIELD]),
129
+ book: book !== '' ? book : coin,
91
130
  minPremium,
92
131
  history: history,
93
132
  overflow: overflow,
94
133
  ...(typeof extras.expiries === 'string' ? { expiries: extras.expiries } : {}),
95
134
  };
96
135
  }
97
- /** Whether a payload is an `option_prints` lane ask the K control serves: it names the OPRA plane and an
98
- * acquisition with a coin (a source asked any other way is declined, fail closed). */
136
+ /**
137
+ * Whether a payload's OPRA stamp agrees with the chain it names, the print classes' one rule for a K control: the
138
+ * payload names its chain's exchange, and it carries the stamp (`wrunPlane: 'opra'`, which Door C judged) exactly when
139
+ * that exchange rides the OPRA plane. An OPRA chain asked without the stamp, or a stamp on another plane's chain, is
140
+ * declined (fail closed).
141
+ */
142
+ export function wrunOptionChainAskStampHolds(payload, exchange) {
143
+ if (exchange === '')
144
+ return false;
145
+ return (payload?.[WRUN_PLANE_PAYLOAD_KEY] === 'opra') === (wrunLaneChainPlaneOf(exchange) === 'opra');
146
+ }
147
+ /** Whether a payload is an `option_prints` lane ask the K control serves: an acquisition with a coin and a chain whose
148
+ * OPRA stamp holds (`wrunOptionChainAskStampHolds`); any other is declined, fail closed. */
99
149
  export function isWrunOptionPrintsAsk(payload) {
100
150
  const acquisition = wrunOptionPrintsAcquisitionOf(payload);
101
- return payload?.[WRUN_PLANE_PAYLOAD_KEY] === 'opra' && acquisition !== undefined && acquisition.coin !== '';
151
+ return (acquisition !== undefined && acquisition.coin !== '' && wrunOptionChainAskStampHolds(payload, acquisition.exchange));
102
152
  }
103
153
  /** Whether the reader serves this floor from the large-print table (and so reaches back as far as it). */
104
154
  export function wrunOptionPrintsReadsLargeTable(minPremium) {
@@ -124,10 +174,11 @@ export function wrunOptionPrintsHorizon(extras, nowMs) {
124
174
  return { servedFromMs, completeFromMs: Math.max(wholeFrom, barLimitFrom) };
125
175
  }
126
176
  /**
127
- * The reads a window needs at an acquisition's floor: one read at the floor (the reader picks the table), except a
128
- * "90d" floor below the large floor, whose part older than the raw table's 3 days reads `option_print_large` twice,
129
- * the large premiums (`minQuoteAmount` 25,000) and the large sizes at the floor (`minAmount` 150 with the floor), so
130
- * the two together are every large print at or above the floor (a print in both is merged by its id).
177
+ * The reads a window needs at an acquisition's floor on its chain's plane (`exchange`): one read at the floor (the
178
+ * reader picks the table), except a "90d" floor below the large floor, whose part older than the raw table's 3 days
179
+ * reads `option_print_large`: the large premiums (`minQuoteAmount` 25,000) and, on a plane whose large table also
180
+ * keeps large sizes (OPRA and CME), those at the floor (`minAmount` 150 with the floor), so the reads together are every
181
+ * large print at or above the floor (a print in both is merged by its id).
131
182
  */
132
183
  export function wrunOptionPrintReads(args) {
133
184
  const { fromMs, toMs, minPremium } = args;
@@ -137,11 +188,14 @@ export function wrunOptionPrintReads(args) {
137
188
  return [{ fromMs, toMs, minQuoteAmount: minPremium }];
138
189
  }
139
190
  const rawFrom = args.nowMs - WRUN_OPTION_PRINT_RAW_RETENTION_MS;
191
+ const largeMinSize = WRUN_OPTION_PRINT_LARGE_MIN_SIZE[wrunLaneChainPlaneOf(args.exchange)];
140
192
  const reads = [];
141
193
  if (fromMs < rawFrom) {
142
194
  const end = Math.min(toMs, rawFrom);
143
195
  reads.push({ fromMs, toMs: end, minQuoteAmount: WRUN_OPTION_PRINT_LARGE_MIN_PREMIUM });
144
- reads.push({ fromMs, toMs: end, minQuoteAmount: minPremium, minAmount: WRUN_OPTION_PRINT_LARGE_MIN_CONTRACTS });
196
+ if (largeMinSize !== undefined) {
197
+ reads.push({ fromMs, toMs: end, minQuoteAmount: minPremium, minAmount: largeMinSize });
198
+ }
145
199
  }
146
200
  if (toMs > rawFrom)
147
201
  reads.push({ fromMs: Math.max(fromMs, rawFrom), toMs, minQuoteAmount: minPremium });
@@ -207,7 +261,8 @@ export function wrunOptionPrintTimeMs(timestamp) {
207
261
  const nanos = optionalNumberOf(stamp.nanoseconds) ?? 0;
208
262
  return seconds * 1000 + Math.floor(nanos / 1_000_000);
209
263
  }
210
- /** OptionPrintSide (NONE 0, ASK 1, BID 2, MID 3; a JSON reading names it) as the tuple's aggressor. */
264
+ /** OptionPrintSide (NONE 0, ASK 1, BID 2, MID 3; a JSON reading names it) as the tuple's aggressor: on a crypto venue
265
+ * and CME the taker side rides ASK (a taker buy) and BID (a taker sell), never MID. */
211
266
  export function wrunOptionPrintAggressor(side) {
212
267
  const word = typeof side === 'string' ? side : '';
213
268
  if (side === 1 || word === 'OPTION_PRINT_SIDE_ASK')
@@ -219,33 +274,62 @@ export function wrunOptionPrintAggressor(side) {
219
274
  return 2;
220
275
  }
221
276
  /** The option type (a series' `optionType`: a name, or the enum id PUT 1, CALL 2) as +1 call, -1 put, 0 unknown. */
222
- function sideOf(optionType, osiSide) {
277
+ function sideOf(optionType, symbolSide) {
223
278
  if (optionType === 'CALL' || optionType === 2)
224
279
  return 1;
225
280
  if (optionType === 'PUT' || optionType === 1)
226
281
  return -1;
227
- return osiSide === 'call' ? 1 : osiSide === 'put' ? -1 : 0;
282
+ return symbolSide === 'call' ? 1 : symbolSide === 'put' ? -1 : 0;
228
283
  }
229
284
  const CONTRACT_CACHE_MAX = 50_000;
230
- const contracts = new Map();
231
- /** The contract an OSI symbol names (its root's code and side), or null for no OPRA contract symbol. */
232
- export function wrunOptionContractOf(symbol) {
285
+ const contractsByVenue = new Map();
286
+ let contractsHeld = 0;
287
+ /** The venue id each exchange named so far reads (`optionVenueForExchange`), null for no options venue. */
288
+ const venueIdByExchange = new Map();
289
+ /**
290
+ * The contract a raw symbol names on an exchange (its root's code and side), parsed by the venue of the exchange (the
291
+ * pane options-flow worker's parse: `optionVenueForExchange`, then the venue's own symbol shape), or null for a symbol
292
+ * that venue does not spell, and for an exchange that is no options venue.
293
+ */
294
+ export function wrunOptionContractOf(exchange, symbol) {
295
+ let venueId = venueIdByExchange.get(exchange);
296
+ if (venueId === undefined) {
297
+ venueId = optionVenueForExchange(exchange)?.id ?? null;
298
+ venueIdByExchange.set(exchange, venueId);
299
+ }
300
+ if (venueId === null)
301
+ return null;
302
+ let contracts = contractsByVenue.get(venueId);
303
+ if (contracts === undefined) {
304
+ contracts = new Map();
305
+ contractsByVenue.set(venueId, contracts);
306
+ }
233
307
  const cached = contracts.get(symbol);
234
308
  if (cached !== undefined)
235
309
  return cached;
236
- const parsed = parseOptionSymbol('opra', symbol);
310
+ const parsed = parseOptionSymbol(venueId, symbol);
237
311
  const contract = parsed === null ? null : { rootCode: encodeSymbol(parsed.root), side: parsed.side };
238
- if (contracts.size >= CONTRACT_CACHE_MAX)
239
- contracts.clear();
312
+ if (contractsHeld >= CONTRACT_CACHE_MAX) {
313
+ for (const held of contractsByVenue.values())
314
+ held.clear();
315
+ contractsHeld = 0;
316
+ }
240
317
  contracts.set(symbol, contract);
318
+ contractsHeld += 1;
241
319
  return contract;
242
320
  }
321
+ /** The tuple's `venue` off OPRA: the pb-common `Exchange` id of the print's exchange (NaN for a name it lacks). */
322
+ function exchangeIdOf(exchange) {
323
+ const id = Exchange[exchange];
324
+ return typeof id === 'number' ? id : Number.NaN;
325
+ }
243
326
  /**
244
- * One OPRA print as the class's tuple, from the history shape (a reshaped protobuf-es message: int64 as bigint,
245
- * enums as ids, unset optionals undefined) or the live shape (the feed's JSON: int64 as strings, enums as names,
246
- * unset optionals omitted), so the two paths build the same tuple for the same print. `series` is the point's
247
- * series (the contract: its OSI symbol, the underlying as coin, the option type). A print missing its id, time or
248
- * contract, or whose root the codec refuses, is dropped and counted.
327
+ * One print as the class's tuple, from the history shape (a reshaped protobuf-es message: int64 as bigint, enums as
328
+ * ids, unset optionals undefined) or the live shape (the feed's JSON: int64 as strings, enums as names, unset optionals
329
+ * omitted), so the two paths build the same tuple for the same print. `series` is the point's series (the contract:
330
+ * its exchange, by name or pb-common id, its raw symbol, the option type). A print missing its id, time or contract (a
331
+ * series naming no exchange, or a symbol its venue does not spell), or whose root the codec refuses, is dropped and
332
+ * counted.
249
333
  */
250
334
  export function wrunOptionPrintOf(print, series) {
251
335
  const drop = (reason) => {
@@ -260,8 +344,10 @@ export function wrunOptionPrintOf(print, series) {
260
344
  const tsMs = wrunOptionPrintTimeMs(print.timestamp);
261
345
  if (!Number.isFinite(tsMs))
262
346
  return drop('time');
347
+ // The series names its exchange by name on the feed's JSON, by the pb-common id where a reader kept the enum.
348
+ const exchange = exchangeCodeOf(series?.exchange) ?? '';
263
349
  const symbol = typeof series?.symbol === 'string' ? series.symbol : '';
264
- const contract = symbol === '' ? null : wrunOptionContractOf(symbol);
350
+ const contract = symbol === '' || exchange === '' ? null : wrunOptionContractOf(exchange, symbol);
265
351
  if (contract === null)
266
352
  return drop('contract');
267
353
  if (contract.rootCode === undefined)
@@ -273,7 +359,7 @@ export function wrunOptionPrintOf(print, series) {
273
359
  const price = numberOf(print.price);
274
360
  const size = numberOf(print.size);
275
361
  const premium = numberOf(print.premiumUsd);
276
- const venue = numberOf(print.venue ?? 0);
362
+ const venue = wrunLaneChainPlaneOf(exchange) === 'opra' ? numberOf(print.venue ?? 0) : exchangeIdOf(exchange);
277
363
  if (![expiryMs, strike, price, size, premium, venue].every(Number.isFinite) || sideCp === 0)
278
364
  return drop('value');
279
365
  const aggressor = wrunOptionPrintAggressor(print.side);
@@ -311,10 +397,26 @@ export function wrunOptionPrintOf(print, series) {
311
397
  ];
312
398
  // dte_days is a plain int32: the feed's JSON leaves out a zero (expiration day), so an absent one reads 0.
313
399
  const dteDays = numberOf(print.dteDays ?? 0);
314
- return { id, tsMs, dteDays: Number.isFinite(dteDays) ? dteDays : undefined, premium, tuple };
400
+ return {
401
+ id,
402
+ tsMs,
403
+ exchange,
404
+ symbol,
405
+ dteDays: Number.isFinite(dteDays) ? dteDays : undefined,
406
+ premium,
407
+ tuple,
408
+ };
315
409
  }
316
- /** Whether a print passes an acquisition's own filters: its floor, and "0dte" (expiring on the print's trade date). */
410
+ /**
411
+ * Whether a print passes an acquisition's own filters, on history and live alike: its chain (the print's exchange is
412
+ * the chain's, and its book, the series its raw symbol spells, is the ONE book the acquisition reads: two books of one
413
+ * coin never merge), its floor, and "0dte" (expiring on the print's trade date, the producer's `dte_days`).
414
+ */
317
415
  export function wrunOptionPrintKept(print, acquisition) {
416
+ if (print.exchange !== acquisition.exchange)
417
+ return false;
418
+ if (wrunOptionSeriesOf(acquisition.coin, print.symbol) !== acquisition.book)
419
+ return false;
318
420
  if (!(print.premium >= acquisition.minPremium))
319
421
  return false;
320
422
  return acquisition.expiries !== '0dte' || print.dteDays === 0;