@orangecharts/wrun-chart-host 0.5.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 (157) hide show
  1. package/README.md +17 -8
  2. package/dist/constants/feature-flags.constants.js +7 -2
  3. package/dist/constants/marketCapabilities.constants.d.ts +5 -0
  4. package/dist/constants/marketCapabilities.constants.js +16 -0
  5. package/dist/host-env.d.ts +3 -19
  6. package/dist/host-ports.types.d.ts +36 -17
  7. package/dist/index.d.ts +12 -1
  8. package/dist/index.js +12 -1
  9. package/dist/indicators/controls/tpo-session.util.js +42 -18
  10. package/dist/interfaces/wrun-runtime.interface.d.ts +88 -13
  11. package/dist/interfaces/wrun-runtime.interface.js +17 -3
  12. package/dist/market-data/billing.interface.d.ts +2 -1
  13. package/dist/settings-templates/indicator-fields.js +10 -0
  14. package/dist/utility/chart/chart-mount-epoch.util.d.ts +12 -0
  15. package/dist/utility/chart/chart-mount-epoch.util.js +32 -0
  16. package/dist/utility/chart/crypto-index.leaf.d.ts +16 -0
  17. package/dist/utility/chart/crypto-index.leaf.js +19 -0
  18. package/dist/utility/chart/index-mode-admission.util.js +9 -1
  19. package/dist/utility/chart/index-mode.util.d.ts +11 -5
  20. package/dist/utility/chart/index-mode.util.js +22 -10
  21. package/dist/utility/chart/kscript-source-answer-budget.leaf.d.ts +36 -0
  22. package/dist/utility/chart/kscript-source-answer-budget.leaf.js +39 -0
  23. package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +38 -1
  24. package/dist/utility/chart/kscript-source-degrade.leaf.js +39 -1
  25. package/dist/utility/chart/live-bucket.util.d.ts +2 -1
  26. package/dist/utility/chart/live-bucket.util.js +47 -15
  27. package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +15 -1
  28. package/dist/utility/chart/local-kscript-warmup-depth.util.js +9 -0
  29. package/dist/utility/chart/market-session-schedule.util.d.ts +3 -1
  30. package/dist/utility/chart/market-session-schedule.util.js +24 -2
  31. package/dist/utility/chart/marketKind.util.d.ts +12 -7
  32. package/dist/utility/chart/marketKind.util.js +15 -5
  33. package/dist/utility/chart/ny-calendar.util.d.ts +104 -0
  34. package/dist/utility/chart/ny-calendar.util.js +346 -0
  35. package/dist/utility/chart/om-panel.util.d.ts +14 -2
  36. package/dist/utility/chart/om-panel.util.js +108 -40
  37. package/dist/utility/chart/rth-session.util.d.ts +10 -7
  38. package/dist/utility/chart/rth-session.util.js +17 -22
  39. package/dist/utility/chart/trading-day.util.js +90 -18
  40. package/dist/utility/chart/us-equities-session.util.js +20 -67
  41. package/dist/utility/chart/wrun-bar-session-facts.util.js +14 -1
  42. package/dist/utility/common/time.util.d.ts +7 -1
  43. package/dist/utility/common/time.util.js +11 -41
  44. package/dist/utility/number-format.util.d.ts +17 -7
  45. package/dist/utility/number-format.util.js +18 -8
  46. package/dist/utility/options/option-symbol.util.js +13 -2
  47. package/dist/utility/symbol-selection/contract-expiry.util.js +9 -1
  48. package/dist/utility/watchlist/import/import-request.leaf.d.ts +4 -1
  49. package/dist/utility/watchlist/import/import-request.leaf.js +5 -2
  50. package/dist/utility/watchlist/import/tradingview-symbols.leaf.d.ts +25 -4
  51. package/dist/utility/watchlist/import/tradingview-symbols.leaf.js +62 -4
  52. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +19 -0
  53. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +57 -0
  54. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +23 -0
  55. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +90 -0
  56. package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.d.ts +39 -0
  57. package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.js +60 -0
  58. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +77 -0
  59. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +195 -0
  60. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +56 -0
  61. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +70 -0
  62. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +53 -0
  63. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +239 -0
  64. package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +16 -0
  65. package/dist/utility/wrun/sources/lanes/option_stats_10m.js +14 -0
  66. package/dist/utility/wrun/sources/lanes/options_flow.d.ts +43 -18
  67. package/dist/utility/wrun/sources/lanes/options_flow.js +209 -72
  68. package/dist/utility/wrun/sources/lanes/token_supply.js +5 -31
  69. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +3 -18
  70. package/dist/utility/wrun/sources/opra-option-lanes.util.js +12 -57
  71. package/dist/utility/wrun/sources/row-lane-registry.d.ts +1 -1
  72. package/dist/utility/wrun/sources/row-lane-registry.js +22 -8
  73. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +61 -0
  74. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +103 -8
  75. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +5 -0
  76. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +24 -12
  77. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +55 -0
  78. package/dist/utility/wrun/sources/row-lanes/option_prints.js +95 -18
  79. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +15 -1
  80. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +23 -8
  81. package/dist/utility/wrun/sources/row-lanes/option_surface.js +11 -11
  82. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +14 -2
  83. package/dist/utility/wrun/sources/wrun-poll-lane.types.js +6 -3
  84. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +43 -8
  85. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +77 -11
  86. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +31 -16
  87. package/dist/utility/wrun/sources/wrun-row-lane.types.js +2 -0
  88. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +52 -12
  89. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +110 -46
  90. package/dist/utility/wrun/wrun-bar-count.util.d.ts +17 -6
  91. package/dist/utility/wrun/wrun-bar-count.util.js +27 -12
  92. package/dist/utility/wrun/wrun-browser-sources.leaf.d.ts +10 -0
  93. package/dist/utility/wrun/wrun-browser-sources.leaf.js +12 -0
  94. package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +3 -3
  95. package/dist/utility/wrun/wrun-coin-lane-live.util.js +53 -18
  96. package/dist/utility/wrun/wrun-color-settings.util.d.ts +6 -0
  97. package/dist/utility/wrun/wrun-color-settings.util.js +45 -0
  98. package/dist/utility/wrun/wrun-draft-overlay.util.js +14 -8
  99. package/dist/utility/wrun/wrun-failure-cause.d.ts +1 -1
  100. package/dist/utility/wrun/wrun-failure-cause.js +14 -0
  101. package/dist/utility/wrun/wrun-frames.js +6 -2
  102. package/dist/utility/wrun/wrun-host.service.d.ts +131 -59
  103. package/dist/utility/wrun/wrun-host.service.js +391 -194
  104. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +1 -1
  105. package/dist/utility/wrun/wrun-hosted-wire-caps.js +2 -0
  106. package/dist/utility/wrun/wrun-hover.util.d.ts +3 -0
  107. package/dist/utility/wrun/wrun-hover.util.js +25 -4
  108. package/dist/utility/wrun/wrun-input-requirements.leaf.js +7 -4
  109. package/dist/utility/wrun/wrun-kit-run-tables.util.d.ts +24 -0
  110. package/dist/utility/wrun/wrun-kit-run-tables.util.js +87 -0
  111. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +2 -1
  112. package/dist/utility/wrun/wrun-live-tick.util.d.ts +8 -2
  113. package/dist/utility/wrun/wrun-live-tick.util.js +35 -16
  114. package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +40 -13
  115. package/dist/utility/wrun/wrun-opra-flow.leaf.js +39 -12
  116. package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +70 -21
  117. package/dist/utility/wrun/wrun-option-contract-flow.util.js +257 -112
  118. package/dist/utility/wrun/wrun-option-prints.util.d.ts +62 -22
  119. package/dist/utility/wrun/wrun-option-prints.util.js +148 -46
  120. package/dist/utility/wrun/wrun-option-views.util.d.ts +262 -0
  121. package/dist/utility/wrun/wrun-option-views.util.js +356 -0
  122. package/dist/utility/wrun/wrun-options-chain.util.d.ts +23 -2
  123. package/dist/utility/wrun/wrun-options-chain.util.js +37 -3
  124. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +20 -5
  125. package/dist/utility/wrun/wrun-overlay-drivers.util.js +32 -7
  126. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +9 -3
  127. package/dist/utility/wrun/wrun-overlay-recovery.util.js +146 -18
  128. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +52 -8
  129. package/dist/utility/wrun/wrun-overlay-run.util.js +816 -243
  130. package/dist/utility/wrun/wrun-pack.util.d.ts +2 -1
  131. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +5 -0
  132. package/dist/utility/wrun/wrun-pin-spelling.util.js +28 -12
  133. package/dist/utility/wrun/wrun-pin-venues.util.js +4 -6
  134. package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +1 -1
  135. package/dist/utility/wrun/wrun-prefix-cohort.util.js +1 -1
  136. package/dist/utility/wrun/wrun-present-bits.util.d.ts +9 -0
  137. package/dist/utility/wrun/wrun-present-bits.util.js +39 -0
  138. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +3 -2
  139. package/dist/utility/wrun/wrun-refusal-surface.util.js +5 -4
  140. package/dist/utility/wrun/wrun-refusal.util.d.ts +66 -6
  141. package/dist/utility/wrun/wrun-refusal.util.js +335 -40
  142. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
  143. package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +2 -2
  144. package/dist/utility/wrun/wrun-sha256.leaf.d.ts +13 -0
  145. package/dist/utility/wrun/wrun-sha256.leaf.js +84 -0
  146. package/dist/utility/wrun/wrun-source-rows.util.js +11 -0
  147. package/dist/utility/wrun/wrun-tier-grid.util.d.ts +28 -3
  148. package/dist/utility/wrun/wrun-tier-grid.util.js +79 -19
  149. package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +14 -3
  150. package/dist/utility/wrun/wrun-transient-rerun.util.js +33 -8
  151. package/dist/workers/wrun/wrun-abi-host.d.ts +15 -2
  152. package/dist/workers/wrun/wrun-abi-host.js +31 -12
  153. package/dist/workers/wrun/wrun-engine-handler.d.ts +11 -28
  154. package/dist/workers/wrun/wrun-engine-handler.js +181 -12
  155. package/package.json +5 -5
  156. package/dist/utility/wrun/wrun-opra-underlying.util.d.ts +0 -12
  157. package/dist/utility/wrun/wrun-opra-underlying.util.js +0 -1
