@orangecharts/wrun-chart-host 0.7.0 → 0.8.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 (125) hide show
  1. package/README.md +25 -2
  2. package/dist/constants/feature-flags.constants.d.ts +1 -0
  3. package/dist/constants/feature-flags.constants.js +5 -0
  4. package/dist/constants/option-venues.constants.d.ts +18 -0
  5. package/dist/constants/option-venues.constants.js +14 -0
  6. package/dist/constants/venue-presets.constants.d.ts +17 -3
  7. package/dist/constants/venue-presets.constants.js +17 -3
  8. package/dist/host-env.d.ts +24 -0
  9. package/dist/host-env.js +21 -0
  10. package/dist/host-ports.types.d.ts +12 -0
  11. package/dist/index.d.ts +16 -0
  12. package/dist/index.js +16 -0
  13. package/dist/indicators/controls/tpo-session.util.d.ts +40 -11
  14. package/dist/indicators/controls/tpo-session.util.js +138 -14
  15. package/dist/interfaces/option-instrument.interface.d.ts +6 -0
  16. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +4 -0
  17. package/dist/kscript-data/controls/live-trades-merge.util.js +4 -0
  18. package/dist/settings-templates/footprint-rows.d.ts +25 -0
  19. package/dist/settings-templates/footprint-rows.js +127 -0
  20. package/dist/settings-templates/form-rows.d.ts +56 -0
  21. package/dist/settings-templates/form-rows.js +19 -0
  22. package/dist/settings-templates/frvp-fields.js +14 -0
  23. package/dist/settings-templates/index.d.ts +11 -0
  24. package/dist/settings-templates/index.js +29 -6
  25. package/dist/settings-templates/indicator-fields.d.ts +2 -0
  26. package/dist/settings-templates/indicator-fields.js +78 -0
  27. package/dist/settings-templates/tool-rules.d.ts +40 -4
  28. package/dist/settings-templates/tool-rules.js +45 -4
  29. package/dist/settings-templates/tool-tables.generated.js +22 -2
  30. package/dist/utility/chart/candle-volume-unit.leaf.d.ts +16 -0
  31. package/dist/utility/chart/candle-volume-unit.leaf.js +61 -0
  32. package/dist/utility/chart/footprint-columns.util.d.ts +74 -0
  33. package/dist/utility/chart/footprint-columns.util.js +106 -0
  34. package/dist/utility/chart/footprint-display-mode.util.d.ts +40 -0
  35. package/dist/utility/chart/footprint-display-mode.util.js +62 -0
  36. package/dist/utility/chart/footprint-sierra-look.util.d.ts +2 -0
  37. package/dist/utility/chart/footprint-sierra-look.util.js +37 -0
  38. package/dist/utility/chart/kscript-venue-policy.util.js +4 -2
  39. package/dist/utility/chart/om-panel.util.d.ts +11 -0
  40. package/dist/utility/chart/om-panel.util.js +59 -0
  41. package/dist/utility/chart/window-geometry.leaf.d.ts +23 -1
  42. package/dist/utility/chart/window-geometry.leaf.js +78 -6
  43. package/dist/utility/chart/window-owner.leaf.d.ts +13 -0
  44. package/dist/utility/chart/window-owner.leaf.js +5 -0
  45. package/dist/utility/options/cme-options-root.util.d.ts +25 -0
  46. package/dist/utility/options/cme-options-root.util.js +40 -0
  47. package/dist/utility/options/option-book.util.d.ts +27 -0
  48. package/dist/utility/options/option-book.util.js +76 -0
  49. package/dist/utility/options/option-trade-date.util.d.ts +50 -0
  50. package/dist/utility/options/option-trade-date.util.js +120 -0
  51. package/dist/utility/wrun/sources/host-grid-landing.d.ts +4 -2
  52. package/dist/utility/wrun/sources/host-grid-landing.js +8 -0
  53. package/dist/utility/wrun/sources/lanes/options_flow.d.ts +40 -4
  54. package/dist/utility/wrun/sources/lanes/options_flow.js +115 -18
  55. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +12 -9
  56. package/dist/utility/wrun/sources/opra-option-lanes.util.js +10 -7
  57. package/dist/utility/wrun/sources/row-lane-registry.js +9 -5
  58. package/dist/utility/wrun/sources/row-lanes/index.js +2 -0
  59. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +3 -2
  60. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +30 -5
  61. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +14 -1
  62. package/dist/utility/wrun/sources/row-lanes/option_prints.js +100 -23
  63. package/dist/utility/wrun/sources/row-lanes/option_strike_flow.d.ts +4 -0
  64. package/dist/utility/wrun/sources/row-lanes/option_strike_flow.js +65 -0
  65. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +47 -1
  66. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +71 -2
  67. package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +14 -1
  68. package/dist/utility/wrun/sources/row-lanes/option_surface.js +30 -2
  69. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +7 -1
  70. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +45 -5
  71. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +115 -3
  72. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +10 -0
  73. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +57 -0
  74. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +60 -6
  75. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +160 -23
  76. package/dist/utility/wrun/wrun-cloud-record.leaf.d.ts +27 -0
  77. package/dist/utility/wrun/wrun-cloud-record.leaf.js +71 -0
  78. package/dist/utility/wrun/wrun-cloud-record.util.d.ts +4 -21
  79. package/dist/utility/wrun/wrun-cloud-record.util.js +5 -65
  80. package/dist/utility/wrun/wrun-color-settings.util.d.ts +7 -5
  81. package/dist/utility/wrun/wrun-color-settings.util.js +26 -11
  82. package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +4 -2
  83. package/dist/utility/wrun/wrun-draft-overlay.util.js +40 -3
  84. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +1 -1
  85. package/dist/utility/wrun/wrun-hosted-wire-caps.js +4 -0
  86. package/dist/utility/wrun/wrun-lane-refusal.leaf.d.ts +29 -3
  87. package/dist/utility/wrun/wrun-lane-refusal.leaf.js +33 -3
  88. package/dist/utility/wrun/wrun-live-tick.util.d.ts +4 -1
  89. package/dist/utility/wrun/wrun-live-tick.util.js +39 -6
  90. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +106 -0
  91. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +159 -0
  92. package/dist/utility/wrun/wrun-market-size-defaults.util.d.ts +44 -0
  93. package/dist/utility/wrun/wrun-market-size-defaults.util.js +213 -0
  94. package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +43 -8
  95. package/dist/utility/wrun/wrun-opra-flow.leaf.js +37 -6
  96. package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +51 -10
  97. package/dist/utility/wrun/wrun-option-contract-flow.util.js +85 -33
  98. package/dist/utility/wrun/wrun-option-prints.util.d.ts +133 -3
  99. package/dist/utility/wrun/wrun-option-prints.util.js +318 -8
  100. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +96 -0
  101. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +215 -0
  102. package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +342 -0
  103. package/dist/utility/wrun/wrun-option-strike-flow.util.js +742 -0
  104. package/dist/utility/wrun/wrun-option-views.util.d.ts +183 -3
  105. package/dist/utility/wrun/wrun-option-views.util.js +504 -7
  106. package/dist/utility/wrun/wrun-options-chain.util.d.ts +6 -4
  107. package/dist/utility/wrun/wrun-options-chain.util.js +8 -5
  108. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +2 -1
  109. package/dist/utility/wrun/wrun-overlay-recovery.util.js +7 -2
  110. package/dist/utility/wrun/wrun-overlay-run.util.js +120 -18
  111. package/dist/utility/wrun/wrun-pack-widths.leaf.d.ts +15 -0
  112. package/dist/utility/wrun/wrun-pack-widths.leaf.js +22 -0
  113. package/dist/utility/wrun/wrun-pack.util.d.ts +9 -8
  114. package/dist/utility/wrun/wrun-pack.util.js +21 -15
  115. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +4 -0
  116. package/dist/utility/wrun/wrun-panel-mount.util.js +62 -22
  117. package/dist/utility/wrun/wrun-panel-style.util.d.ts +17 -2
  118. package/dist/utility/wrun/wrun-panel-style.util.js +47 -9
  119. package/dist/utility/wrun/wrun-pin-spelling.util.js +19 -10
  120. package/dist/utility/wrun/wrun-refusal.util.js +7 -1
  121. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +13 -0
  122. package/dist/utility/wrun/wrun-script-inputs.util.js +43 -0
  123. package/dist/utility/wrun/wrun-tape-source.util.d.ts +9 -0
  124. package/dist/utility/wrun/wrun-tape-source.util.js +18 -0
  125. package/package.json +3 -3
