@orangecharts/wrun-chart-host 0.10.0 → 0.11.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 (145) hide show
  1. package/README.md +1 -0
  2. package/dist/constants/feature-flags.constants.d.ts +9 -0
  3. package/dist/constants/feature-flags.constants.js +67 -4
  4. package/dist/constants/governed-exchanges.constants.d.ts +12 -0
  5. package/dist/constants/governed-exchanges.constants.js +16 -0
  6. package/dist/constants/option-venues.constants.d.ts +2 -2
  7. package/dist/host-env.d.ts +1 -9
  8. package/dist/host-ports.types.d.ts +36 -7
  9. package/dist/index.d.ts +6 -1
  10. package/dist/index.js +6 -1
  11. package/dist/interfaces/cancel-reason.interface.d.ts +1 -1
  12. package/dist/interfaces/cme-realtime.interface.d.ts +16 -9
  13. package/dist/interfaces/cme-realtime.interface.js +6 -3
  14. package/dist/interfaces/kscript-diagnostics.interface.d.ts +6 -0
  15. package/dist/interfaces/opra-realtime.interface.d.ts +1 -5
  16. package/dist/interfaces/prediction-market.interface.d.ts +7 -0
  17. package/dist/interfaces/stocks-realtime.interface.d.ts +57 -0
  18. package/dist/interfaces/stocks-realtime.interface.js +32 -0
  19. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +48 -117
  20. package/dist/kscript-data/controls/live-trades-merge.util.js +97 -207
  21. package/dist/market-data/billing.interface.d.ts +86 -12
  22. package/dist/market-data/billing.interface.js +23 -4
  23. package/dist/market-data/venue.d.ts +65 -2
  24. package/dist/market-data/venues/index.d.ts +135 -5
  25. package/dist/market-data/venues/index.js +2 -1
  26. package/dist/market-data/venues/opra.contract.copy.json +3 -2
  27. package/dist/market-data/venues/opra.d.ts +2 -2
  28. package/dist/market-data/venues/opra.js +5 -2
  29. package/dist/market-data/venues/stocks.contract.copy.json +64 -0
  30. package/dist/market-data/venues/stocks.d.ts +130 -0
  31. package/dist/market-data/venues/stocks.js +117 -0
  32. package/dist/settings-templates/footprint-rows.js +35 -2
  33. package/dist/settings-templates/form-rows.d.ts +2 -1
  34. package/dist/settings-templates/indicator-fields.js +34 -4
  35. package/dist/settings-templates/tool-rules.d.ts +12 -5
  36. package/dist/settings-templates/tool-rules.js +11 -5
  37. package/dist/settings-templates/tool-tables.generated.js +4 -0
  38. package/dist/utility/chart/cme-cache-context.util.d.ts +5 -3
  39. package/dist/utility/chart/cme-cache-context.util.js +10 -6
  40. package/dist/utility/chart/cme-realtime.util.js +10 -0
  41. package/dist/utility/chart/cme-user-scripts-gate.util.d.ts +83 -0
  42. package/dist/utility/chart/cme-user-scripts-gate.util.js +142 -0
  43. package/dist/utility/chart/effective-chart-session.util.d.ts +14 -0
  44. package/dist/utility/chart/effective-chart-session.util.js +39 -0
  45. package/dist/utility/chart/host-bar-placement.util.d.ts +28 -0
  46. package/dist/utility/chart/host-bar-placement.util.js +170 -30
  47. package/dist/utility/chart/index-host-tier.util.d.ts +3 -1
  48. package/dist/utility/chart/index-host-tier.util.js +7 -2
  49. package/dist/utility/chart/index-mode-admission.util.js +25 -11
  50. package/dist/utility/chart/kscript-apply-fingerprint.util.js +1 -1
  51. package/dist/utility/chart/kscript-live-coalesce.util.d.ts +6 -9
  52. package/dist/utility/chart/kscript-live-coalesce.util.js +8 -9
  53. package/dist/utility/chart/kscript-live-source-identity.util.d.ts +9 -0
  54. package/dist/utility/chart/kscript-live-source-identity.util.js +10 -1
  55. package/dist/utility/chart/kscript-provenance-keys.util.js +7 -0
  56. package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +3 -1
  57. package/dist/utility/chart/kscript-venue-policy.util.d.ts +115 -21
  58. package/dist/utility/chart/kscript-venue-policy.util.js +194 -40
  59. package/dist/utility/chart/live-bucket.util.d.ts +24 -8
  60. package/dist/utility/chart/live-bucket.util.js +85 -27
  61. package/dist/utility/chart/marketKind.util.js +5 -0
  62. package/dist/utility/chart/mixed-mode.util.d.ts +7 -0
  63. package/dist/utility/chart/mixed-mode.util.js +14 -0
  64. package/dist/utility/chart/opra-user-scripts-gate.util.d.ts +11 -16
  65. package/dist/utility/chart/opra-user-scripts-gate.util.js +12 -28
  66. package/dist/utility/chart/rth-session.util.d.ts +9 -8
  67. package/dist/utility/chart/rth-session.util.js +23 -20
  68. package/dist/utility/chart/trading-day.util.d.ts +17 -0
  69. package/dist/utility/chart/trading-day.util.js +59 -0
  70. package/dist/utility/chart/window-owner.leaf.d.ts +23 -2
  71. package/dist/utility/chart/window-owner.leaf.js +45 -3
  72. package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +33 -15
  73. package/dist/utility/chart/wrun-bar-session-facts.util.js +70 -20
  74. package/dist/utility/intl-locale.util.js +5 -0
  75. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +2 -0
  76. package/dist/utility/v2/gate-plane.util.d.ts +12 -3
  77. package/dist/utility/v2/gate-plane.util.js +30 -4
  78. package/dist/utility/v2/gate-session-latch.util.js +1 -1
  79. package/dist/utility/v2/stocks-governed.util.d.ts +16 -0
  80. package/dist/utility/v2/stocks-governed.util.js +34 -0
  81. package/dist/utility/wrun/derived-roots.leaf.d.ts +13 -0
  82. package/dist/utility/wrun/derived-roots.leaf.js +27 -0
  83. package/dist/utility/wrun/derived-roots.util.d.ts +1 -9
  84. package/dist/utility/wrun/derived-roots.util.js +3 -23
  85. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +4 -3
  86. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +24 -3
  87. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +46 -10
  88. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +2 -0
  89. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.d.ts +63 -16
  90. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.js +58 -14
  91. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +34 -11
  92. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +106 -30
  93. package/dist/utility/wrun/wrun-browser-sources.leaf.js +1 -2
  94. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +7 -4
  95. package/dist/utility/wrun/wrun-chart-market-facts.util.js +12 -8
  96. package/dist/utility/wrun/wrun-color-settings.util.d.ts +9 -0
  97. package/dist/utility/wrun/wrun-color-settings.util.js +33 -0
  98. package/dist/utility/wrun/wrun-handles.util.d.ts +7 -3
  99. package/dist/utility/wrun/wrun-handles.util.js +9 -8
  100. package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +68 -0
  101. package/dist/utility/wrun/wrun-input-requirements.leaf.js +163 -7
  102. package/dist/utility/wrun/wrun-leg-close.util.d.ts +59 -23
  103. package/dist/utility/wrun/wrun-leg-close.util.js +186 -28
  104. package/dist/utility/wrun/wrun-live-intake.util.d.ts +26 -12
  105. package/dist/utility/wrun/wrun-live-intake.util.js +219 -155
  106. package/dist/utility/wrun/wrun-live-tick.util.d.ts +9 -5
  107. package/dist/utility/wrun/wrun-live-tick.util.js +130 -94
  108. package/dist/utility/wrun/wrun-market-facts.util.d.ts +13 -3
  109. package/dist/utility/wrun/wrun-market-facts.util.js +13 -3
  110. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +20 -10
  111. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +10 -5
  112. package/dist/utility/wrun/wrun-option-book-rows.util.d.ts +56 -0
  113. package/dist/utility/wrun/wrun-option-book-rows.util.js +96 -0
  114. package/dist/utility/wrun/wrun-option-views.util.d.ts +281 -20
  115. package/dist/utility/wrun/wrun-option-views.util.js +391 -50
  116. package/dist/utility/wrun/wrun-options-chain.util.d.ts +3 -3
  117. package/dist/utility/wrun/wrun-options-chain.util.js +2 -0
  118. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +15 -2
  119. package/dist/utility/wrun/wrun-overlay-drivers.util.js +13 -3
  120. package/dist/utility/wrun/wrun-overlay-recovery.util.js +3 -1
  121. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +60 -11
  122. package/dist/utility/wrun/wrun-overlay-run.util.js +529 -113
  123. package/dist/utility/wrun/wrun-panel-mount.util.js +51 -6
  124. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +15 -2
  125. package/dist/utility/wrun/wrun-pin-spelling.util.js +27 -3
  126. package/dist/utility/wrun/wrun-refusal.util.d.ts +3 -2
  127. package/dist/utility/wrun/wrun-refusal.util.js +22 -0
  128. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +26 -0
  129. package/dist/utility/wrun/wrun-registry-errors.util.js +34 -0
  130. package/dist/utility/wrun/wrun-replay-lane.util.js +3 -2
  131. package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +20 -6
  132. package/dist/utility/wrun/wrun-run-interval-session.util.js +22 -7
  133. package/dist/utility/wrun/wrun-run-interval.util.d.ts +39 -7
  134. package/dist/utility/wrun/wrun-run-interval.util.js +49 -9
  135. package/dist/utility/wrun/wrun-socket-row-source.js +7 -2
  136. package/dist/utility/wrun/wrun-source-rows.util.d.ts +29 -22
  137. package/dist/utility/wrun/wrun-source-rows.util.js +62 -41
  138. package/dist/utility/wrun/wrun-tape-per-order.util.js +1 -20
  139. package/dist/utility/wrun/wrun-tape-source.util.d.ts +17 -9
  140. package/dist/utility/wrun/wrun-tape-source.util.js +20 -12
  141. package/dist/workers/constants/socket-slots.d.ts +91 -6
  142. package/dist/workers/constants/socket-slots.js +85 -6
  143. package/package.json +11 -11
  144. package/dist/kscript-data/controls/live-trades-order-gate.util.d.ts +0 -56
  145. package/dist/kscript-data/controls/live-trades-order-gate.util.js +0 -107
