@orangecharts/wrun-chart-host 0.7.1 → 0.9.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 (210) hide show
  1. package/README.md +27 -4
  2. package/dist/constants/feature-flags.constants.d.ts +5 -0
  3. package/dist/constants/feature-flags.constants.js +32 -0
  4. package/dist/constants/marketCapabilities.constants.d.ts +14 -9
  5. package/dist/constants/marketCapabilities.constants.js +36 -13
  6. package/dist/constants/opra-compliance.constants.d.ts +14 -0
  7. package/dist/constants/opra-compliance.constants.js +14 -0
  8. package/dist/constants/option-venues.constants.d.ts +29 -6
  9. package/dist/constants/option-venues.constants.js +19 -2
  10. package/dist/constants/venue-presets.constants.d.ts +17 -3
  11. package/dist/constants/venue-presets.constants.js +17 -3
  12. package/dist/host-env.d.ts +34 -4
  13. package/dist/host-env.js +21 -0
  14. package/dist/host-ports.types.d.ts +51 -3
  15. package/dist/index.d.ts +17 -0
  16. package/dist/index.js +17 -0
  17. package/dist/indicators/controls/tpo-session.util.d.ts +40 -11
  18. package/dist/indicators/controls/tpo-session.util.js +138 -14
  19. package/dist/interfaces/opra-realtime.interface.d.ts +13 -11
  20. package/dist/interfaces/opra-realtime.interface.js +10 -10
  21. package/dist/interfaces/option-instrument.interface.d.ts +6 -0
  22. package/dist/interfaces/wrun-runtime.interface.d.ts +34 -13
  23. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +57 -10
  24. package/dist/kscript-data/controls/live-trades-merge.util.js +85 -16
  25. package/dist/market-data/billing.interface.d.ts +138 -17
  26. package/dist/market-data/billing.interface.js +25 -8
  27. package/dist/market-data/venues/index.d.ts +3 -3
  28. package/dist/market-data/venues/opra.contract.copy.json +5 -3
  29. package/dist/market-data/venues/opra.d.ts +3 -3
  30. package/dist/market-data/venues/opra.js +5 -4
  31. package/dist/replay/replayLadder.js +3 -1
  32. package/dist/settings-templates/footprint-rows.d.ts +25 -0
  33. package/dist/settings-templates/footprint-rows.js +127 -0
  34. package/dist/settings-templates/form-rows.d.ts +56 -0
  35. package/dist/settings-templates/form-rows.js +19 -0
  36. package/dist/settings-templates/frvp-fields.js +14 -0
  37. package/dist/settings-templates/index.d.ts +10 -1
  38. package/dist/settings-templates/index.js +11 -2
  39. package/dist/settings-templates/indicator-fields.js +78 -0
  40. package/dist/settings-templates/tool-rules.d.ts +35 -9
  41. package/dist/settings-templates/tool-rules.js +42 -8
  42. package/dist/settings-templates/tool-tables.generated.js +13 -2
  43. package/dist/utility/chart/candle-volume-unit.leaf.d.ts +16 -0
  44. package/dist/utility/chart/candle-volume-unit.leaf.js +61 -0
  45. package/dist/utility/chart/crypto-index.leaf.d.ts +2 -2
  46. package/dist/utility/chart/crypto-index.leaf.js +2 -2
  47. package/dist/utility/chart/footprint-columns.util.d.ts +74 -0
  48. package/dist/utility/chart/footprint-columns.util.js +106 -0
  49. package/dist/utility/chart/footprint-display-mode.util.d.ts +40 -0
  50. package/dist/utility/chart/footprint-display-mode.util.js +62 -0
  51. package/dist/utility/chart/footprint-sierra-look.util.d.ts +2 -0
  52. package/dist/utility/chart/footprint-sierra-look.util.js +37 -0
  53. package/dist/utility/chart/index-mode-admission.util.js +9 -1
  54. package/dist/utility/chart/index-mode.util.d.ts +5 -2
  55. package/dist/utility/chart/index-mode.util.js +23 -13
  56. package/dist/utility/chart/kscript-venue-policy.util.d.ts +28 -21
  57. package/dist/utility/chart/kscript-venue-policy.util.js +34 -26
  58. package/dist/utility/chart/marketKind.util.d.ts +12 -10
  59. package/dist/utility/chart/marketKind.util.js +17 -7
  60. package/dist/utility/chart/om-panel-push-style.util.d.ts +7 -7
  61. package/dist/utility/chart/om-panel-push-style.util.js +17 -15
  62. package/dist/utility/chart/om-panel.util.d.ts +11 -0
  63. package/dist/utility/chart/om-panel.util.js +65 -6
  64. package/dist/utility/chart/profile-block-size.util.d.ts +16 -0
  65. package/dist/utility/chart/profile-block-size.util.js +7 -0
  66. package/dist/utility/chart/quote-perp.leaf.d.ts +17 -0
  67. package/dist/utility/chart/quote-perp.leaf.js +20 -0
  68. package/dist/utility/chart/window-geometry.leaf.d.ts +23 -1
  69. package/dist/utility/chart/window-geometry.leaf.js +78 -6
  70. package/dist/utility/chart/window-owner.leaf.d.ts +13 -0
  71. package/dist/utility/chart/window-owner.leaf.js +5 -0
  72. package/dist/utility/chart/wrun-run-result.util.d.ts +5 -0
  73. package/dist/utility/chart/wrun-run-result.util.js +4 -1
  74. package/dist/utility/common/transformations.util.d.ts +7 -0
  75. package/dist/utility/common/transformations.util.js +11 -0
  76. package/dist/utility/options/cme-options-root.util.d.ts +25 -0
  77. package/dist/utility/options/cme-options-root.util.js +40 -0
  78. package/dist/utility/options/option-book.util.d.ts +27 -0
  79. package/dist/utility/options/option-book.util.js +76 -0
  80. package/dist/utility/options/option-trade-date.util.d.ts +50 -0
  81. package/dist/utility/options/option-trade-date.util.js +120 -0
  82. package/dist/utility/options/option-venue.util.d.ts +3 -3
  83. package/dist/utility/options/option-venue.util.js +3 -3
  84. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +1 -1
  85. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +2 -2
  86. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +2 -2
  87. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +5 -1
  88. package/dist/utility/wrun/sources/host-grid-landing.d.ts +4 -2
  89. package/dist/utility/wrun/sources/host-grid-landing.js +8 -0
  90. package/dist/utility/wrun/sources/lanes/options_flow.d.ts +40 -4
  91. package/dist/utility/wrun/sources/lanes/options_flow.js +115 -18
  92. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +12 -9
  93. package/dist/utility/wrun/sources/opra-option-lanes.util.js +10 -7
  94. package/dist/utility/wrun/sources/row-lane-registry.js +10 -5
  95. package/dist/utility/wrun/sources/row-lanes/index.js +2 -0
  96. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +3 -2
  97. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +30 -5
  98. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +9 -3
  99. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +13 -5
  100. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +25 -1
  101. package/dist/utility/wrun/sources/row-lanes/option_prints.js +161 -30
  102. package/dist/utility/wrun/sources/row-lanes/option_strike_flow.d.ts +4 -0
  103. package/dist/utility/wrun/sources/row-lanes/option_strike_flow.js +65 -0
  104. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +55 -1
  105. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +83 -2
  106. package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +17 -1
  107. package/dist/utility/wrun/sources/row-lanes/option_surface.js +33 -2
  108. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +7 -1
  109. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +51 -5
  110. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +136 -3
  111. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +42 -0
  112. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +146 -0
  113. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +25 -5
  114. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +111 -20
  115. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +291 -48
  116. package/dist/utility/wrun/wrun-batched-marks.util.d.ts +16 -3
  117. package/dist/utility/wrun/wrun-batched-marks.util.js +30 -19
  118. package/dist/utility/wrun/wrun-batched-readout.util.d.ts +37 -9
  119. package/dist/utility/wrun/wrun-batched-readout.util.js +61 -15
  120. package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +4 -0
  121. package/dist/utility/wrun/wrun-cell-capacity.leaf.d.ts +66 -0
  122. package/dist/utility/wrun/wrun-cell-capacity.leaf.js +86 -0
  123. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +147 -9
  124. package/dist/utility/wrun/wrun-chart-market-facts.util.js +345 -11
  125. package/dist/utility/wrun/wrun-cloud-record.leaf.d.ts +27 -0
  126. package/dist/utility/wrun/wrun-cloud-record.leaf.js +71 -0
  127. package/dist/utility/wrun/wrun-cloud-record.util.d.ts +4 -21
  128. package/dist/utility/wrun/wrun-cloud-record.util.js +5 -65
  129. package/dist/utility/wrun/wrun-color-facts.util.d.ts +19 -9
  130. package/dist/utility/wrun/wrun-color-facts.util.js +24 -14
  131. package/dist/utility/wrun/wrun-color-settings.util.d.ts +22 -9
  132. package/dist/utility/wrun/wrun-color-settings.util.js +57 -23
  133. package/dist/utility/wrun/wrun-dollar-unit-port.leaf.d.ts +17 -0
  134. package/dist/utility/wrun/wrun-dollar-unit-port.leaf.js +9 -0
  135. package/dist/utility/wrun/wrun-download-meter.util.d.ts +92 -0
  136. package/dist/utility/wrun/wrun-download-meter.util.js +122 -0
  137. package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +10 -3
  138. package/dist/utility/wrun/wrun-draft-overlay.util.js +63 -6
  139. package/dist/utility/wrun/wrun-frames.js +5 -5
  140. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +2 -2
  141. package/dist/utility/wrun/wrun-hosted-wire-caps.js +11 -0
  142. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +33 -17
  143. package/dist/utility/wrun/wrun-hud-looks.util.js +30 -16
  144. package/dist/utility/wrun/wrun-lane-refusal.leaf.d.ts +29 -3
  145. package/dist/utility/wrun/wrun-lane-refusal.leaf.js +33 -3
  146. package/dist/utility/wrun/wrun-lifecycle-runtime.util.d.ts +8 -6
  147. package/dist/utility/wrun/wrun-lifecycle-runtime.util.js +8 -6
  148. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +4 -2
  149. package/dist/utility/wrun/wrun-live-intake.util.d.ts +6 -2
  150. package/dist/utility/wrun/wrun-live-intake.util.js +136 -21
  151. package/dist/utility/wrun/wrun-live-tick.util.d.ts +4 -1
  152. package/dist/utility/wrun/wrun-live-tick.util.js +130 -44
  153. package/dist/utility/wrun/wrun-market-size-contract-carry.leaf.d.ts +53 -0
  154. package/dist/utility/wrun/wrun-market-size-contract-carry.leaf.js +162 -0
  155. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +224 -0
  156. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +342 -0
  157. package/dist/utility/wrun/wrun-market-size-defaults.util.d.ts +88 -0
  158. package/dist/utility/wrun/wrun-market-size-defaults.util.js +471 -0
  159. package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +43 -8
  160. package/dist/utility/wrun/wrun-opra-flow.leaf.js +37 -6
  161. package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +51 -10
  162. package/dist/utility/wrun/wrun-option-contract-flow.util.js +85 -33
  163. package/dist/utility/wrun/wrun-option-prints.util.d.ts +172 -3
  164. package/dist/utility/wrun/wrun-option-prints.util.js +394 -17
  165. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +99 -0
  166. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +218 -0
  167. package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +365 -0
  168. package/dist/utility/wrun/wrun-option-strike-flow.util.js +797 -0
  169. package/dist/utility/wrun/wrun-option-views.util.d.ts +231 -7
  170. package/dist/utility/wrun/wrun-option-views.util.js +643 -23
  171. package/dist/utility/wrun/wrun-options-chain.util.d.ts +6 -4
  172. package/dist/utility/wrun/wrun-options-chain.util.js +8 -5
  173. package/dist/utility/wrun/wrun-options-stop.util.d.ts +2 -1
  174. package/dist/utility/wrun/wrun-options-stop.util.js +3 -2
  175. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +3 -0
  176. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.d.ts +31 -14
  177. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.js +22 -0
  178. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +9 -1
  179. package/dist/utility/wrun/wrun-overlay-recovery.util.js +32 -3
  180. package/dist/utility/wrun/wrun-overlay-result.util.d.ts +7 -1
  181. package/dist/utility/wrun/wrun-overlay-result.util.js +2 -0
  182. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +34 -6
  183. package/dist/utility/wrun/wrun-overlay-run.util.js +527 -180
  184. package/dist/utility/wrun/wrun-pack-widths.leaf.d.ts +15 -0
  185. package/dist/utility/wrun/wrun-pack-widths.leaf.js +22 -0
  186. package/dist/utility/wrun/wrun-pack.util.d.ts +13 -8
  187. package/dist/utility/wrun/wrun-pack.util.js +38 -21
  188. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +4 -0
  189. package/dist/utility/wrun/wrun-panel-mount.util.js +62 -22
  190. package/dist/utility/wrun/wrun-panel-style.util.d.ts +41 -14
  191. package/dist/utility/wrun/wrun-panel-style.util.js +86 -26
  192. package/dist/utility/wrun/wrun-param-map.util.d.ts +7 -6
  193. package/dist/utility/wrun/wrun-param-map.util.js +8 -5
  194. package/dist/utility/wrun/wrun-param-values.util.d.ts +10 -2
  195. package/dist/utility/wrun/wrun-param-values.util.js +2 -0
  196. package/dist/utility/wrun/wrun-pin-spelling.util.js +19 -10
  197. package/dist/utility/wrun/wrun-prefix-lanes.util.js +2 -2
  198. package/dist/utility/wrun/wrun-refusal.util.js +17 -2
  199. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +20 -0
  200. package/dist/utility/wrun/wrun-script-inputs.util.js +43 -0
  201. package/dist/utility/wrun/wrun-source-rows.util.d.ts +4 -0
  202. package/dist/utility/wrun/wrun-source-rows.util.js +92 -40
  203. package/dist/utility/wrun/wrun-tape-source.util.d.ts +133 -48
  204. package/dist/utility/wrun/wrun-tape-source.util.js +205 -62
  205. package/dist/utility/wrun/wrun-volume-profile-lane.util.d.ts +7 -5
  206. package/dist/utility/wrun/wrun-volume-profile-lane.util.js +8 -6
  207. package/dist/workers/utils/volume-profile.worker.util.d.ts +4 -1
  208. package/dist/workers/utils/volume-profile.worker.util.js +5 -2
  209. package/dist/workers/wrun/wrun-abi-host.js +3 -2
  210. package/package.json +11 -11
