@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
@@ -95,7 +95,10 @@
95
95
  * acquisition the lane would plan otherwise now (its `acquisitionMoved`: a
96
96
  * CME surface or a CME chain's statistics read off a continuous alias whose
97
97
  * lead rolled; the full run re-plans it and the fresh session holds none of
98
- * its old rows). A pan-back page left to its wave
98
+ * its old rows), or a reconcile lane whose window held more than its read
99
+ * takes (a refusal by name the leaf declares `over-cap`: the tape past the
100
+ * trades worker's cap), whose window stays owed while the session is held
101
+ * and hands ONE full run off (`handWrunLiveOverCapBack`). A pan-back page left to its wave
99
102
  * (contract C1: a verified backward extension under an owner pending or
100
103
  * landed over it, or on a prefix-capable session within the grace its wave
101
104
  * has to stamp one) moves no history: the wave lands the page's rows into
@@ -201,8 +204,9 @@ import { attachWrunHandles, wrunHandlesOf } from './wrun-handles.util.js';
201
204
  import { mergeWrunCandleEvidence, wrunCandleFingerprintsOf } from './wrun-prefix-proof.util.js';
202
205
  import { noteWrunLaneRevision } from './wrun-prefix-lanes.util.js';
203
206
  import { attachWrunFrames, WRUN_CELL_BLOCK_TOO_LARGE_CODE, wrunAbiVersion, wrunCellTupleWidths, wrunFramesOf, } from './wrun-pack.util.js';
207
+ import { wrunCellBoundWords, wrunSheetCellBlockTuples } from './wrun-cell-capacity.leaf.js';
204
208
  import { LIVE_MAX_CELLS_PER_BAR, tradesBarOpenMs, tradesLaneLimits, tradesServedStartMs, } from '../../kscript-data/controls/live-trades-merge.util.js';
205
- import { parseWrunTapeHistory, wrunTapeFloorSettings, wrunTapeHistoryOf } from './wrun-tape-source.util.js';
209
+ import { isWrunAskedTapeSource, parseWrunTapeHistory, wrunTapeAcquisitionFloor, wrunTapeFloorSettings, wrunTapeFloorSettingWords, wrunTapeHistoryOf, } from './wrun-tape-source.util.js';
206
210
  import { serverNowMs } from '../auth/server-clock.util.js';
207
211
  import { wrunModuleReadsBarCount } from './wrun-bar-count.util.js';
208
212
  import { isWrunBatchedChildRefused, mountWrunChildOverlays } from './wrun-panel-mount.util.js';
@@ -217,13 +221,13 @@ import { wrunLiveReconcileMaySound } from './wrun-signal-sound-reasons.leaf.js';
217
221
  import { wrunCanvasChildId, wrunCellRowsOf } from './wrun-canvases.util.js';
218
222
  import { readWrunBatchedSections, wrunBatchedChildId, wrunSheetHasBatchedMarks } from './wrun-batched-marks.util.js';
219
223
  import { isWrunStyleTargetHidden } from './wrun-color-settings.util.js';
220
- import { buildWrunOverlayRunResult, closedLegCandles, forgetWrunOverlayCanvasState, openLegCandles, wrunLegReadsFormingOpen, wrunLegReadsLiveCandleOnly, cutWrunOddsLegRows, placeWrunResultTables, presentWrunIntegration, publishWrunRunHealth, publishWrunSessionCanvasNotices, recordWrunHostBuildMs, reseedWrunOverlayFromBuffers, wrunCanvasHostFillFor, wrunChartPriceDigits, wrunHostFillContextFor, wrunLegFetchType, wrunLegPayloadExtras, wrunIntegratedRowsView, wrunSessionCanvasFillOf, wrunSessionPinnedSheet, wrunSessionRespelledSheet, wrunSessionRunHealth, } from './wrun-overlay-run.util.js';
224
+ import { buildWrunOverlayRunResult, closedLegCandles, forgetWrunOverlayCanvasState, openLegCandles, wrunLegReadsFormingOpen, wrunLegReadsLiveCandleOnly, cutWrunOddsLegRows, placeWrunResultTables, presentWrunIntegration, publishWrunRunHealth, publishWrunSessionCanvasNotices, recordWrunHostBuildMs, reseedWrunOverlayFromBuffers, wrunCanvasHostFillFor, wrunChartPriceDigits, wrunHostFillContextFor, wrunLegFetchType, wrunLegPayloadExtras, wrunIntegratedRowsView, wrunSessionCanvasFillOf, wrunSessionPinnedSheet, wrunSessionRespelledSheet, wrunResultMarketUnits, wrunSessionRunHealth, } from './wrun-overlay-run.util.js';
221
225
  import { forgetWrunCanvasCache } from './wrun-canvas-cache.util.js';
222
226
  import { wrunLegNativeRowsOption } from './wrun-pin-venues.util.js';
223
227
  import { wrunSessionChartNamesOf } from './wrun-chart-context-names.util.js';
224
- import { wrunChartSizeUnit, wrunReadsMarketFacts } from './wrun-chart-market-facts.util.js';
228
+ import { wrunReadsMarketFacts } from './wrun-chart-market-facts.util.js';
225
229
  import { wrunReadsEarningsFacts } from './wrun-earnings-facts.util.js';
226
- import { wrunLaneRefusedCodeOf } from './wrun-lane-refusal.leaf.js';
230
+ import { wrunLaneRefusalLeavesWindowOwed, wrunLaneRefusedCodeOf } from './wrun-lane-refusal.leaf.js';
227
231
  import { WRUN_RUN_INTERVAL_ROWS_KEY, wrunRunIntervalComputeRows, wrunRunIntervalProjectionOf, wrunRunIntervalRowsThrough, wrunRunIntervalSentRow, wrunRunIntervalSessionOf, } from './wrun-run-interval-session.util.js';
228
232
  import { WRUN_NO_READY_ROWS_CODE, wrunNothingReadyRefusal, wrunRunHealthDiagnostics } from './wrun-run-health.util.js';
229
233
  import { attachWrunRefusal, serializeWrunRefusal, wrunOverlayEditable, wrunRefusalFor, } from './wrun-refusal.util.js';
@@ -234,6 +238,7 @@ import { advanceWrunInputCarry, buildWrunInputTailRows, planWrunPinnedWires, wru
234
238
  import { isWrunTradesLegLane, WRUN_TRADES_LANES, wrunTradesLegExtras } from './wrun-trades-lane.util.js';
235
239
  import { drainWrunLiveIntake, dropWrunLiveQueuedBuckets, dropWrunLiveQueuedLegBuckets, enqueueWrunLiveFrame, markWrunLiveGap, noteWrunLiveIntakeEvent, setWrunLiveDrainRequester, takeWrunLiveGaps, wrunLaneAnswerCoversBucket, wrunLiveBucketTs, wrunLiveIntakeBacklogDue, wrunLiveIntakeStats, WRUN_LIVE_LANE_OF_SCRIPT_SOURCE, } from './wrun-live-intake.util.js';
236
240
  import { stampWrunLiveFrameOpra } from './wrun-cloud-opra-stamp.util.js';
241
+ import { createWrunDownloadMeter } from './wrun-download-meter.util.js';
237
242
  /** Book frames are full snapshots and book runs are the heavy case: same 1s
238
243
  * floor the kScript coalescer applies to orderbook-sourced scripts. */
239
244
  const WRUN_BOOK_LIVE_UPDATE_MIN_MS = 1_000;
@@ -352,6 +357,17 @@ const wrunHiddenHeldIds = new Set();
352
357
  * which wakes a drain that re-asks the legs. Dropped on teardown. */
353
358
  const pinnedCloseTimers = new Map();
354
359
  const ledgers = new Map();
360
+ /** Each live session's download meter (wrun-download-meter.util), by session: every reconcile ask charges it. Counted,
361
+ * never budgeted: a reconcile re-asks the newest bars, and the add's attempt settled with its first run. */
362
+ const liveDownloadMeters = new WeakMap();
363
+ function wrunLiveDownloadMeter(context) {
364
+ let meter = liveDownloadMeters.get(context);
365
+ if (meter === undefined) {
366
+ meter = createWrunDownloadMeter(0);
367
+ liveDownloadMeters.set(context, meter);
368
+ }
369
+ return meter;
370
+ }
355
371
  function emptyTickStats() {
356
372
  return {
357
373
  computes: 0,
@@ -1464,7 +1480,8 @@ export async function runWrunOverlayLiveTick(indicatorId) {
1464
1480
  : null;
1465
1481
  if (plan.kind === 'reconcile') {
1466
1482
  const verdict = await reconcileWrunOverlayLanes(context, ledger, plan, meta, mainClock, lastTs);
1467
- if (!wrunLiveContextCurrent(context, generation))
1483
+ // A window over its read's cap held the session and handed the overlay back to a full run: nothing more drains.
1484
+ if (!wrunLiveContextCurrent(context, generation) || verdict === 'handed-back')
1468
1485
  return;
1469
1486
  const owed = verdict === 'closed-bar-revised' || (context.dirtyFromTs !== null && reseedBudgetOpen(ledger));
1470
1487
  // A page ahead of the session holds the reseed (wrunPrefixHoldsReseed):
@@ -1766,15 +1783,18 @@ export class WrunTapeLiveRefusal extends Error {
1766
1783
  this.name = 'WrunTapeLiveRefusal';
1767
1784
  }
1768
1785
  }
1769
- /** The tape inputs of a sheet, by declaration order: index, name, cap, and whether an oversize
1770
- * block reads empty (C1.2b `missing: "empty"`, the packer's own rule). */
1786
+ /** The tape inputs the session asks (isWrunAskedTapeSource: an unasked tape reads zero cells and folds no print), by
1787
+ * declaration order: index, name, `max_cells`, the tuples a bar's block may hold in the module (the packer's own
1788
+ * bound, wrun-cell-capacity.leaf `wrunSheetCellBlockTuples`: the sheet's `capacity ?? max_cells`, unbounded without
1789
+ * either), and whether an oversize block reads empty (C1.2b `missing: "empty"`, the packer's own rule). */
1771
1790
  function wrunTapeInputsOf(metadata) {
1772
1791
  return metadata.inputs
1773
- .filter((input) => metadata.inputSources[input.name]?.source === 'tape')
1792
+ .filter((input) => isWrunAskedTapeSource(metadata.inputSources[input.name]))
1774
1793
  .map((input) => ({
1775
1794
  index: input.index,
1776
1795
  name: input.name,
1777
1796
  ...(input.max_cells !== undefined ? { maxCells: input.max_cells } : {}),
1797
+ capacity: wrunSheetCellBlockTuples(metadata, input),
1778
1798
  emptyWhenOversize: metadata.inputSources[input.name]?.missing === 'empty',
1779
1799
  }));
1780
1800
  }
@@ -1789,7 +1809,8 @@ function refuseWrunTapeCappedBucket(context) {
1789
1809
  const input = wrunTapeInputsOf(context.metadata)[0];
1790
1810
  throw attachWrunRefusal(new WrunTapeLiveRefusal(`WRUN ${context.metadata.id}: input '${input?.name ?? 'tape'}' bar at ts ${bucket} holds more prints than ` +
1791
1811
  `the live tape keeps (${LIVE_MAX_CELLS_PER_BAR}), so its block would be truncated ` +
1792
- `(${WRUN_CELL_BLOCK_TOO_LARGE_CODE}). Blocks are never truncated: raise min_size so fewer prints qualify`), { cls: 'live-stopped', severity: 'note', out: { kind: 'resume-live' } });
1812
+ `(${WRUN_CELL_BLOCK_TOO_LARGE_CODE}). Blocks are never truncated: raise ${wrunTapeFloorSettingWords(context.metadata)} ` +
1813
+ 'so fewer prints qualify'), { cls: 'live-stopped', severity: 'note', out: { kind: 'resume-live' } });
1793
1814
  }
1794
1815
  /** The intake's queue cap dropped live prints of a tape bar that nothing can restore (a live-edge
1795
1816
  * tape, history "0", or a market the large-print table never holds; a restorable loss rides the
@@ -1803,12 +1824,13 @@ function refuseWrunTapeLostBucket(context) {
1803
1824
  const input = wrunTapeInputsOf(context.metadata)[0];
1804
1825
  throw attachWrunRefusal(new WrunTapeLiveRefusal(`WRUN ${context.metadata.id}: input '${input?.name ?? 'tape'}' bar at ts ${bucket} lost live prints to the ` +
1805
1826
  'intake queue cap between drains, and nothing restores them (a live-edge tape with history "0", or a ' +
1806
- 'market the large-print table does not hold), so its block would be incomplete. Raise min_size so ' +
1807
- 'fewer prints qualify, or declare a history so the reconcile can restore them'), { cls: 'live-stopped', severity: 'note', out: { kind: 'resume-live' } });
1827
+ 'market the large-print table does not hold), so its block would be incomplete. Raise ' +
1828
+ `${wrunTapeFloorSettingWords(context.metadata)} so fewer prints qualify, or declare a history so the reconcile ` +
1829
+ 'can restore them'), { cls: 'live-stopped', severity: 'note', out: { kind: 'resume-live' } });
1808
1830
  }
1809
- /** A forming tape block over its input's max_cells (the packer's refusal, in its words, so the
1810
- * record reads the counts): a tape bar's block only grows until the bar closes. An input reading
1811
- * an oversize block as empty (C1.2b) is left to the packer. */
1831
+ /** A forming tape block over the tuples its module holds a bar in (the packer's bound and refusal, in its words, so
1832
+ * the record reads the counts): a tape bar's block only grows until the bar closes. An input reading an oversize
1833
+ * block as empty (C1.2b) is left to the packer. */
1812
1834
  function refuseWrunTapeTailOverCap(context, tailRows) {
1813
1835
  const inputs = wrunTapeInputsOf(context.metadata);
1814
1836
  if (inputs.length === 0)
@@ -1816,14 +1838,14 @@ function refuseWrunTapeTailOverCap(context, tailRows) {
1816
1838
  const width = wrunCellTupleWidths().tape ?? 4;
1817
1839
  for (const row of tailRows) {
1818
1840
  for (const input of inputs) {
1819
- if (input.maxCells === undefined || input.emptyWhenOversize)
1841
+ if (input.emptyWhenOversize)
1820
1842
  continue;
1821
1843
  const tuples = (row.cellBlocks?.get(input.index)?.length ?? 0) / width;
1822
- if (!(tuples > input.maxCells))
1844
+ if (!(tuples > input.capacity))
1823
1845
  continue;
1824
1846
  throw new WrunTapeLiveRefusal(`WRUN ${context.metadata.id}: ${WRUN_CELL_BLOCK_TOO_LARGE_CODE}: input ${input.index} bar at ts ${row.ts} ` +
1825
- `has ${tuples} cells; max_cells is ${input.maxCells}, so the evaluation is refused (a block is never ` +
1826
- `truncated): raise max_cells or min_size`);
1847
+ `has ${tuples} cells; ${wrunCellBoundWords(input.maxCells, input.capacity)}, so the evaluation is refused ` +
1848
+ `(a block is never truncated): raise max_cells or ${wrunTapeFloorSettingWords(context.metadata)}`);
1827
1849
  }
1828
1850
  }
1829
1851
  }
@@ -1837,6 +1859,21 @@ function suspendWrunLiveOnTapeRefusal(context, ledger, generation, error) {
1837
1859
  console.warn(`[wrun] live session suspended for '${context.indicatorId}' (${error.message})`);
1838
1860
  void noteWrunLiveTickRefusal(context, ledger, generation, error);
1839
1861
  }
1862
+ /**
1863
+ * A reconcile lane whose window held more than its read takes (wrunLaneRefusalLeavesWindowOwed: the tape held more
1864
+ * prints at its floor than the trades worker reads, `tape-too-many-trades`): its prints are there, so the window stays
1865
+ * owed, and the next poll would ask the same window at the same floor and meet the same cap. The session is held (no
1866
+ * drains, its picture kept) and hands the overlay back to the full run once, the handoff a reseed's failed reopen
1867
+ * makes: the full run asks the declared history at the same floor, which holds the window, so it meets the cap too
1868
+ * and shows the lane's record (the tape's: too much data, Open the settings), and a settings save with a higher floor
1869
+ * installs a fresh session. Like the budget holds it leaves `liveSuspendedBy` unset: a heal run over the same history
1870
+ * is refused again, so the heal ladder leaves the held session alone.
1871
+ */
1872
+ function handWrunLiveOverCapBack(context, ledger, lane, reason) {
1873
+ context.liveSuspended = true;
1874
+ console.warn(`[wrun] live reconcile lane '${lane}' for '${context.indicatorId}' held more than its read takes (its window stays owed); live suspended, rebuilding once through the full run:`, reason);
1875
+ noteWrunLiveRebuild(ledger, context.indicatorId);
1876
+ }
1840
1877
  /** A rebuild handoff to the full-run driver, counted here and in the intake's
1841
1878
  * stats. Its reason is 'live-rebuild': the session cannot extend, so the run
1842
1879
  * is never merged as a range refresh nor skipped as a duplicate range. */
@@ -2289,8 +2326,9 @@ async function integrateWrunLiveTail(tail) {
2289
2326
  // reads like the session's and a superseded run's late lookup never
2290
2327
  // retitles it.
2291
2328
  chartNames: wrunSessionChartNamesOf(context),
2292
- // The session market's size unit: an output its `visible_by` leaves out mounts nothing.
2293
- sizeUnit: wrunChartSizeUnit(context.market),
2329
+ // The session market's size unit (an output its `visible_by` leaves out mounts nothing) and its dollar unit
2330
+ // (the batched marks' `units`), the ones its full run handed the children.
2331
+ ...wrunResultMarketUnits(context.market),
2294
2332
  // A session at another interval: the run timeline rides the result
2295
2333
  // (the adapter's projection places its bar-index drawings).
2296
2334
  ...(runSession ? { runTimeline: true } : {}),
@@ -2777,7 +2815,7 @@ function laneSourcesOf(context, ohlcvRows) {
2777
2815
  tapeRows: context.tapeRows,
2778
2816
  // The session's own tape floor, the one its lane was asked at (a param-bound floor the plan
2779
2817
  // resolves from these settings).
2780
- settings: wrunTapeFloorSettings(context.metadata, context.acquisition.tape?.minSize),
2818
+ settings: wrunTapeFloorSettings(context.metadata, wrunTapeAcquisitionFloor(context.acquisition.tape)),
2781
2819
  pollLanes: context.pollLanes,
2782
2820
  pollLaneRows: context.pollLaneRows,
2783
2821
  rowLanes: context.rowLanes,
@@ -2910,12 +2948,22 @@ lastMainTs) {
2910
2948
  let revisedFromTs = null;
2911
2949
  const liveCandleOnlyLegs = wrunLiveCandleOnlyLegKeys(context);
2912
2950
  const formingOpenLegs = wrunFormingOpenLegKeys(context);
2951
+ // The first lane whose window held more than its read takes (handed back below, once).
2952
+ let overCap;
2913
2953
  plan.lanes.forEach((lane, at) => {
2914
2954
  const outcome = settled[at];
2915
- // An answer the data plane refused by name (wrun-lane-refusal.leaf: a read switched off, a series it does not
2916
- // sample here) is refused the same way on every ask: read as an answer with no new rows (its window covered,
2955
+ const refusedCode = outcome.status === 'rejected' ? wrunLaneRefusedCodeOf(outcome.reason) : undefined;
2956
+ // A window over its read's cap (wrunLaneRefusalLeavesWindowOwed: the tape held more prints at its floor than
2957
+ // the trades worker reads) holds data the chart lacks: it keeps its obligation as a failed lane does (its fed
2958
+ // buckets outstanding, its coverage behind), and the session hands the overlay back to a full run below.
2959
+ if (outcome.status === 'rejected' && refusedCode !== undefined && wrunLaneRefusalLeavesWindowOwed(refusedCode)) {
2960
+ overCap ??= { lane, reason: outcome.reason };
2961
+ return;
2962
+ }
2963
+ // Any other answer the data plane refused by name (wrun-lane-refusal.leaf: a read switched off, a series it does
2964
+ // not sample here) is refused the same way on every ask: read as an answer with no new rows (its window covered,
2917
2965
  // the held rows kept), so the session neither warns nor widens its window on every poll.
2918
- const refused = outcome.status === 'rejected' && wrunLaneRefusedCodeOf(outcome.reason) !== undefined;
2966
+ const refused = refusedCode !== undefined;
2919
2967
  if (outcome.status === 'rejected' && !refused) {
2920
2968
  // A failed lane keeps its obligation: its fed buckets stay outstanding
2921
2969
  // and the next reconcile window reaches back to them.
@@ -3016,6 +3064,10 @@ lastMainTs) {
3016
3064
  });
3017
3065
  }
3018
3066
  }
3067
+ if (overCap !== undefined) {
3068
+ handWrunLiveOverCapBack(context, ledger, overCap.lane, overCap.reason);
3069
+ return 'handed-back';
3070
+ }
3019
3071
  if (revisedFromTs === null)
3020
3072
  return 'clean';
3021
3073
  // A revised closed bar is a committed bar the session evaluated on other
@@ -3128,7 +3180,12 @@ async function fetchWrunReconcileLane(context, ledger, lane, fromTs, toTs, meta)
3128
3180
  // The full run already stamped this overlay's legend; a reconcile
3129
3181
  // must not re-stamp it (every stamp is a legend repaint). A session
3130
3182
  // at another interval asks its lanes at the run interval.
3131
- { ...wrunReconcileRunIntervalOption(context), ...fetchOptions, silentLegend: true }), WRUN_SOURCE_FETCH_DEADLINE_MS, `wrun live reconcile fetch '${spec.type}' for '${context.fetchKey}'`);
3183
+ {
3184
+ ...wrunReconcileRunIntervalOption(context),
3185
+ ...fetchOptions,
3186
+ silentLegend: true,
3187
+ meter: wrunLiveDownloadMeter(context),
3188
+ }), WRUN_SOURCE_FETCH_DEADLINE_MS, `wrun live reconcile fetch '${spec.type}' for '${context.fetchKey}'`);
3132
3189
  // Packed-lane SUCCESS arrives as the packed transport object: unpack it,