@@ -1,14 +1,22 @@
1
1
  /**
2
- * The `option_contract_flow` class (UW-PARITY source contract v2, S4): one 17-value tuple per contract of the
3
- * chart's underlying that traded in the bar, summed per host bar from OPTION_PRINT_AGG's CONTRACT rows (one per
4
- * contract per tier bucket). Pure and light: the row lane (`sources/row-lanes/option_contract_flow.ts`), its K
5
- * control (`K_OPTION_CONTRACT_FLOW`) and the worker twin read the same rules from here.
2
+ * The `option_contract_flow` class (UW-PARITY source contract v2, S4; on every chain since OPTIONS-PORT P7): one
3
+ * 17-value tuple per contract of the chain's ONE book that traded in the bar, summed per host bar from
4
+ * OPTION_PRINT_AGG's CONTRACT rows (one per contract per tier bucket). Pure and light: the row lane
5
+ * (`sources/row-lanes/option_contract_flow.ts`), its K control (`K_OPTION_CONTRACT_FLOW`) and the worker twin read the
6
+ * same rules from here.
6
7
  *
7
8
  * The tuple: `[root_code, expiry_ms, side_cp, strike, vol_ask, vol_bid, vol_mid, vol_none, prem_ask, prem_bid,
8
- * share_delta_net, vwap, last_price, iv_last, vol_above_ask, vol_below_bid, present]`.
9
+ * share_delta_net, vwap, last_price, iv_last, vol_above_ask, vol_below_bid, present]`, in the units the producer stores
10
+ * on the chain's plane (OPTIONS-PORT C7-3; no conversion here): `vol_*` in contracts on OPRA and CME and in coin on a
11
+ * crypto chain, `prem_*` in USD, `vwap` and `last_price` in USD per unit of the underlying (a share, a coin, a CME index
12
+ * point: the root's point value is the multiplier fact, C7-4), `iv_last` in percent. On a crypto venue and CME `_ask`
13
+ * and `_bid` are the taker sides (buyer and seller initiated): nothing trades at a mid or outside a quote there, so
14
+ * `vol_mid`, `vol_none`, `vol_above_ask` and `vol_below_bid` read 0 on a bucket that has a row.
15
+ * - `root_code`: `encodeSymbol(root)` of the contract's root, its raw symbol parsed by the venue of its exchange (the
16
+ * print class's one parse, wrun-option-prints.util `wrunOptionContractOf`);
9
17
  * - `vwap` = sum_px_size / sum_size over the bar (bit 0 when sum_size > 0);
10
- * - `share_delta_net` = share_delta_ask - share_delta_bid, buyer-initiated minus seller-initiated delta in shares
11
- * (mid and none left out; bit 2 when either side is present);
18
+ * - `share_delta_net` = share_delta_ask - share_delta_bid, buyer-initiated minus seller-initiated delta in the chart's
19
+ * size unit (mid and none left out; bit 2 when either side is present);
12
20
  * - `last_price` the bar's last print price and `iv_last` its last IV among the prints that had one (bit 1 when
13
21
  * set): the backend's own rollup of a coarser bucket (`last(iv_last) FILTER (WHERE iv_last IS NOT NULL)`), so a
14
22
  * bar read from 5m buckets equals one read from its 1h bucket;
@@ -20,16 +28,21 @@
20
28
  * takes the coarsest tier choice, wrun-tier-grid.util).
21
29
  *
22
30
  * The backend (tsdb-gateway `pkg/tsdb/selects/option_print_agg.go`): a request with no scope word is a CONTRACT
23
- * read, by underlying (`coin`), served from `option_print_agg_<tier>` (1m kept 7 days, 5m 30 days, 1h and 1d kept).
24
- * The worker asks one tier per ask (the lane's tier rule) and answers one row per bucket `[bucketMs, raw, ...]`,
25
- * each raw tuple the bucket's sums for one contract (`WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH` values); the lane's
26
- * per-bar fold sums them per contract and applies the knobs that need the whole bar.
31
+ * read, by the chain's exchange and underlying (`coin`), served from `option_print_agg_<tier>` (1m kept 7 days, 5m 30
32
+ * days, 1h and 1d kept). A CONTRACT row's symbol is the venue's raw symbol, so its book is the series that symbol
33
+ * spells, and the worker keeps the ONE book the acquisition names. The worker asks one tier per ask (the lane's tier
34
+ * rule) and answers one row per bucket `[bucketMs, block]`, the block one Float64Array of the bucket's raw tuples back
35
+ * to back, each the bucket's sums for one contract (`WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH` values;
36
+ * `packWrunOptionContractFlowRaws`), handed to the page by transfer; the lane's per-bar fold reads the blocks in place
37
+ * (a plain raw tuple reads the same), sums them per contract and applies the knobs that need the whole bar.
27
38
  */