@@ -9,22 +9,41 @@
9
9
  * params ride the input as flat knobs (`WrunOptionViewSpec` `params`: the knob, then the wire name the gateway
10
10
  * reads), each a finite number once the paint seam ran (`wrunSheetWithSettings` writes a `"@<param>"` handle's
11
11
  * current value, the `ticks_per_bar` rule). The views' `expiries` param rides `view_expiries`: the class keeps its own
12
- * `expiries` word. Every refusal is om's one knob name (`wrun_option_knob_invalid`), but for a fold (below).
12
+ * `expiries` word. Every refusal is om's one knob name (`wrun_option_knob_invalid`), but for a view this host does
13
+ * not read yet (below).
13
14
  * - Answers. A projection (`answer: 'tuples'`) is a subsequence of B in B's order with B's values, so a package whose
14
15
  * code is unchanged reads it as it reads B: it reaches the package as the class's own block. A fold
15
- * (`answer: 'fold'`: totals, boards, the curve) answers rows of another layout, which no reader of this host takes
16
- * yet (the shared host's kit adapter reads class tuples only): such a view refuses by name before any read
17
- * (`wrun_option_view_unread`), never an empty or misread block.
18
- * - Hinted views (`hinted`: the window board, the smile and surface reads) cover every close within
16
+ * (`answer: 'fold'`: totals, boards, the curve) answers rows of another layout, so an input naming one reads a view
17
+ * block (`wrunOptionInputTupleWidth`: its projections' tuples as `[0, ...tuple]`, then each fold's rows as
18
+ * `[layout, ...cells]`, every row padded to the class's `WRUN_OPTION_VIEW_ROW_WIDTHS`). This host reads
19
+ * option_contract_state's folds (Top Contracts' totals); a view it does not read yet (`wrunOptionViewUnread`: an
20
+ * options_chain fold, whose twin reads class tuples alone, and a state view that follows the chart's close, which
21
+ * the state lane does not send) refuses by name before any read (`wrun_option_view_unread`), never an empty or
22
+ * misread block.
23
+ * - Hinted views (`hinted`: the window board, the smile and surface reads, and the folds that read the close where a
24
+ * contract carries no underlying: exposure, strike_table, gex_curve, oi_board) cover every close within
19
25
  * `WRUN_OPTION_VIEW_MARGIN_PCT` of the hint the ask carries, the chart's close at ask time; a run whose close left
20
- * the band asks again before it reads (`wrunOptionViewHintCovers`, `wrunOptionViewHint`).
26
+ * the band asks again before it reads (`wrunOptionViewHintCovers`, `wrunOptionViewHint`). The gateway refuses a
27
+ * hinted view's ask without the hint. The table is the SDK's (`WRUN_OPTION_PAGE_VIEWS`, kit 0.90.0), pinned word
28
+ * for word by tests/utility/wrun/wrun-option-views.kit-pin.spec.ts.
29
+ * - The per-bar words (OPTLOAD-CHAIN-PLAN 6.2, 6.3 and 9): `pick` on `option_surface` ("nearest_days" or
30
+ * "tenor_bracket", the bar's newest 5m bucket picked to the tuples Skew History and Options Sentiment read) and
31
+ * `fold` "kit" on `option_strikes` (the bar's newest minute folded to one levels row and the strike rows Spot
32
+ * Exposures draws), their params read by the SDK's rules (`WRUN_OPTION_LANE_KNOBS`, `wrunOptionLaneAskOfSource`) and
33
+ * asked of the gateway in the lane's fields (`wrunOptionLaneAskFields`, the `OptionReadShape` G5 fields 40 to 51).
34
+ * The kit fold keeps its expiries with its own `nearest`: an `expiries` word other than "all" beside it is refused
35
+ * at declaration (kit 0.91.1, `WRUN_OPTION_STRIKES_KIT_EXPIRIES_TAKES`).
21
36
  * - The ask's payload fields (`wrunOptionViewLaneFields`): `<prefix>Views`, the canonical text (`wrunOptionViewsText`:
22
37
  * one spelling for one set of views and values, whatever the declaration order, so equal asks share one key and one
23
38
  * read), `<prefix>SpotMarginPct` for a hinted set, and on `options_chain` the gateway's scope inputs
24
39
  * (`chainNearestExpiries`, `chainMaxContracts`: the gateway sizes B on its page, so a view ask reads no expiry
25
40
  * directory). The worker twins read them back (`wrunOptionViewsOf`, `wrunOptionViewAskFieldsOf`).
26
- * - A gateway without the views answers `knobsVersion` 0: the worker refuses the views by name
27
- * (`WRUN_OPTION_VIEWS_UNSERVED_CODE`), and an input that declares none reads today's path.
41
+ * - A gateway without the views answers `knobsVersion` 0. On a crypto chain (the plain reader serves none) the worker
42
+ * projects the views over the block today's path builds, in the very rows a served answer reads as
43
+ * (option-views-local.worker.util, the SDK's reference); a governed gateway without them is refused by name
44
+ * (`WRUN_OPTION_VIEWS_UNSERVED_CODE`). An input that declares no views reads its block B whole through its class's
45
+ * implicit view (`WRUN_OPTIONS_CHAIN_IMPLICIT_VIEW`, `WRUN_OPTION_STATE_IMPLICIT_VIEW`): B's rows from the gateway,
46
+ * or today's path for an answer that is not B's rows; a crypto chain keeps its plain reader.
28
47
  *
29
48
  * Worker-safe: the worker twins parse the same words. The one main-thread door (`wrunHeldOpraPlaneChain`) touches the
30
49
  * host env only when called.
@@ -33,6 +52,7 @@ import { wrunChartHostEnv } from '../../host-env.js';
33
52
  import { gateSessionHeldElsewhere } from '../v2/gate-session-latch.util.js';
34
53
  import { refuseWrunPollInput } from './sources/wrun-poll-lane.types.js';
35
54
  import { refuseWrunOptionKnob } from './wrun-option-knobs.util.js';
55
+ import { wrunPresentHasBit, wrunPresentIsPartial, wrunPresentWithPartial } from './wrun-present-bits.util.js';
36
56
  import { wrunAuthorRuleSeed } from './wrun-refusal.util.js';
37
57
  /** Every view word, in section 6.1's order. The worker names each by `OPTION_CHAIN_VIEW_<WORD>` (pb-common
38
58
  * `OptionChainViewKind`; tests/utility/wrun/wrun-option-views.util.spec.ts pins every name). */
@@ -97,29 +117,58 @@ export const WRUN_OPTION_VIEWS = Object.freeze({
97
117
  cls: 'options_chain',
98
118
  params: { lens: 'lens', units: 'units', scope: 'scope', nearest: 'nearest', rate: 'rate' },
99
119
  answer: 'fold',
120
+ hinted: true,
100
121
  },
101
- strike_table: { cls: 'options_chain', params: {}, answer: 'fold' },
122
+ strike_table: { cls: 'options_chain', params: {}, answer: 'fold', hinted: true },
102
123
  gex_curve: {
103
124
  cls: 'options_chain',
104
125
  params: { grid_down: 'gridDown', grid_up: 'gridUp', points: 'points' },
105
126
  answer: 'fold',
127
+ hinted: true,
106
128
  },
107
129
  });
108
130
  /** The hint band each side of the hint, percent of it (section 12: 0.5% of the close). */
109
131
  export const WRUN_OPTION_VIEW_MARGIN_PCT = 0.5;
110
132
  /** The lane refusal code (wrun-lane-refusal.leaf) of a view ask the gateway answered without the views. */
111
133
  export const WRUN_OPTION_VIEWS_UNSERVED_CODE = 'option-views-unserved';
112
- /** The plan's refusal of a view whose answer no reader of this host takes yet (a fold). */
134
+ /** The plan's refusal of a view this host does not read yet (`wrunOptionViewUnread`). */
113
135
  export const WRUN_OPTION_VIEW_UNREAD_CODE = 'wrun_option_view_unread';
114
136
  /** The plan's refusal of one chain lane whose inputs read it through views and whole at once (one ask serves both
115
137
  * never: B and a view of B are two answers). */
116
138
  export const WRUN_OPTION_VIEWS_ONE_ASK_CODE = 'wrun_option_views_one_ask';
139
+ /** The plan's refusal of one chain lane whose view inputs declare different `expiries` words: the lane asks ONE block
140
+ * B of the gateway, built for one `nearestExpiries`, so an input of another word would read views of another B (the
141
+ * SDK asks each word apart; one acquisition per word would serve them). */
142
+ export const WRUN_OPTION_VIEWS_ONE_EXPIRIES_CODE = 'wrun_option_views_one_expiries';
117
143
  /** A view's spec, or undefined for a word that names none. */
118
144
  export function wrunOptionViewSpec(word) {
119
145
  return typeof word === 'string' && Object.prototype.hasOwnProperty.call(WRUN_OPTION_VIEWS, word)
120
146
  ? WRUN_OPTION_VIEWS[word]
121
147
  : undefined;
122
148
  }
149
+ /**
150
+ * What this host reads of each class's views (web: the `k-options-chain` and `k-option-contract-state` workers and
151
+ * their lanes): `folds`, whether the twin reads a fold's rows (option_contract_state's twin reads the answer's fold
152
+ * entries as the view block, `optionsChainViewRows`; options_chain's reads class tuples alone); `hint`, whether the
153
+ * lane sends a hinted view the chart's close (`chainSpotHint`; the state lane sends none, and the gateway and the kit
154
+ * refuse a hinted view without it).
155
+ */
156
+ const WRUN_OPTION_VIEW_HOST_READS = Object.freeze({
157
+ options_chain: Object.freeze({ folds: false, hint: true }),
158
+ option_contract_state: Object.freeze({ folds: true, hint: false }),
159
+ });
160
+ /** Why this host does not read a view yet, in a refusal's words, or undefined when it reads it (every projection,
161
+ * option_contract_state's folds but `oi_board`, which follows the chart's close). */
162
+ export function wrunOptionViewUnread(spec) {
163
+ const reads = WRUN_OPTION_VIEW_HOST_READS[spec.cls];
164
+ if (spec.answer === 'fold' && !reads.folds) {
165
+ return `its answer is a fold, whose rows no ${spec.cls} reader of this host takes yet`;
166
+ }
167
+ if (spec.hinted === true && !reads.hint) {
168
+ return `it follows the chart's close, which this host's ${spec.cls} lane does not send yet`;
169
+ }
170
+ return undefined;
171
+ }
123
172
  /** The words of one class, spelled for a refusal. */
124
173
  function wrunOptionViewWordsOf(cls) {
125
174
  const words = Object.keys(WRUN_OPTION_VIEWS)
@@ -135,14 +184,23 @@ function wrunOptionViewWordsOf(cls) {
135
184
  export const WRUN_OPTION_VIEW_KNOB = 'page_view';
136
185
  export const WRUN_OPTION_VIEWS_KNOB = 'page_views';
137
186
  /** Every view word an input source declares, in either knob, unvalidated (the paint seam and the stray-knob rule
138
- * read which params the declared views take). */
187
+ * read which params the declared views take; the tuple width reads whether one is a fold). A `page_views` that is
188
+ * no list reads as its one value, as the SDK's `wrunOptionViewWordsDeclared` reads it (its declaration refuses). */
139
189
  export function wrunOptionViewWordsDeclared(source) {
140
190
  const many = source[WRUN_OPTION_VIEWS_KNOB];
141
- return [source[WRUN_OPTION_VIEW_KNOB], ...(Array.isArray(many) ? many : [])].filter((word) => word !== undefined);
191
+ return [source[WRUN_OPTION_VIEW_KNOB], ...(Array.isArray(many) ? many : [many])].filter((word) => word !== undefined);
142
192
  }
143
- /** The knob names every view the source declares takes as params. */
193
+ /** The knob names every view the source declares takes as params, and on a per-bar class the number params its
194
+ * declared word takes (a flag takes no setting: true or false only). */
144
195
  export function wrunOptionViewParamKnobs(source) {
145
- return new Set(wrunOptionViewWordsDeclared(source).flatMap((word) => Object.keys(wrunOptionViewSpec(word)?.params ?? {})));
196
+ const knobs = new Set(wrunOptionViewWordsDeclared(source).flatMap((word) => Object.keys(wrunOptionViewSpec(word)?.params ?? {})));
197
+ const cls = wrunOptionLaneClassOf(source.source);
198
+ const word = cls === undefined ? undefined : source[WRUN_OPTION_LANE_WORDS[cls].knob];
199
+ const specs = typeof word === 'string' && cls !== undefined ? wrunOptionLaneKnobSpecs(cls, word) : {};
200
+ for (const [knob, spec] of Object.entries(specs))
201
+ if (spec.kind !== 'flag')
202
+ knobs.add(knob);
203
+ return knobs;
146
204
  }
147
205
  /** The input's declared view words (`page_view` or `page_views`), undefined when it declares neither. */
148
206
  function declaredViewWords(source, ctx) {
@@ -163,8 +221,8 @@ function declaredViewWords(source, ctx) {
163
221
  /**
164
222
  * An input's views, validated (main thread, after the paint seam): undefined when it declares none (today's path),
165
223
  * else the views in canonical order (`canonicalViews`). Refuses by name a word that names no view of the input's
166
- * class, a param that is no finite number (a `"@<param>"` the sheet declares no param of stays a string here), and a
167
- * fold, which no reader of this host takes yet.
224
+ * class, a view this host does not read yet (`wrunOptionViewUnread`), and a param that is no finite number (a
225
+ * `"@<param>"` the sheet declares no param of stays a string here).
168
226
  */
169
227
  export function wrunOptionViewsOfSource(input, ctx, cls) {
170
228
  // A sheet's input source, read by knob name (its knobs are open: the class's own and each view's params).
@@ -179,9 +237,10 @@ export function wrunOptionViewsOfSource(input, ctx, cls) {
179
237
  if (spec === undefined || spec.cls !== cls) {
180
238
  return refuseWrunOptionKnob(ctx, knob, word, wrunOptionViewWordsOf(cls));
181
239
  }
182
- if (spec.answer === 'fold') {
183
- return refuseWrunPollInput(ctx, `reads ${cls} with ${knob} "${String(word)}" (${WRUN_OPTION_VIEW_UNREAD_CODE}): its answer is a fold, whose ` +
184
- 'rows no reader of this host takes yet; declare a projection view or read the block whole', wrunAuthorRuleSeed(WRUN_OPTION_VIEW_UNREAD_CODE));
240
+ const unread = wrunOptionViewUnread(spec);
241
+ if (unread !== undefined) {
242
+ return refuseWrunPollInput(ctx, `reads ${cls} with ${knob} "${String(word)}" (${WRUN_OPTION_VIEW_UNREAD_CODE}): ${unread}; declare another ` +
243
+ 'view or read the block whole', wrunAuthorRuleSeed(WRUN_OPTION_VIEW_UNREAD_CODE));
185
244
  }
186
245
  const params = {};
187
246
  for (const [knob, wire] of Object.entries(spec.params)) {
@@ -222,7 +281,8 @@ export function wrunOptionViewsHinted(views) {
222
281
  /**
223
282
  * A payload's `<prefix>Views` read back (the worker twins, the K controls): the views of `cls`, canonical, or
224
283
  * undefined for a payload that names none; null for a text that is not one this module writes (a word of another
225
- * class, a param that is no finite number, garbage): the ask is refused, never widened to B whole.
284
+ * class, a view this host does not read, a param that is no finite number, garbage): the ask is refused, never
285
+ * widened to B whole.
226
286
  */
227
287
  export function wrunOptionViewsOf(text, cls) {
228
288
  if (text === undefined || text === null)
@@ -242,7 +302,7 @@ export function wrunOptionViewsOf(text, cls) {
242
302
  for (const entry of parsed) {
243
303
  const record = entry;
244
304
  const spec = wrunOptionViewSpec(record?.view);
245
- if (spec === undefined || spec.cls !== cls || spec.answer !== 'tuples')
305
+ if (spec === undefined || spec.cls !== cls || wrunOptionViewUnread(spec) !== undefined)
246
306
  return null;
247
307
  const params = record?.params;
248
308
  if (params === null || typeof params !== 'object' || Array.isArray(params))
@@ -291,16 +351,65 @@ function positiveNumber(value) {
291
351
  function positiveInteger(value) {
292
352
  return typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : undefined;
293
353
  }
354
+ /**
355
+ * The implicit view (OPTLOAD W3 FE-STATE): an `option_contract_state` input that declares no view reads its block B
356
+ * whole, so its lane asks the gateway for exactly that, the `WHOLE` view of B (pb-common `OPTION_CHAIN_VIEW_WHOLE`,
357
+ * which the gateway answers on either class), in ONE chain summary read: no expiry directory, no page of every strike,
358
+ * no per-contract registry read. The answer is B's own class tuples in B's order, so the input reads it as it read B.
359
+ * The acquisition names it apart from any view text (`stateViews: "whole"`, never a JSON list: the authoring table
360
+ * keeps `whole` an options_chain word, as the kit does, and no author declares it on this class), so it keys an
361
+ * instance of its own (one key per chain, tier, expiries word, window and book), and the worker twin reads it back as
362
+ * the `whole` view, `implicit` (`wrunOptionViewAskFieldsOf`).
363
+ */
364
+ export const WRUN_OPTION_STATE_IMPLICIT_VIEW = 'whole';
365
+ /** The payload field of the implicit view (`WRUN_OPTION_STATE_IMPLICIT_VIEW`), as the state lane writes it. */
366
+ export function wrunOptionStateImplicitViewFields() {
367
+ return { [`${WRUN_OPTION_VIEW_PREFIX.option_contract_state}Views`]: WRUN_OPTION_STATE_IMPLICIT_VIEW };
368
+ }
369
+ /**
370
+ * The implicit view of an `options_chain` input (OPTLOAD W3 FE-CHAIN), FE-STATE's rule on the chain class: a governed
371
+ * chain whose inputs declare no view reads its block B whole, so its lane asks the gateway's `WHOLE` view of B in ONE
372
+ * chain summary read, sized on the gateway's page by the inputs' expiries word and budget (`chainNearestExpiries`, the
373
+ * inputs' `nearest:N` when every input declares one; `chainMaxContracts`, the smallest `max_cells`; the gateway ports the
374
+ * lane scope's arithmetic, `wrunOptionsChainLaneScope`): no expiry directory before the ask and no per-contract registry
375
+ * read after it. The answer is B's 10-value tuples in B's order, so the inputs read it as they read B. The acquisition
376
+ * names it by the bare word (`chainViews: "whole"`), never a JSON list, so it never shares an author's spelling (an
377
+ * explicit `page_view: "whole"` rides as view text and is refused like any view when the gateway does not answer it),
378
+ * and the worker twin reads it back as the `whole` view, `implicit` (`wrunOptionViewAskFieldsOf`).
379
+ */
380
+ export const WRUN_OPTIONS_CHAIN_IMPLICIT_VIEW = 'whole';
381
+ /** The payload fields of the options_chain implicit view (`WRUN_OPTIONS_CHAIN_IMPLICIT_VIEW`), as the chain lane writes
382
+ * them: the bare word, then the gateway's scope inputs. */
383
+ export function wrunOptionsChainImplicitViewFields(scope) {
384
+ return {
385
+ [`${WRUN_OPTION_VIEW_PREFIX.options_chain}Views`]: WRUN_OPTIONS_CHAIN_IMPLICIT_VIEW,
386
+ ...(scope.nearestExpiries !== undefined ? { chainNearestExpiries: scope.nearestExpiries } : {}),
387
+ ...(scope.maxContracts !== undefined ? { chainMaxContracts: scope.maxContracts } : {}),
388
+ };
389
+ }
390
+ /** Each class's implicit view word, as its lane writes it. */
391
+ const WRUN_OPTION_IMPLICIT_VIEWS = Object.freeze({
392
+ options_chain: WRUN_OPTIONS_CHAIN_IMPLICIT_VIEW,
393
+ option_contract_state: WRUN_OPTION_STATE_IMPLICIT_VIEW,
394
+ });
294
395
  export function wrunOptionViewAskFieldsOf(cls, payload) {
295
396
  const prefix = WRUN_OPTION_VIEW_PREFIX[cls];
397
+ const nearestExpiries = cls === 'options_chain' ? positiveInteger(payload.chainNearestExpiries) : undefined;
398
+ const maxContracts = cls === 'options_chain' ? positiveInteger(payload.chainMaxContracts) : undefined;
399
+ if (payload[`${prefix}Views`] === WRUN_OPTION_IMPLICIT_VIEWS[cls]) {
400
+ return {
401
+ views: [{ view: 'whole', params: {} }],
402
+ implicit: true,
403
+ ...(nearestExpiries !== undefined ? { nearestExpiries } : {}),
404
+ ...(maxContracts !== undefined ? { maxContracts } : {}),
405
+ };
406
+ }
296
407
  const views = wrunOptionViewsOf(payload[`${prefix}Views`], cls);
297
408
  if (views === undefined || views === null)
298
409
  return views;
299
410
  const hinted = wrunOptionViewsHinted(views);
300
411
  const spotHint = hinted ? positiveNumber(payload[`${prefix}SpotHint`]) : undefined;
301
412
  const spotMarginPct = hinted ? positiveNumber(payload[`${prefix}SpotMarginPct`]) : undefined;
302
- const nearestExpiries = cls === 'options_chain' ? positiveInteger(payload.chainNearestExpiries) : undefined;
303
- const maxContracts = cls === 'options_chain' ? positiveInteger(payload.chainMaxContracts) : undefined;
304
413
  return {
305
414
  views,
306
415
  ...(nearestExpiries !== undefined ? { nearestExpiries } : {}),
@@ -332,6 +441,517 @@ export function wrunChartLastClose(rows) {
332
441
  const close = Number(rows[rows.length - 1]?.[4]);
333
442
  return Number.isFinite(close) && close > 0 ? close : undefined;
334
443
  }
444
+ /** Each per-bar class's word knob and its words, in the SDK's order (`WRUN_OPTION_SURFACE_PICKS`,
445
+ * `WRUN_OPTION_STRIKES_FOLDS`). */
446
+ export const WRUN_OPTION_LANE_WORDS = Object.freeze({
447
+ option_surface: Object.freeze({ knob: 'pick', words: Object.freeze(['nearest_days', 'tenor_bracket']) }),
448
+ option_strikes: Object.freeze({ knob: 'fold', words: Object.freeze(['kit']) }),
449
+ });
450
+ const DAYS_SPEC = { kind: 'number', min: 0, max: 3650, above: true };
451
+ /** The per-bar words' knobs, by word, in the SDK's order (`WRUN_OPTION_LANE_KNOBS`, kit 0.90.0; the surface pick's
452
+ * `delta` 0 reads the 25 delta wings, 1 the 10 delta ones). tests/utility/wrun/wrun-option-views.kit-pin.spec.ts holds
453
+ * every spec equal to the installed kit's. */
454
+ export const WRUN_OPTION_LANE_KNOBS = Object.freeze({
455
+ nearest_days: Object.freeze({
456
+ days: Object.freeze({ ...DAYS_SPEC, what: 'the days to expiry the pick sits nearest' }),
457
+ delta: Object.freeze({
458
+ kind: 'whole',
459
+ codes: Object.freeze({ 0: '25 delta', 1: '10 delta' }),
460
+ what: 'the wings',
461
+ fallback: 0,
462
+ }),
463
+ }),
464
+ tenor_bracket: Object.freeze({
465
+ tenor: Object.freeze({ ...DAYS_SPEC, what: 'the tenor in days the two anchors bracket' }),
466
+ }),
467
+ kit: Object.freeze({
468
+ nearest: Object.freeze({
469
+ kind: 'whole',
470
+ min: 0,
471
+ max: 999,
472
+ what: 'the soonest expiries kept (0: every one)',
473
+ fallback: 0,
474
+ }),
475
+ window_pct: Object.freeze({
476
+ kind: 'number',
477
+ min: 0,
478
+ max: 100,
479
+ above: true,
480
+ what: "the map's window, percent of the kit's spot",
481
+ }),
482
+ lens: Object.freeze({
483
+ kind: 'whole',
484
+ codes: Object.freeze({ 0: 'gamma', 1: 'delta', 2: 'vega' }),
485
+ what: 'the lens',
486
+ fallback: 0,
487
+ }),
488
+ step_rows: Object.freeze({ kind: 'whole', min: 1, max: 1000, what: 'the strike steps each side kept' }),
489
+ carry: Object.freeze({ kind: 'flag', what: "the next bar's drawn strikes kept too", fallback: 0 }),
490
+ levels: Object.freeze({ kind: 'flag', what: 'one levels row per bar', fallback: 0 }),
491
+ curve: Object.freeze({
492
+ kind: 'flag',
493
+ what: "one curve row after each levels row: the gamma curve's net GEX at spot, its flip, spot and the rows' clock",
494
+ fallback: 0,
495
+ }),
496
+ }),
497
+ });
498
+ /** What `expiries` takes beside the strike kit fold (the SDK's `WRUN_OPTION_STRIKES_KIT_EXPIRIES_TAKES`, kit 0.91.1):
499
+ * the fold keeps its expiries with its own `nearest`, so any other word beside it is refused at declaration. */
500
+ export const WRUN_OPTION_STRIKES_KIT_EXPIRIES_TAKES = '"all" (or no expiries) beside fold "kit": the fold keeps its expiries with its own `nearest`';
501
+ /** What `curve` takes beside the strike kit fold (the SDK's `WRUN_OPTION_STRIKES_KIT_CURVE_TAKES`, kit 0.96.0): the
502
+ * curve row follows each bar's levels row, so `curve: true` without `levels: true` is refused at declaration. */
503
+ export const WRUN_OPTION_STRIKES_KIT_CURVE_TAKES = "true only beside levels: true (the curve row follows each bar's levels row), or false";
504
+ /** A per-bar class, or undefined for a class that declares no per-bar word. */
505
+ export function wrunOptionLaneClassOf(sourceClass) {
506
+ return sourceClass === 'option_surface' || sourceClass === 'option_strikes' ? sourceClass : undefined;
507
+ }
508
+ /** One word's knobs on a per-bar class (empty for a word the class does not take). */
509
+ export function wrunOptionLaneKnobSpecs(cls, word) {
510
+ return WRUN_OPTION_LANE_WORDS[cls].words.includes(word) ? (WRUN_OPTION_LANE_KNOBS[word] ?? {}) : {};
511
+ }
512
+ /** Every param knob a per-bar class takes, over its words, each once, in table order (the SDK's
513
+ * `wrunOptionViewParamKnobsOf`). */
514
+ export function wrunOptionLaneParamKnobs(cls) {
515
+ const knobs = new Set();
516
+ for (const word of WRUN_OPTION_LANE_WORDS[cls].words) {
517
+ for (const knob of Object.keys(wrunOptionLaneKnobSpecs(cls, word)))
518
+ knobs.add(knob);
519
+ }
520
+ return [...knobs];
521
+ }
522
+ /** Whether a number is a legal value of a per-bar knob, a flag's 0 or 1 included (the SDK's
523
+ * `wrunOptionKnobSpecLegal`). */
524
+ export function wrunOptionKnobSpecLegal(spec, value) {
525
+ if (!Number.isFinite(value))
526
+ return false;
527
+ if (spec.kind === 'flag')
528
+ return value === 0 || value === 1;
529
+ if (spec.codes !== undefined)
530
+ return Object.prototype.hasOwnProperty.call(spec.codes, String(value));
531
+ if (spec.kind === 'whole' && !Number.isInteger(value))
532
+ return false;
533
+ if (spec.min !== undefined && (spec.above === true ? !(value > spec.min) : value < spec.min))
534
+ return false;
535
+ if (spec.max !== undefined && (spec.below === true ? !(value < spec.max) : value > spec.max))
536
+ return false;
537
+ return true;
538
+ }
539
+ /** What a per-bar knob takes, as a refusal spells it (the SDK's `wrunOptionKnobSpecTakes`). */
540
+ export function wrunOptionKnobSpecTakes(spec) {
541
+ if (spec.kind === 'flag')
542
+ return `true or false (${spec.what})`;
543
+ if (spec.codes !== undefined) {
544
+ const codes = Object.entries(spec.codes).map(([code, word]) => `${code} (${word})`);
545
+ return `${spec.what}: ${codes.join(', ')}, or "@<param>" naming a select setting whose picked value it reads`;
546
+ }
547
+ const lo = spec.min === undefined ? '' : `${spec.above === true ? 'above' : 'from'} ${spec.min}`;
548
+ const hi = spec.max === undefined ? '' : `${spec.below === true ? 'below' : 'up to'} ${spec.max}`;
549
+ const span = [lo, hi].filter((part) => part !== '').join(', ');
550
+ const kind = spec.kind === 'whole' ? 'a whole number' : spec.kind === 'time' ? 'an instant in epoch seconds' : 'a number';
551
+ return `${spec.what}, ${kind}${span === '' ? '' : ` ${span}`}, or "@<param>" naming a declared setting`;
552
+ }
553
+ /**
554
+ * ONE reader of a per-bar class's knobs, the SDK's `wrunOptionViewAskOf` for `option_surface` and `option_strikes`
555
+ * (no handle option: a `"@<param>"` the paint seam did not replace is refused as any other value): the ask, or
556
+ * undefined when the input declares neither the word nor a param of it, or the first issue in the SDK's order (the
557
+ * word; each declared param in table order, taken by the word and legal on it; each required param; an `expiries` word
558
+ * other than "all" beside the kit fold, `WRUN_OPTION_STRIKES_KIT_EXPIRIES_TAKES`). Pure: the lane's facets refuse its
559
+ * issue by name (`wrunOptionLaneAskOfSource`), its per-input projection reads the ask.
560
+ */
561
+ export function wrunOptionLaneAskOf(source) {
562
+ const cls = wrunOptionLaneClassOf(source.source);
563
+ if (cls === undefined)
564
+ return undefined;
565
+ const { knob: wordKnob, words: known } = WRUN_OPTION_LANE_WORDS[cls];
566
+ const paramKnobs = wrunOptionLaneParamKnobs(cls);
567
+ if (source[wordKnob] === undefined && paramKnobs.every((knob) => source[knob] === undefined))
568
+ return undefined;
569
+ const issues = [];
570
+ const declared = source[wordKnob];
571
+ const word = typeof declared === 'string' && known.includes(declared) ? declared : undefined;
572
+ if (word === undefined) {
573
+ issues.push({
574
+ knob: wordKnob,
575
+ value: declared ?? '(none)',
576
+ takes: `one of ${known.map((candidate) => `"${candidate}"`).join(', ')}`,
577
+ });
578
+ }
579
+ for (const knob of paramKnobs) {
580
+ const value = source[knob];
581
+ if (value === undefined)
582
+ continue;
583
+ const spec = word === undefined ? undefined : wrunOptionLaneKnobSpecs(cls, word)[knob];
584
+ if (spec === undefined) {
585
+ if (word !== undefined) {
586
+ const owners = known.filter((candidate) => wrunOptionLaneKnobSpecs(cls, candidate)[knob] !== undefined);
587
+ issues.push({ knob, value, takes: `a param of ${owners.map((owner) => `"${owner}"`).join(', ')} only` });
588
+ }
589
+ continue;
590
+ }
591
+ if (spec.kind === 'flag') {
592
+ if (typeof value !== 'boolean')
593
+ issues.push({ knob, value, takes: wrunOptionKnobSpecTakes(spec) });
594
+ continue;
595
+ }
596
+ if (typeof value !== 'number' || !wrunOptionKnobSpecLegal(spec, value)) {
597
+ issues.push({ knob, value, takes: `${wrunOptionKnobSpecTakes(spec)} (${word})` });
598
+ }
599
+ }
600
+ if (word !== undefined) {
601
+ for (const [knob, spec] of Object.entries(wrunOptionLaneKnobSpecs(cls, word))) {
602
+ if (spec.fallback === undefined && source[knob] === undefined) {
603
+ issues.push({ knob, value: '(none)', takes: `${wrunOptionKnobSpecTakes(spec)} (required by "${word}")` });
604
+ }
605
+ }
606
+ }
607
+ if (cls === 'option_strikes' && word === 'kit' && source.expiries !== undefined && source.expiries !== 'all') {
608
+ issues.push({ knob: 'expiries', value: source.expiries, takes: WRUN_OPTION_STRIKES_KIT_EXPIRIES_TAKES });
609
+ }
610
+ // The kit fold's curve row follows each bar's levels row: curve without levels refuses by name (kit 0.96.0).
611
+ if (cls === 'option_strikes' && word === 'kit' && source.curve === true && source.levels !== true) {
612
+ issues.push({ knob: 'curve', value: source.curve, takes: WRUN_OPTION_STRIKES_KIT_CURVE_TAKES });
613
+ }
614
+ if (issues.length > 0 || word === undefined)
615
+ return { issue: issues[0] };
616
+ const params = {};
617
+ for (const [knob, spec] of Object.entries(wrunOptionLaneKnobSpecs(cls, word))) {
618
+ const value = source[knob];
619
+ if (typeof value === 'number')
620
+ params[knob] = value;
621
+ else if (typeof value === 'boolean')
622
+ params[knob] = value ? 1 : 0;
623
+ else if (spec.fallback !== undefined)
624
+ params[knob] = spec.fallback;
625
+ }
626
+ return { ask: { cls, word, params } };
627
+ }
628
+ /** An input's per-bar ask, its first issue refused by name (`wrun_option_knob_invalid`): undefined when it declares no
629
+ * per-bar knob (today's read). */
630
+ export function wrunOptionLaneAskOfSource(source, ctx) {
631
+ const read = wrunOptionLaneAskOf(source);
632
+ if (read === undefined)
633
+ return undefined;
634
+ if ('issue' in read)
635
+ return refuseWrunOptionKnob(ctx, read.issue.knob, read.issue.value, read.issue.takes);
636
+ return read.ask;
637
+ }
638
+ /** f64s per row of a view block (the page views' folds) and of the strike kit fold (the SDK's
639
+ * `WRUN_OPTION_VIEW_ROW_WIDTHS`): the layout, then the widest layout's fields. */
640
+ export const WRUN_OPTION_VIEW_ROW_WIDTHS = Object.freeze({
641
+ options_chain: 11,
642
+ option_contract_state: 16,
643
+ option_strikes: 14,
644
+ });
645
+ /** Column 0 of every strike kit fold row (the SDK's `WRUN_OPTION_STRIKES_KIT_LAYOUTS`): a strike row, a bar's levels
646
+ * row and, with `curve` (kit 0.96.0), its curve row after the levels row. */
647
+ export const WRUN_OPTION_STRIKES_KIT_LAYOUTS = Object.freeze({ strike: 0, levels: 1, curve: 2 });
648
+ /** The column of a kit levels row that says the bar was refused (its newest minute held more rows than the input's
649
+ * `max_cells`): 1 refused, 0 served. */
650
+ export const WRUN_OPTION_STRIKES_KIT_REFUSED_COLUMN = 13;
651
+ /** Whether page view words name a fold of `cls` (the SDK's `wrunOptionViewWordsFold` on a page view class). */
652
+ function pageViewWordsFold(cls, words) {
653
+ return words.some((word) => {
654
+ const spec = wrunOptionViewSpec(word);
655
+ return spec?.cls === cls && spec.answer === 'fold';
656
+ });
657
+ }
658
+ /**
659
+ * The f64s per tuple one input's block carries (the SDK's `wrunOptionInputTupleWidth`, the one rule every host sizes
660
+ * by): a view block's row width when its words name a fold (a page view fold, the strike kit fold), else the class's
661
+ * own width. The words alone decide it, never a param, so a setting never resizes a block.
662
+ */
663
+ export function wrunOptionInputTupleWidth(source, classWidth) {
664
+ const cls = source.source;
665
+ if (cls === 'option_strikes') {
666
+ return source[WRUN_OPTION_LANE_WORDS.option_strikes.knob] === 'kit'
667
+ ? WRUN_OPTION_VIEW_ROW_WIDTHS.option_strikes
668
+ : classWidth;
669
+ }
670
+ if (cls !== 'options_chain' && cls !== 'option_contract_state')
671
+ return classWidth;
672
+ return pageViewWordsFold(cls, wrunOptionViewWordsDeclared(source)) ? WRUN_OPTION_VIEW_ROW_WIDTHS[cls] : classWidth;
673
+ }
674
+ /** pb-common `OptionSurfacePick` by word (the gateway decodes numbers, never names). */
675
+ export const WRUN_OPTION_SURFACE_PICK_CODES = Object.freeze({
676
+ nearest_days: 1,
677
+ tenor_bracket: 2,
678
+ });
679
+ /** pb-common `StrikeMetric` by the kit fold's lens code (0 gamma, 1 delta, 2 vega): NET_GEX, DEX, VEX. */
680
+ export const WRUN_OPTION_STRIKES_KIT_METRICS = Object.freeze({ 0: 1, 1: 2, 2: 3 });
681
+ /**
682
+ * The `OptionReadShape` G5 fields (pb-common 12.72.0, fields 40 to 51) a per-bar ask names, as they ride the lane's
683
+ * payload and the gateway reads them (JSON names, enums as numbers):
684
+ * - the surface pick: `surfacePick` (1 nearest_days, 2 tenor_bracket) with `surfaceDays` and `surfaceDelta` (25 or
685
+ * 10, the wings) or `surfaceTenorDays`;
686
+ * - the strike kit fold: `strikeKitFold`, `strikeNearest`, `strikeKitWindowPct`, `strikeStepRows`, `strikeCarryNext`,
687
+ * `strikeLevels`, `strikeMaxCells` (the input's `max_cells`: a minute with more rows answers a refused levels row)
688
+ * and `strikeKitMetric` (the lens).
689
+ * The fields key the lane instance, so two inputs asking two picks are two reads, and an input declaring no word asks
690
+ * none of them (today's read).
691
+ */
692
+ export function wrunOptionLaneAskFields(ask, facts = {}) {
693
+ const { params } = ask;
694
+ if (ask.cls === 'option_surface') {
695
+ return ask.word === 'nearest_days'
696
+ ? {
697
+ surfacePick: WRUN_OPTION_SURFACE_PICK_CODES.nearest_days,
698
+ surfaceDays: params.days,
699
+ surfaceDelta: params.delta === 1 ? 10 : 25,
700
+ }
701
+ : { surfacePick: WRUN_OPTION_SURFACE_PICK_CODES.tenor_bracket, surfaceTenorDays: params.tenor };
702
+ }
703
+ return {
704
+ strikeKitFold: true,
705
+ strikeNearest: params.nearest,
706
+ strikeKitWindowPct: params.window_pct,
707
+ strikeStepRows: params.step_rows,
708
+ strikeCarryNext: params.carry === 1,
709
+ strikeLevels: params.levels === 1,
710
+ ...(facts.maxCells !== undefined ? { strikeMaxCells: facts.maxCells } : {}),
711
+ strikeKitMetric: WRUN_OPTION_STRIKES_KIT_METRICS[params.lens] ?? WRUN_OPTION_STRIKES_KIT_METRICS[0],
712
+ };
713
+ }
714
+ /** The payload fields of a per-bar ask, by class (the K controls copy exactly these onto the request they build). */
715
+ const WRUN_OPTION_LANE_PAYLOAD_FIELDS = Object.freeze({
716
+ option_surface: Object.freeze(['surfacePick', 'surfaceDays', 'surfaceDelta', 'surfaceTenorDays']),
717
+ option_strikes: Object.freeze([
718
+ 'strikeKitFold',
719
+ 'strikeNearest',
720
+ 'strikeKitWindowPct',
721
+ 'strikeStepRows',
722
+ 'strikeCarryNext',
723
+ 'strikeLevels',
724
+ 'strikeMaxCells',
725
+ 'strikeKitMetric',
726
+ ]),
727
+ });
728
+ /** A per-bar ask's fields of a payload, as they ride (a K control copies them onto the request it builds). */
729
+ export function wrunOptionLanePayloadFields(cls, payload) {
730
+ const fields = {};
731
+ for (const key of WRUN_OPTION_LANE_PAYLOAD_FIELDS[cls])
732
+ if (payload?.[key] !== undefined)
733
+ fields[key] = payload[key];
734
+ return fields;
735
+ }
736
+ function finiteOrUndefined(value) {
737
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
738
+ }
739
+ /** A payload's per-bar ask (the worker twins): its G5 fields, each of its own type, or undefined when it names no
740
+ * word of its class (`surfacePick` 1 or 2, `strikeKitFold` true). */
741
+ export function wrunOptionLaneAskOfPayload(cls, payload) {
742
+ if (cls === 'option_surface') {
743
+ const pick = payload.surfacePick;
744
+ if (pick !== WRUN_OPTION_SURFACE_PICK_CODES.nearest_days && pick !== WRUN_OPTION_SURFACE_PICK_CODES.tenor_bracket) {
745
+ return undefined;
746
+ }
747
+ const days = finiteOrUndefined(payload.surfaceDays);
748
+ const delta = finiteOrUndefined(payload.surfaceDelta);
749
+ const tenor = finiteOrUndefined(payload.surfaceTenorDays);
750
+ return {
751
+ surfacePick: pick,
752
+ ...(pick === WRUN_OPTION_SURFACE_PICK_CODES.nearest_days && days !== undefined ? { surfaceDays: days } : {}),
753
+ ...(pick === WRUN_OPTION_SURFACE_PICK_CODES.nearest_days && delta !== undefined ? { surfaceDelta: delta } : {}),
754
+ ...(pick === WRUN_OPTION_SURFACE_PICK_CODES.tenor_bracket && tenor !== undefined
755
+ ? { surfaceTenorDays: tenor }
756
+ : {}),
757
+ };
758
+ }
759
+ if (payload.strikeKitFold !== true)
760
+ return undefined;
761
+ const read = { strikeKitFold: true };
762
+ for (const key of [
763
+ 'strikeNearest',
764
+ 'strikeKitWindowPct',
765
+ 'strikeStepRows',
766
+ 'strikeMaxCells',
767
+ 'strikeKitMetric',
768
+ ]) {
769
+ const value = finiteOrUndefined(payload[key]);
770
+ if (value !== undefined)
771
+ read[key] = value;
772
+ }
773
+ read.strikeCarryNext = payload.strikeCarryNext === true;
774
+ read.strikeLevels = payload.strikeLevels === true;
775
+ return read;
776
+ }
777
+ /** The kit fold's params by knob (the SDK reference's names) off a payload's ask, the lens back to its code. */
778
+ export function wrunOptionStrikesKitParamsOf(read) {
779
+ const lens = Object.entries(WRUN_OPTION_STRIKES_KIT_METRICS).find(([, metric]) => metric === read.strikeKitMetric);
780
+ return {
781
+ nearest: read.strikeNearest ?? 0,
782
+ window_pct: read.strikeKitWindowPct ?? 0,
783
+ lens: lens === undefined ? 0 : Number(lens[0]),
784
+ step_rows: read.strikeStepRows ?? 48,
785
+ carry: read.strikeCarryNext === true ? 1 : 0,
786
+ levels: read.strikeLevels === true ? 1 : 0,
787
+ };
788
+ }
789
+ /** Whether a lane instance's acquisition asks a per-bar word (a pick or the kit fold): its rows are landed on the
790
+ * chart's bars by the gateway (or by the lane's own fallback by the same rules). */
791
+ export function wrunOptionLaneAcquisitionAsks(sourceClass, acquisition) {
792
+ const cls = wrunOptionLaneClassOf(sourceClass);
793
+ return cls !== undefined && wrunOptionLaneAskOfPayload(cls, acquisition) !== undefined;
794
+ }
795
+ /** Whether an instance's acquisition asks the kit fold with `carry`: each bar's rows then hold the strikes the NEXT bar
796
+ * with rows draws, and the gateway's carry stops at its read window, so a paged read must ask each older page through
797
+ * the newer page's first bar with rows (wrun-row-lanes.util `fetchWrunRowLaneRows`). */
798
+ export function wrunOptionLaneCarriesNext(sourceClass, acquisition) {
799
+ return sourceClass === 'option_strikes' && acquisition.strikeKitFold === true && acquisition.strikeCarryNext === true;
800
+ }
801
+ /** Whether one landed kit fold bar has rows the carry reads: any row, its levels row not the refusal (a refused bar
802
+ * keeps no strike, so the carry passes over it to the next bar). */
803
+ export function wrunOptionKitBarHasRows(tuples) {
804
+ if (tuples.length === 0)
805
+ return false;
806
+ return !tuples.some((tuple) => Array.isArray(tuple) &&
807
+ tuple[0] === WRUN_OPTION_STRIKES_KIT_LAYOUTS.levels &&
808
+ tuple[WRUN_OPTION_STRIKES_KIT_REFUSED_COLUMN] === 1);
809
+ }
810
+ /**
811
+ * The f64s per row an instance's rows carry, by its facets (the SDK's `wrunAskTupleWidth`, the ask's side of
812
+ * `wrunOptionInputTupleWidth`: the views ride the instance's key, so every input it serves shares its width): the kit
813
+ * fold's rows on an instance asking it, a view block's rows on one whose views (`<prefix>Views`) name a fold of its
814
+ * class (Top Contracts' totals), else the class's own tuple (`classWidth`).
815
+ */
816
+ export function wrunOptionLaneTupleWidth(sourceClass, acquisition, classWidth) {
817
+ if (sourceClass === 'option_strikes') {
818
+ return acquisition.strikeKitFold === true ? WRUN_OPTION_VIEW_ROW_WIDTHS.option_strikes : classWidth;
819
+ }
820
+ if (sourceClass !== 'options_chain' && sourceClass !== 'option_contract_state')
821
+ return classWidth;
822
+ const text = acquisition[`${WRUN_OPTION_VIEW_PREFIX[sourceClass]}Views`];
823
+ return pageViewWordsFold(sourceClass, viewWordsOfText(text)) ? WRUN_OPTION_VIEW_ROW_WIDTHS[sourceClass] : classWidth;
824
+ }
825
+ /** The view words a `<prefix>Views` text names, unvalidated (the width reads the words alone, as the SDK's
826
+ * `wrunAskTupleWidth` does); none for a text that is no list of views. */
827
+ function viewWordsOfText(text) {
828
+ if (typeof text !== 'string')
829
+ return [];
830
+ let parsed;
831
+ try {
832
+ parsed = JSON.parse(text);
833
+ }
834
+ catch {
835
+ return [];
836
+ }
837
+ return Array.isArray(parsed)
838
+ ? parsed.map((view) => (view !== null && typeof view === 'object' ? view.view : undefined))
839
+ : [];
840
+ }
841
+ /** The rows a strike kit fold bar is projected to hold for the first paint: the levels row, the window's strikes
842
+ * within `step_rows` + 1 finest steps each side of the centre, the finest pair and the two edges. */
843
+ function wrunOptionStrikesKitBarRows(acquisition) {
844
+ const stepRows = finiteOrUndefined(acquisition.strikeStepRows) ?? 48;
845
+ return 1 + 2 * (Math.max(0, stepRows) + 1) + 1 + 4;
846
+ }
847
+ /**
848
+ * The row budget the first-paint slice sizes an instance asking a per-bar word by (wrun-row-lane-first-paint.util, the
849
+ * slice FE-STRIKE-LANE added; no second one): the answered row's cells and the rows one bar is projected to hold (a
850
+ * nearest_days pick 1, a tenor bracket 2, a kit fold bar its levels row and drawn strikes). Undefined for an instance
851
+ * that asks no per-bar word: its asks are today's, unsliced.
852
+ */
853
+ export function wrunOptionLaneFirstPaintBudget(sourceClass, acquisition, classWidth) {
854
+ if (!wrunOptionLaneAcquisitionAsks(sourceClass, acquisition))
855
+ return undefined;
856
+ const cellsPerRow = wrunOptionLaneTupleWidth(sourceClass, acquisition, classWidth);
857
+ const rows = sourceClass === 'option_strikes'
858
+ ? wrunOptionStrikesKitBarRows(acquisition)
859
+ : acquisition.surfacePick === WRUN_OPTION_SURFACE_PICK_CODES.tenor_bracket
860
+ ? 2
861
+ : 1;
862
+ return { cellsPerRow, barRows: () => rows };
863
+ }
864
+ /** The option_surface tuple's width and its `present` bits: dte_days 1, iv_p25 4, iv_c25 5, iv_p10 6, iv_c10 7. */
865
+ const SURFACE_WIDTH = 9;
866
+ const SURFACE_BIT = Object.freeze({ dteDays: 1, ivP25: 4, ivC25: 5, ivP10: 6, ivC10: 7 });
867
+ /**
868
+ * One bar's option_surface block under a pick, the SDK's reference (`wrunOptionSurfacePick` and
869
+ * `wrunOptionSurfacePickBlock`, wrun-host/option-views.ts) on the bar's tuples:
870
+ * - `nearest_days` (Skew History): the tuple with dte_days served and at least 1 and both wings served at `delta` (0:
871
+ * iv_p25 and iv_c25, 1: iv_p10 and iv_c10), its dte nearest `days`, the earlier expiry on a tie (the first tuple on
872
+ * an exact one);
873
+ * - `tenor_bracket` (Options Sentiment's AVAR): the anchors (dte_days and both 25-delta wings served, dte above 0.5
874
+ * and both wings above 0) ordered by dte, ties in the block's order; the one before the first at or past `tenor`
875
+ * days and that one, or the first alone, or the last alone.
876
+ * The kept tuples ride in the block's order. A bar that held tuples and whose pick keeps none answers one all-zero
877
+ * tuple (a served bar still reads served); a partial bar's bit 14 rides the first tuple of the answer. Idempotent: a
878
+ * bar the gateway already picked picks to itself, so the gateway's answer and today's read land the same block.
879
+ */
880
+ export function wrunOptionSurfacePickTuples(tuples, word, params) {
881
+ const blocks = tuples.filter((tuple) => tuple.length === SURFACE_WIDTH);
882
+ const present = (tuple) => tuple[SURFACE_WIDTH - 1];
883
+ const partial = blocks.some((tuple) => wrunPresentIsPartial(present(tuple)));
884
+ let kept = [];
885
+ if (word === 'nearest_days') {
886
+ const tenDelta = (params.delta ?? 0) === 1;
887
+ const putBit = tenDelta ? SURFACE_BIT.ivP10 : SURFACE_BIT.ivP25;
888
+ const callBit = tenDelta ? SURFACE_BIT.ivC10 : SURFACE_BIT.ivC25;
889
+ const targetDays = params.days ?? Number.NaN;
890
+ let best = -1;
891
+ let bestGap = Number.POSITIVE_INFINITY;
892
+ let bestExpiry = Number.POSITIVE_INFINITY;
893
+ blocks.forEach((tuple, at) => {
894
+ const mask = present(tuple);
895
+ if (!wrunPresentHasBit(mask, SURFACE_BIT.dteDays) ||
896
+ !wrunPresentHasBit(mask, putBit) ||
897
+ !wrunPresentHasBit(mask, callBit)) {
898
+ return;
899
+ }
900
+ const dte = tuple[1];
901
+ if (!(dte >= 1.0))
902
+ return;
903
+ const gap = Math.abs(dte - targetDays);
904
+ const expiry = tuple[0];
905
+ if (gap < bestGap || (gap === bestGap && expiry < bestExpiry)) {
906
+ bestGap = gap;
907
+ bestExpiry = expiry;
908
+ best = at;
909
+ }
910
+ });
911
+ kept = best >= 0 ? [best] : [];
912
+ }
913
+ else if (word === 'tenor_bracket') {
914
+ const anchors = [];
915
+ blocks.forEach((tuple, at) => {
916
+ const mask = present(tuple);
917
+ if (!wrunPresentHasBit(mask, SURFACE_BIT.dteDays) ||
918
+ !wrunPresentHasBit(mask, SURFACE_BIT.ivP25) ||
919
+ !wrunPresentHasBit(mask, SURFACE_BIT.ivC25)) {
920
+ return;
921
+ }
922
+ const days = tuple[1];
923
+ if (!(days > 0.5) || !(tuple[4] > 0.0) || !(tuple[5] > 0.0))
924
+ return;
925
+ let k = anchors.length;
926
+ anchors.push({ at, days });
927
+ while (k > 0 && anchors[k - 1].days > days) {
928
+ anchors[k] = anchors[k - 1];
929
+ k -= 1;
930
+ }
931
+ anchors[k] = { at, days };
932
+ });
933
+ if (anchors.length > 0) {
934
+ const years = (params.tenor ?? Number.NaN) / 365.0;
935
+ kept = [anchors[anchors.length - 1].at];
936
+ for (let k = 0; k < anchors.length; k += 1) {
937
+ if (years <= anchors[k].days / 365.0) {
938
+ kept = k === 0 ? [anchors[0].at] : [anchors[k - 1].at, anchors[k].at];
939
+ break;
940
+ }
941
+ }
942
+ kept = [...new Set(kept)].sort((a, b) => a - b);
943
+ }
944
+ }
945
+ else {
946
+ return blocks.map((tuple) => [...tuple]);
947
+ }
948
+ const out = kept.map((at) => [...blocks[at]]);
949
+ if (out.length === 0 && blocks.length > 0)
950
+ out.push(new Array(SURFACE_WIDTH).fill(0));
951
+ if (partial && out.length > 0)
952
+ out[0][SURFACE_WIDTH - 1] = wrunPresentWithPartial(present(out[0]));
953
+ return out;
954
+ }
335
955
  /**
336
956
  * The chart's chain on the OPRA plane by coin, held in place of the chain directory's answer (section 8, O1): the
337
957
  * chain `wrunLaneOpraPlaneChain` reads for the chart's coin when the chart's options ride the OPRA plane (the