3133
3190
  // or a real success misclassifies as a decline.
3134
3191
  if (isPackedOhlcvRows(fetched))
@@ -3187,6 +3244,7 @@ async function askWrunReconcileSourceAnswer(context, ledger, ask, meta) {
3187
3244
  ...(ask.interval === undefined ? wrunReconcileRunIntervalOption(context) : { interval: ask.interval }),
3188
3245
  ...(ask.nativeRows === true ? { nativeRows: true } : {}),
3189
3246
  ...(ask.endExclusive === true ? { endExclusive: true } : {}),
3247
+ meter: wrunLiveDownloadMeter(context),
3190
3248
  }), WRUN_SOURCE_FETCH_DEADLINE_MS, `wrun live reconcile fetch '${ask.type}' (${ask.key}) for '${context.fetchKey}'`);
3191
3249
  return Array.isArray(fetched) ? fetched : null;
3192
3250
  }
@@ -3449,7 +3507,12 @@ async function fetchWrunReconcileLeg(context, ledger, leg, meta) {
3449
3507
  const native = leg.nativeRows === true ? { nativeRows: true } : wrunLegNativeRowsOption(leg, context.market?.exchange);
3450
3508
  const fetchType = wrunLegFetchType(leg);
3451
3509
  const ask = async (fromTs, toTs, options, onSourceVerdict) => {
3452
- const fetched = await withWrunDeadline(wrunChartHostEnv().transport.fetchSource(context.chartIndex, fetchType, { symbol: 'currentSymbol', exchange: 'currentExchange', ...wrunLegPayloadExtras(leg) }, fromTs, toTs, meta, `${context.fetchKey}-live-${suffix}`, false, { silentLegend: true, ...options, ...(onSourceVerdict !== undefined ? { onSourceVerdict } : {}) }), WRUN_SOURCE_FETCH_DEADLINE_MS, `wrun live reconcile fetch '${fetchType}' (${suffix}) for '${context.fetchKey}'`);
3510
+ const fetched = await withWrunDeadline(wrunChartHostEnv().transport.fetchSource(context.chartIndex, fetchType, { symbol: 'currentSymbol', exchange: 'currentExchange', ...wrunLegPayloadExtras(leg) }, fromTs, toTs, meta, `${context.fetchKey}-live-${suffix}`, false, {
3511
+ silentLegend: true,
3512
+ ...options,
3513
+ ...(onSourceVerdict !== undefined ? { onSourceVerdict } : {}),
3514
+ meter: wrunLiveDownloadMeter(context),
3515
+ }), WRUN_SOURCE_FETCH_DEADLINE_MS, `wrun live reconcile fetch '${fetchType}' (${suffix}) for '${context.fetchKey}'`);
3453
3516
  if (isPackedOhlcvRows(fetched))
3454
3517
  return unpackOhlcvRows(fetched);
3455
3518
  return Array.isArray(fetched) ? fetched : [];
@@ -3627,8 +3690,9 @@ function noteWrunRunIntervalLive(context, session, details) {
3627
3690
  * lane's covered watermark advances to the window's end, and a closed bar
3628
3691
  * (before the session watermark) whose value changed reports as revised.
3629
3692
  *
3630
- * Every answered row is installed whatever its stamp, so a revision is
3631
- * looked for over every row the answer can replace: from the window's start
3693
+ * Every answered row is installed whatever its stamp (but a row lane drawing
3694
+ * its first slice alone, `rowLaneFilling`, takes none before the slice), so a
3695
+ * revision is looked for over every row the answer can replace: from the window's start
3632
3696
  * or the earliest answered row, whichever is earlier. A control may answer
3633
3697
  * rows stamped before its window (a monthly series answers the month its
3634
3698
  * window opens inside, stamped on the 1st); such a row used to overwrite the
@@ -3646,7 +3710,12 @@ servedStartMs) {
3646
3710
  // window's day, the lane's lookback earlier): the answer is authoritative
3647
3711
  // from there, and a revised or late-published day is detected from there,
3648
3712
  // not from the chart-bar window.
3649
- const windowFrom = wrunReconcileLaneWindowFrom(context, lane, fromTs, toTs);
3713
+ // A row lane drawing its first slice alone (`rowLaneFilling`, by the slice's first bar): the reconcile lands none of
3714
+ // its rows before that bar. Those bars read partial until the fill, with the earlier bars of their session, so a row
3715
+ // landed on one would sum a session from its middle; the fill's own run lands them all.
3716
+ const fillFromTs = isWrunRowLaneId(lane) ? context.rowLaneFilling?.[lane] : undefined;
3717
+ const windowFrom = Math.max(wrunReconcileLaneWindowFrom(context, lane, fromTs, toTs), fillFromTs ?? Number.NEGATIVE_INFINITY);
3718
+ const answerRowsInWindow = fillFromTs === undefined ? answerRows : answerRows.filter((row) => Number(row[0]) >= fillFromTs);
3650
3719
  const before = laneRowsOf(context, lane) ?? [];
3651
3720
  // The tape lane answers DENSE rows from its served start only: K_TRADES aligns and clamps the
3652
3721
  // history start (the declared history, the gateway's bar limit, the table's retention), so a
@@ -3666,7 +3735,7 @@ servedStartMs) {
3666
3735
  ? answerRows
3667
3736
  : wrunTapeAnswerWithoutPartialHead(answerRows, servedStartMs, context.intervalMs, context.market?.exchange), before)
3668
3737
  : isWrunRowLaneId(lane)
3669
- ? wrunRowLaneReconcileAnswer(context, lane, before, answerRows)
3738
+ ? wrunRowLaneReconcileAnswer(context, lane, before, answerRowsInWindow)
3670
3739
  : answerRows;
3671
3740
  const horizonTs = lane === 'tape' ? wrunTapeAnswerHorizonTs(answer) : Number.NEGATIVE_INFINITY;
3672
3741
  // A row lane fed live with a union rule of its own (`liveByCoin.reconcile`) keeps, like the tape, every held bar the
@@ -3868,18 +3937,27 @@ function wrunTapeAnswerWithoutPartialHead(answer, servedStartMs, intervalMs, exc
3868
3937
  return answer;
3869
3938
  return answer.filter((row) => Number(row[0]) !== horizonTs);
3870
3939
  }
3871
- /** A tape print's identity in a union: its whole `[offsetMs, price, size, side]` tuple. */
3872
- function wrunTapeCellKey(cell) {
3873
- return `${cell[0]}|${cell[1]}|${cell[2]}|${cell[3]}`;
3940
+ /** A tape print's place in a union: its `[offsetMs, price, size, side]` tuple without the size, the columns both
3941
+ * copies of one print carry bit for bit (the stamp and the price as the venue sent them, the side). */
3942
+ function wrunTapePrintPlaceKey(cell) {
3943
+ return `${cell[0]}|${cell[1]}|${cell[3]}`;
3874
3944
  }
3875
3945
  /**
3876
3946
  * A tape answer folded over the held rows: each answered bucket with a held row becomes the union
3877
- * of both rows' prints, a multiset union by tuple (a print the two share is kept once, two equal
3947
+ * of both rows' prints, a multiset union by print (a print the two share is kept once, two equal
3878
3948
  * prints of one row stay two), in time order with the answer's prints first among equal offsets.
3879
3949
  * A reconcile only ever adds prints to a bar: the large-print table holds no print of a quote it
3880
3950
  * does not price, and the live floors can still keep a print it lacks (a contract's notional, a
3881
3951
  * print the writer had not committed when the ask landed), so a print shown live never vanishes
3882
3952
  * on the next poll.
3953
+ *
3954
+ * A print is the same print in both rows when its stamp, price and side are equal and its size agrees within float
3955
+ * rounding (`laneValuesEqual`, the session's own noise rule): two hosts compute one print's size, and under a dollar
3956
+ * floor (C-DOLLAR) they compute it differently, the gateway's writer on the stored row (an inverse contract's dollar
3957
+ * face), this browser as price x the live-feed COIN-arm size x the market's dollar unit: Binance delivery BTCUSD_PERP
3958
+ * trade 1160180465 (2026-10-22, tests/fixtures/wrun/tape-live-history-pairs.json) is $179,300 stored and
3959
+ * 84,428.9 x 2.12368039853652 = 179299.99999999997 live. Two equal prints still stay two: each held print matches one
3960
+ * answer print at most.
3883
3961
  */
3884
3962
  function wrunTapeAnswerUnion(answer, held) {
3885
3963
  if (held.length === 0)
@@ -3891,21 +3969,26 @@ function wrunTapeAnswerUnion(answer, held) {
3891
3969
  const previous = heldByTs.get(Number(row[0]));
3892
3970
  if (previous === undefined || previous.length <= 1)
3893
3971
  return row;
3972
+ // The answer's sizes not matched yet, by the place of their print.
3894
3973
  const unmatched = new Map();
3895
3974
  const cells = [];
3896
3975
  for (let at = 1; at < row.length; at += 1) {
3897
3976
  const cell = row[at];
3898
3977
  cells.push(cell);
3899
- const key = wrunTapeCellKey(cell);
3900
- unmatched.set(key, (unmatched.get(key) ?? 0) + 1);
3978
+ const key = wrunTapePrintPlaceKey(cell);
3979
+ const sizes = unmatched.get(key);
3980
+ if (sizes === undefined)
3981
+ unmatched.set(key, [cell[2]]);
3982
+ else
3983
+ sizes.push(cell[2]);
3901
3984
  }
3902
3985
  const extra = [];
3903
3986
  for (let at = 1; at < previous.length; at += 1) {
3904
3987
  const cell = previous[at];
3905
- const key = wrunTapeCellKey(cell);
3906
- const left = unmatched.get(key) ?? 0;
3907
- if (left > 0)
3908
- unmatched.set(key, left - 1);
3988
+ const sizes = unmatched.get(wrunTapePrintPlaceKey(cell));
3989
+ const match = sizes === undefined ? -1 : sizes.findIndex((size) => laneValuesEqual(size, cell[2]));
3990
+ if (match >= 0)
3991
+ sizes?.splice(match, 1);
3909
3992
  else
3910
3993
  extra.push(cell);
3911
3994
  }
@@ -3929,9 +4012,12 @@ function wrunTapeServedStartMs(context, windowFromTs, nowMs) {
3929
4012
  catch {
3930
4013
  // The full run validated the history; a malformed record reads as the live edge.
3931
4014
  }
3932
- // The lane the ask rode (tradesLaneLimits, the control's own rule): the table's retention and bar
3933
- // limit, or the raw tape's two-hour seed on a CME Group root the table skips.
3934
- const lane = tradesLaneLimits(context.acquisition.tape?.large === true, context.market ?? {});
4015
+ // The lane the ask rode (tradesLaneLimits, the control's own rule, under the acquisition's floor): the table's
4016
+ // retention and bar limit, the raw tape's two-hour seed on a CME Group root the table skips, or no history at all
4017
+ // for a dollar floor there.
4018
+ const lane = tradesLaneLimits(context.acquisition.tape?.large === true, context.market ?? {}, {
4019
+ minValue: context.acquisition.tape?.minValue,
4020
+ });
3935
4021
  return tradesServedStartMs(nowMs, Math.min(historySec, lane.historyCapSec), context.intervalMs, {
3936
4022
  windowFromMs: windowFromTs,
3937
4023
  retentionSec: lane.retentionSec,
@@ -0,0 +1,53 @@
1
+ /** One carry into a contracts param (`to`), from the raw count's old name (`raw`) or the changed dollar param
2
+ * (`dollars`). */
3
+ export interface WrunContractCarryRule {
4
+ readonly to: string;
5
+ readonly raw: string;
6
+ readonly dollars: string;
7
+ }
8
+ /** The contracts carries by package, by param name (never by version: every saved version moves the same way).
9
+ * tests/utility/wrun/wrun-market-size-contract-carry.leaf.spec.ts holds each row to the 0.8.0 sheet and its dollar
10
+ * rule. */
11
+ export declare const WRUN_CONTRACT_CARRIES: Readonly<Record<string, readonly WrunContractCarryRule[]>>;
12
+ /** The record's stamp of a pending migration carry (above): `true` from the pin move until a run head settles it. */
13
+ export declare const WRUN_CONTRACT_CARRY_PENDING = "wrunContractCarryPending";
14
+ /** A pending contracts carry: the rule and what it carries from (`raw`: the count itself; `dollars`: a dollar value
15
+ * priced at the market's dollars per contract; `stale`: a raw count a later dollar choice of the user's replaced,
16
+ * cleared and carried nowhere). */
17
+ export type WrunPendingContractCarry = WrunContractCarryRule & ({
18
+ readonly from: 'raw';
19
+ readonly count: number;
20
+ } | {
21
+ readonly from: 'dollars';
22
+ readonly value: number;
23
+ } | {
24
+ readonly from: 'stale';
25
+ });
26
+ /**
27
+ * The smallest whole contract count at or above `dollars` at `perContract` dollars a contract: `ceil(dollars /
28
+ * perContract)`, the float noise of a count priced back taken off first (6.9999999999 is 7, never 8). Undefined when
29
+ * either is not finite and above zero (the carry waits, never guesses).
30
+ */
31
+ export declare function wrunCarriedContracts(dollars: unknown, perContract: number): number | undefined;
32
+ /**
33
+ * The contracts carries a record (`settings`: its `scriptInputs` rows and each value flat under its row's name) holds
34
+ * for a sheet declaring `sheetParams`, on a market of size unit `sizeUnit`, in table order: none off contracts, none
35
+ * for a contracts param the sheet does not declare or the user already set (or a carry marked). Pure.
36
+ */
37
+ export declare function wrunPendingContractCarries(settings: unknown, packageName: string | undefined, sheetParams: ReadonlySet<string>, sizeUnit: number | undefined): WrunPendingContractCarry[];
38
+ /**
39
+ * Whether the run head settles the record's migration stamp now (`WRUN_CONTRACT_CARRY_PENDING` cleared on the engine
40
+ * copy and the workspace row): a stamped record, on a sheet declaring its package's contracts params (the version the
41
+ * stamp moved it to), at once on a market that does not count contracts (nothing converts there, and nothing may later),
42
+ * and on one that does once no dollar carry of `pending` waits on its price (`perContract` unproven: the next run asks
43
+ * again). Pure.
44
+ */
45
+ export declare function wrunContractCarrySettles(settings: unknown, packageName: string | undefined, sheetParams: ReadonlySet<string>, sizeUnit: number | undefined, pending: readonly WrunPendingContractCarry[], perContract: number | undefined): boolean;
46
+ /**
47
+ * The patch that carries a record's pending contracts carries once (above): each contracts value (a raw count as it
48
+ * is, a dollar value at `perContract` dollars a contract, `wrunCarriedContracts`), held to its row's bounds, written
49
+ * flat under the contracts param with its row marked (`carriedValue`); the old name cleared; the dollar row back to
50
+ * untouched (its row default, its mark dropped). A dollar carry with no proven `perContract` writes nothing (the next
51
+ * run asks again). Undefined when nothing moves. Pure.
52
+ */
53
+ export declare function wrunContractCarryPatch(settings: unknown, pending: readonly WrunPendingContractCarry[], perContract: number | undefined): Record<string, unknown> | undefined;
@@ -0,0 +1,162 @@
1
+ import { WRUN_MARKET_SIZE_UNITS } from './wrun-market-facts.util.js';
2
+ /** The contracts carries by package, by param name (never by version: every saved version moves the same way).
3
+ * tests/utility/wrun/wrun-market-size-contract-carry.leaf.spec.ts holds each row to the 0.8.0 sheet and its dollar
4
+ * rule. */
5
+ export const WRUN_CONTRACT_CARRIES = Object.freeze({
6
+ '@om-core/big-trades': Object.freeze([
7
+ Object.freeze({ to: 'min_contracts', raw: 'min_size', dollars: 'min_value' }),
8
+ Object.freeze({ to: 'whale_contracts', raw: 'whale_size', dollars: 'whale_value' }),
9
+ ]),
10
+ });
11
+ /** The record's stamp of a pending migration carry (above): `true` from the pin move until a run head settles it. */
12
+ export const WRUN_CONTRACT_CARRY_PENDING = 'wrunContractCarryPending';
13
+ /** `market.size_unit()`'s contracts code (the kit's table, wrun-market-facts.util). */
14
+ const CONTRACTS_SIZE_UNIT = WRUN_MARKET_SIZE_UNITS.indexOf('contracts');
15
+ /** The float noise a dollar value priced from a whole count carries (7 x $584,875 read back as 6.9999999999). */
16
+ const CONTRACTS_EPSILON = 1e-9;
17
+ function isRecord(value) {
18
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
19
+ }
20
+ function positive(value) {
21
+ const number = typeof value === 'number' ? value : typeof value === 'string' && value.trim() !== '' ? Number(value) : NaN;
22
+ return Number.isFinite(number) && number > 0 ? number : undefined;
23
+ }
24
+ function rowNamed(record, name) {
25
+ const rows = Array.isArray(record.scriptInputs) ? record.scriptInputs : [];
26
+ return rows.find((row) => isRecord(row) && row.name === name);
27
+ }
28
+ /** Whether a number row reads untouched: its value is its row default and it holds no carried mark (the settings
29
+ * panel's reset test on a plain number row: the value absent reads the default). */
30
+ function untouched(record, row) {
31
+ if (row === undefined || typeof row.carriedValue === 'number')
32
+ return false;
33
+ const value = record[row.name];
34
+ return value === undefined || value === null || Number(value) === Number(row.defaultValue);
35
+ }
36
+ /**
37
+ * The smallest whole contract count at or above `dollars` at `perContract` dollars a contract: `ceil(dollars /
38
+ * perContract)`, the float noise of a count priced back taken off first (6.9999999999 is 7, never 8). Undefined when
39
+ * either is not finite and above zero (the carry waits, never guesses).
40
+ */
41
+ export function wrunCarriedContracts(dollars, perContract) {
42
+ const value = positive(dollars);
43
+ if (value === undefined || !Number.isFinite(perContract) || perContract <= 0)
44
+ return undefined;
45
+ const count = Math.ceil(value / perContract - CONTRACTS_EPSILON);
46
+ return Number.isFinite(count) && count >= 1 ? count : 1;
47
+ }
48
+ /**
49
+ * The contracts carries a record (`settings`: its `scriptInputs` rows and each value flat under its row's name) holds
50
+ * for a sheet declaring `sheetParams`, on a market of size unit `sizeUnit`, in table order: none off contracts, none
51
+ * for a contracts param the sheet does not declare or the user already set (or a carry marked). Pure.
52
+ */
53
+ export function wrunPendingContractCarries(settings, packageName, sheetParams, sizeUnit) {
54
+ if (sizeUnit !== CONTRACTS_SIZE_UNIT || packageName === undefined)
55
+ return [];
56
+ if (!Object.hasOwn(WRUN_CONTRACT_CARRIES, packageName))
57
+ return [];
58
+ const record = isRecord(settings) ? settings : {};
59
+ const pending = [];
60
+ for (const rule of WRUN_CONTRACT_CARRIES[packageName]) {
61
+ if (!sheetParams.has(rule.to) || !untouched(record, rowNamed(record, rule.to)))
62
+ continue;
63
+ const dollarsRow = rowNamed(record, rule.dollars);
64
+ const mark = typeof dollarsRow?.carriedValue === 'number' ? dollarsRow.carriedValue : undefined;
65
+ const dollars = Number(record[rule.dollars]);
66
+ // The raw count is the user's latest word while the dollar row was never priced from it, or still reads the value
67
+ // that carry priced (an edit since is newer).
68
+ const count = sheetParams.has(rule.raw) ? undefined : positive(record[rule.raw]);
69
+ if (count !== undefined && (mark === undefined || dollars === mark)) {
70
+ pending.push({ ...rule, from: 'raw', count });
71
+ continue;
72
+ }
73
+ // A changed dollar value (the settings panel's test: off its row default, or the value a carry marked), on a
74
+ // migration's first head alone: a record never stamped converts no dollar value.
75
+ const changed = record[WRUN_CONTRACT_CARRY_PENDING] === true &&
76
+ dollarsRow !== undefined &&
77
+ positive(dollars) !== undefined &&
78
+ (dollars !== Number(dollarsRow.defaultValue) || (mark !== undefined && dollars === mark));
79
+ if (changed)
80
+ pending.push({ ...rule, from: 'dollars', value: dollars });
81
+ else if (count !== undefined)
82
+ pending.push({ ...rule, from: 'stale' });
83
+ }
84
+ return pending;
85
+ }
86
+ /**
87
+ * Whether the run head settles the record's migration stamp now (`WRUN_CONTRACT_CARRY_PENDING` cleared on the engine
88
+ * copy and the workspace row): a stamped record, on a sheet declaring its package's contracts params (the version the
89
+ * stamp moved it to), at once on a market that does not count contracts (nothing converts there, and nothing may later),
90
+ * and on one that does once no dollar carry of `pending` waits on its price (`perContract` unproven: the next run asks
91
+ * again). Pure.
92
+ */
93
+ export function wrunContractCarrySettles(settings, packageName, sheetParams, sizeUnit, pending, perContract) {
94
+ const record = isRecord(settings) ? settings : {};
95
+ if (record[WRUN_CONTRACT_CARRY_PENDING] !== true || packageName === undefined)
96
+ return false;
97
+ if (!Object.hasOwn(WRUN_CONTRACT_CARRIES, packageName))
98
+ return false;
99
+ if (!WRUN_CONTRACT_CARRIES[packageName].some((rule) => sheetParams.has(rule.to)))
100
+ return false;
101
+ if (sizeUnit !== CONTRACTS_SIZE_UNIT)
102
+ return true;
103
+ return !pending.some((carry) => carry.from === 'dollars' &&
104
+ (perContract === undefined || wrunCarriedContracts(carry.value, perContract) === undefined));
105
+ }
106
+ /**
107
+ * The patch that carries a record's pending contracts carries once (above): each contracts value (a raw count as it
108
+ * is, a dollar value at `perContract` dollars a contract, `wrunCarriedContracts`), held to its row's bounds, written
109
+ * flat under the contracts param with its row marked (`carriedValue`); the old name cleared; the dollar row back to
110
+ * untouched (its row default, its mark dropped). A dollar carry with no proven `perContract` writes nothing (the next
111
+ * run asks again). Undefined when nothing moves. Pure.
112
+ */
113
+ export function wrunContractCarryPatch(settings, pending, perContract) {
114
+ if (pending.length === 0)
115
+ return undefined;
116
+ const record = isRecord(settings) ? settings : {};
117
+ const patch = {};
118
+ const carried = new Map();
119
+ const reset = new Set();
120
+ for (const carry of pending) {
121
+ if (carry.from === 'stale') {
122
+ // The user's later dollar choice replaced the count: the old name goes, nothing carries.
123
+ patch[carry.raw] = undefined;
124
+ continue;
125
+ }
126
+ const counted = carry.from === 'raw'
127
+ ? carry.count
128
+ : perContract === undefined
129
+ ? undefined
130
+ : wrunCarriedContracts(carry.value, perContract);
131
+ if (counted === undefined)
132
+ continue;
133
+ const row = rowNamed(record, carry.to);
134
+ const min = typeof row?.constraints?.min === 'number' ? row.constraints.min : undefined;
135
+ const max = typeof row?.constraints?.max === 'number' ? row.constraints.max : undefined;
136
+ const value = min !== undefined && counted < min ? min : max !== undefined && counted > max ? max : counted;
137
+ patch[carry.to] = value;
138
+ if (Object.hasOwn(record, carry.raw))
139
+ patch[carry.raw] = undefined;
140
+ const dollarsRow = rowNamed(record, carry.dollars);
141
+ if (dollarsRow !== undefined)
142
+ patch[carry.dollars] = dollarsRow.defaultValue;
143
+ carried.set(carry.to, value);
144
+ reset.add(carry.dollars);
145
+ }
146
+ if (carried.size === 0)
147
+ return Object.keys(patch).length > 0 ? patch : undefined;
148
+ if (Array.isArray(record.scriptInputs)) {
149
+ patch.scriptInputs = record.scriptInputs.map((row) => {
150
+ if (!isRecord(row) || typeof row.name !== 'string')
151
+ return row;
152
+ if (carried.has(row.name))
153
+ return { ...row, carriedValue: carried.get(row.name) };
154
+ if (reset.has(row.name) && Object.hasOwn(row, 'carriedValue')) {
155
+ const { carriedValue: _mark, ...rest } = row;
156
+ return rest;
157
+ }
158
+ return row;
159
+ });
160
+ }
161
+ return patch;
162
+ }