@@ -23,24 +23,14 @@
23
23
  * - liquidations: K_LIQUIDATIONS (additive per side; the increment is amount x price, USD like
24
24
  * the lane's history ask, or the amount in coins when the acquisition asked for coins);
25
25
  * - tape: K_TRADES's live fold (`mergeLiveTradesDataPoint`, the leaf the control and the history
26
- * worker share): one `[offsetMs, price, size, side]` cell per raw print appended to its bar's
27
- * row, the side from the series envelope, prints below the acquisition's `minSize` rejected,
28
- * the bar the worker keys (a week on its Monday, the CME lattice on its venues), a delayed
29
- * print for a bar older than the newest row never appending an out-of-order row, a live bar
30
- * capped at 20k prints (the bucket reported as capped, which the tick refuses by name); prints
31
- * below the floor are dropped at the enqueue too, so a busy tape never crowds a qualifying print
32
- * out of the queue (the kScript fan-out's rule). The floor includes the large-print table's own
33
- * (`tradesBelowLargeFloor`: a dollar-quoted print under 10,000 notional, a CME Group print under
34
- * its root's contracts floor), so no print appears live that the next reconcile cannot answer. A
35
- * tape judged per aggressor order (`wrunTapePerOrder`: a CME Group venue under the per-order
36
- * switch) judges no single fill at the enqueue or the fold: its order gate
37
- * (live-trades-order-gate.util) holds the forming order of its raw prints and queues every fill of an
38
- * order at or above the acquisition's floor, the order the per-order reconcile answers, and turns an
39
- * order below it away whole, so the package adds a big order's fills back into one trade (a floor per
40
- * fill drew a 147-contract NQZ6 buy of 45 fills as its two 17-lot fills). A
41
- * print the queue cap drops leaves its bar short: the
42
- * drain marks the bucket for the reconcile (`tape-lost`) when the table can restore it, else the
43
- * tick refuses the bucket by name (`tapeLostBuckets`);
26
+ * worker share): one cell per TRADE_LARGE row, one order each, never a raw TRADE print (`ignored:other-channel`),
27
+ * each print in the host bar holding its instant where the chart's bars leave the tape's own grid
28
+ * (`wrunTapeHostBarResolver`, the cell placement its history gets);
29
+ * - a push lane the run asked on another market than the chart's (its acquisition names it: the run market, a US
30
+ * stock Trades chart's ticker on its consolidated tape, for the tape, trades and profile lanes) takes its rows from
31
+ * that market alone (`pinnedLaneMarketOf`), admitted at the fan-out and the enqueue; every other market's frame,
32
+ * the chart's included, is foreign to it. The session, the bar grid and the units stay the chart's: the folds key
33
+ * the chart's bars and a tape's floors read the chart's market (`wrunTapeLaneHostBarOf` places a print over both);
44
34
  * - a row lane fed live by COIN (`WrunRowLaneDescriptor.liveByCoin`, sources/row-lane-registry.ts): a
45
35
  * point of the frame's script source is admitted when its coin (the lane's `coinOf`, else the series'
46
36
  * coin) is the coin the instance was asked for (its acquisition's `coin`: the chart's underlying),
@@ -54,7 +44,10 @@
54
44
  * market's bar (`bookLiveBucketMs`: an exact bar boundary belongs to the
55
45
  * PREVIOUS bar, on the CME session lattice on a CME Group market); rows
56
46
  * marked `bucketed: true` (the heatmap rider's projection, keyed by the same
57
- * rule) are taken as-is;
47
+ * rule) are taken as-is; the fold then lands each keyed row on the host bar
48
+ * the chart's history puts it in (`wrunBookRowHostBarResolver`: a CME chart
49
+ * in RTH above 30m opens its bars on the 09:30 New York anchor, off the
50
+ * book's own hours), the latest snapshot per bar winning;
58
51
  * - a foreign GRID leg (a pinned market's rows at the chart interval, the
59
52
  * G4 round-3 contract): K_OHLCV.mergeLiveDataPoint over that market's