@@ -123,6 +123,27 @@ export declare function packWrunOptionContractFlowRaws(raws: ReadonlyArray<Reado
123
123
  export declare const WRUN_OPTION_CONTRACT_FLOW_EXCHANGE_FIELD = "flowExchange";
124
124
  export declare const WRUN_OPTION_CONTRACT_FLOW_BOOK_FIELD = "flowBook";
125
125
  export declare const WRUN_OPTION_CONTRACT_FLOW_CONTINUOUS_FIELD = "flowContinuous";
126
+ /**
127
+ * `history` "today"'s field on a flow request (both flow classes, under one name): the first instant of today, the
128
+ * trade date of the chart's newest bar on the chain's venue clock (option-trade-date.util `optionTodayStartMsByClock`),
129
+ * named by the K control off the chart's bars (option-flow-bars.util `optionFlowTodayFields`), never off a clock. The
130
+ * worker twins read it (wrun-option-strike-flow.util `wrunOptionFlowTodayWindow`); a "today" request naming none
131
+ * reads nothing.
132
+ */
133
+ export declare const WRUN_OPTION_FLOW_TODAY_FIELD = "todayFromMs";
134
+ /** Today's first instant a request or an acquisition names (`WRUN_OPTION_FLOW_TODAY_FIELD`), else undefined. */
135
+ export declare function wrunOptionFlowTodayFromOf(record: Readonly<Record<string, unknown>> | null | undefined): number | undefined;
136
+ /**
137
+ * Whether a bar reads nothing under `history` "today", so a row budget projects it at no rows (both flow lanes'
138
+ * `rowBudget.barRows`, and the strike flow fold's plan): it ends at or before today's first instant as the acquisition
139
+ * names it (`WRUN_OPTION_FLOW_TODAY_FIELD`). An acquisition naming no today (the host's plan hands its projection no
140
+ * newest bar to date today by) holds no such bar: today is never dated off a clock, so a bar of the newest trade date
141
+ * the chart holds is never projected at nothing. An older bar is then projected like any other and may be left
142
+ * partial where the budget stops; it reads nothing either way.
143
+ */
144
+ export declare function wrunOptionFlowBarBeforeToday(bar: {
145
+ endMs: number;
146
+ }, acquisition: Readonly<Record<string, unknown>>): boolean;
126
147
  /** The acquisition an `option_contract_flow` instance asks with. */
127
148
  export interface WrunOptionContractFlowAcquisition {
128
149
  /** The chain's underlying, upper case: the key its plane files the rows under (the OPRA ticker, a crypto venue's
@@ -136,6 +157,14 @@ export interface WrunOptionContractFlowAcquisition {
136
157
  expiries?: string;
137
158
  strikeWindowPct?: number;
138
159
  minVolume?: number;
160
+ /** A contract's group premium floor (USD, the four sides' sum), "session" (a row set per trade date) and "today" (the
161
+ * newest trade date only): the worker twin's (OPTLOAD, kit 0.89.0). */
162
+ minPremium?: number;
163
+ span?: 'session';
164
+ history?: 'today';
165
+ /** Today's first instant as the request names it (`WRUN_OPTION_FLOW_TODAY_FIELD`: the K control's, off the chart's
166
+ * newest bar); an instance's own payload names none. */
167
+ todayFromMs?: number;
139
168
  /** The tier key of the ask (a fold reads the ask's own). */
140
169
  tier?: string;
141
170
  }
@@ -166,26 +195,38 @@ export interface WrunOptionContractFlowRow {
166
195
  * and counted.
167
196
  */
168
197
  export declare function wrunOptionContractFlowRowOf(point: Readonly<Record<string, unknown>> | null | undefined, series: Readonly<Record<string, unknown>> | null | undefined): WrunOptionContractFlowRow | WrunOptionContractFlowDrop;
169
- /**
170
- * 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
171
- * market (`tradeDay`, the trade date an instant falls on in days: the worker hands the chain summary's one rule,
172
- * option-contract-state.worker.util `optionChainTradeDay` over the chain's exchange: OPRA's New York date, a CME Group
173
- * exchange's Globex session date, a crypto venue's UTC date), read at the bucket's middle so a UTC day bucket reads its
174
- * own session's date.
175
- */
176
- export declare function wrunOptionContractFlowRowIsZeroDte(row: WrunOptionContractFlowRow, tierMs: number, tradeDay: (instantMs: number) => number): boolean;
177
198
  /** The raw tuples a bucket row holds (a packed block counts each of its tuples). */
178
199
  export declare function wrunOptionContractFlowRawCount(row: ReadonlyArray<unknown>): number;
200
+ /** One contract's sums over a group, its joined flags, and its newest last price's and IV's buckets. */
201
+ export interface WrunOptionContractFlowContractSum {
202
+ raw: number[];
203
+ flags: number;
204
+ /** The bucket of the last print price kept. */
205
+ lastAt: number;
206
+ ivAt: number;
207
+ }
208
+ /** Each contract's sums over raw tuples taken in bucket order (the backend's rollup): the fold's, and the worker twin's
209
+ * when it groups a read itself. `add` answers the contract's key, `spot` the tuples' contract-weighted underlying,
210
+ * `raws` each contract's summed raw tuple. */
211
+ export interface WrunOptionContractFlowSums {
212
+ add(at: number, source: ArrayLike<number>, offset: number): string;
213
+ spot(): number | undefined;
214
+ raws(): number[][];
215
+ sums(): WrunOptionContractFlowContractSum[];
216
+ }
217
+ /** A new accumulator of per-contract sums (`WrunOptionContractFlowSums`). */
218
+ export declare function wrunOptionContractFlowSums(): WrunOptionContractFlowSums;
179
219
  /**
180
220
  * One host bar's contract tuples from its buckets' raw rows (in bucket order), under the acquisition's knobs:
181
221
  * - every contract's sums over the bar, its last price from its newest bucket and its IV from its newest bucket that
182
- * had one;
222
+ * had one (`wrunOptionContractFlowSums`);
183
223
  * - `expiries: "nearest:N"`: the contracts of the bar's N nearest expiries (among every contract that traded);
184
224
  * - `strike_window_pct`: the strikes within that many percent of the bar's underlying, its contract-weighted price
185
225
  * over the bar's prints that carried one (sum_spot_size / size_priced over every contract row of the bar: the same
186
226
  * from any tier and any row order; a bar no priced print reached keeps every strike, there being nothing to judge
187
227
  * by);
188
228
  * - `min_volume`: a contract whose bar total contracts (`sum_size`) is below it is dropped.
189
- * Sorted by root, expiry, strike, then side.
229
+ * (`min_premium` and a session span are the worker twin's, before any row lands.) Sorted by root, expiry, strike, then
230
+ * side.
190
231
  */
191
232
  export declare function foldWrunOptionContractFlowBar(rows: ReadonlyArray<ReadonlyArray<unknown>>, acquisition: Readonly<Record<string, unknown>>): number[][];
@@ -35,6 +35,9 @@
35
35
  * to back, each the bucket's sums for one contract (`WRUN_OPTION_CONTRACT_FLOW_RAW_WIDTH` values;
36
36
  * `packWrunOptionContractFlowRaws`), handed to the page by transfer; the lane's per-bar fold reads the blocks in place
37
37
  * (a plain raw tuple reads the same), sums them per contract and applies the knobs that need the whole bar.
38
+ *
39
+ * OPTLOAD (kit 0.89.0): `span`, `history` and `min_premium`, read by the worker twin's grouped CONTRACT read and its
40
+ * fallback (wrun-option-strike-flow.util, off the boot path; docs/features/kscript/wrun/wrun-browser-runtime.md).
38
41
  */
39
42
  import { newYorkDayNumber, newYorkInstantMs } from '../options/option-symbol.util.js';
40
43
  import { KSCRIPT_SOURCE_ANSWER_CEILING_BYTES, kScriptSourceAnswerRows, } from '../chart/kscript-source-answer-budget.leaf.js';
@@ -213,7 +216,12 @@ const WRUN_OPTION_CONTRACT_FLOW_PROJECTIONS = Object.freeze({
213
216
  * No tier: none.
214
217
  */
215
218
  export function wrunOptionContractFlowBarRows(bar, nowMs, acquisition) {
216
- const plane = wrunLaneChainPlaneOf(wrunOptionContractFlowAcquisitionOf(acquisition).exchange);
219
+ const knobs = wrunOptionContractFlowAcquisitionOf(acquisition);
220
+ // `history` "today": a bar before today's first instant as the acquisition names it reads nothing, so it costs the
221
+ // budget nothing (never dated off `nowMs`: `wrunOptionFlowBarBeforeToday`).
222
+ if (wrunOptionFlowBarBeforeToday(bar, acquisition))
223
+ return 0;
224
+ const plane = wrunLaneChainPlaneOf(knobs.exchange);
217
225
  const projection = WRUN_OPTION_CONTRACT_FLOW_PROJECTIONS[plane];
218
226
  const perDay = bar.tier === undefined ? undefined : projection.dayRows[bar.tier.key];
219
227
  if (perDay === undefined)
@@ -277,14 +285,43 @@ const RAW_FLAG = Object.freeze({ shareDeltaAsk: 1, shareDeltaBid: 2, ivLast: 4 }
277
285
  export const WRUN_OPTION_CONTRACT_FLOW_EXCHANGE_FIELD = 'flowExchange';
278
286
  export const WRUN_OPTION_CONTRACT_FLOW_BOOK_FIELD = 'flowBook';
279
287
  export const WRUN_OPTION_CONTRACT_FLOW_CONTINUOUS_FIELD = 'flowContinuous';
288
+ /**
289
+ * `history` "today"'s field on a flow request (both flow classes, under one name): the first instant of today, the
290
+ * trade date of the chart's newest bar on the chain's venue clock (option-trade-date.util `optionTodayStartMsByClock`),
291
+ * named by the K control off the chart's bars (option-flow-bars.util `optionFlowTodayFields`), never off a clock. The
292
+ * worker twins read it (wrun-option-strike-flow.util `wrunOptionFlowTodayWindow`); a "today" request naming none
293
+ * reads nothing.
294
+ */
295
+ export const WRUN_OPTION_FLOW_TODAY_FIELD = 'todayFromMs';
296
+ /** Today's first instant a request or an acquisition names (`WRUN_OPTION_FLOW_TODAY_FIELD`), else undefined. */
297
+ export function wrunOptionFlowTodayFromOf(record) {
298
+ const value = record?.[WRUN_OPTION_FLOW_TODAY_FIELD];
299
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
300
+ }
301
+ /**
302
+ * Whether a bar reads nothing under `history` "today", so a row budget projects it at no rows (both flow lanes'
303
+ * `rowBudget.barRows`, and the strike flow fold's plan): it ends at or before today's first instant as the acquisition
304
+ * names it (`WRUN_OPTION_FLOW_TODAY_FIELD`). An acquisition naming no today (the host's plan hands its projection no
305
+ * newest bar to date today by) holds no such bar: today is never dated off a clock, so a bar of the newest trade date
306
+ * the chart holds is never projected at nothing. An older bar is then projected like any other and may be left
307
+ * partial where the budget stops; it reads nothing either way.
308
+ */
309
+ export function wrunOptionFlowBarBeforeToday(bar, acquisition) {
310
+ if (acquisition.history !== 'today')
311
+ return false;
312
+ const todayFromMs = wrunOptionFlowTodayFromOf(acquisition);
313
+ return todayFromMs !== undefined && bar.endMs <= todayFromMs;
314
+ }
280
315
  /** An instance's payload as its acquisition (knob fields that are not valid read absent). */
281
316
  export function wrunOptionContractFlowAcquisitionOf(extras) {
282
317
  const positive = (value) => typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : undefined;
283
318
  const upper = (value) => (typeof value === 'string' ? value.trim().toUpperCase() : '');
284
319
  const strikeWindowPct = positive(extras?.strikeWindowPct);
285
320
  const minVolume = positive(extras?.minVolume);
321
+ const minPremium = positive(extras?.minPremium);
286
322
  const coin = upper(extras?.coin);
287
323
  const book = upper(extras?.[WRUN_OPTION_CONTRACT_FLOW_BOOK_FIELD]);
324
+ const todayFromMs = wrunOptionFlowTodayFromOf(extras);
288
325
  return {
289
326
  coin,
290
327
  exchange: upper(extras?.[WRUN_OPTION_CONTRACT_FLOW_EXCHANGE_FIELD]),
@@ -292,6 +329,10 @@ export function wrunOptionContractFlowAcquisitionOf(extras) {
292
329
  ...(typeof extras?.expiries === 'string' ? { expiries: extras.expiries } : {}),
293
330
  ...(strikeWindowPct !== undefined ? { strikeWindowPct } : {}),
294
331
  ...(minVolume !== undefined ? { minVolume } : {}),
332
+ ...(minPremium !== undefined ? { minPremium } : {}),
333
+ ...(extras?.span === 'session' ? { span: 'session' } : {}),
334
+ ...(extras?.history === 'today' ? { history: 'today' } : {}),
335
+ ...(extras?.history === 'today' && todayFromMs !== undefined ? { todayFromMs } : {}),
295
336
  ...(typeof extras?.tier === 'string' ? { tier: extras.tier } : {}),
296
337
  };
297
338
  }
@@ -416,17 +457,6 @@ export function wrunOptionContractFlowRowOf(point, series) {
416
457
  ],
417
458
  };
418
459
  }
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) {
427
- const middle = row.bucketMs + Math.floor(Math.max(0, tierMs) / 2);
428
- return tradeDay(middle) === tradeDay(row.raw[WRUN_OPTION_CONTRACT_FLOW_RAW.expiry]);
429
- }
430
460
  /** Whether a cell is a raw contract tuple: exactly the raw width of finite numbers. */
431
461
  function isRawTuple(cell) {
432
462
  return (Array.isArray(cell) &&
@@ -470,7 +500,8 @@ export function wrunOptionContractFlowRawCount(row) {
470
500
  });
471
501
  return count;
472
502
  }
473
- /** The raw columns a contract's bar sums add up (the rest are its identity, its newest price or IV, its flags). */
503
+ /** The raw columns a contract's sums add up (the rest are its identity, its newest price or IV, its flags), the spot's
504
+ * two sums among them. */
474
505
  const SUMMED_RAW_COLUMNS = [
475
506
  WRUN_OPTION_CONTRACT_FLOW_RAW.volAsk,
476
507
  WRUN_OPTION_CONTRACT_FLOW_RAW.volBid,
@@ -482,30 +513,19 @@ const SUMMED_RAW_COLUMNS = [
482
513
  WRUN_OPTION_CONTRACT_FLOW_RAW.shareDeltaBid,
483
514
  WRUN_OPTION_CONTRACT_FLOW_RAW.sumPxSize,
484
515
  WRUN_OPTION_CONTRACT_FLOW_RAW.sumSize,
516
+ WRUN_OPTION_CONTRACT_FLOW_RAW.sumSpotSize,
485
517
  WRUN_OPTION_CONTRACT_FLOW_RAW.volAboveAsk,
486
518
  WRUN_OPTION_CONTRACT_FLOW_RAW.volBelowBid,
519
+ WRUN_OPTION_CONTRACT_FLOW_RAW.sizePriced,
487
520
  ];
488
- /**
489
- * One host bar's contract tuples from its buckets' raw rows (in bucket order), under the acquisition's knobs:
490
- * - every contract's sums over the bar, its last price from its newest bucket and its IV from its newest bucket that
491
- * had one;
492
- * - `expiries: "nearest:N"`: the contracts of the bar's N nearest expiries (among every contract that traded);
493
- * - `strike_window_pct`: the strikes within that many percent of the bar's underlying, its contract-weighted price
494
- * over the bar's prints that carried one (sum_spot_size / size_priced over every contract row of the bar: the same
495
- * from any tier and any row order; a bar no priced print reached keeps every strike, there being nothing to judge
496
- * by);
497
- * - `min_volume`: a contract whose bar total contracts (`sum_size`) is below it is dropped.
498
- * Sorted by root, expiry, strike, then side.
499
- */
500
- export function foldWrunOptionContractFlowBar(rows, acquisition) {
501
- const knobs = wrunOptionContractFlowAcquisitionOf(acquisition);
521
+ /** A new accumulator of per-contract sums (`WrunOptionContractFlowSums`). */
522
+ export function wrunOptionContractFlowSums() {
502
523
  const R = WRUN_OPTION_CONTRACT_FLOW_RAW;
503
524
  const byContract = new Map();
504
525
  let spotSize = 0;
505
526
  let sizePriced = 0;
506
- for (const row of rows) {
507
- const at = Number(row[0]);
508
- forEachWrunOptionContractFlowRaw(row, (source, offset) => {
527
+ return {
528
+ add(at, source, offset) {
509
529
  const flags = source[offset + R.flags];
510
530
  spotSize += source[offset + R.sumSpotSize];
511
531
  sizePriced += source[offset + R.sizePriced];
@@ -521,7 +541,7 @@ export function foldWrunOptionContractFlowBar(rows, acquisition) {
521
541
  lastAt: at,
522
542
  ivAt: (flags & RAW_FLAG.ivLast) !== 0 ? at : Number.NEGATIVE_INFINITY,
523
543
  });
524
- return;
544
+ return key;
525
545
  }
526
546
  for (const column of SUMMED_RAW_COLUMNS)
527
547
  sum.raw[column] += source[offset + column];
@@ -535,16 +555,48 @@ export function foldWrunOptionContractFlowBar(rows, acquisition) {
535
555
  sum.ivAt = at;
536
556
  sum.flags |= RAW_FLAG.ivLast;
537
557
  }
558
+ return key;
559
+ },
560
+ spot: () => (sizePriced > 0 ? spotSize / sizePriced : undefined),
561
+ raws: () => [...byContract.values()].map((sum) => {
562
+ const raw = [...sum.raw];
563
+ raw[R.flags] = sum.flags;
564
+ return raw;
565
+ }),
566
+ sums: () => [...byContract.values()],
567
+ };
568
+ }
569
+ /**
570
+ * One host bar's contract tuples from its buckets' raw rows (in bucket order), under the acquisition's knobs:
571
+ * - every contract's sums over the bar, its last price from its newest bucket and its IV from its newest bucket that
572
+ * had one (`wrunOptionContractFlowSums`);
573
+ * - `expiries: "nearest:N"`: the contracts of the bar's N nearest expiries (among every contract that traded);
574
+ * - `strike_window_pct`: the strikes within that many percent of the bar's underlying, its contract-weighted price
575
+ * over the bar's prints that carried one (sum_spot_size / size_priced over every contract row of the bar: the same
576
+ * from any tier and any row order; a bar no priced print reached keeps every strike, there being nothing to judge
577
+ * by);
578
+ * - `min_volume`: a contract whose bar total contracts (`sum_size`) is below it is dropped.
579
+ * (`min_premium` and a session span are the worker twin's, before any row lands.) Sorted by root, expiry, strike, then
580
+ * side.
581
+ */
582
+ export function foldWrunOptionContractFlowBar(rows, acquisition) {
583
+ const knobs = wrunOptionContractFlowAcquisitionOf(acquisition);
584
+ const R = WRUN_OPTION_CONTRACT_FLOW_RAW;
585
+ const accumulator = wrunOptionContractFlowSums();
586
+ for (const row of rows) {
587
+ const at = Number(row[0]);
588
+ forEachWrunOptionContractFlowRaw(row, (source, offset) => {
589
+ accumulator.add(at, source, offset);
538
590
  });
539
591
  }
540
- let sums = [...byContract.values()];
592
+ let sums = accumulator.sums();
541
593
  const expiries = wrunOptionExpiriesOf(knobs.expiries);
542
594
  if (expiries?.kind === 'nearest') {
543
595
  const kept = new Set(wrunNearestExpiryTuples(sums.map((sum) => sum.raw), expiries.count, R.expiry));
544
596
  sums = sums.filter((sum) => kept.has(sum.raw));
545
597
  }
546
598
  const pct = knobs.strikeWindowPct;
547
- const spot = sizePriced > 0 ? spotSize / sizePriced : undefined;
599
+ const spot = accumulator.spot();
548
600
  if (pct !== undefined && spot !== undefined && spot > 0) {
549
601
  const reach = (spot * pct) / 100;
550
602
  sums = sums.filter((sum) => Math.abs(sum.raw[R.strike] - spot) <= reach);
@@ -54,6 +54,64 @@ export declare const WRUN_OPTION_PRINTS_HISTORY: readonly ["live", "3d", "90d"];
54
54
  export type WrunOptionPrintsHistory = (typeof WRUN_OPTION_PRINTS_HISTORY)[number];
55
55
  export declare const WRUN_OPTION_PRINTS_OVERFLOW: readonly ["refuse", "largest"];
56
56
  export type WrunOptionPrintsOverflow = (typeof WRUN_OPTION_PRINTS_OVERFLOW)[number];
57
+ /** `newest` (om `WRUN_OPTION_PRINTS_NEWEST_MAX`): also keep the window's N newest prints, 0 to 20,000 (0 or absent: no
58
+ * newest cut). */
59
+ export declare const WRUN_OPTION_PRINTS_NEWEST_MAX = 20000;
60
+ /** `newest_tail_ms` (om `WRUN_OPTION_PRINTS_NEWEST_TAIL_MAX_MS`, with `newest` only): also every print up to this many
61
+ * ms before the oldest newest print, 0 to 60,000 (the legs of an order the cut would split). */
62
+ export declare const WRUN_OPTION_PRINTS_NEWEST_TAIL_MAX_MS = 60000;
63
+ /** `types` (om `WRUN_OPTION_PRINTS_TYPES`): "both" (absent too), "calls" or "puts". */
64
+ export declare const WRUN_OPTION_PRINTS_TYPES: readonly ["both", "calls", "puts"];
65
+ export type WrunOptionPrintsTypes = Exclude<(typeof WRUN_OPTION_PRINTS_TYPES)[number], 'both'>;
66
+ /** `sides` (om `WRUN_OPTION_PRINT_SIDES`), in om's order: the side of the quote a print is kept on (the aggressor
67
+ * against the NBBO on OPRA, "none" a print with no quote to side it; off OPRA the taker's side, "ask" or "bid"). */
68
+ export declare const WRUN_OPTION_PRINT_SIDES: readonly ["ask", "bid", "mid", "none"];
69
+ export type WrunOptionPrintSide = (typeof WRUN_OPTION_PRINT_SIDES)[number];
70
+ /** `moneyness` (om `WRUN_OPTIONS_FLOW_MONEYNESS`): "all" (absent too), "otm" or "itm". */
71
+ export declare const WRUN_OPTION_PRINTS_MONEYNESS: readonly ["all", "otm", "itm"];
72
+ export type WrunOptionPrintsMoneyness = Exclude<(typeof WRUN_OPTION_PRINTS_MONEYNESS)[number], 'all'>;
73
+ /** `max_dte` (om `WRUN_OPTION_MAX_DTE_DAYS`): keep the prints at most this many days to expiry, 0 to 3,650 (0 or
74
+ * absent: every expiry). */
75
+ export declare const WRUN_OPTION_MAX_DTE_DAYS = 3650;
76
+ /** The words a word or list knob of the print classes takes (om `wrunOptionKnobWords`); none for any other knob. The
77
+ * planners read a knob naming a setting by them (wrun-poll-lanes.util `resolveWrunOptionSettingKnobs`, whose one table
78
+ * `WRUN_OPTION_SETTING_KNOBS` holds the print class's row of om's `WRUN_OPTION_PARAM_KNOBS`). */
79
+ export declare function wrunOptionPrintKnobWords(knob: string): readonly string[];
80
+ /**
81
+ * The payload fields an acquisition carries its cuts and filters in (OPTLOAD G4), each absent at its default, so a
82
+ * sheet declaring none asks exactly as before. Where the gateway applies each:
83
+ * - `wire`: the cut ask's `optionRead` field (the worker twin's `optionPrintReadShape`), wherever the gateway's answer is
84
+ * the lane's own cut;
85
+ * - `request`: the request's own DataRequest field (`types` as `optionType`, the reader's type filter), on every read,
86
+ * so the gateway's cut is the lane's own when one type is asked (it filters before it cuts).
87
+ * The worker twin keeps every filter over the prints it read too (`wrunOptionPrintKept`), so today's ask paints alike.
88
+ * ONE table: the acquisition reads exactly these fields, and the class spec
89
+ * (tests/workers/indicators/controls/k-option-print.worker.class.spec.ts) fails on a field the asks leave out.
90
+ */
91
+ export declare const WRUN_OPTION_PRINTS_CUT_FIELDS: Readonly<{
92
+ readonly newest: {
93
+ readonly wire: "newest";
94
+ };
95
+ readonly newestTailMs: {
96
+ readonly wire: "newestTailMs";
97
+ };
98
+ readonly largestPerBar: {
99
+ readonly wire: "largestPerBar";
100
+ };
101
+ readonly sides: {
102
+ readonly wire: "sides";
103
+ };
104
+ readonly maxDte: {
105
+ readonly wire: "maxDteDays";
106
+ };
107
+ readonly moneyness: {
108
+ readonly wire: "moneyness";
109
+ };
110
+ readonly types: {
111
+ readonly request: "optionType";
112
+ };
113
+ }>;
114
+ export type WrunOptionPrintsCutField = keyof typeof WRUN_OPTION_PRINTS_CUT_FIELDS;
57
115
  /** The acquisition an `option_prints` instance asks with (its payload's facets and its chain). */
58
116
  export interface WrunOptionPrintsAcquisition {
59
117
  /** The chain's underlying, upper case: the key its plane files the prints under (the OPRA ticker, a crypto venue's
@@ -68,9 +126,27 @@ export interface WrunOptionPrintsAcquisition {
68
126
  overflow: WrunOptionPrintsOverflow;
69
127
  /** "nearest:N" or "0dte"; absent is "all". */
70
128
  expiries?: string;
129
+ /** The window's N newest prints (1 to 20,000), with `newestTailMs` (1 to 60,000) the prints that many ms before. */
130
+ newest?: number;
131
+ newestTailMs?: number;
132
+ /** The largest premiums each chart bar keeps on the gateway: the inputs' `max_cells` + 1 (2 and up). */
133
+ largestPerBar?: number;
134
+ types?: WrunOptionPrintsTypes;
135
+ /** The sides kept, in om's order (one to three of them: none or all four is every side, no field). */
136
+ sides?: readonly WrunOptionPrintSide[];
137
+ /** The most days to expiry a print has (1 to 3,650). */
138
+ maxDte?: number;
139
+ moneyness?: WrunOptionPrintsMoneyness;
71
140
  }
72
- /** An instance's payload as the acquisition it carries, or undefined when it names no valid floor or history. */
141
+ /** The sides a payload's `sides` field names ("ask,bid": om's facet spelling, the words in om's order, one to three
142
+ * of them), or undefined for anything else. */
143
+ export declare function wrunOptionPrintSidesOf(value: unknown): WrunOptionPrintSide[] | undefined;
144
+ /** An instance's payload as the acquisition it carries, or undefined when it names no valid floor or history, or a
145
+ * cut or filter outside its words. */
73
146
  export declare function wrunOptionPrintsAcquisitionOf(extras: Readonly<Record<string, unknown>> | null | undefined): WrunOptionPrintsAcquisition | undefined;
147
+ /** An acquisition's cut and filter fields as the payload carries them (`sides` in om's facet spelling), each absent at
148
+ * its default: what the K control forwards to the worker twin. */
149
+ export declare function wrunOptionPrintsCutPayloadOf(acquisition: Pick<WrunOptionPrintsAcquisition, WrunOptionPrintsCutField>): Record<string, unknown>;
74
150
  /**
75
151
  * Whether a payload's OPRA stamp agrees with the chain it names, the print classes' one rule for a K control: the
76
152
  * payload names its chain's exchange, and it carries the stamp (`wrunPlane: 'opra'`, which Door C judged) exactly when
@@ -164,16 +240,70 @@ export interface WrunOptionPrint {
164
240
  * counted.
165
241
  */
166
242
  export declare function wrunOptionPrintOf(print: Readonly<Record<string, unknown>> | null | undefined, series: Readonly<Record<string, unknown>> | null | undefined): WrunOptionPrint | WrunOptionPrintDrop;
243
+ /** The at-the-money band of the print rule (tsdb-gateway `optionPrintAtTheMoneyBand`, OptionPrint.moneyness): a
244
+ * strike within half a percent of the underlying counts as out of the money. */
245
+ export declare const WRUN_OPTION_PRINT_AT_THE_MONEY_BAND = 0.005;
246
+ /**
247
+ * A print's moneyness by the producer's rule (OptionPrint.moneyness, the gateway's option print job): -1 in the money
248
+ * (a call struck below the underlying less the band, a put struck above it plus the band), +1 otherwise, undefined
249
+ * without an underlying price (the tuple's bit 2 clear). Read off the tuple, so history (whose columns carry no
250
+ * moneyness) and live judge one print alike.
251
+ */
252
+ export declare function wrunOptionPrintMoneyness(tuple: ArrayLike<number>, at?: number): 1 | -1 | undefined;
253
+ /** The side word of a tuple's aggressor (+1 ask, -1 bid, 0 mid, 2 none). */
254
+ export declare function wrunOptionPrintSideWord(aggressor: number): WrunOptionPrintSide;
167
255
  /**
168
256
  * Whether a print passes an acquisition's own filters, on history and live alike: its chain (the print's exchange is
169
257
  * 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`).
258
+ * coin never merge), its floor, "0dte" (expiring on the print's trade date, the producer's `dte_days`), and the OPTLOAD
259
+ * filters: `types` (the tuple's call or put), `sides` (its aggressor's side word), `maxDte` (the producer's
260
+ * `dte_days`, at most) and `moneyness` (`wrunOptionPrintMoneyness`; a print without an underlying price has none).
171
261
  */
172
- export declare function wrunOptionPrintKept(print: WrunOptionPrint, acquisition: Pick<WrunOptionPrintsAcquisition, 'coin' | 'exchange' | 'book' | 'minPremium' | 'expiries'>): boolean;
262
+ export declare function wrunOptionPrintKept(print: WrunOptionPrint, acquisition: Pick<WrunOptionPrintsAcquisition, 'coin' | 'exchange' | 'book' | 'minPremium' | 'expiries'> & Partial<Pick<WrunOptionPrintsAcquisition, 'types' | 'sides' | 'maxDte' | 'moneyness'>>): boolean;
173
263
  /** Whether a cell is a print tuple of the class: exactly 16 finite numbers. */
174
264
  export declare function isWrunOptionPrintTuple(cell: unknown): cell is number[];
265
+ /** The order prints happened in: by offset, then by key (two prints in one millisecond). */
266
+ export declare function compareWrunOptionPrintsInTimeOrder(a: ArrayLike<number>, b: ArrayLike<number>): number;
175
267
  /** A bar's print tuples in the order they printed: by offset, then by key (two prints in one millisecond). */
176
268
  export declare function wrunOptionPrintsInTimeOrder(tuples: ReadonlyArray<ReadonlyArray<number>>): number[][];
269
+ /**
270
+ * The newest cut over a window's prints, the gateway's rule (OPTLOAD-READ-CONTRACT 7.2: `ORDER BY "timestamp" DESC,
271
+ * original_id DESC LIMIT newest`, then every print up to `tailMs` before the oldest kept one): every print stamped at
272
+ * or after the `newest`-th newest print's millisecond less the tail, in the order given. Inclusive at that millisecond:
273
+ * the stamps here are whole ms, so prints the gateway told apart below the ms (or by their id) stay together, and
274
+ * cutting a cut answer again keeps it whole (the worker cuts the union of several reads, each cut on the gateway, to
275
+ * the window's one cut). Fewer prints than `newest`: every print.
276
+ */
277
+ export declare function wrunNewestOptionPrints<T extends {
278
+ tsMs: number;
279
+ }>(prints: readonly T[], newest: number, tailMs?: number): T[];
280
+ /** Whether a tuple is a partial bar's marker (every value 0 but `present`, bit 14 alone set), never a print. */
281
+ export declare function isWrunOptionPrintMarker(tuple: ArrayLike<number>): boolean;
282
+ /**
283
+ * An instance's host-bar rows `[barOpen, ...tuples]` cut to its acquisition's newest cut over the whole window they
284
+ * hold, the gateway's rule (`wrunNewestOptionPrints`: every print stamped at or after the `newest`-th newest print's
285
+ * millisecond less `newestTailMs`, a print's time its bar's open plus its offset): what a history read of the window
286
+ * answers. The live fold applies it after every drain, so a live bar never outgrows the cut its history was read under
287
+ * (Flow Tape's day bar held the newest 3,000 prints from history, then every live print of the day on top, past its
288
+ * `max_cells`). A bar the cut empties keeps its row, empty or, when it was partial, the marker; a marker is no print.
289
+ * No newest cut, or `overflow: "largest"` (each bar's largest prints are the projection's, and the newest cut changes no
290
+ * bar it draws): the rows as they are (copied).
291
+ */
292
+ export declare function wrunNewestOptionPrintRows(rows: ReadonlyArray<ReadonlyArray<unknown>>, acquisition: Pick<WrunOptionPrintsAcquisition, 'newest' | 'newestTailMs' | 'overflow'>): unknown[][];
293
+ /**
294
+ * A window's rows `[secondMs, tuples]` as they cross to the page: every tuple packed back to back in ONE Float64Array
295
+ * (16 values each), each row `[secondMs, block]` with the block a view of its second's tuples. The worker posts them
296
+ * BY TRANSFER (comm.worker.util `sendV2RowsTransferringCellsToMainThread`: the one buffer moves, no structured clone
297
+ * walks it) and the lane reads the blocks in place (`forEachWrunOptionPrintTuple`).
298
+ */
299
+ export declare function packWrunOptionPrintRows(rows: ReadonlyArray<readonly [number, ReadonlyArray<ReadonlyArray<number>>]>): Array<[number, Float64Array]>;
300
+ /**
301
+ * Every print tuple a row's cells hold (from cell 1: cell 0 is the row's stamp), in order, read in place as
302
+ * (source, offset): a packed block's tuples back to back (a Float64Array holding a whole number of them, the worker's
303
+ * answer), a plain tuple (the live fold's, a spec's) at offset 0. A cell of any other shape, and a tuple holding a value
304
+ * that is not finite, is skipped.
305
+ */
306
+ export declare function forEachWrunOptionPrintTuple(row: ReadonlyArray<unknown>, visit: (source: ArrayLike<number>, offset: number) => void): void;
177
307
  /**
178
308
  * `overflow: "largest"` over a bar over its bound (om's packer rule, wrun-host/pack.ts `wrunLargestPremiumBlock`):
179
309
  * the `maxCells` prints with the largest premium (an equal premium keeps the earlier print; a non-finite premium