28
- import { newYorkDayNumber, newYorkInstantMs, parseOptionSymbol } from '../options/option-symbol.util.js';
29
- import { WRUN_PLANE_PAYLOAD_KEY } from '../chart/opra-read-access.leaf.js';
39
+ import { newYorkDayNumber, newYorkInstantMs } from '../options/option-symbol.util.js';
40
+ import { KSCRIPT_SOURCE_ANSWER_CEILING_BYTES, kScriptSourceAnswerRows, } from '../chart/kscript-source-answer-budget.leaf.js';
30
41
  import { wrunPresentMaskOf } from './wrun-present-bits.util.js';
31
- import { encodeSymbol } from './wrun-symbol-code.util.js';
32
42
  import { wrunNearestExpiryTuples, wrunOptionExpiriesOf } from './wrun-option-knobs.util.js';
43
+ import { wrunOptionChainAskStampHolds, wrunOptionContractOf } from './wrun-option-prints.util.js';
44
+ import { wrunLaneChainPlaneOf } from './sources/wrun-row-lane.types.js';
45
+ import { exchangeCodeOf } from '../v2/gate-plane.util.js';
33
46
  /** The gateway type the class reads, by name. */
34
47
  export const WRUN_OPTION_PRINT_AGG_TYPE = 'OPTION_PRINT_AGG';
35
48
  /** f64s per tuple, the `present` mask included. */
