@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
@@ -39,13 +39,27 @@
39
39
  * read at the input's floor from whichever table the reader picks for it; "3d" every print of the last three days;
40
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
41
  * an older bar holds only those and is partial.
42
+ *
43
+ * OPTLOAD G4 (OPTLOAD-READ-CONTRACT sections 7.2 and 7.5, om kit 0.89.0): the cuts and filters a package declares
44
+ * ride the acquisition (`WRUN_OPTION_PRINTS_CUT_FIELDS`), so the gateway sends the prints the package draws, never
45
+ * every print of the window:
46
+ * - cuts: `newest` (the window's N newest prints) with `newestTailMs` (every print up to that many ms before the
47
+ * oldest of them), and `largestPerBar` (K = the inputs' `max_cells` + 1 largest premiums of each chart bar, which
48
+ * the per-input projection cuts to `max_cells` as before, bit 14 on a bar that answered more);
49
+ * - filters, per print (`wrunOptionPrintKept`, the one rule history and live read): `types`, `sides`, `maxDte` and
50
+ * `moneyness` (the producer's rule, `wrunOptionPrintMoneyness`).
51
+ * The worker twin asks the gateway for each of them where its answer is exactly the lane's own cut (`types` as the
52
+ * request's own `optionType`, the rest in `optionRead`), and makes the rest itself over the prints it read
53
+ * (`wrunNewestOptionPrints`, the filters), so every answer is the same picture.
54
+ * Its rows cross to the page packed (`packWrunOptionPrintRows`: one buffer, a block of tuples per second, moved by
55
+ * transfer) and the lane reads the blocks in place (`forEachWrunOptionPrintTuple`).
42
56
  */
43
57
  import { Exchange } from '@orangecharts/orange-v2-pb-common';
44
58
  import { parseOptionSymbol } from '../options/option-symbol.util.js';
45
59
  import { optionVenueForExchange } from '../options/option-venue.util.js';
46
60
  import { WRUN_PLANE_PAYLOAD_KEY } from '../chart/opra-read-access.leaf.js';
47
61
  import { exchangeCodeOf } from '../v2/gate-plane.util.js';
48
- import { wrunPresentMaskOf, wrunPresentWithPartial } from './wrun-present-bits.util.js';
62
+ import { wrunPartialMarkerTuple, wrunPresentHasBit, wrunPresentIsPartial, wrunPresentMaskOf, wrunPresentWithPartial, } from './wrun-present-bits.util.js';
49
63
  import { encodeSymbol } from './wrun-symbol-code.util.js';
50
64
  import { wrunOptionSeriesOf } from './sources/opra-option-lanes.util.js';
51
65
  import { wrunLaneChainPlaneOf } from './sources/wrun-row-lane.types.js';
@@ -104,11 +118,118 @@ export const WRUN_OPTION_PRINT_BAR_LIMIT_MS = 15_000 * 60_000;
104
118
  export const WRUN_OPTION_PRINT_CLOCK_MARGIN_MS = 10 * 60_000;
105
119
  export const WRUN_OPTION_PRINTS_HISTORY = Object.freeze(['live', '3d', '90d']);
106
120
  export const WRUN_OPTION_PRINTS_OVERFLOW = Object.freeze(['refuse', 'largest']);
121
+ /** `newest` (om `WRUN_OPTION_PRINTS_NEWEST_MAX`): also keep the window's N newest prints, 0 to 20,000 (0 or absent: no
122
+ * newest cut). */
123
+ export const WRUN_OPTION_PRINTS_NEWEST_MAX = 20_000;
124
+ /** `newest_tail_ms` (om `WRUN_OPTION_PRINTS_NEWEST_TAIL_MAX_MS`, with `newest` only): also every print up to this many
125
+ * ms before the oldest newest print, 0 to 60,000 (the legs of an order the cut would split). */
126
+ export const WRUN_OPTION_PRINTS_NEWEST_TAIL_MAX_MS = 60_000;
127
+ /** `types` (om `WRUN_OPTION_PRINTS_TYPES`): "both" (absent too), "calls" or "puts". */
128
+ export const WRUN_OPTION_PRINTS_TYPES = Object.freeze(['both', 'calls', 'puts']);
129
+ /** `sides` (om `WRUN_OPTION_PRINT_SIDES`), in om's order: the side of the quote a print is kept on (the aggressor
130
+ * against the NBBO on OPRA, "none" a print with no quote to side it; off OPRA the taker's side, "ask" or "bid"). */
131
+ export const WRUN_OPTION_PRINT_SIDES = Object.freeze(['ask', 'bid', 'mid', 'none']);
132
+ /** `moneyness` (om `WRUN_OPTIONS_FLOW_MONEYNESS`): "all" (absent too), "otm" or "itm". */
133
+ export const WRUN_OPTION_PRINTS_MONEYNESS = Object.freeze(['all', 'otm', 'itm']);
134
+ /** `max_dte` (om `WRUN_OPTION_MAX_DTE_DAYS`): keep the prints at most this many days to expiry, 0 to 3,650 (0 or
135
+ * absent: every expiry). */
136
+ export const WRUN_OPTION_MAX_DTE_DAYS = 3_650;
137
+ /** The words a word or list knob of the print classes takes (om `wrunOptionKnobWords`); none for any other knob. The
138
+ * planners read a knob naming a setting by them (wrun-poll-lanes.util `resolveWrunOptionSettingKnobs`, whose one table
139
+ * `WRUN_OPTION_SETTING_KNOBS` holds the print class's row of om's `WRUN_OPTION_PARAM_KNOBS`). */
140
+ export function wrunOptionPrintKnobWords(knob) {
141
+ if (knob === 'types')
142
+ return WRUN_OPTION_PRINTS_TYPES;
143
+ if (knob === 'moneyness')
144
+ return WRUN_OPTION_PRINTS_MONEYNESS;
145
+ if (knob === 'sides')
146
+ return WRUN_OPTION_PRINT_SIDES;
147
+ return [];
148
+ }
149
+ /**
150
+ * The payload fields an acquisition carries its cuts and filters in (OPTLOAD G4), each absent at its default, so a
151
+ * sheet declaring none asks exactly as before. Where the gateway applies each:
152
+ * - `wire`: the cut ask's `optionRead` field (the worker twin's `optionPrintReadShape`), wherever the gateway's answer is
153
+ * the lane's own cut;
154
+ * - `request`: the request's own DataRequest field (`types` as `optionType`, the reader's type filter), on every read,
155
+ * so the gateway's cut is the lane's own when one type is asked (it filters before it cuts).
156
+ * The worker twin keeps every filter over the prints it read too (`wrunOptionPrintKept`), so today's ask paints alike.
157
+ * ONE table: the acquisition reads exactly these fields, and the class spec
158
+ * (tests/workers/indicators/controls/k-option-print.worker.class.spec.ts) fails on a field the asks leave out.
159
+ */
160
+ export const WRUN_OPTION_PRINTS_CUT_FIELDS = Object.freeze({
161
+ newest: { wire: 'newest' },
162
+ newestTailMs: { wire: 'newestTailMs' },
163
+ largestPerBar: { wire: 'largestPerBar' },
164
+ sides: { wire: 'sides' },
165
+ maxDte: { wire: 'maxDteDays' },
166
+ moneyness: { wire: 'moneyness' },
167
+ types: { request: 'optionType' },
168
+ });
107
169
  /** A payload field's text, trimmed and upper case ('' for anything else). */
108
170
  function upperTextOf(value) {
109
171
  return typeof value === 'string' ? value.trim().toUpperCase() : '';
110
172
  }
111
- /** An instance's payload as the acquisition it carries, or undefined when it names no valid floor or history. */
173
+ /** A whole number from `min` to `max`. */
174
+ function wholeIn(value, min, max) {
175
+ return typeof value === 'number' && Number.isInteger(value) && value >= min && value <= max;
176
+ }
177
+ /** The sides a payload's `sides` field names ("ask,bid": om's facet spelling, the words in om's order, one to three
178
+ * of them), or undefined for anything else. */
179
+ export function wrunOptionPrintSidesOf(value) {
180
+ if (typeof value !== 'string' || value === '')
181
+ return undefined;
182
+ const words = value.split(',');
183
+ const sides = WRUN_OPTION_PRINT_SIDES.filter((side) => words.includes(side));
184
+ if (sides.length !== words.length || sides.length === WRUN_OPTION_PRINT_SIDES.length)
185
+ return undefined;
186
+ return sides.join(',') === value ? sides : undefined;
187
+ }
188
+ /** The cut and filter fields of a payload (`WRUN_OPTION_PRINTS_CUT_FIELDS`), or null when one is outside its words
189
+ * (a payload the lane never builds: fail closed). */
190
+ function cutFieldsOf(extras) {
191
+ const fields = {};
192
+ const { newest, newestTailMs, largestPerBar, types, sides, maxDte, moneyness } = extras;
193
+ if (newest !== undefined) {
194
+ if (!wholeIn(newest, 1, WRUN_OPTION_PRINTS_NEWEST_MAX))
195
+ return null;
196
+ fields.newest = newest;
197
+ }
198
+ if (newestTailMs !== undefined) {
199
+ if (fields.newest === undefined || !wholeIn(newestTailMs, 1, WRUN_OPTION_PRINTS_NEWEST_TAIL_MAX_MS))
200
+ return null;
201
+ fields.newestTailMs = newestTailMs;
202
+ }
203
+ if (largestPerBar !== undefined) {
204
+ if (!wholeIn(largestPerBar, 2, Number.MAX_SAFE_INTEGER))
205
+ return null;
206
+ fields.largestPerBar = largestPerBar;
207
+ }
208
+ if (types !== undefined) {
209
+ if (types !== 'calls' && types !== 'puts')
210
+ return null;
211
+ fields.types = types;
212
+ }
213
+ if (sides !== undefined) {
214
+ const read = wrunOptionPrintSidesOf(sides);
215
+ if (read === undefined)
216
+ return null;
217
+ fields.sides = read;
218
+ }
219
+ if (maxDte !== undefined) {
220
+ if (!wholeIn(maxDte, 1, WRUN_OPTION_MAX_DTE_DAYS))
221
+ return null;
222
+ fields.maxDte = maxDte;
223
+ }
224
+ if (moneyness !== undefined) {
225
+ if (moneyness !== 'otm' && moneyness !== 'itm')
226
+ return null;
227
+ fields.moneyness = moneyness;
228
+ }
229
+ return fields;
230
+ }
231
+ /** An instance's payload as the acquisition it carries, or undefined when it names no valid floor or history, or a
232
+ * cut or filter outside its words. */
112
233
  export function wrunOptionPrintsAcquisitionOf(extras) {
113
234
  if (!extras)
114
235
  return undefined;
@@ -121,6 +242,10 @@ export function wrunOptionPrintsAcquisitionOf(extras) {
121
242
  return undefined;
122
243
  if (!WRUN_OPTION_PRINTS_OVERFLOW.includes(overflow))
123
244
  return undefined;
245
+ const cuts = cutFieldsOf(extras);
246
+ // A per-bar cut exists under "largest" alone (the projection cuts each bar to its largest).
247
+ if (cuts === null || (cuts.largestPerBar !== undefined && overflow !== 'largest'))
248
+ return undefined;
124
249
  const coin = upperTextOf(extras.coin);
125
250
  const book = upperTextOf(extras[WRUN_OPTION_PRINTS_BOOK_FIELD]);
126
251
  return {
@@ -131,8 +256,21 @@ export function wrunOptionPrintsAcquisitionOf(extras) {
131
256
  history: history,
132
257
  overflow: overflow,
133
258
  ...(typeof extras.expiries === 'string' ? { expiries: extras.expiries } : {}),
259
+ ...cuts,
134
260
  };
135
261
  }
262
+ /** An acquisition's cut and filter fields as the payload carries them (`sides` in om's facet spelling), each absent at
263
+ * its default: what the K control forwards to the worker twin. */
264
+ export function wrunOptionPrintsCutPayloadOf(acquisition) {
265
+ const payload = {};
266
+ for (const field of Object.keys(WRUN_OPTION_PRINTS_CUT_FIELDS)) {
267
+ const value = acquisition[field];
268
+ if (value === undefined)
269
+ continue;
270
+ payload[field] = field === 'sides' ? value.join(',') : value;
271
+ }
272
+ return payload;
273
+ }
136
274
  /**
137
275
  * Whether a payload's OPRA stamp agrees with the chain it names, the print classes' one rule for a K control: the
138
276
  * payload names its chain's exchange, and it carries the stamp (`wrunPlane: 'opra'`, which Door C judged) exactly when
@@ -407,10 +545,42 @@ export function wrunOptionPrintOf(print, series) {
407
545
  tuple,
408
546
  };
409
547
  }
548
+ /** The at-the-money band of the print rule (tsdb-gateway `optionPrintAtTheMoneyBand`, OptionPrint.moneyness): a
549
+ * strike within half a percent of the underlying counts as out of the money. */
550
+ export const WRUN_OPTION_PRINT_AT_THE_MONEY_BAND = 0.005;
551
+ /**
552
+ * A print's moneyness by the producer's rule (OptionPrint.moneyness, the gateway's option print job): -1 in the money
553
+ * (a call struck below the underlying less the band, a put struck above it plus the band), +1 otherwise, undefined
554
+ * without an underlying price (the tuple's bit 2 clear). Read off the tuple, so history (whose columns carry no
555
+ * moneyness) and live judge one print alike.
556
+ */
557
+ export function wrunOptionPrintMoneyness(tuple, at = 0) {
558
+ const C = WRUN_OPTION_PRINT_COLUMN;
559
+ const underlying = tuple[at + C.underlying];
560
+ if (!wrunPresentHasBit(tuple[at + C.present], WRUN_OPTION_PRINT_BIT.underlying) || !(underlying > 0)) {
561
+ return undefined;
562
+ }
563
+ const strike = tuple[at + C.strike];
564
+ const side = tuple[at + C.side];
565
+ const band = underlying * WRUN_OPTION_PRINT_AT_THE_MONEY_BAND;
566
+ if ((side === 1 && strike < underlying - band) || (side === -1 && strike > underlying + band))
567
+ return -1;
568
+ return 1;
569
+ }
570
+ /** The side word of a tuple's aggressor (+1 ask, -1 bid, 0 mid, 2 none). */
571
+ export function wrunOptionPrintSideWord(aggressor) {
572
+ if (aggressor === 1)
573
+ return 'ask';
574
+ if (aggressor === -1)
575
+ return 'bid';
576
+ return aggressor === 0 ? 'mid' : 'none';
577
+ }
410
578
  /**
411
579
  * Whether a print passes an acquisition's own filters, on history and live alike: its chain (the print's exchange is
412
580
  * 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`).
581
+ * coin never merge), its floor, "0dte" (expiring on the print's trade date, the producer's `dte_days`), and the OPTLOAD
582
+ * filters: `types` (the tuple's call or put), `sides` (its aggressor's side word), `maxDte` (the producer's
583
+ * `dte_days`, at most) and `moneyness` (`wrunOptionPrintMoneyness`; a print without an underlying price has none).
414
584
  */
415
585
  export function wrunOptionPrintKept(print, acquisition) {
416
586
  if (print.exchange !== acquisition.exchange)
@@ -419,7 +589,17 @@ export function wrunOptionPrintKept(print, acquisition) {
419
589
  return false;
420
590
  if (!(print.premium >= acquisition.minPremium))
421
591
  return false;
422
- return acquisition.expiries !== '0dte' || print.dteDays === 0;
592
+ if (acquisition.expiries === '0dte' && print.dteDays !== 0)
593
+ return false;
594
+ const C = WRUN_OPTION_PRINT_COLUMN;
595
+ const { types, sides, maxDte, moneyness } = acquisition;
596
+ if (types !== undefined && print.tuple[C.side] !== (types === 'calls' ? 1 : -1))
597
+ return false;
598
+ if (sides !== undefined && !sides.includes(wrunOptionPrintSideWord(print.tuple[C.aggressor])))
599
+ return false;
600
+ if (maxDte !== undefined && !(print.dteDays !== undefined && print.dteDays <= maxDte))
601
+ return false;
602
+ return moneyness === undefined || wrunOptionPrintMoneyness(print.tuple) === (moneyness === 'otm' ? 1 : -1);
423
603
  }
424
604
  /** Whether a cell is a print tuple of the class: exactly 16 finite numbers. */
425
605
  export function isWrunOptionPrintTuple(cell) {
@@ -427,12 +607,142 @@ export function isWrunOptionPrintTuple(cell) {
427
607
  cell.length === WRUN_OPTION_PRINTS_WIDTH &&
428
608
  cell.every((value) => typeof value === 'number' && Number.isFinite(value)));
429
609
  }
610
+ /** The order prints happened in: by offset, then by key (two prints in one millisecond). */
611
+ export function compareWrunOptionPrintsInTimeOrder(a, b) {
612
+ return (a[WRUN_OPTION_PRINT_COLUMN.offset] - b[WRUN_OPTION_PRINT_COLUMN.offset] ||
613
+ a[WRUN_OPTION_PRINT_COLUMN.key] - b[WRUN_OPTION_PRINT_COLUMN.key]);
614
+ }
430
615
  /** A bar's print tuples in the order they printed: by offset, then by key (two prints in one millisecond). */
431
616
  export function wrunOptionPrintsInTimeOrder(tuples) {
432
- return tuples
433
- .map((tuple) => [...tuple])
434
- .sort((a, b) => a[WRUN_OPTION_PRINT_COLUMN.offset] - b[WRUN_OPTION_PRINT_COLUMN.offset] ||
435
- a[WRUN_OPTION_PRINT_COLUMN.key] - b[WRUN_OPTION_PRINT_COLUMN.key]);
617
+ return tuples.map((tuple) => [...tuple]).sort(compareWrunOptionPrintsInTimeOrder);
618
+ }
619
+ // ---------------------------------------------------------------------------
620
+ // The newest cut, and the rows as they cross to the page.
621
+ // ---------------------------------------------------------------------------
622
+ /**
623
+ * The newest cut over a window's prints, the gateway's rule (OPTLOAD-READ-CONTRACT 7.2: `ORDER BY "timestamp" DESC,
624
+ * original_id DESC LIMIT newest`, then every print up to `tailMs` before the oldest kept one): every print stamped at
625
+ * or after the `newest`-th newest print's millisecond less the tail, in the order given. Inclusive at that millisecond:
626
+ * the stamps here are whole ms, so prints the gateway told apart below the ms (or by their id) stay together, and
627
+ * cutting a cut answer again keeps it whole (the worker cuts the union of several reads, each cut on the gateway, to
628
+ * the window's one cut). Fewer prints than `newest`: every print.
629
+ */
630
+ export function wrunNewestOptionPrints(prints, newest, tailMs = 0) {
631
+ if (!(newest >= 1) || prints.length <= newest)
632
+ return [...prints];
633
+ const stamps = prints.map((print) => print.tsMs).sort((a, b) => b - a);
634
+ const fromMs = stamps[newest - 1] - Math.max(0, tailMs);
635
+ return prints.filter((print) => print.tsMs >= fromMs);
636
+ }
637
+ /** Whether a tuple is a partial bar's marker (every value 0 but `present`, bit 14 alone set), never a print. */
638
+ export function isWrunOptionPrintMarker(tuple) {
639
+ const present = tuple[WRUN_OPTION_PRINT_COLUMN.present];
640
+ if (!wrunPresentIsPartial(present))
641
+ return false;
642
+ for (let at = 0; at < WRUN_OPTION_PRINTS_WIDTH; at += 1) {
643
+ if (at !== WRUN_OPTION_PRINT_COLUMN.present && tuple[at] !== 0)
644
+ return false;
645
+ }
646
+ return true;
647
+ }
648
+ /**
649
+ * An instance's host-bar rows `[barOpen, ...tuples]` cut to its acquisition's newest cut over the whole window they
650
+ * hold, the gateway's rule (`wrunNewestOptionPrints`: every print stamped at or after the `newest`-th newest print's
651
+ * millisecond less `newestTailMs`, a print's time its bar's open plus its offset): what a history read of the window
652
+ * answers. The live fold applies it after every drain, so a live bar never outgrows the cut its history was read under
653
+ * (Flow Tape's day bar held the newest 3,000 prints from history, then every live print of the day on top, past its
654
+ * `max_cells`). A bar the cut empties keeps its row, empty or, when it was partial, the marker; a marker is no print.
655
+ * No newest cut, or `overflow: "largest"` (each bar's largest prints are the projection's, and the newest cut changes no
656
+ * bar it draws): the rows as they are (copied).
657
+ */
658
+ export function wrunNewestOptionPrintRows(rows, acquisition) {
659
+ const newest = acquisition.newest;
660
+ const copy = () => rows.map((row) => [...row]);
661
+ if (newest === undefined || !(newest >= 1) || acquisition.overflow === 'largest')
662
+ return copy();
663
+ const C = WRUN_OPTION_PRINT_COLUMN;
664
+ const isPrint = (cell) => isWrunOptionPrintTuple(cell) && !isWrunOptionPrintMarker(cell);
665
+ const stamps = [];
666
+ for (const row of rows) {
667
+ const open = Number(row[0]);
668
+ for (let at = 1; at < row.length; at += 1) {
669
+ const cell = row[at];
670
+ if (isPrint(cell))
671
+ stamps.push(open + cell[C.offset]);
672
+ }
673
+ }
674
+ if (stamps.length <= newest)
675
+ return copy();
676
+ stamps.sort((a, b) => b - a);
677
+ const fromMs = stamps[newest - 1] - Math.max(0, acquisition.newestTailMs ?? 0);
678
+ return rows.map((row) => {
679
+ const open = Number(row[0]);
680
+ const cells = row.slice(1);
681
+ const prints = cells.filter(isPrint);
682
+ const kept = prints.filter((tuple) => open + tuple[C.offset] >= fromMs);
683
+ if (kept.length === prints.length)
684
+ return [...row];
685
+ const partial = cells.some((cell) => isWrunOptionPrintTuple(cell) && wrunPresentIsPartial(cell[C.present]));
686
+ if (kept.length > 0)
687
+ return [row[0], ...kept];
688
+ return partial ? [row[0], wrunPartialMarkerTuple(WRUN_OPTION_PRINTS_WIDTH)] : [row[0]];
689
+ });
690
+ }
691
+ /**
692
+ * A window's rows `[secondMs, tuples]` as they cross to the page: every tuple packed back to back in ONE Float64Array
693
+ * (16 values each), each row `[secondMs, block]` with the block a view of its second's tuples. The worker posts them
694
+ * BY TRANSFER (comm.worker.util `sendV2RowsTransferringCellsToMainThread`: the one buffer moves, no structured clone
695
+ * walks it) and the lane reads the blocks in place (`forEachWrunOptionPrintTuple`).
696
+ */
697
+ export function packWrunOptionPrintRows(rows) {
698
+ const width = WRUN_OPTION_PRINTS_WIDTH;
699
+ let count = 0;
700
+ for (const [, tuples] of rows)
701
+ count += tuples.length;
702
+ const packed = new Float64Array(count * width);
703
+ const out = [];
704
+ let at = 0;
705
+ for (const [secondMs, tuples] of rows) {
706
+ const start = at;
707
+ for (const tuple of tuples) {
708
+ for (let column = 0; column < width; column += 1)
709
+ packed[at + column] = tuple[column];
710
+ at += width;
711
+ }
712
+ out.push([secondMs, packed.subarray(start, at)]);
713
+ }
714
+ return out;
715
+ }
716
+ /** Whether the tuple at `offset` of a block holds finite numbers only (a plain tuple's rule, read in place). */
717
+ function printTupleFiniteAt(block, offset) {
718
+ for (let column = 0; column < WRUN_OPTION_PRINTS_WIDTH; column += 1) {
719
+ if (!Number.isFinite(block[offset + column]))
720
+ return false;
721
+ }
722
+ return true;
723
+ }
724
+ /**
725
+ * Every print tuple a row's cells hold (from cell 1: cell 0 is the row's stamp), in order, read in place as
726
+ * (source, offset): a packed block's tuples back to back (a Float64Array holding a whole number of them, the worker's
727
+ * 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
728
+ * that is not finite, is skipped.
729
+ */
730
+ export function forEachWrunOptionPrintTuple(row, visit) {
731
+ const width = WRUN_OPTION_PRINTS_WIDTH;
732
+ for (let index = 1; index < row.length; index += 1) {
733
+ const cell = row[index];
734
+ if (cell instanceof Float64Array) {
735
+ if (cell.length % width !== 0)
736
+ continue;
737
+ for (let offset = 0; offset < cell.length; offset += width) {
738
+ if (printTupleFiniteAt(cell, offset))
739
+ visit(cell, offset);
740
+ }
741
+ }
742
+ else if (isWrunOptionPrintTuple(cell)) {
743
+ visit(cell, 0);
744
+ }
745
+ }
436
746
  }
437
747
  /**
438
748
  * `overflow: "largest"` over a bar over its bound (om's packer rule, wrun-host/pack.ts `wrunLargestPremiumBlock`):
@@ -0,0 +1,96 @@
1
+ import type { WrunBackendTier } from './wrun-tier-grid.util.js';
2
+ /** The class, its lane key and its K type word (om `WRUN_OPTION_FETCH_TYPES.option_strike_flow`). */
3
+ export declare const WRUN_OPTION_STRIKE_FLOW_CLASS = "option_strike_flow";
4
+ /** f64s per tuple, the `present` mask included (om `WRUN_OPTION_TUPLE_WIDTHS.option_strike_flow`). */
5
+ export declare const WRUN_OPTION_STRIKE_FLOW_WIDTH = 15;
6
+ /** The tuple's columns (om `WRUN_OPTION_CELL_COLUMNS.option_strike_flow`). */
7
+ export declare const WRUN_OPTION_STRIKE_FLOW_COLUMN: Readonly<{
8
+ readonly expiry: 0;
9
+ readonly strike: 1;
10
+ readonly side: 2;
11
+ readonly dteClass: 3;
12
+ readonly volAsk: 4;
13
+ readonly volBid: 5;
14
+ readonly volMid: 6;
15
+ readonly volNone: 7;
16
+ readonly volAboveAsk: 8;
17
+ readonly volBelowBid: 9;
18
+ readonly premAsk: 10;
19
+ readonly premBid: 11;
20
+ readonly premMid: 12;
21
+ readonly premNone: 13;
22
+ readonly present: 14;
23
+ }>;
24
+ /** `group` (om `WRUN_OPTION_STRIKE_FLOW_GROUPS`, required). */
25
+ export declare const WRUN_OPTION_STRIKE_FLOW_GROUPS: readonly ["strike", "expiry", "expiry_strike"];
26
+ export type WrunOptionStrikeFlowGroup = (typeof WRUN_OPTION_STRIKE_FLOW_GROUPS)[number];
27
+ /** `span` and `history` on the grouped flow classes (om `WRUN_OPTION_FLOW_SPANS`, `WRUN_OPTION_FLOW_HISTORY`). */
28
+ export declare const WRUN_OPTION_FLOW_SPANS: readonly ["bar", "session"];
29
+ export declare const WRUN_OPTION_FLOW_HISTORY: readonly ["window", "today"];
30
+ /** The tiers each group is served at (om `WRUN_OPTION_STRIKE_FLOW_TIERS`, contract 6.3): 1m 7 days, 5m 30, 30m kept
31
+ * (30 days on `expiry_strike`, the lane's horizon). Every tier serves the forming bar. */
32
+ export declare const WRUN_OPTION_STRIKE_FLOW_TIERS: Readonly<Record<WrunOptionStrikeFlowGroup, readonly WrunBackendTier[]>>;
33
+ /** `expiries` on this class: the contract classes' words and "after_today" (om `wrunOptionStrikeFlowExpiries`). */
34
+ export type WrunOptionStrikeFlowExpiries = {
35
+ kind: 'all';
36
+ } | {
37
+ kind: '0dte';
38
+ } | {
39
+ kind: 'after_today';
40
+ } | {
41
+ kind: 'nearest';
42
+ count: number;
43
+ };
44
+ /** An `expiries` word as this class reads it (absent is "all"), or undefined for a word outside them. */
45
+ export declare function wrunOptionStrikeFlowExpiriesOf(value: unknown): WrunOptionStrikeFlowExpiries | undefined;
46
+ /** One input's knobs, canonical: each absent at its default (one acquisition for equal reads). */
47
+ export interface WrunOptionStrikeFlowKnobs {
48
+ group: WrunOptionStrikeFlowGroup;
49
+ /** "0dte", "after_today" or "nearest:N"; absent is "all". */
50
+ expiries?: string;
51
+ strikeWindowPct?: number;
52
+ strikeRows?: number;
53
+ splitDte?: true;
54
+ foldTypes?: true;
55
+ /** "session"; absent is "bar". */
56
+ span?: 'session';
57
+ /** "today"; absent is "window". */
58
+ history?: 'today';
59
+ minVolume?: number;
60
+ }
61
+ /** The knobs an acquisition (an instance's payload) names, a field that is not valid read absent. */
62
+ export declare function wrunOptionStrikeFlowPayloadKnobsOf(payload: Readonly<Record<string, unknown>> | null | undefined): WrunOptionStrikeFlowKnobs;
63
+ /** The span the class is served over for one acquisition: `expiry_strike`'s 30-minute view keeps 30 days; every other
64
+ * group's tiers say it alone. */
65
+ export declare function wrunOptionStrikeFlowHorizon(extras: Readonly<Record<string, unknown>>, nowMs: number): {
66
+ servedFromMs: number;
67
+ completeFromMs: number;
68
+ } | undefined;
69
+ /** The tuples one SPY bar of a group holds (one 30-minute session of 13 bars measured 2026-10-19): STRIKE 357 (471 with
70
+ * the 0DTE split), EXPIRY 75, the per-(expiry, strike) rows 2,326; 33 traded expiries. Any bar width, every chain. */
71
+ export declare const WRUN_OPTION_STRIKE_FLOW_BAR_TUPLES: Readonly<{
72
+ strike: 357;
73
+ strikeSplit: 471;
74
+ expiry: 75;
75
+ expiryStrike: 2326;
76
+ expiries: 33;
77
+ }>;
78
+ /** The tuples a bar of one acquisition is projected to hold, from its knobs over SPY's measured bars. */
79
+ export declare function wrunOptionStrikeFlowTuplesPerBar(acquisition: Readonly<Record<string, unknown>>): number;
80
+ /** The rows one host bar is projected to read (the lane's row budget): its projected tuples, none for a bar before
81
+ * today's first instant as the acquisition names it under `history` "today" (it reads nothing;
82
+ * wrun-option-contract-flow.util `wrunOptionFlowBarBeforeToday`, never dated off `nowMs`). */
83
+ export declare function wrunOptionStrikeFlowBarRows(bar: {
84
+ openMs: number;
85
+ endMs: number;
86
+ tier?: WrunBackendTier;
87
+ }, _nowMs: number, acquisition: Readonly<Record<string, unknown>>): number;
88
+ /** Every finite tuple a host bar row's cells hold, in order: a packed block's tuples back to back, a plain tuple as it
89
+ * is. A cell of another shape, and a tuple holding a value that is not finite, is skipped. */
90
+ export declare function wrunOptionStrikeFlowTuplesOfRow(row: ReadonlyArray<unknown>): number[][];
91
+ /** The canonical order of a bar's tuples: expiry, strike, calls before puts (folded last), then the 0DTE part first. */
92
+ export declare function compareWrunOptionStrikeFlowTuples(a: ArrayLike<number>, b: ArrayLike<number>): number;
93
+ /** One host bar's tuples from its rows (the lane's fold): a grouped bar's tuples as they are, several rows of one bar
94
+ * merged key by key (expiry, strike, side, class: values summed, a partial mark kept), a partial marker kept as the
95
+ * bar's marker. Sorted canonically. */
96
+ export declare function foldWrunOptionStrikeFlowBar(rows: ReadonlyArray<ReadonlyArray<unknown>>): number[][];