60
53
  * candle frames (`mergeLiveOhlcvDataPoint`: high/low widen, close
@@ -81,18 +74,20 @@ import { findMonday, getDecimalPlaces } from '../chart/titan-constants.pin.js';
81
74
  import { Intervals } from '../../constants/interval.constants.js';
82
75
  import { FUNDING_INTERVAL_MAP } from '../../constants/overlay-data.constants.js';
83
76
  import { mergeLiveOhlcvDataPoint } from '../../kscript-data/controls/live-ohlcv-merge.util.js';
84
- import { mergeLiveTradesDataPoint, readLiveTradePrint, tradesBarStartMs, tradesBelowLargeFloor, tradesLargeHistoryAnswers, tradesTapeCellSize, tradesTapeFloorValuesPrints, } from '../../kscript-data/controls/live-trades-merge.util.js';
77
+ import { liveTradeOfPoint, mergeLiveTradesDataPoint, readLiveTradePrint, tradesBarStartMs, tradesTapeCellSize, tradesTapeFloorValuesPrints, } from '../../kscript-data/controls/live-trades-merge.util.js';
85
78
  import { liveAmountUsd, peekOptionTradeUnits } from '../options/option-trade-units.util.js';
86
79
  import { parseWrunTapeHistory, wrunTapeHistoryOf } from './wrun-tape-source.util.js';
87
- import { wrunTapePerOrder } from './wrun-tape-per-order.util.js';
88
- import { TradesOrderGate } from '../../kscript-data/controls/live-trades-order-gate.util.js';
89
80
  import { wrunDollarUnitReader } from './wrun-dollar-unit-port.leaf.js';
90
81
  import { wrunChartHostEnv } from '../../host-env.js';
91
82
  import { v2LiveTradePrintBelowFloor } from '../chart/kscript-live-coalesce.util.js';
92
83
  import { bookLiveBucketMs, bookLiveBucketRows } from '../chart/book-live-bucket.util.js';
93
84
  import { liveFeedSeriesMatchesChartStream } from '../chart/live-feed-series-match.leaf.js';
85
+ import { KSCRIPT_CURRENT_EXCHANGE_SENTINEL, KSCRIPT_CURRENT_SYMBOL_SENTINEL, } from '../chart/kscript-live-source-identity.util.js';
94
86
  import { liveBucketStartMs, liveBucketVenueOf } from '../chart/live-bucket.util.js';
95
- import { hostBucketResolverFor } from '../chart/host-bar-placement.util.js';
87
+ import { hostBucketResolverFor, sourceRowHostBarResolverFor } from '../chart/host-bar-placement.util.js';
88
+ import { sourceRowsStraddleHostBars } from '../chart/index-host-tier.util.js';
89
+ import { wrunLaneServedOnMarket } from '../chart/index-mode-admission.util.js';
90
+ import { serverNowMs } from '../auth/server-clock.util.js';
96
91
  import { wrunRowLaneByKey } from './sources/row-lane-registry.js';
97
92
  import { wrunHostBarOf } from './wrun-tier-grid.util.js';
98
93
  import { barStartMs } from '../chart/calendar-interval.util.js';
@@ -102,9 +97,7 @@ import { getProfileBucketHeight, normalizeTicksPerBar } from '../../workers/util
102
97
  import { WRUN_RUN_INTERVAL_ROWS_KEY, wrunRunIntervalSessionOf, } from './wrun-run-interval-session.util.js';
103
98
  import { isWrunLegStreamClass } from './wrun-leg-stream-classes.js';
104
99
  import { isWrunTradesLegLane, wrunTradesLegOf, } from './wrun-trades-lane.util.js';
105
- /** The fan-out's script source name of a frame -> the lane it feeds. The `trades` SOURCE (K_TRADES,
106
- * the raw TRADE channel) feeds the `tape` lane; the `trades` LANE (the package's per-bar volume
107
- * by side) is fed by the `buy_sell_volume` source (K_BUY_SELL_VOLUME, TRADE_AGG). */
100
+ /** The `trades` SOURCE (K_TRADES) feeds the `tape` lane; the `trades` LANE is fed by `buy_sell_volume` (TRADE_AGG). */
108
101
  export const WRUN_LIVE_LANE_OF_SCRIPT_SOURCE = {
109
102
  ohlcv: 'ohlcv',
110
103
  buy_sell_volume: 'trades',
@@ -211,10 +204,8 @@ function intakeFor(indicatorId, chartIndex, intervalMs, generation) {
211
204
  function discardQueuesForGeneration(intake, generation) {
212
205
  const pending = pendingCount(intake);
213
206
  intake.additive = {};
214
- // The fresh full run's fetch holds the prints the cap dropped: nothing is owed for them, nor for an order still held.
207
+ // The fresh full run's fetch holds the prints the cap dropped: nothing is owed for them.
215
208
  intake.tapeLost = new Set();
216
- intake.tapeGate?.dispose();
217
- intake.tapeGate = undefined;
218
209
  intake.bookLive = new Map();
219
210
  intake.bookReplay = new Map();
220
211
  intake.funding = new Map();
@@ -642,6 +633,60 @@ export function foldWrunLegCandleRows(base, points, intervalMs, market) {
642
633
  function bookVenueOf(market) {
643
634
  return market ? { exchange: market.exchange, symbol: market.symbol } : null;
644
635
  }
636
+ /**
637
+ * The two grids a chart-own lane's live rows are placed between (`hostBar`, the chart's bars; `row`, the lane's own
638
+ * wire bars), or undefined where its history keeps the lane's own bars, so the fold keeps its key. The lane's ask
639
+ * leaves session-blind (`kScriptSourceRowVenue`'s rule for every K lane but K_OHLCV: the book, the tape), so its wire
640
+ * answers the full session's bars (the :00 hours, the Chicago lattice); titan-charts dataFetch lands that history in
641
+ * the chart's bars (STEP 4 and its packed book lane) exactly where those rows straddle the chart's bars
642
+ * (`sourceRowsStraddleHostBars`): a CME chart in RTH above 30m opens its bars on the 09:30 New York anchor (13:30Z
643
+ * hours in EDT). A lane the chart's fetch serves nothing on (`wrunLaneServedOnMarket`: a stock's or a forex market's
644
+ * book) has no history row to meet, and keeps its key too.
645
+ */
646
+ function wrunLaneHostGridsOf(type, intervalMs, market,
647
+ // The market the lane's rows come from (the run market: a Trades chart's tape) when it is not the chart's own.
648
+ rowMarket = market) {
649
+ if (!market || !rowMarket || !(intervalMs > 0))
650
+ return undefined;
651
+ if (!wrunLaneServedOnMarket({ type, exchange: rowMarket.exchange }))
652
+ return undefined;
653
+ const hostBar = liveBucketVenueOf(market);
654
+ const row = liveBucketVenueOf({ exchange: rowMarket.exchange, symbol: rowMarket.symbol, sessionType: 'extended' });
655
+ return sourceRowsStraddleHostBars(intervalMs, hostBar, intervalMs, row) ? { hostBar, row } : undefined;
656
+ }
657
+ /**
658
+ * The host bar a keyed book row lands on (`wrunLiveBookRows`' key: the snapshot's own bar, its row's open), judged
659
+ * at `nowMs`: the bar the chart's history puts that row in, through the live doors' resolver
660
+ * (`sourceRowHostBarResolverFor`: the bar holding the row's last instant once the chart printed it, before that the
661
+ * forming bar holding its open; none, null, for a row closing past the session's close). On ES1! in RTH at 1h a
662
+ * 14:10Z snapshot (the 14:00Z row) lands in the forming 13:30Z bar and a 15:05Z one (the 15:00Z row) in the 14:30Z
663
+ * bar. Undefined where the history keeps the book's own bars (`wrunLaneHostGridsOf`: 30m and finer, ETH, a day and
664
+ * longer, a 24/7 market, a market served no book): every key is its own bar.
665
+ */
666
+ export function wrunBookRowHostBarResolver(intervalMs, market) {
667
+ const grids = wrunLaneHostGridsOf('orderbook', intervalMs, market);
668
+ return grids && sourceRowHostBarResolverFor(intervalMs, grids.hostBar, intervalMs, grids.row);
669
+ }
670
+ /**
671
+ * The host bar a tape print lands in: the bar holding its own instant (the cell placement its history gets,
672
+ * `placeRowsInHostBars` with `cells`), null where no chart bar holds it. Undefined where the chart's bars are the
673
+ * tape's own (`wrunLaneHostGridsOf`): the print keeps the bar its own grid names (`tradesBarStartMs`).
674
+ */
675
+ export function wrunTapeHostBarResolver(intervalMs, market, rowMarket = market) {
676
+ const grids = wrunLaneHostGridsOf('trades', intervalMs, market, rowMarket);
677
+ return grids && hostBucketResolverFor(intervalMs, grids.hostBar);
678
+ }
679
+ /** The bar a tape print folds into (`wrunTapeHostBarResolver`'s host bar, else its own grid's): the fold, the queue's
680
+ * loss marks and the reconcile's drops key a print here, so they name one bar. Null: no chart bar holds it. */
681
+ function wrunTapePrintBarTs(print, intervalMs, hostBarOf) {
682
+ return hostBarOf === undefined ? tradesBarStartMs(print.tsMs, intervalMs, print.exchange) : hostBarOf(print.tsMs);
683
+ }
684
+ /** A copy of a book row stamped on `barTs` (the row handed in, a rider's included, is never written). */
685
+ function bookRowStampedOn(row, barTs) {
686
+ const copy = Float64Array.from(row);
687
+ copy[0] = barTs;
688
+ return copy;
689
+ }
645
690
  /** K_ORDERBOOK.buildLiveDataRows over a raw frame: replay bursts key
646
691
  * every row (copied), a live snapshot keys its one row (copied), each on
647
692
  * `market`'s bar (`bookLiveBucketMs`: the session lattice on a CME Group
@@ -674,9 +719,23 @@ function foldBook(base, points, intervalMs, market) {
674
719
  const replaced = new Map();
675
720
  const added = new Map();
676
721
  const touched = new Set();
722
+ // Each keyed row lands on the host bar the chart's history puts it in (judged now, once per fold), and a bar keeps
723
+ // the latest snapshot it holds: a row of an earlier key never replaces a later one there, a later point of the same
724
+ // key does (the replay-then-live order, a live snapshot of the bucket winning).
725
+ const barOf = wrunBookRowHostBarResolver(intervalMs, market);
726
+ const nowMs = barOf === undefined ? 0 : serverNowMs();
727
+ const keyOnBar = new Map();
677
728
  for (const point of points) {
678
- for (const row of wrunLiveBookRows(point, intervalMs, market)) {
679
- const bucket = Number(row[0]);
729
+ for (const keyed of wrunLiveBookRows(point, intervalMs, market)) {
730
+ const key = Number(keyed[0]);
731
+ const bucket = barOf === undefined ? key : barOf(key, nowMs);
732
+ // No chart bar holds the row (it closes past the session's close): nothing to fold.
733
+ if (bucket === null)
734
+ continue;
735
+ if ((keyOnBar.get(bucket) ?? Number.NEGATIVE_INFINITY) > key)
736
+ continue;
737
+ keyOnBar.set(bucket, key);
738
+ const row = bucket === key ? keyed : bookRowStampedOn(keyed, bucket);
680
739
  if (indexByTs.has(bucket))
681
740
  replaced.set(bucket, row);
682
741
  else
@@ -826,26 +885,30 @@ function foldVolumeProfile(base, points, intervalMs, acquisition, market) {
826
885
  return null;
827
886
  return foldResult(mergeLaneRows(base, replaced, added), touched);
828
887
  }
829
- /** The tape fold: K_TRADES's live fold per raw print (`mergeLiveTradesDataPoint`), each point onto
830
- * the rows as folded so far, under the acquisition's floor (`wrunTapeLiveFloorOf`: its `minSize`,
831
- * or its dollar `minValue`, where each cell's size is the print's dollar value). The leaf answers a
832
- * NEW container with the touched row new and every other row shared, or null for a rejected print
833
- * (the rows stand); the touched bucket is the newest row (a fold never writes behind it). A bucket
834
- * the fold capped (its newest 20k prints kept, the oldest dropped) is reported: its row is
835
- * truncated, and a block is never truncated, so the tick refuses it by name where the kScript lane
836
- * only warns. On the large lane the large-print table's floor applies too (`largeFloor`, the
837
- * chart's market for a frame that names none). */
838
- function foldTape(base, points, intervalMs, acquisition, market) {
888
+ /** Reports the buckets it capped: a block is never served truncated, so the tick refuses them by name. */
889
+ function foldTape(base, points, intervalMs, acquisition, market, rowMarket) {
839
890
  let rows = base;
840
891
  const touched = new Set();
841
892
  const capped = new Set();
842
- const largeFloor = acquisition.large === true ? largeFloorMarketOf(market ?? {}) : undefined;
843
893
  const floor = wrunTapeLiveFloorOf(acquisition, market);
894
+ const large = acquisition.large === true;
895
+ // A print lands in the host bar holding its instant where the chart's bars leave the tape's own grid.
896
+ const hostBarOf = wrunTapeHostBarResolver(intervalMs, market, rowMarket ?? market);
844
897
  for (const point of points) {
845
898
  let cappedNow = false;
899
+ let barTs;
900
+ if (hostBarOf !== undefined) {
901
+ const print = readLiveTradePrint(point, large);
902
+ const bar = print === null ? null : wrunTapePrintBarTs(print, intervalMs, hostBarOf);
903
+ // No print to fold (the fold reads none either), or no chart bar holding it: nothing to fold.
904
+ if (bar === null)
905
+ continue;
906
+ barTs = bar;
907
+ }
846
908
  const next = mergeLiveTradesDataPoint(rows, point, intervalMs, {
847
909
  ...floor,
848
- largeFloor,
910
+ large,
911
+ ...(barTs !== undefined ? { barTs } : {}),
849
912
  onCapped: () => {
850
913
  cappedNow = true;
851
914
  },
@@ -867,10 +930,15 @@ function foldTape(base, points, intervalMs, acquisition, market) {
867
930
  * touched buckets and the earliest of them, or null when nothing folded.
868
931
  * Never mutates `rows` or any point. `acquisition` is the SAME payload the
869
932
  * history fetch used for the lane, so the fold's units equal the lane's;
870
- * `market` is the market that fetch resolved to (the chart's own), so the
871
- * fold keys the bars its rows have (wrunLiveBucketTs).
933
+ * `market` is the market that fetch resolved to (the chart's own, with the
934
+ * chart's session), so the fold keys the bars its rows have (wrunLiveBucketTs),
935
+ * and lands the book and the tape on the chart's bars where their history is
936
+ * placed there (`wrunBookRowHostBarResolver`, judged at the server clock's now,
937
+ * and `wrunTapeHostBarResolver`).
872
938
  */
873
- export function foldWrunLaneRows(lane, rows, points, intervalMs, acquisition, market) {
939
+ export function foldWrunLaneRows(lane, rows, points, intervalMs, acquisition, market,
940
+ // The market the lane's rows come from when it is not the chart's (the tape lane's host bars read both).
941
+ rowMarket) {
874
942
  if (points.length === 0)
875
943
  return null;
876
944
  if (!Number.isFinite(intervalMs) || intervalMs <= 0)
@@ -892,7 +960,7 @@ export function foldWrunLaneRows(lane, rows, points, intervalMs, acquisition, ma
892
960
  return foldVolumeProfile(base, points, intervalMs, acquisition, market);
893
961
  case 'tape':
894
962
  // The print's own envelope names its venue (the CME lattice reads it), never the chart's.
895
- return foldTape(base, points, intervalMs, acquisition, market);
963
+ return foldTape(base, points, intervalMs, acquisition, market, rowMarket);
896
964
  default: {
897
965
  // A trades leg folds as its quote's own lane, on its market; the poll lanes have no live fold.
898
966
  const leg = wrunTradesLegOf(lane);
@@ -931,16 +999,38 @@ function isForeignFrame(context, frame) {
931
999
  return false;
932
1000
  return !liveFeedSeriesMatchesChartStream({ exchange: frame.incomingExchange, symbol: frame.incomingSymbol }, { ...market, ...context.market });
933
1001
  }
934
- /** The market the large-print floor judges a chart's tape prints on: its identity and, on an option
935
- * contract of a plain option venue, its registry trade units as answered (`peekOptionTradeUnits`;
936
- * the K_TRADES control starts the read with the acquisition), so the floor reads the premium the
937
- * resolver prices. Until the read answers, the units price nothing and no print passes the floor. */
938
- function largeFloorMarketOf(market) {
939
- const { exchange, symbol } = market;
1002
+ /** True when the frame carries a full series identity that is not `market`'s (the same alias-aware matcher). */
1003
+ function isForeignToMarket(market, frame) {
1004
+ if (!frame.incomingExchange || !frame.incomingSymbol)
1005
+ return false;
1006
+ return !liveFeedSeriesMatchesChartStream({ exchange: frame.incomingExchange, symbol: frame.incomingSymbol }, market);
1007
+ }
1008
+ /** The market a lane's acquisition names when it is not the chart's own (the run market: a Trades chart's tape). */
1009
+ function pinnedLaneMarketOf(context, lane) {
1010
+ const exchange = context.acquisition[lane]?.exchange;
1011
+ const symbol = context.acquisition[lane]?.symbol;
940
1012
  if (typeof exchange !== 'string' || typeof symbol !== 'string')
941
- return market;
942
- const optionUnits = peekOptionTradeUnits({ exchange, symbol });
943
- return optionUnits ? { ...market, optionUnits } : market;
1013
+ return undefined;
1014
+ if (exchange === KSCRIPT_CURRENT_EXCHANGE_SENTINEL || symbol === KSCRIPT_CURRENT_SYMBOL_SENTINEL)
1015
+ return undefined;
1016
+ const pinned = { exchange, symbol };
1017
+ const chart = chartMarketOf(context);
1018
+ return chart && liveFeedSeriesMatchesChartStream(pinned, { ...chart, ...context.market }) ? undefined : pinned;
1019
+ }
1020
+ /** Every market a push lane's acquisition names beside the chart's own, once each (the fan-out admits their frames). */
1021
+ function pinnedLaneMarketsOf(context) {
1022
+ const markets = new Map();
1023
+ for (const lane of WRUN_PUSH_LANES) {
1024
+ const pinned = pinnedLaneMarketOf(context, lane);
1025
+ if (pinned)
1026
+ markets.set(`${pinned.exchange}|${pinned.symbol}`, pinned);
1027
+ }
1028
+ return [...markets.values()];
1029
+ }
1030
+ /** The host bar a tape print lands in: the chart's bars (its session and grid) over the rows of the lane's market. */
1031
+ function wrunTapeLaneHostBarOf(context, intervalMs) {
1032
+ const chart = chartMarketOf(context);
1033
+ return wrunTapeHostBarResolver(intervalMs, chart, pinnedLaneMarketOf(context, 'tape') ?? chart);
944
1034
  }
945
1035
  /** The market facts' dollar unit reader through its port (wrun-dollar-unit-port.leaf): live-feed loads this module
946
1036
  * before the first candle, and the facts module stays out of that closure. A dollar tape's full run loads the facts
@@ -975,19 +1065,16 @@ function wrunTapeLiveValuePerUnit(market) {
975
1065
  * market's `valuePerUnit` the full run priced (C-DOLLAR), else the one the market facts prove now
976
1066
  * (`wrunTapeLiveValuePerUnit`: never a transient unknown frozen for the session) and, on an option contract of a
977
1067
  * plain option venue, the registry trade units as answered (a dollar floor values an option print by its USD
978
- * premium). On a tape whose live prints arrive judged per aggressor order (`wrunTapePerOrder`, the chart market's
979
- * venue: the tape's frames are its market's) the floor is marked `perOrder`: the shared rules then judge no fill by
980
- * it, nor by the large-print table's floor. */
1068
+ * premium). */
981
1069
  function wrunTapeLiveFloorOf(acquisition, market) {
982
- const perOrder = wrunTapePerOrder(market?.exchange) ? { perOrder: true } : {};
983
- const floor = { minSize: acquisition?.minSize, ...perOrder };
1070
+ const floor = { minSize: acquisition?.minSize };
984
1071
  if (acquisition?.minValue === undefined)
985
1072
  return floor;
986
1073
  const { exchange, symbol } = market ?? {};
987
1074
  const optionUnits = typeof exchange === 'string' && typeof symbol === 'string' ? peekOptionTradeUnits({ exchange, symbol }) : null;
988
1075
  const frozen = Number(acquisition.valuePerUnit);
989
1076
  const valuePerUnit = Number.isFinite(frozen) && frozen > 0 ? frozen : optionUnits ? undefined : wrunTapeLiveValuePerUnit(market);
990
- const priced = { minValue: acquisition.minValue, valuePerUnit, ...perOrder };
1077
+ const priced = { minValue: acquisition.minValue, valuePerUnit };
991
1078
  return optionUnits ? { ...priced, optionUnits } : priced;
992
1079
  }
993
1080
  /** The dollar tapes the intake recorded as unable to value a live print (no `valuePerUnit` yet), by overlay, so the
@@ -1017,7 +1104,7 @@ function noteWrunTapeUnvalued(indicatorId, context) {
1017
1104
  }
1018
1105
  /** A live print a dollar tape could not value (its unit not proven yet): it never folds, and its bar is owed the
1019
1106
  * print, exactly like a print the queue cap dropped (`pushAdditive`): the drain has the reconcile restore the bar
1020
- * from the large-print table where it holds the market (`tape-lost`), else the tick refuses the bar by name
1107
+ * from the large-print table on a tape with a history (`tape-lost`), else the tick refuses the bar by name
1021
1108
  * (`tapeLostBuckets`). A unit that no read can ever prove by now (a later answer: no point value, a quote that is no
1022
1109
  * dollar) values no print of the session again, so its bar is refused by name at once, never re-asked on every drain
1023
1110
  * (the Resume's full run then refuses the tape by name, `wrun_tape_value_unproven`). A block is never served short
@@ -1028,8 +1115,11 @@ function wrunTapePrintUnvalued(intake, context, intervalMs, data) {
1028
1115
  const print = readLiveTradePrint(data);
1029
1116
  if (print === null)
1030
1117
  return;
1031
- const bucket = tradesBarStartMs(print.tsMs, intervalMs, print.exchange);
1032
- const market = context.market;
1118
+ const market = chartMarketOf(context);
1119
+ const bucket = wrunTapePrintBarTs(print, intervalMs, wrunTapeLaneHostBarOf(context, intervalMs));
1120
+ // No chart bar holds the print: no bar is owed it.
1121
+ if (bucket === null)
1122
+ return;
1033
1123
  const unit = typeof market?.exchange === 'string' && typeof market.symbol === 'string'
1034
1124
  ? wrunLiveDollarUnitReader()?.unit(market)
1035
1125
  : undefined;
@@ -1038,45 +1128,7 @@ function wrunTapePrintUnvalued(intake, context, intervalMs, data) {
1038
1128
  else
1039
1129
  intake.tapeLost.add(bucket);
1040
1130
  }
1041
- /** A per-order tape's order gate (live-trades-order-gate.util), made on the tape's first held print: an order at or
1042
- * above the acquisition's floor queues every fill and wakes the drain (the hold timer judges an order with no frame
1043
- * to arm one); an order below it is turned away whole, each fill counted `ignored:below-floor`. A gate whose intake
1044
- * is gone (a teardown, a reset) queues nothing. */
1045
- function wrunTapeOrderGateOf(intake, indicatorId) {
1046
- if (intake.tapeGate !== undefined)
1047
- return intake.tapeGate;
1048
- const gate = new TradesOrderGate({
1049
- admit: (points) => {
1050
- if (intakes.get(indicatorId) !== intake || intake.tapeGate !== gate)
1051
- return;
1052
- for (const point of points)
1053
- pushAdditive(intake, 'tape', point);
1054
- drainRequester?.(indicatorId);
1055
- },
1056
- drop: (points) => {
1057
- const ignored = intake.stats.ignored;
1058
- ignored['ignored:below-floor'] = (ignored['ignored:below-floor'] ?? 0) + points.length;
1059
- },
1060
- });
1061
- intake.tapeGate = gate;
1062
- return gate;
1063
- }
1064
- /** The large-print table's floor at the tape enqueue (the fold applies it again): on the large
1065
- * lane, a print under the table's floor (`tradesBelowLargeFloor`: a dollar-quoted market's notional,
1066
- * a CME Group root's contracts, an option book's premium; the frame's envelope names the market,
1067
- * else the chart's). */
1068
- function wrunTapePrintBelowLargeFloor(context, data) {
1069
- if (context.acquisition.tape?.large !== true)
1070
- return false;
1071
- const print = readLiveTradePrint(data);
1072
- return (print !== null && tradesBelowLargeFloor(print, context.market ? largeFloorMarketOf(context.market) : undefined));
1073
- }
1074
- /** Whether a reconcile can restore the tape prints the queue cap dropped: the large lane with a
1075
- * history to re-ask (not the live edge, history "0") on a market the re-ask answers under the
1076
- * acquisition's floor (`tradesLargeHistoryAnswers`, the lane rule `tradesLaneLimits` the request
1077
- * builder reads: the table on a dollar quote, the raw tape on a CME Group root the table skips under
1078
- * a size floor and never under a dollar floor, which that lane serves no history to; a context that
1079
- * names no normalized symbol is assumed held). */
1131
+ /** Every live row is also in the large-print table, so any large tape with a history can restore dropped rows. */
1080
1132
  function wrunTapeLostRestorable(context) {
1081
1133
  const acquisition = context.acquisition.tape;
1082
1134
  if (acquisition?.large !== true)
@@ -1089,21 +1141,25 @@ function wrunTapeLostRestorable(context) {
1089
1141
  catch {
1090
1142
  // The full run validated the history; a malformed record reads as the live edge.
1091
1143
  }
1092
- return historySec > 0 && tradesLargeHistoryAnswers(context.market ?? {}, { minValue: acquisition.minValue });
1144
+ return historySec > 0;
1093
1145
  }
1094
- function pushAdditive(intake, lane, point) {
1146
+ function pushAdditive(intake, lane, point, tapeContext) {
1095
1147
  let queue = intake.additive[lane];
1096
1148
  if (!queue) {
1097
1149
  queue = { points: [], head: 0 };
1098
1150
  intake.additive[lane] = queue;
1099
1151
  }
1100
1152
  const dropped = pushBoundedQueue(intake, queue, point);
1101
- // A tape print the cap dropped leaves its bar's block a print short: its bucket is owed a repair
1102
- // (the drain marks it for the reconcile, or the tick refuses it by name).
1153
+ // A tape print the cap dropped leaves its bar's block a print short: its bucket (the bar the fold keys it on,
1154
+ // `wrunTapePrintBarTs` over the lane's market) is owed a repair (the drain marks it for the reconcile, or the tick
1155
+ // refuses it by name).
1103
1156
  if (lane === 'tape' && dropped !== undefined && intake.intervalMs > 0) {
1104
1157
  const print = readLiveTradePrint(dropped);
1105
- if (print !== null)
1106
- intake.tapeLost.add(tradesBarStartMs(print.tsMs, intake.intervalMs, print.exchange));
1158
+ const bucket = print === null
1159
+ ? null
1160
+ : wrunTapePrintBarTs(print, intake.intervalMs, tapeContext && wrunTapeLaneHostBarOf(tapeContext, intake.intervalMs));
1161
+ if (bucket !== null)
1162
+ intake.tapeLost.add(bucket);
1107
1163
  }
1108
1164
  }
1109
1165
  function pushLegPoint(intake, fetchKey, point) {
@@ -1239,6 +1295,8 @@ export function wrunLiveFrameMarketAdmitted(indicatorId, series) {
1239
1295
  incomingSymbol: series.symbol,
1240
1296
  };
1241
1297
  return (!isForeignFrame(context, frame) ||
1298
+ // A lane the run asked on another market (the run market) takes that market's frames (the enqueue judges the lane).
1299
+ pinnedLaneMarketsOf(context).some((pinned) => !isForeignToMarket(pinned, frame)) ||
1242
1300
  gridLegKeysForFrame(context, frame).length > 0 ||
1243
1301
  tradesLegLanesForFrame(context, frame).length > 0 ||
1244
1302
  // A row lane fed by coin takes every contract of its coin (a coin-scoped channel), foreign or not.
@@ -1323,7 +1381,14 @@ export function enqueueWrunLiveFrame(a) {
1323
1381
  return 'queued';
1324
1382
  }
1325
1383
  const lane = WRUN_LIVE_LANE_OF_SCRIPT_SOURCE[a.frame.scriptSource];
1326
- const foreign = isForeignFrame(context, a.frame);
1384
+ // Each push lane takes the frames of the market its acquisition names (the run market), else the chart's own.
1385
+ const candidates = lane !== undefined && lane !== 'ohlcv' && WRUN_PUSH_LANES.has(lane) ? frameLanesOf(context, lane) : [];
1386
+ const takers = candidates.filter((fedLane) => {
1387
+ const pinned = pinnedLaneMarketOf(context, fedLane);
1388
+ return pinned ? !isForeignToMarket(pinned, a.frame) : !isForeignFrame(context, a.frame);
1389
+ });
1390
+ // A frame no lane could take is judged against the chart's market, as before.
1391
+ const foreign = candidates.length > 0 ? takers.length === 0 : isForeignFrame(context, a.frame);
1327
1392
  // A candle frame of a declared grid leg's market is that leg's (a pinned
1328
1393
  // market's feed, subscribed for it): admitted by the leg, never by the
1329
1394
  // chart. Every other foreign frame is refused.
@@ -1357,9 +1422,7 @@ export function enqueueWrunLiveFrame(a) {
1357
1422
  }
1358
1423
  if (!context.pushEligible)
1359
1424
  return noteVerdict(a.indicatorId, 'ignored:ineligible', context);
1360
- const fed = WRUN_PUSH_LANES.has(lane)
1361
- ? [...(foreign ? [] : frameLanesOf(context, lane)), ...tradeLegs]
1362
- : [];
1425
+ const fed = WRUN_PUSH_LANES.has(lane) ? [...takers, ...tradeLegs] : [];
1363
1426
  if (fed.length === 0)
1364
1427
  return noteVerdict(a.indicatorId, 'ignored:undeclared', context);
1365
1428
  const intervalMs = context.intervalMs;
@@ -1389,20 +1452,15 @@ export function enqueueWrunLiveFrame(a) {
1389
1452
  intake.funding.set(bucket, a.frame.data);
1390
1453
  }
1391
1454
  else if (lane === 'tape') {
1392
- // Every raw print that reaches the lane is a tape frame, the ones the floors turn away included:
1393
- // the count is the live leg's own signal, and a floor that turns most of a busy tape away (a 1
1394
- // BTC floor on a perp) must never read as a dead feed. `ignored:below-floor` counts the turned
1395
- // away ones, `queued` what remains.
1455
+ // The router hands every trades source both channels: a print of the other one never counts or takes a slot.
1456
+ const large = context.acquisition.tape?.large === true;
1457
+ if (liveTradeOfPoint(a.frame.data, large) === undefined && liveTradeOfPoint(a.frame.data, !large) !== undefined) {
1458
+ return noteVerdict(a.indicatorId, 'ignored:other-channel', context);
1459
+ }
1460
+ // Counts rows the floor turns away too: a floor that drops most of a busy tape must not read as a dead feed.
1396
1461
  intake.stats.frames.tape = (intake.stats.frames.tape ?? 0) + 1;
1397
- // The tape's own floor (`tradesTapeCellSize`, the rule the fold applies again): a print below the
1398
- // acquisition's minSize, or one whose dollar value is below its minValue, can never fold, so it
1399
- // never takes a slot a qualifying print needs in the capped queue. A dollar tape that cannot value
1400
- // a print at all (C-DOLLAR: no proven dollar unit) folds none, recorded once by name. The
1401
- // large-print table's own floor too: a print under it (a dollar-quoted market's notional, a CME
1402
- // Group root's contracts) would fold live and vanish when the next reconcile answers the bucket
1403
- // from the table. A per-order tape (`floor.perOrder`) judges neither on one fill: its order gate does
1404
- // (below), and the per-order reconcile answers every fill of an order the gate admits.
1405
- const floor = wrunTapeLiveFloorOf(context.acquisition.tape, context.market);
1462
+ // Floors at the door as the fold does, so a row that can never fold never crowds a qualifying one out of the queue.
1463
+ const floor = wrunTapeLiveFloorOf(context.acquisition.tape, chartMarketOf(context));
1406
1464
  if (!tradesTapeFloorValuesPrints(floor)) {
1407
1465
  noteWrunTapeUnvalued(a.indicatorId, context);
1408
1466
  wrunTapePrintUnvalued(intake, context, intervalMs, a.frame.data);
@@ -1410,22 +1468,15 @@ export function enqueueWrunLiveFrame(a) {
1410
1468
  }
1411
1469
  // A frame the fold cannot read as a print (no side, a bad stamp) is judged by its raw amount under a
1412
1470
  // size floor, as it always was, and never folds under a dollar floor.
1413
- const print = readLiveTradePrint(a.frame.data);
1414
- // A per-order tape's print joins the forming order (the order gate, live-trades-order-gate.util): it takes a queue
1415
- // slot only with every fill of an order at or above the floor, judged when the order ends or its hold runs out.
1416
- if (floor.perOrder === true && print !== null) {
1417
- wrunTapeOrderGateOf(intake, a.indicatorId).push(a.frame.data, print, floor);
1418
- return 'held';
1419
- }
1471
+ const print = readLiveTradePrint(a.frame.data, large);
1420
1472
  const minSize = Number(floor.minSize);
1421
1473
  const belowTapeFloor = print === null
1422
1474
  ? floor.minValue !== undefined ||
1423
1475
  v2LiveTradePrintBelowFloor(a.frame.data, Number.isFinite(minSize) ? minSize : 0)
1424
1476
  : tradesTapeCellSize(print, floor) === null;
1425
- if (belowTapeFloor || (floor.perOrder !== true && wrunTapePrintBelowLargeFloor(context, a.frame.data))) {
1477
+ if (belowTapeFloor)
1426
1478
  return noteVerdict(a.indicatorId, 'ignored:below-floor', context);
1427
- }
1428
- pushAdditive(intake, 'tape', a.frame.data);
1479
+ pushAdditive(intake, 'tape', a.frame.data, context);
1429
1480
  return 'queued';
1430
1481
  }
1431
1482
  else {
@@ -1561,13 +1612,15 @@ export function drainWrunLiveIntake(ctx) {
1561
1612
  intake.funding = new Map();
1562
1613
  }
1563
1614
  let dirtyFromTs = null;
1564
- // Every lane fetched the chart's own market; a grid leg its own.
1615
+ // Every lane folds on the chart's own bars (a grid leg on its own), its rows from its acquisition's market.
1565
1616
  const chartMarket = chartMarketOf(ctx);
1566
1617
  for (const [lane, points] of batches) {
1567
1618
  // A trades leg folds on its own grid at its own tier (the interval its history was asked at), as its history
1568
1619
  // rows sit; every other lane at the chart's interval.
1569
1620
  const foldIntervalMs = laneFoldIntervalMs(ctx, lane, ctx.intervalMs);
1570
- const folded = foldWrunLaneRows(lane, laneRowsOf(ctx, lane), points, foldIntervalMs, ctx.acquisition[lane] ?? {}, isWrunTradesLegLane(lane) ? tradesLegBucketMarket(ctx, lane) : chartMarket);
1621
+ const folded = foldWrunLaneRows(lane, laneRowsOf(ctx, lane), points, foldIntervalMs, ctx.acquisition[lane] ?? {}, isWrunTradesLegLane(lane) ? tradesLegBucketMarket(ctx, lane) : chartMarket,
1622
+ // The lane's rows came from the run market: the tape's host bars read it over the chart's bars.
1623
+ pinnedLaneMarketOf(ctx, lane) ?? chartMarket);
1571
1624
  result.points[lane] = points.length;
1572
1625
  if (!folded)
1573
1626
  continue;
@@ -1593,11 +1646,7 @@ export function drainWrunLiveIntake(ctx) {
1593
1646
  }
1594
1647
  }
1595
1648
  if (intake.tapeLost.size > 0) {
1596
- // Tape prints the queue cap dropped: their bars' blocks are short. When the large-print table
1597
- // holds what the live floors keep, the buckets stay fed (the reconcile window reaches back to
1598
- // them) and `tape-lost` re-asks them before this drain computes: the answer's union restores
1599
- // the prints. A live-edge tape (history "0") or a market the table never holds has nothing to
1600
- // restore them from: the tick refuses the bucket by name instead (`tapeLostBuckets`).
1649
+ // Dropped rows leave their bars short: re-asked (`tape-lost`) before this drain computes, else refused by name.
1601
1650
  const lost = [...intake.tapeLost].sort((x, y) => x - y);
1602
1651
  intake.tapeLost = new Set();
1603
1652
  result.tapeLost = lost;
@@ -1648,8 +1697,10 @@ export function drainWrunLiveIntake(ctx) {
1648
1697
  // when that bar is committed, from that bar. A row no chart bar holds (off the chart's session) revises none.
1649
1698
  const legMs = legRecord?.tierMs ?? legRecord?.legMs ?? ctx.intervalMs;
1650
1699
  const barOf = hostBucketResolverFor(ctx.intervalMs, liveBucketVenueOf(ctx.market));
1700
+ // The leg's own grid: a session's stub row lasts to its close (wrunLegRowHostBar's `rowVenue`).
1701
+ const legVenue = legMarketOfKey(ctx, key);
1651
1702
  for (const bucket of folded.touched) {
1652
- const bar = wrunLegRowHostBar(bucket, legMs, barOf);
1703
+ const bar = wrunLegRowHostBar(bucket, legMs, barOf, legVenue);
1653
1704
  if (bar !== null && bar < ctx.lastRowTs && (dirtyFromTs === null || bar < dirtyFromTs))
1654
1705
  dirtyFromTs = bar;
1655
1706
  }
@@ -1793,11 +1844,26 @@ export function dropWrunLiveQueuedBuckets(indicatorId, lane, buckets) {
1793
1844
  const drop = new Set(buckets);
1794
1845
  let dropped = 0;
1795
1846
  if (lane === 'book') {
1796
- for (const bucket of drop) {
1797
- if (intake.bookLive.delete(bucket))
1798
- dropped += 1;
1799
- if (intake.bookReplay.delete(bucket))
1800
- dropped += 1;
1847
+ // A queued row is keyed on its own bar and folds onto the host bar the chart's history puts it in
1848
+ // (`wrunBookRowHostBarResolver`), the bar an answer names: the row a covered bar would take is dropped.
1849
+ const bookContext = getWrunOverlayLiveContext(indicatorId);
1850
+ const barOf = bookContext ? wrunBookRowHostBarResolver(intake.intervalMs, chartMarketOf(bookContext)) : undefined;
1851
+ if (barOf === undefined) {
1852
+ for (const bucket of drop) {
1853
+ if (intake.bookLive.delete(bucket))
1854
+ dropped += 1;
1855
+ if (intake.bookReplay.delete(bucket))
1856
+ dropped += 1;
1857
+ }
1858
+ return dropped;
1859
+ }
1860
+ const nowMs = serverNowMs();
1861
+ for (const slot of [intake.bookLive, intake.bookReplay]) {
1862
+ for (const key of [...slot.keys()]) {
1863
+ const bar = barOf(key, nowMs);
1864
+ if (bar !== null && drop.has(bar) && slot.delete(key))
1865
+ dropped += 1;
1866
+ }
1801
1867
  }
1802
1868
  return dropped;
1803
1869
  }
@@ -1850,11 +1916,12 @@ export function dropWrunLiveQueuedBuckets(indicatorId, lane, buckets) {
1850
1916
  const market = context ? (leg ? tradesLegBucketMarket(context, lane) : chartMarketOf(context)) : null;
1851
1917
  const bucketLane = leg ? wrunTradesLegOf(lane).lane : lane;
1852
1918
  const bucketIntervalMs = context ? laneFoldIntervalMs(context, lane, intake.intervalMs) : intake.intervalMs;
1919
+ const tapeHostBarOf = lane === 'tape' && context ? wrunTapeLaneHostBarOf(context, intake.intervalMs) : undefined;
1853
1920
  const bucketOf = (point) => {
1854
1921
  if (lane === 'tape') {
1855
- // A raw print's stamp and venue as the tape fold reads them (seconds plus nanoseconds).
1922
+ // A print's stamp and venue as the tape fold reads them (seconds plus nanoseconds), on the bar the fold keys.
1856
1923
  const print = readLiveTradePrint(point);
1857
- return print === null ? null : tradesBarStartMs(print.tsMs, intake.intervalMs, print.exchange);
1924
+ return print === null ? null : wrunTapePrintBarTs(print, intake.intervalMs, tapeHostBarOf);
1858
1925
  }
1859
1926
  if (!isRecord(point))
1860
1927
  return null;
@@ -1934,7 +2001,6 @@ export function takeWrunLiveGaps(indicatorId) {
1934
2001
  /** Queues, gaps and stats of one overlay: registered on the drivers'
1935
2002
  * teardown hook at import time. */
1936
2003
  export function disposeWrunLiveIntake(indicatorId) {
1937
- intakes.get(indicatorId)?.tapeGate?.dispose();
1938
2004
  intakes.delete(indicatorId);
1939
2005
  wrunTapeUnvaluedNoted.delete(indicatorId);
1940
2006
  }
@@ -2176,8 +2242,6 @@ export function wrunLiveContextSnapshot(indicatorId) {
2176
2242
  };
2177
2243
  }
2178
2244
  export function __resetWrunLiveIntakeForTests() {
2179
- for (const intake of intakes.values())
2180
- intake.tapeGate?.dispose();
2181
2245
  intakes.clear();
2182
2246
  wrunTapeUnvaluedNoted.clear();
2183
2247
  drainRequester = null;