@@ -59,10 +72,12 @@ export const WRUN_OPTION_CONTRACT_FLOW_BIT = Object.freeze({ vwap: 0, iv: 1, sha
59
72
  const MINUTE_MS = 60_000;
60
73
  const DAY_MS = 86_400_000;
61
74
  /** The delayed OPRA embargo with the governed route's margin (15 minutes plus 120 s): a delayed read ends that far
62
- * behind now, and the reader serves the bucket holding its end whole. */
75
+ * behind now, and the reader serves the bucket holding its end whole. Kept on every plane (the tiers are the lane's,
76
+ * not an instance's): on CME (a 10-minute delay) and a crypto chain (none) it only waits longer than it must. */
63
77
  const DELAYED_WINDOW_LAG_MS = 17 * MINUTE_MS;
64
- /** OPTION_PRINT_AGG's contract tiers (tsdb-gateway `option_print_agg_{1m,5m,1h,1d}`): 1m kept 7 days, 5m 30, the
65
- * hour and the day for good. Each key is the interval word the K control asks the tier by.
78
+ /** OPTION_PRINT_AGG's contract tiers (tsdb-gateway `option_print_agg_{1m,5m,1h,1d}`, the same on the cme and ore
79
+ * planes, contract C7-1): 1m kept 7 days, 5m 30, the hour and the day for good. Each key is the interval word the K
80
+ * control asks the tier by.
66
81
  * `servedLagMs` (read by the coarsest tier choice only: the 1m tier stays the fallback for every bar): how long after
67
82
  * a bar ends a coarser tier may serve it.
68
83
  * - Every coarser tier waits out the delayed window's lag, so a delayed read's end never falls inside one of its
@@ -78,15 +93,14 @@ export const WRUN_OPTION_PRINT_AGG_TIERS = Object.freeze([
78
93
  { key: '1h', ms: 60 * MINUTE_MS, servedLagMs: 20 * MINUTE_MS },
79
94
  { key: '1d', ms: DAY_MS, servedLagMs: 6 * 60 * MINUTE_MS },
80
95
  ]);
81
- /** The most contract rows one read may hold: the worker twin fails a window past it loudly, never truncated, and the
82
- * lane's row budget keeps its asks under it before any fetch. */
83
- export const WRUN_OPTION_CONTRACT_FLOW_MAX_ROWS = 500_000;
84
96
  /**
85
- * The contract rows one regular session holds at each tier (one row per contract per bucket it traded in), the row
86
- * budget's projection for EVERY underlying: SPY's, measured on 2026-10-14 (120 of its 13,168 listed contracts sampled
87
- * at random, every 1m trade bar of the session, scaled to the chain), the upper end of a bootstrap 90% interval (the
88
- * point estimates: 169k, 84k, 23k and 6.0k). A smaller chain is projected as SPY's (its older bars go partial sooner
89
- * than they need to); a larger one could still reach the worker's cap, which then fails loudly.
97
+ * The contract rows one regular OPRA session holds at each tier (one row per contract per bucket it traded in), the row
98
+ * budget's projection for EVERY underlying on the OPRA plane: SPY's, measured on 2026-10-14 (120 of its 13,168 listed
99
+ * contracts sampled at random, every 1m trade bar of the session, scaled to the chain), the upper end of a bootstrap 90%
100
+ * interval (the point estimates: 169k, 84k, 23k and 6.0k). A smaller chain is projected as SPY's (its older bars go
101
+ * partial sooner than they need to); a larger one could still reach the worker's cap, which then fails loudly. A CME
102
+ * chain is projected with the same rows per Globex trade day until one is measured: its OPTION_PRINT_AGG rows start
103
+ * with the CME print producer, and the ore gateway carries no CME option trades to measure.
90
104
  */
91
105
  export const WRUN_OPTION_CONTRACT_FLOW_SESSION_ROWS = Object.freeze({
92
106
  '1m': 262_000,
@@ -94,52 +108,117 @@ export const WRUN_OPTION_CONTRACT_FLOW_SESSION_ROWS = Object.freeze({
94
108
  '1h': 28_000,
95
109
  '1d': 7_000,
96
110
  });
97
- /** A regular session's print span in New York, 09:30 to 16:15 (ETF options trade to 16:15), in minutes. */
111
+ /**
112
+ * The contract rows one UTC day of a crypto chain holds at each tier, the projection for every crypto chain: measured on
113
+ * 2026-10-20 over the ore gateway's TRADE_AGG minute bars of the venues' option trades (one row per contract per bucket
114
+ * that traded, the rows the print rollups write), the busiest chain at each tier doubled: Bybit BTC at 1m, 5m and 1h
115
+ * (2026-10-16: 28,084, 15,754 and 4,283 rows), Deribit BTC at 1d (at most 756 over 13 days from 2026-09-22; Deribit's
116
+ * busiest 1m day 7,133, OKX BTC 5,678).
117
+ */
118
+ export const WRUN_OPTION_CONTRACT_FLOW_CRYPTO_DAY_ROWS = Object.freeze({
119
+ '1m': 60_000,
120
+ '5m': 35_000,
121
+ '1h': 10_000,
122
+ '1d': 2_000,
123
+ });
124
+ /** A regular OPRA session's print span in New York, 09:30 to 16:15 (ETF options trade to 16:15), in minutes. */
98
125
  const SESSION_PRINT_MINUTES = 405;
99
- /** Each New York trade day's print span `[open, close)` in ms, by day number (memoized: a window walks the same days
100
- * again on every plan). */
101
- const sessionSpans = new Map();
102
- const SESSION_SPANS_MAX = 4_096;
103
- function sessionSpanOfDay(day) {
104
- const held = sessionSpans.get(day);
126
+ /** A CME Globex trade day in minutes: 17:00 to 16:00 Chicago. */
127
+ const GLOBEX_PRINT_MINUTES = 1_380;
128
+ /** A crypto venue's trade day in minutes: every minute of the UTC day. */
129
+ const UTC_DAY_MINUTES = 1_440;
130
+ const OPRA_SESSION_SPANS = [[9 * 60 + 30, 16 * 60 + 15]];
131
+ const GLOBEX_WEEKDAY_SPANS = [
132
+ [0, 17 * 60],
133
+ [18 * 60, 24 * 60],
134
+ ];
135
+ const PRINT_SPANS_NY = Object.freeze({
136
+ opra: [[], OPRA_SESSION_SPANS, OPRA_SESSION_SPANS, OPRA_SESSION_SPANS, OPRA_SESSION_SPANS, OPRA_SESSION_SPANS, []],
137
+ cme: [
138
+ [[18 * 60, 24 * 60]],
139
+ GLOBEX_WEEKDAY_SPANS,
140
+ GLOBEX_WEEKDAY_SPANS,
141
+ GLOBEX_WEEKDAY_SPANS,
142
+ GLOBEX_WEEKDAY_SPANS,
143
+ [[0, 17 * 60]],
144
+ [],
145
+ ],
146
+ });
147
+ /** Each New York calendar day's print spans `[open, close)` in ms on a plane's calendar, by plane and day number
148
+ * (memoized: a window walks the same days again on every plan). */
149
+ const printSpans = new Map();
150
+ const PRINT_SPANS_MAX = 4_096;
151
+ function printSpansOfDay(plane, day) {
152
+ const key = `${plane}|${day}`;
153
+ const held = printSpans.get(key);
105
154
  if (held !== undefined)
106
155
  return held;
107
156
  const date = new Date(day * DAY_MS);
108
157
  const [year, month, dayOfMonth] = [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()];
109
- const span = [
110
- newYorkInstantMs(year, month, dayOfMonth, 9, 30),
111
- newYorkInstantMs(year, month, dayOfMonth, 16, 15),
112
- ];
113
- if (sessionSpans.size >= SESSION_SPANS_MAX)
114
- sessionSpans.clear();
115
- sessionSpans.set(day, span);
116
- return span;
158
+ const spans = PRINT_SPANS_NY[plane][date.getUTCDay()].map(([open, close]) => [
159
+ newYorkInstantMs(year, month, dayOfMonth, 0, open),
160
+ newYorkInstantMs(year, month, dayOfMonth, 0, close),
161
+ ]);
162
+ if (printSpans.size >= PRINT_SPANS_MAX)
163
+ printSpans.clear();
164
+ printSpans.set(key, spans);
165
+ return spans;
117
166
  }
118
- /** The regular-session print minutes inside `[fromMs, toMs)`: each weekday's 09:30 to 16:15 New York (a holiday
119
- * counts as a session, so the projection only errs high). */
120
- export function wrunOptionPrintSessionMinutes(fromMs, toMs) {
167
+ /** The print minutes inside `[fromMs, toMs)` on a plane's calendar (`PRINT_SPANS_NY`). */
168
+ function calendarPrintMinutes(plane, fromMs, toMs) {
121
169
  if (!Number.isFinite(fromMs) || !Number.isFinite(toMs) || !(toMs > fromMs))
122
170
  return 0;
123
171
  let minutes = 0;
124
172
  const lastDay = newYorkDayNumber(toMs - 1);
125
173
  for (let day = newYorkDayNumber(fromMs); day <= lastDay; day += 1) {
126
- const weekday = new Date(day * DAY_MS).getUTCDay();
127
- if (weekday === 0 || weekday === 6)
128
- continue;
129
- const [open, close] = sessionSpanOfDay(day);
130
- const overlap = Math.min(toMs, close) - Math.max(fromMs, open);
131
- if (overlap > 0)
132
- minutes += overlap / MINUTE_MS;
174
+ for (const [open, close] of printSpansOfDay(plane, day)) {
175
+ const overlap = Math.min(toMs, close) - Math.max(fromMs, open);
176
+ if (overlap > 0)
177
+ minutes += overlap / MINUTE_MS;
178
+ }
133
179
  }
134
180
  return minutes;
135
181
  }
136
- /** The rows one host bar is projected to read at its tier, up to the clock (the lane's row budget): the session's
137
- * rows at that tier in proportion to the print minutes the bar covers. No tier: none. */
138
- export function wrunOptionContractFlowBarRows(bar, nowMs) {
139
- const perSession = bar.tier === undefined ? undefined : WRUN_OPTION_CONTRACT_FLOW_SESSION_ROWS[bar.tier.key];
140
- if (perSession === undefined)
182
+ /** The regular-session print minutes inside `[fromMs, toMs)`: each weekday's 09:30 to 16:15 New York (a holiday
183
+ * counts as a session, so the projection only errs high). */
184
+ export function wrunOptionPrintSessionMinutes(fromMs, toMs) {
185
+ return calendarPrintMinutes('opra', fromMs, toMs);
186
+ }
187
+ /** The CME Globex print minutes inside `[fromMs, toMs)`: Sunday 17:00 Chicago to Friday 16:00, less the daily 16:00
188
+ * to 17:00 halt (a holiday counts as a trade day, so the projection only errs high). */
189
+ export function wrunOptionGlobexPrintMinutes(fromMs, toMs) {
190
+ return calendarPrintMinutes('cme', fromMs, toMs);
191
+ }
192
+ const WRUN_OPTION_CONTRACT_FLOW_PROJECTIONS = Object.freeze({
193
+ opra: {
194
+ dayRows: WRUN_OPTION_CONTRACT_FLOW_SESSION_ROWS,
195
+ dayMinutes: SESSION_PRINT_MINUTES,
196
+ printMinutes: wrunOptionPrintSessionMinutes,
197
+ },
198
+ cme: {
199
+ dayRows: WRUN_OPTION_CONTRACT_FLOW_SESSION_ROWS,
200
+ dayMinutes: GLOBEX_PRINT_MINUTES,
201
+ printMinutes: wrunOptionGlobexPrintMinutes,
202
+ },
203
+ plain: {
204
+ dayRows: WRUN_OPTION_CONTRACT_FLOW_CRYPTO_DAY_ROWS,
205
+ dayMinutes: UTC_DAY_MINUTES,
206
+ printMinutes: (fromMs, toMs) => Number.isFinite(fromMs) && Number.isFinite(toMs) && toMs > fromMs ? (toMs - fromMs) / MINUTE_MS : 0,
207
+ },
208
+ });
209
+ /**
210
+ * The rows one host bar is projected to read at its tier, up to the clock (the lane's row budget), on the plane of the
211
+ * instance's chain (`acquisition`, its payload: the exchange it names, which the host hands every projection): the
212
+ * plane's rows per trade day at that tier in proportion to the print minutes the bar covers on the plane's calendar.
213
+ * No tier: none.
214
+ */
215
+ export function wrunOptionContractFlowBarRows(bar, nowMs, acquisition) {
216
+ const plane = wrunLaneChainPlaneOf(wrunOptionContractFlowAcquisitionOf(acquisition).exchange);
217
+ const projection = WRUN_OPTION_CONTRACT_FLOW_PROJECTIONS[plane];
218
+ const perDay = bar.tier === undefined ? undefined : projection.dayRows[bar.tier.key];
219
+ if (perDay === undefined)
141
220
  return 0;
142
- return (perSession * wrunOptionPrintSessionMinutes(bar.openMs, Math.min(bar.endMs, nowMs))) / SESSION_PRINT_MINUTES;
221
+ return (perDay * projection.printMinutes(bar.openMs, Math.min(bar.endMs, nowMs))) / projection.dayMinutes;
143
222
  }
144
223
  /** One bucket's sums for one contract, as the worker hands them to the fold. */
145
224
  export const WRUN_OPTION_CONTRACT_FLOW_RAW = Object.freeze({
@@ -168,28 +247,62 @@ export const WRUN_OPTION_CONTRACT_FLOW_RAW = Object.freeze({
168
247
  sizePriced: 20,
169
248
  });
170
249
  export const WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH = 21;
250
+ /** The most contract rows one read may hold: the source answer CEILING (kscript-source-answer-budget.leaf) in raw
251
+ * tuples, about 99,900. The worker twin fails a window past it loudly, never truncated; the lane's row budget plans
252
+ * its asks to half of it (the budget), so only a session busier than twice its projection reaches it. */
253
+ export const WRUN_OPTION_CONTRACT_FLOW_MAX_ROWS = kScriptSourceAnswerRows(WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH, KSCRIPT_SOURCE_ANSWER_CEILING_BYTES);
254
+ /**
255
+ * A bucket's raw tuples packed as the worker hands them over: one Float64Array of `count x RAW_WIDTH` values, the
256
+ * tuples back to back. The page receives the block by transfer (no structured clone walks it), the row cache copies
257
+ * and weighs it by its bytes, and the fold reads it in place; a raw tuple as a plain array (a spec's, a JSON shape)
258
+ * reads the same.
259
+ */
260
+ export function packWrunOptionContractFlowRaws(raws) {
261
+ const block = new Float64Array(raws.length * WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH);
262
+ let at = 0;
263
+ for (const raw of raws) {
264
+ for (let column = 0; column < WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH; column += 1)
265
+ block[at + column] = raw[column];
266
+ at += WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH;
267
+ }
268
+ return block;
269
+ }
171
270
  /** The raw tuple's `flags`: which optional sums the bucket carried. */
172
271
  const RAW_FLAG = Object.freeze({ shareDeltaAsk: 1, shareDeltaBid: 2, ivLast: 4 });
272
+ /**
273
+ * The payload fields an instance names its chain in (the lane's acquisition, and the K control's request to the worker
274
+ * twin under the same names): the exchange the chain lists on (its plane follows it), the ONE book when it is not the
275
+ * underlying's own series, and the continuous alias a CME chain was read off (its lead contract is `coin`).
276
+ */
277
+ export const WRUN_OPTION_CONTRACT_FLOW_EXCHANGE_FIELD = 'flowExchange';
278
+ export const WRUN_OPTION_CONTRACT_FLOW_BOOK_FIELD = 'flowBook';
279
+ export const WRUN_OPTION_CONTRACT_FLOW_CONTINUOUS_FIELD = 'flowContinuous';
173
280
  /** An instance's payload as its acquisition (knob fields that are not valid read absent). */
174
281
  export function wrunOptionContractFlowAcquisitionOf(extras) {
175
282
  const positive = (value) => typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : undefined;
283
+ const upper = (value) => (typeof value === 'string' ? value.trim().toUpperCase() : '');
176
284
  const strikeWindowPct = positive(extras?.strikeWindowPct);
177
285
  const minVolume = positive(extras?.minVolume);
286
+ const coin = upper(extras?.coin);
287
+ const book = upper(extras?.[WRUN_OPTION_CONTRACT_FLOW_BOOK_FIELD]);
178
288
  return {
179
- coin: typeof extras?.coin === 'string' ? extras.coin : '',
289
+ coin,
290
+ exchange: upper(extras?.[WRUN_OPTION_CONTRACT_FLOW_EXCHANGE_FIELD]),
291
+ book: book !== '' ? book : coin,
180
292
  ...(typeof extras?.expiries === 'string' ? { expiries: extras.expiries } : {}),
181
293
  ...(strikeWindowPct !== undefined ? { strikeWindowPct } : {}),
182
294
  ...(minVolume !== undefined ? { minVolume } : {}),
183
295
  ...(typeof extras?.tier === 'string' ? { tier: extras.tier } : {}),
184
296
  };
185
297
  }
186
- /** Whether a payload is an `option_contract_flow` lane ask the K control serves: it names the OPRA plane, a coin and
187
- * one of the contract tiers (any other caller is declined, fail closed). */
298
+ /** Whether a payload is an `option_contract_flow` lane ask the K control serves: a coin, one of the contract tiers
299
+ * and a chain whose OPRA stamp holds (the print classes' one rule, wrun-option-prints.util
300
+ * `wrunOptionChainAskStampHolds`); any other caller is declined, fail closed. */
188
301
  export function isWrunOptionContractFlowAsk(payload) {
189
302
  const acquisition = wrunOptionContractFlowAcquisitionOf(payload);
190
- return (payload?.[WRUN_PLANE_PAYLOAD_KEY] === 'opra' &&
191
- acquisition.coin !== '' &&
192
- WRUN_OPTION_PRINT_AGG_TIERS.some((tier) => tier.key === acquisition.tier));
303
+ return (acquisition.coin !== '' &&
304
+ WRUN_OPTION_PRINT_AGG_TIERS.some((tier) => tier.key === acquisition.tier) &&
305
+ wrunOptionChainAskStampHolds(payload, acquisition.exchange));
193
306
  }
194
307
  /** The tier a key names (one of the contract tiers), or undefined. */
195
308
  export function wrunOptionPrintAggTierOf(key) {
@@ -231,24 +344,12 @@ function bucketMsOf(timestamp) {
231
344
  function isContractRow(scope) {
232
345
  return scope === undefined || scope === null || scope === 0 || scope === 'OPTION_PRINT_AGG_SCOPE_CONTRACT';
233
346
  }
234
- const CONTRACT_CACHE_MAX = 50_000;
235
- const contracts = new Map();
236
- function contractOf(symbol) {
237
- const cached = contracts.get(symbol);
238
- if (cached !== undefined)
239
- return cached;
240
- const parsed = parseOptionSymbol('opra', symbol);
241
- const contract = parsed === null ? null : { rootCode: encodeSymbol(parsed.root), side: parsed.side };
242
- if (contracts.size >= CONTRACT_CACHE_MAX)
243
- contracts.clear();
244
- contracts.set(symbol, contract);
245
- return contract;
246
- }
247
347
  /**
248
348
  * One OPTION_PRINT_AGG CONTRACT row as a raw tuple (the history shape: a reshaped protobuf-es message, int64 as
249
- * bigint, unset optionals undefined; a JSON shape reads the same). `series` names the contract (its OSI symbol, the
250
- * option type). A scope row, a row missing its time or contract, or one whose root the codec refuses is dropped and
251
- * counted.
349
+ * bigint, unset optionals undefined; a JSON shape reads the same). `series` names the contract (its exchange, by name
350
+ * or pb-common id, its raw symbol, parsed by the venue of the exchange, and the option type). A scope row, a row missing its time or contract
351
+ * (a series naming no exchange, or a symbol its venue does not spell), or one whose root the codec refuses is dropped
352
+ * and counted.
252
353
  */
253
354
  export function wrunOptionContractFlowRowOf(point, series) {
254
355
  const drop = (reason) => {
@@ -262,8 +363,9 @@ export function wrunOptionContractFlowRowOf(point, series) {
262
363
  const bucketMs = bucketMsOf(point.timestamp);
263
364
  if (!Number.isFinite(bucketMs))
264
365
  return drop('time');
366
+ const exchange = exchangeCodeOf(series?.exchange) ?? '';
265
367
  const symbol = typeof series?.symbol === 'string' ? series.symbol : '';
266
- const contract = symbol === '' ? null : contractOf(symbol);
368
+ const contract = symbol === '' || exchange === '' ? null : wrunOptionContractOf(exchange, symbol);
267
369
  if (contract === null)
268
370
  return drop('contract');
269
371
  if (contract.rootCode === undefined)
@@ -314,11 +416,16 @@ export function wrunOptionContractFlowRowOf(point, series) {
314
416
  ],
315
417
  };
316
418
  }
317
- /** Whether a contract row is a "0dte" row: its expiry falls on the trade date of its bucket (the New York date at
318
- * the bucket's middle, so a UTC day bucket reads its own session's date). */
319
- export function wrunOptionContractFlowRowIsZeroDte(row, tierMs) {
419
+ /**
420
+ * Whether a contract row is a "0dte" row: its expiry falls on the trade date of its bucket, on the clock of the chain's
421
+ * market (`tradeDay`, the trade date an instant falls on in days: the worker hands the chain summary's one rule,
422
+ * option-contract-state.worker.util `optionChainTradeDay` over the chain's exchange: OPRA's New York date, a CME Group
423
+ * exchange's Globex session date, a crypto venue's UTC date), read at the bucket's middle so a UTC day bucket reads its
424
+ * own session's date.
425
+ */
426
+ export function wrunOptionContractFlowRowIsZeroDte(row, tierMs, tradeDay) {
320
427
  const middle = row.bucketMs + Math.floor(Math.max(0, tierMs) / 2);
321
- return newYorkDayNumber(middle) === newYorkDayNumber(row.raw[WRUN_OPTION_CONTRACT_FLOW_RAW.expiry]);
428
+ return tradeDay(middle) === tradeDay(row.raw[WRUN_OPTION_CONTRACT_FLOW_RAW.expiry]);
322
429
  }
323
430
  /** Whether a cell is a raw contract tuple: exactly the raw width of finite numbers. */
324
431
  function isRawTuple(cell) {
@@ -326,6 +433,58 @@ function isRawTuple(cell) {
326
433
  cell.length === WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH &&
327
434
  cell.every((value) => typeof value === 'number' && Number.isFinite(value)));
328
435
  }
436
+ /** Whether a cell is a packed block of raw tuples (`packWrunOptionContractFlowRaws`): a Float64Array holding a whole
437
+ * number of them. */
438
+ function isRawBlock(cell) {
439
+ return cell instanceof Float64Array && cell.length % WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH === 0;
440
+ }
441
+ /** Whether the raw tuple at `offset` of a block holds finite numbers only (a plain tuple's rule, read in place). */
442
+ function rawTupleFiniteAt(block, offset) {
443
+ for (let column = 0; column < WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH; column += 1) {
444
+ if (!Number.isFinite(block[offset + column]))
445
+ return false;
446
+ }
447
+ return true;
448
+ }
449
+ /** Every raw tuple a bucket row's cells hold, in order, as (source, offset): a packed block's tuples back to back, a
450
+ * plain tuple at offset 0. A cell of any other shape, and a tuple holding a value that is not finite, is skipped. */
451
+ function forEachWrunOptionContractFlowRaw(row, visit) {
452
+ for (let index = 1; index < row.length; index += 1) {
453
+ const cell = row[index];
454
+ if (isRawBlock(cell)) {
455
+ for (let offset = 0; offset < cell.length; offset += WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH) {
456
+ if (rawTupleFiniteAt(cell, offset))
457
+ visit(cell, offset);
458
+ }
459
+ }
460
+ else if (isRawTuple(cell)) {
461
+ visit(cell, 0);
462
+ }
463
+ }
464
+ }
465
+ /** The raw tuples a bucket row holds (a packed block counts each of its tuples). */
466
+ export function wrunOptionContractFlowRawCount(row) {
467
+ let count = 0;
468
+ forEachWrunOptionContractFlowRaw(row, () => {
469
+ count += 1;
470
+ });
471
+ return count;
472
+ }
473
+ /** The raw columns a contract's bar sums add up (the rest are its identity, its newest price or IV, its flags). */
474
+ const SUMMED_RAW_COLUMNS = [
475
+ WRUN_OPTION_CONTRACT_FLOW_RAW.volAsk,
476
+ WRUN_OPTION_CONTRACT_FLOW_RAW.volBid,
477
+ WRUN_OPTION_CONTRACT_FLOW_RAW.volMid,
478
+ WRUN_OPTION_CONTRACT_FLOW_RAW.volNone,
479
+ WRUN_OPTION_CONTRACT_FLOW_RAW.premAsk,
480
+ WRUN_OPTION_CONTRACT_FLOW_RAW.premBid,
481
+ WRUN_OPTION_CONTRACT_FLOW_RAW.shareDeltaAsk,
482
+ WRUN_OPTION_CONTRACT_FLOW_RAW.shareDeltaBid,
483
+ WRUN_OPTION_CONTRACT_FLOW_RAW.sumPxSize,
484
+ WRUN_OPTION_CONTRACT_FLOW_RAW.sumSize,
485
+ WRUN_OPTION_CONTRACT_FLOW_RAW.volAboveAsk,
486
+ WRUN_OPTION_CONTRACT_FLOW_RAW.volBelowBid,
487
+ ];
329
488
  /**
330
489
  * One host bar's contract tuples from its buckets' raw rows (in bucket order), under the acquisition's knobs:
331
490
  * - every contract's sums over the bar, its last price from its newest bucket and its IV from its newest bucket that
@@ -346,51 +505,37 @@ export function foldWrunOptionContractFlowBar(rows, acquisition) {
346
505
  let sizePriced = 0;
347
506
  for (const row of rows) {
348
507
  const at = Number(row[0]);
349
- for (let index = 1; index < row.length; index += 1) {
350
- const raw = row[index];
351
- if (!isRawTuple(raw))
352
- continue;
353
- const flags = raw[R.flags];
354
- spotSize += raw[R.sumSpotSize];
355
- sizePriced += raw[R.sizePriced];
356
- const key = `${raw[R.root]}|${raw[R.expiry]}|${raw[R.side]}|${raw[R.strike]}`;
508
+ forEachWrunOptionContractFlowRaw(row, (source, offset) => {
509
+ const flags = source[offset + R.flags];
510
+ spotSize += source[offset + R.sumSpotSize];
511
+ sizePriced += source[offset + R.sizePriced];
512
+ const key = `${source[offset + R.root]}|${source[offset + R.expiry]}|${source[offset + R.side]}|${source[offset + R.strike]}`;
357
513
  const sum = byContract.get(key);
358
514
  if (sum === undefined) {
515
+ const raw = new Array(WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH);
516
+ for (let column = 0; column < WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH; column += 1)
517
+ raw[column] = source[offset + column];
359
518
  byContract.set(key, {
360
- raw: [...raw],
519
+ raw,
361
520
  flags,
362
521
  lastAt: at,
363
522
  ivAt: (flags & RAW_FLAG.ivLast) !== 0 ? at : Number.NEGATIVE_INFINITY,
364
523
  });
365
- continue;
366
- }
367
- for (const column of [
368
- R.volAsk,
369
- R.volBid,
370
- R.volMid,
371
- R.volNone,
372
- R.premAsk,
373
- R.premBid,
374
- R.shareDeltaAsk,
375
- R.shareDeltaBid,
376
- R.sumPxSize,
377
- R.sumSize,
378
- R.volAboveAsk,
379
- R.volBelowBid,
380
- ]) {
381
- sum.raw[column] += raw[column];
524
+ return;
382
525
  }
526
+ for (const column of SUMMED_RAW_COLUMNS)
527
+ sum.raw[column] += source[offset + column];
383
528
  sum.flags |= flags & (RAW_FLAG.shareDeltaAsk | RAW_FLAG.shareDeltaBid);
384
529
  if (at >= sum.lastAt) {
385
- sum.raw[R.lastPrice] = raw[R.lastPrice];
530
+ sum.raw[R.lastPrice] = source[offset + R.lastPrice];
386
531
  sum.lastAt = at;
387
532
  }
388
533
  if ((flags & RAW_FLAG.ivLast) !== 0 && at >= sum.ivAt) {
389
- sum.raw[R.ivLast] = raw[R.ivLast];
534
+ sum.raw[R.ivLast] = source[offset + R.ivLast];
390
535
  sum.ivAt = at;
391
536
  sum.flags |= RAW_FLAG.ivLast;
392
537
  }
393
- }
538
+ });
394
539
  }
395
540
  let sums = [...byContract.values()];
396
541
  const expiries = wrunOptionExpiriesOf(knobs.expiries);