@orangecharts/wrun-chart-host 0.9.0 → 0.10.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.
- package/README.md +1 -0
- package/dist/constants/feature-flags.constants.d.ts +6 -1
- package/dist/constants/feature-flags.constants.js +67 -24
- package/dist/constants/opra-compliance.constants.d.ts +3 -2
- package/dist/constants/opra-compliance.constants.js +3 -2
- package/dist/constants/scriptEditor/builtin-script-snippets.d.ts +26 -0
- package/dist/constants/scriptEditor/builtin-script-snippets.js +6 -0
- package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +15 -0
- package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +17 -0
- package/dist/constants/venue-presets.constants.d.ts +20 -20
- package/dist/constants/venue-presets.constants.js +24 -26
- package/dist/host-env.d.ts +29 -5
- package/dist/host-env.js +6 -0
- package/dist/host-ports.types.d.ts +69 -15
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/interfaces/kscript-diagnostics.interface.d.ts +6 -0
- package/dist/interfaces/replay.interface.d.ts +8 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +18 -2
- package/dist/kscript-data/controls/live-trades-merge.util.d.ts +41 -4
- package/dist/kscript-data/controls/live-trades-merge.util.js +52 -7
- package/dist/kscript-data/controls/live-trades-order-gate.util.d.ts +56 -0
- package/dist/kscript-data/controls/live-trades-order-gate.util.js +107 -0
- package/dist/market-data/billing.interface.d.ts +95 -31
- package/dist/market-data/billing.interface.js +36 -5
- package/dist/market-data/venue.d.ts +88 -6
- package/dist/market-data/venues/cme.contract.copy.json +66 -0
- package/dist/market-data/venues/cme.d.ts +126 -0
- package/dist/market-data/venues/cme.js +133 -0
- package/dist/market-data/venues/index.d.ts +162 -5
- package/dist/market-data/venues/index.js +48 -6
- package/dist/settings-templates/index.js +7 -3
- package/dist/settings-templates/indicator-fields.d.ts +5 -4
- package/dist/settings-templates/indicator-fields.js +45 -6
- package/dist/settings-templates/tool-rules.d.ts +27 -17
- package/dist/settings-templates/tool-rules.js +27 -11
- package/dist/settings-templates/tool-tables.generated.js +91 -31
- package/dist/utility/chart/book-live-bucket.util.d.ts +15 -0
- package/dist/utility/chart/book-live-bucket.util.js +47 -0
- package/dist/utility/chart/index-mode-admission.util.js +15 -2
- package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +35 -11
- package/dist/utility/chart/kscript-drawing-safe-area.util.js +145 -35
- package/dist/utility/chart/kscript-live-coalesce.util.d.ts +7 -2
- package/dist/utility/chart/kscript-live-coalesce.util.js +9 -3
- package/dist/utility/chart/kscript-provenance-keys.util.js +6 -0
- package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +3 -1
- package/dist/utility/chart/kscript-titancharts-render-keys.constants.d.ts +32 -2
- package/dist/utility/chart/kscript-titancharts-render-keys.constants.js +45 -0
- package/dist/utility/chart/kscript-venue-policy.util.d.ts +54 -35
- package/dist/utility/chart/kscript-venue-policy.util.js +78 -42
- package/dist/utility/chart/market-session-schedule.util.d.ts +10 -0
- package/dist/utility/chart/market-session-schedule.util.js +16 -0
- package/dist/utility/chart/opra-read-access.leaf.d.ts +5 -3
- package/dist/utility/chart/opra-read-access.leaf.js +5 -3
- package/dist/utility/chart/rth-session.util.d.ts +3 -2
- package/dist/utility/chart/rth-session.util.js +2 -1
- package/dist/utility/chart/window-geometry.leaf.d.ts +8 -0
- package/dist/utility/chart/window-geometry.leaf.js +22 -6
- package/dist/utility/chart/wrun-run-result.util.d.ts +12 -0
- package/dist/utility/chart/wrun-run-result.util.js +141 -6
- package/dist/utility/options/option-bar-anchor.util.d.ts +145 -0
- package/dist/utility/options/option-bar-anchor.util.js +340 -0
- package/dist/utility/options/option-venue.util.d.ts +18 -0
- package/dist/utility/options/option-venue.util.js +27 -0
- package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +2 -0
- package/dist/utility/wrun/derived-roots.util.d.ts +213 -0
- package/dist/utility/wrun/derived-roots.util.js +471 -0
- package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +41 -6
- package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +89 -19
- package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +9 -4
- package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +47 -6
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +4 -2
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +4 -2
- package/dist/utility/wrun/sources/lanes/option_daily.js +5 -2
- package/dist/utility/wrun/sources/lanes/options_flow.js +5 -2
- package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +64 -19
- package/dist/utility/wrun/sources/opra-option-lanes.util.js +105 -35
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +2 -1
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +2 -1
- package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +3 -0
- package/dist/utility/wrun/sources/row-lanes/option_prints.js +19 -4
- package/dist/utility/wrun/sources/row-lanes/option_strike_flow.js +17 -4
- package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +52 -13
- package/dist/utility/wrun/sources/row-lanes/option_strikes.js +88 -19
- package/dist/utility/wrun/sources/row-lanes/option_surface.js +2 -1
- package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +19 -0
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +24 -9
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +39 -10
- package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.d.ts +64 -0
- package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.js +89 -0
- package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +15 -3
- package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +22 -3
- package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +31 -0
- package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +174 -13
- package/dist/utility/wrun/sources/wrun-row-lanes.util.js +685 -27
- package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +12 -0
- package/dist/utility/wrun/wrun-builtin-twin.util.js +21 -0
- package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +53 -12
- package/dist/utility/wrun/wrun-chart-market-facts.util.js +101 -53
- package/dist/utility/wrun/wrun-download-meter.util.d.ts +15 -0
- package/dist/utility/wrun/wrun-download-meter.util.js +14 -2
- package/dist/utility/wrun/wrun-download-plan.util.d.ts +99 -0
- package/dist/utility/wrun/wrun-download-plan.util.js +118 -0
- package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +11 -3
- package/dist/utility/wrun/wrun-draft-legend-note.util.js +26 -4
- package/dist/utility/wrun/wrun-frames.d.ts +27 -6
- package/dist/utility/wrun/wrun-frames.js +73 -10
- package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +7 -1
- package/dist/utility/wrun/wrun-hosted-wire.util.js +12 -2
- package/dist/utility/wrun/wrun-hud-looks.util.d.ts +18 -4
- package/dist/utility/wrun/wrun-hud-looks.util.js +45 -13
- package/dist/utility/wrun/wrun-latest-snapshot.d.ts +11 -0
- package/dist/utility/wrun/wrun-live-intake.util.d.ts +13 -7
- package/dist/utility/wrun/wrun-live-intake.util.js +82 -29
- package/dist/utility/wrun/wrun-live-tick.util.d.ts +4 -0
- package/dist/utility/wrun/wrun-live-tick.util.js +158 -14
- package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +49 -10
- package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +65 -5
- package/dist/utility/wrun/wrun-market-size-defaults.util.js +31 -5
- package/dist/utility/wrun/wrun-opra-lane.util.d.ts +17 -4
- package/dist/utility/wrun/wrun-opra-lane.util.js +6 -4
- package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.d.ts +31 -0
- package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.js +119 -0
- package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +23 -6
- package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +47 -11
- package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +86 -19
- package/dist/utility/wrun/wrun-option-strike-flow.util.js +168 -62
- package/dist/utility/wrun/wrun-option-views.util.d.ts +47 -13
- package/dist/utility/wrun/wrun-option-views.util.js +98 -26
- package/dist/utility/wrun/wrun-output-style.util.d.ts +6 -2
- package/dist/utility/wrun/wrun-output-style.util.js +20 -2
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +17 -0
- package/dist/utility/wrun/wrun-overlay-lifecycle.util.d.ts +10 -1
- package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +52 -4
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +100 -31
- package/dist/utility/wrun/wrun-overlay-run.util.js +733 -114
- package/dist/utility/wrun/wrun-pane-format.util.d.ts +2 -1
- package/dist/utility/wrun/wrun-pane-format.util.js +7 -3
- package/dist/utility/wrun/wrun-panel-mount.util.d.ts +9 -0
- package/dist/utility/wrun/wrun-panel-mount.util.js +63 -13
- package/dist/utility/wrun/wrun-panel-style.util.d.ts +10 -9
- package/dist/utility/wrun/wrun-panel-style.util.js +58 -9
- package/dist/utility/wrun/wrun-param-map.util.d.ts +14 -11
- package/dist/utility/wrun/wrun-param-map.util.js +10 -5
- package/dist/utility/wrun/wrun-param-values.util.d.ts +14 -4
- package/dist/utility/wrun/wrun-param-values.util.js +4 -0
- package/dist/utility/wrun/wrun-pin-spelling.util.js +12 -11
- package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +50 -0
- package/dist/utility/wrun/wrun-refusal-surface.util.js +68 -0
- package/dist/utility/wrun/wrun-refused-latest.util.d.ts +10 -0
- package/dist/utility/wrun/wrun-refused-latest.util.js +12 -0
- package/dist/utility/wrun/wrun-row-source.d.ts +11 -0
- package/dist/utility/wrun/wrun-run-interval.util.d.ts +4 -2
- package/dist/utility/wrun/wrun-run-interval.util.js +9 -6
- package/dist/utility/wrun/wrun-script-inputs.util.d.ts +45 -1
- package/dist/utility/wrun/wrun-script-inputs.util.js +112 -4
- package/dist/utility/wrun/wrun-setting-words.util.d.ts +7 -3
- package/dist/utility/wrun/wrun-setting-words.util.js +13 -5
- package/dist/utility/wrun/wrun-socket-row-source.d.ts +27 -2
- package/dist/utility/wrun/wrun-socket-row-source.js +113 -8
- package/dist/utility/wrun/wrun-source-rows.util.d.ts +5 -1
- package/dist/utility/wrun/wrun-source-rows.util.js +16 -3
- package/dist/utility/wrun/wrun-style-words.util.js +6 -4
- package/dist/utility/wrun/wrun-table-chrome.util.d.ts +3 -2
- package/dist/utility/wrun/wrun-table-chrome.util.js +19 -11
- package/dist/utility/wrun/wrun-tape-per-order.util.d.ts +2 -0
- package/dist/utility/wrun/wrun-tape-per-order.util.js +26 -0
- package/dist/utils/replay/replay-buffer-math.d.ts +53 -2
- package/dist/utils/replay/replay-buffer-math.js +227 -20
- package/package.json +11 -11
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { kScriptSourceAnswerRows } from '../../chart/kscript-source-answer-budget.leaf.js';
|
|
1
|
+
import { KSCRIPT_SOURCE_CELL_BYTES, kScriptSourceAnswerRows } from '../../chart/kscript-source-answer-budget.leaf.js';
|
|
2
|
+
import { wrunChartHostEnv } from '../../../host-env.js';
|
|
2
3
|
import { wrunRowLaneByKey, wrunRowLaneOfClass, wrunRowLanes } from './row-lane-registry.js';
|
|
3
|
-
import { assertWrunLaneChainPlaneReadable, stableJson, wrunChainLaneStop, wrunChartOpraPlane, wrunHostGridAsksWithinHorizon, wrunLaneNoChainRefusal, wrunOpraPlaneStopDetail, wrunPollLaneChainAsk, wrunPollLaneChainExchange, wrunPollLaneChainGovernedExchange, wrunPollLaneChainPlane, resolveWrunOptionSettingKnobs, wrunUnservedLaneInput, } from './wrun-poll-lanes.util.js';
|
|
4
|
+
import { assertWrunLaneChainPlaneReadable, stableJson, wrunChainLaneContext, wrunChainLaneStop, wrunChartOpraPlane, wrunHostGridAsksWithinHorizon, wrunLaneNoChainRefusal, wrunOpraPlaneStopDetail, wrunPollLaneChainAsk, wrunPollLaneChainExchange, wrunPollLaneChainGovernedExchange, wrunPollLaneChainPlane, resolveWrunOptionSettingKnobs, wrunUnservedLaneInput, } from './wrun-poll-lanes.util.js';
|
|
4
5
|
import { WRUN_ROW_LANE_ID_PREFIX, } from './wrun-row-lane.types.js';
|
|
5
6
|
import { assertWrunOpraLaneReadable } from '../wrun-opra-lane.util.js';
|
|
7
|
+
import { resolveWrunUnderlyingMarket, resolveWrunUnderlyingSettingKnob, wrunTakesUnderlying, wrunUnderlyingKnob, wrunUnderlyingLaneContext, wrunUnderlyingRootOf, wrunUnderlyingVenueWord, } from '../derived-roots.util.js';
|
|
6
8
|
import { wrunSheetCellBlockTuples } from '../wrun-cell-capacity.leaf.js';
|
|
7
9
|
import { WRUN_OPTION_FLOW_TODAY_FIELD, wrunOptionFlowTodayFromOf } from '../wrun-option-contract-flow.util.js';
|
|
8
10
|
import { wrunOptionInputTupleWidth, wrunOptionKitBarHasRows, wrunOptionLaneCarriesNext, wrunOptionLaneFirstPaintBudget, wrunOptionLaneTupleWidth, } from '../wrun-option-views.util.js';
|
|
9
11
|
import { wrunPartialMarkerTuple, wrunPresentIsPartial, wrunTuplesMarkedPartial } from '../wrun-present-bits.util.js';
|
|
10
12
|
import { wrunCellRowsWithPartialBars, wrunHostBarSpanOf, wrunHostGridAsks, wrunHostGridFallbackAsks, wrunLandCellRowsOnHostBars, } from '../wrun-tier-grid.util.js';
|
|
13
|
+
const MINUTE_MS = 60_000;
|
|
11
14
|
/**
|
|
12
15
|
* A row lane at the width an input's words or an instance's facets make its block (wrun-option-views.util
|
|
13
16
|
* `wrunOptionInputTupleWidth`, `wrunOptionLaneTupleWidth`): the lane itself at its class's tuple width; at any other
|
|
@@ -111,7 +114,9 @@ function wrunRowLaneUnserved(lane, plane, indexMode, run, ctx) {
|
|
|
111
114
|
* 3. the lane's identity, once per lane (the first admitted input's context names a refusal), then the input's
|
|
112
115
|
* facets (awaited, in declaration order), each knob naming a setting first read as the setting's current value
|
|
113
116
|
* (`resolveWrunOptionSettingKnobs` over `run.paramValues`), the context carrying the plan's facts beside the chart
|
|
114
|
-
* (`WrunRowLanePlanFacts`); the instance is the identity and the facets together.
|
|
117
|
+
* (`WrunRowLanePlanFacts`); the instance is the identity and the facets together. An input naming another root
|
|
118
|
+
* (contract F's `underlying`, `planWrunRowLaneUnderlying`) is planned against that root's market instead, its
|
|
119
|
+
* identity once per lane and market. A lane with
|
|
115
120
|
* `acquisitions: 'one'` refuses a second input whose acquisition differs (one fetch, one live fold per package). A
|
|
116
121
|
* chart with no option chain (an identity or facets refusal seeded `no-options` / `chain`, `wrunLaneNoChainRefusal`:
|
|
117
122
|
* a LINK perp, a forex pair) does not serve the feed either: the same one rule, its note naming the feed with the
|
|
@@ -127,7 +132,7 @@ export async function planWrunRowLanes(metadata, chart, run) {
|
|
|
127
132
|
const indexMode = chart.isIndexModeExchange?.(chart.exchange) === true;
|
|
128
133
|
const cryptoVenue = chart.isCryptoVenueExchange?.(chart.exchange);
|
|
129
134
|
// The chart's OPRA plane facts, read once, as the poll lanes' planner reads them (`wrunChartOpraPlane`).
|
|
130
|
-
const plane = wrunChartOpraPlane(chart
|
|
135
|
+
const plane = wrunChartOpraPlane(chart, chart);
|
|
131
136
|
const params = metadata.params ?? [];
|
|
132
137
|
const plannedInputs = planWrunRowLaneInputs(metadata);
|
|
133
138
|
const laneMaxCells = wrunRowLaneMaxCellsByClass(plannedInputs);
|
|
@@ -151,7 +156,13 @@ export async function planWrunRowLanes(metadata, chart, run) {
|
|
|
151
156
|
laneMaxCells: laneMaxCells.get(lane.sourceClass),
|
|
152
157
|
params,
|
|
153
158
|
...(run?.paramValues !== undefined ? { paramValues: run.paramValues } : {}),
|
|
159
|
+
// A chain lane holds the planner's plane verdict where the run judged the plane, as a chain poll lane does: its
|
|
160
|
+
// chain there is the plane's own by coin, read without the gate.
|
|
161
|
+
...(lane.chain !== undefined && chart.isOpraPlaneExchange !== undefined ? { opraPlane: plane.onPlane } : {}),
|
|
154
162
|
};
|
|
163
|
+
// A chain lane reads the run's one options market: a stock twin's stock in place of the chart's
|
|
164
|
+
// (`wrunChainLaneContext`); every other lane, and every chain lane of any other chart, the chart's own context.
|
|
165
|
+
const chainCtx = lane.chain !== undefined ? wrunChainLaneContext(ctx, run?.options) : ctx;
|
|
155
166
|
const unserved = {
|
|
156
167
|
inputName: planned.inputName,
|
|
157
168
|
sourceClass: lane.sourceClass,
|
|
@@ -162,7 +173,7 @@ export async function planWrunRowLanes(metadata, chart, run) {
|
|
|
162
173
|
// where a known stop keeps them off the plane (`wrunChainLaneStop`, the chain poll lanes' one rule). Any other lane
|
|
163
174
|
// is admitted by its plane or the chart's mode.
|
|
164
175
|
const why = lane.chain !== undefined
|
|
165
|
-
? wrunChainLaneStop(plane, run,
|
|
176
|
+
? wrunChainLaneStop(plane, run, chainCtx, planned.source.venue)
|
|
166
177
|
: wrunRowLaneUnserved(lane, plane, indexMode, run, ctx);
|
|
167
178
|
if (why !== undefined) {
|
|
168
179
|
wrunUnservedLaneInput(missing, unserved, WRUN_ROW_LANE_UNSERVED_FILLS, why, cryptoVenue);
|
|
@@ -170,14 +181,27 @@ export async function planWrunRowLanes(metadata, chart, run) {
|
|
|
170
181
|
}
|
|
171
182
|
let extras;
|
|
172
183
|
try {
|
|
173
|
-
|
|
184
|
+
// Contract F: an input naming another root (`underlying`) is planned against that root's market
|
|
185
|
+
// (`planWrunRowLaneUnderlying`); "auto" (absent too) against the chart's, as every other lane's input.
|
|
186
|
+
const underlying = wrunTakesUnderlying(lane.sourceClass)
|
|
187
|
+
? await planWrunRowLaneUnderlying(planned.source, chainCtx, run)
|
|
188
|
+
: undefined;
|
|
189
|
+
if (underlying !== undefined && 'why' in underlying) {
|
|
190
|
+
wrunUnservedLaneInput(missing, unserved, WRUN_ROW_LANE_UNSERVED_FILLS, underlying.why, cryptoVenue);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const laneCtx = underlying?.ctx ?? chainCtx;
|
|
194
|
+
const identityKey = underlying === undefined ? lane.laneKey : `${lane.laneKey}|${underlying.key}`;
|
|
195
|
+
let identity = identities.get(identityKey);
|
|
174
196
|
if (identity === undefined) {
|
|
175
|
-
identity = definedFields(await lane.identity?.(
|
|
176
|
-
identities.set(
|
|
197
|
+
identity = definedFields(await lane.identity?.(laneCtx));
|
|
198
|
+
identities.set(identityKey, identity);
|
|
177
199
|
}
|
|
178
200
|
// A knob naming a setting reads its current value first: a settings change re-plans and re-asks.
|
|
179
|
-
const
|
|
180
|
-
|
|
201
|
+
const read = resolveWrunOptionSettingKnobs(ctx, planned.source, params, run?.paramValues);
|
|
202
|
+
// A root the chart's own crypto venue lists reads that venue, unless the input declares a venue of its own.
|
|
203
|
+
const source = underlying === undefined ? read : { ...read, venue: wrunUnderlyingVenueWord(read.venue, underlying.market) };
|
|
204
|
+
extras = { ...identity, ...definedFields(await lane.facets?.(source, laneCtx)) };
|
|
181
205
|
}
|
|
182
206
|
catch (error) {
|
|
183
207
|
// A chart with no option chain does not serve the feed (`wrunLaneNoChainRefusal`): the same one rule.
|
|
@@ -207,6 +231,40 @@ export async function planWrunRowLanes(metadata, chart, run) {
|
|
|
207
231
|
}
|
|
208
232
|
return { lanes: [...instances.values()], missingFeeds: [...missing.values()] };
|
|
209
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Contract F (SKYLIT-PARITY, derived-roots.util): one input of a lane that takes the `underlying` knob
|
|
236
|
+
* (`option_strikes`) naming another root ("SPX", "derived" for the derived table's default root of the chart's root, a
|
|
237
|
+
* setting picking one, read first: `resolveWrunUnderlyingSettingKnob`) is planned against that root's market, as if the
|
|
238
|
+
* chart were that market (`wrunUnderlyingLaneContext`): the lane's own identity and facets read the root's chain through
|
|
239
|
+
* the one chain resolver, so every venue and book word, wall and refusal of the lane holds, and the instance's
|
|
240
|
+
* acquisition names the root's chain. An OPRA root meets the OPRA wall before any read (`opra-official-only:<class>`),
|
|
241
|
+
* then, kept off the plane by a known stop (the `opra` flag dark), the stop's rule (`wrunUnservedLaneInput`, the chain
|
|
242
|
+
* lanes' own for a stopped chart); a CME root meets the CME display wall before any read too.
|
|
243
|
+
* A root no venue family lists refuses by name (`wrun_underlying_unresolved:<root>`, the no-chain seed). Undefined:
|
|
244
|
+
* "auto" (absent too), the chart's own chain.
|
|
245
|
+
*/
|
|
246
|
+
async function planWrunRowLaneUnderlying(source, ctx, run) {
|
|
247
|
+
const read = resolveWrunUnderlyingSettingKnob(ctx, source, ctx.params ?? [], run?.paramValues);
|
|
248
|
+
const root = wrunUnderlyingRootOf(wrunUnderlyingKnob(read, ctx), ctx);
|
|
249
|
+
if (root === undefined)
|
|
250
|
+
return undefined;
|
|
251
|
+
const market = await resolveWrunUnderlyingMarket(root, ctx, run);
|
|
252
|
+
// A CME root's chain is CME options data whatever the chart: the display wall before any read (and after the facets,
|
|
253
|
+
// as for every chain instance).
|
|
254
|
+
if (market.family === 'cme')
|
|
255
|
+
assertWrunLaneChainPlaneReadable('cme', market.exchange, run, ctx);
|
|
256
|
+
if (market.family === 'opra') {
|
|
257
|
+
assertWrunOpraLaneReadable(run, ctx);
|
|
258
|
+
if (market.opraStop !== undefined) {
|
|
259
|
+
return { why: { words: wrunOpraPlaneStopDetail(market.opraStop), stop: market.opraStop } };
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
ctx: wrunUnderlyingLaneContext(ctx, market),
|
|
264
|
+
key: `${market.exchange}|${market.symbol}|${market.coin}|${market.venue ?? ''}`,
|
|
265
|
+
market,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
210
268
|
/** The most `max_cells` among a sheet's planned inputs of each row-lane class (`WrunRowLanePlanFacts.laneMaxCells`). */
|
|
211
269
|
function wrunRowLaneMaxCellsByClass(planned) {
|
|
212
270
|
const most = new Map();
|
|
@@ -295,6 +353,66 @@ export function wrunRowLaneFetchOptions(lane) {
|
|
|
295
353
|
}
|
|
296
354
|
/** The payload field a tiered ask names its backend tier in (`landing.tiers`, the tier's key). */
|
|
297
355
|
export const WRUN_ROW_LANE_TIER_FIELD = 'tier';
|
|
356
|
+
/** A row lane's window bounded at a replay cursor (`WrunRowLaneWindow.replayCursorMs`): a flow or snapshot lane's bars
|
|
357
|
+
* opening after the cursor are left out; a `latest` lane (the live row's snapshot), and a window naming no cursor,
|
|
358
|
+
* as they are. */
|
|
359
|
+
export function wrunRowLaneWindowAtReplayCursor(lane, window) {
|
|
360
|
+
const cursor = window.replayCursorMs;
|
|
361
|
+
if (lane.landing.kind === 'latest' || cursor === undefined || !Number.isFinite(cursor))
|
|
362
|
+
return window;
|
|
363
|
+
const barOpens = window.barOpens.filter((stampMs) => stampMs <= cursor);
|
|
364
|
+
return barOpens.length === window.barOpens.length ? window : { ...window, barOpens };
|
|
365
|
+
}
|
|
366
|
+
/** Whether a row lane instance reads per bar (a flow or snapshot landing): the lanes a replay's cursor bounds. */
|
|
367
|
+
function wrunRowLaneReadsPerBar(instance) {
|
|
368
|
+
const lane = wrunRowLaneByKey(instance.laneKey);
|
|
369
|
+
return lane !== undefined && lane.landing.kind !== 'latest';
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* The row lane instances a replay run reads through its cursor (`wrunRowLaneWindowAtReplayCursor`: the flow and snapshot
|
|
373
|
+
* lanes), by key: the session's coverage of each is the cursor, never the replay window's end its other lanes reach, so
|
|
374
|
+
* each replay step extends them (`wrunReplayRowLaneExtensions`) and the replay record keeps naming the window's end.
|
|
375
|
+
*/
|
|
376
|
+
export function wrunRowLanesReplayBounded(instances) {
|
|
377
|
+
return new Set((instances ?? []).filter(wrunRowLaneReadsPerBar).map((instance) => instance.key));
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* What a replay step owes a session's row lanes before it computes the bars it reveals (SKYLIT-PARITY L6a): each flow
|
|
381
|
+
* or snapshot lane covered short of the step's cursor (`coveredThroughTs`, the newest bar its buffer holds), from the
|
|
382
|
+
* bar after its coverage (`fromTs`) through the cursor. A lane holding no coverage (the run degraded it) is left to its
|
|
383
|
+
* degrade, and a `latest` lane to its live-row snapshot.
|
|
384
|
+
*/
|
|
385
|
+
export function wrunReplayRowLaneExtensions(instances, coveredThroughTs, cursorMs) {
|
|
386
|
+
if (!Number.isFinite(cursorMs))
|
|
387
|
+
return [];
|
|
388
|
+
const owed = [];
|
|
389
|
+
for (const instance of instances ?? []) {
|
|
390
|
+
if (!wrunRowLaneReadsPerBar(instance))
|
|
391
|
+
continue;
|
|
392
|
+
const covered = coveredThroughTs[instance.key];
|
|
393
|
+
if (typeof covered !== 'number' || !Number.isFinite(covered) || covered >= cursorMs)
|
|
394
|
+
continue;
|
|
395
|
+
owed.push({ key: instance.key, fromTs: covered + 1 });
|
|
396
|
+
}
|
|
397
|
+
return owed;
|
|
398
|
+
}
|
|
399
|
+
/** A replay step's answer merged into a row lane's held rows: one row per bar, ascending, the answer's row in place of
|
|
400
|
+
* a held one of the same bar (a replay holds no live-folded row an answer could lose). */
|
|
401
|
+
export function mergeWrunReplayRowLaneRows(held, answer) {
|
|
402
|
+
const byBar = new Map();
|
|
403
|
+
for (const rows of [held ?? [], answer]) {
|
|
404
|
+
for (const row of rows) {
|
|
405
|
+
const ts = Number(row[0]);
|
|
406
|
+
if (Number.isFinite(ts))
|
|
407
|
+
byBar.set(ts, row);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return [...byBar.entries()].sort((a, b) => a[0] - b[0]).map(([, row]) => row);
|
|
411
|
+
}
|
|
412
|
+
/** The add a row lane read belongs to (`WrunRowLaneFetchOptions.addMemo`): the chart, the indicator, the instance. */
|
|
413
|
+
export function wrunRowLaneAddKey(chartIndex, indicatorId, instanceKey) {
|
|
414
|
+
return `${chartIndex}|${indicatorId}|${instanceKey}`;
|
|
415
|
+
}
|
|
298
416
|
/**
|
|
299
417
|
* A row lane's rows over a chart window `[barOpens[0], last bar's end)`: a flow or snapshot lane's asks under the
|
|
300
418
|
* tier rule and the lane's `tierChoice` (one per run of bars on a tier, the tier's key as `tier` in the ask's
|
|
@@ -316,11 +434,34 @@ export const WRUN_ROW_LANE_TIER_FIELD = 'tier';
|
|
|
316
434
|
* still out a macrotask later: the slice's rows, every older bar the projection reads rows for read partial
|
|
317
435
|
* (wrun-row-lane-first-paint.util `wrunRowLaneFirstSliceHeldBars`), and the slice's first bar. Never when no cut falls
|
|
318
436
|
* on a session's first bar (a session longer than the slice: the plain split, asked as today), for a block with no
|
|
319
|
-
* `present` mask (it cannot read a bar as partial), a kit fold carrying the next bar (its pages ask one at a time),
|
|
320
|
-
*
|
|
437
|
+
* `present` mask (it cannot read a bar as partial), a kit fold carrying the next bar (its pages ask one at a time),
|
|
438
|
+
* Strike Footprint's per-(expiry, strike) rows (it learns its strike step over the whole run:
|
|
439
|
+
* wrun-row-lane-first-paint.util `wrunRowLaneDrawsFirstSlice`), or a snapshot whose empty bars ask a coarser tier (that
|
|
440
|
+
* pass would ask the slice's bars again).
|
|
441
|
+
*
|
|
442
|
+
* A row budget that leaves asked bars partial says so before any ask leaves (`opts.onBudgetCut`, and the debug ring).
|
|
443
|
+
*
|
|
444
|
+
* `opts.download` (a budgeted run, OPTLOAD W3 R2; `landWithinDownloadShare`): after the tier rule, the horizon and the
|
|
445
|
+
* row budget (the smaller cut wins), the read asks its newest slice first and alone, then the newest older bars its
|
|
446
|
+
* share fits by the slice's own wire bytes, and no others; every bar it leaves unasked reads partial (bit 14 with the
|
|
447
|
+
* marker tuple; an empty block on a class with no `present` mask), and the cut is named once the asks landed
|
|
448
|
+
* (`onBudgetCut`, `budget: 'download'`). No early handover in that mode. Absent: today's asks, exactly.
|
|
449
|
+
*
|
|
450
|
+
* A replay's window (`window.replayCursorMs`, plan L6a): a flow or snapshot lane's bars end at the replay's cursor
|
|
451
|
+
* (`wrunRowLaneWindowAtReplayCursor`), so nothing after it is asked, and the read keeps a replay memo (the add memo's
|
|
452
|
+
* machinery, `role: 'replay'`, never the add's own): a replay step's read of the bars it reveals
|
|
453
|
+
* (wrun-live-tick.util, `wrunReplayRowLaneExtensions`) and a reopened run reuse the bars landed whole and final and
|
|
454
|
+
* ask the rest. A read that names no cursor asks exactly as before.
|
|
455
|
+
*
|
|
456
|
+
* `ask` reports its answer's completion through its fourth argument (`whole`: the chart's fetch verdict,
|
|
457
|
+
* wrun-source-rows.util `wrunSourceVerdictWhole`); an ask that never reports is not whole. A memo admits a bar only from
|
|
458
|
+
* an ask reported whole, and the bars of every other ask are named to the caller (`opts.onUnconfirmed`), so a synthetic
|
|
459
|
+
* completion's empty or short answer is asked again, never remembered as the bar.
|
|
321
460
|
*/
|
|
322
|
-
export async function fetchWrunRowLaneRows(lane, extras,
|
|
461
|
+
export async function fetchWrunRowLaneRows(lane, extras, askedWindow, fallback, ask, opts = {}) {
|
|
323
462
|
const landing = lane.landing;
|
|
463
|
+
// A replay run's per-bar lane ends at the replay's cursor: no bar after it is asked.
|
|
464
|
+
const window = wrunRowLaneWindowAtReplayCursor(lane, askedWindow);
|
|
324
465
|
// The instance's rows are its facets' (a strike kit fold's 14-value rows), read as plain tuples once landed; at
|
|
325
466
|
// another width than the class's they carry no `present` mask (`wrunRowLaneAtWidth`).
|
|
326
467
|
const sized = wrunRowLaneAtWidth(lane, wrunOptionLaneTupleWidth(lane.sourceClass, extras, lane.width));
|
|
@@ -332,48 +473,155 @@ export async function fetchWrunRowLaneRows(lane, extras, window, fallback, ask,
|
|
|
332
473
|
// What the row budget and the first-paint slice project the window's bars under: the instance's payload with
|
|
333
474
|
// `history` "today" dated off the window's newest bar as each ask's K control dates it (`wrunRowLaneBudgetAcquisition`).
|
|
334
475
|
const budgetAcquisition = await wrunRowLaneBudgetAcquisition(lane, extras, window);
|
|
335
|
-
const
|
|
476
|
+
const withinHorizon = wrunRowLaneAsksWithinHorizon(wrunHostGridAsks({
|
|
336
477
|
tiers: landing.tiers,
|
|
337
478
|
barOpens: window.barOpens,
|
|
338
479
|
intervalMs: window.intervalMs,
|
|
339
480
|
nowMs: window.nowMs,
|
|
340
481
|
choice: landing.tierChoice,
|
|
341
482
|
sessionGrid,
|
|
342
|
-
}), window, lane.horizon?.(extras, window.nowMs), sessionGrid)
|
|
483
|
+
}), window, lane.horizon?.(extras, window.nowMs), sessionGrid);
|
|
484
|
+
// Every projection of this read, the budget's and the first paint's, at least what the lane's reads measured.
|
|
485
|
+
const rowBudget = lane.rowBudget === undefined ? undefined : wrunRowLaneMeasuredBudget(lane, lane.rowBudget, extras);
|
|
486
|
+
const budgeted = wrunRowLaneAsksWithinRowBudget(withinHorizon, window, rowBudget, budgetAcquisition, sessionGrid);
|
|
487
|
+
const { asks, partialBars } = budgeted;
|
|
488
|
+
// The budget hands back the plan it was given unless it cut bars out of it.
|
|
489
|
+
if (budgeted !== withinHorizon && lane.rowBudget !== undefined) {
|
|
490
|
+
const cut = wrunRowLaneBudgetCutOf(lane.laneKey, lane.rowBudget, withinHorizon, budgeted, window, sessionGrid);
|
|
491
|
+
reportWrunRowLaneBudgetCut(cut, window.intervalMs, opts.onBudgetCut);
|
|
492
|
+
}
|
|
493
|
+
// One download budget per add (`opts.addMemo`, wrun-row-lane-add-memo.util): the bars a budgeted read of this add
|
|
494
|
+
// already landed whole and final are reused, the bars its budget cut stay partial, and only the rest is asked. A
|
|
495
|
+
// replay's read keeps its own memo, never the add's, so a later read at its cursor asks only the bars it lacks.
|
|
496
|
+
const addMemo = window.replayCursorMs !== undefined && Number.isFinite(window.replayCursorMs)
|
|
497
|
+
? { key: `replay|${wrunRowLaneAddFingerprintOf(lane, extras, window)}`, role: 'replay' }
|
|
498
|
+
: opts.addMemo;
|
|
499
|
+
const memoUtil = addMemo === undefined ? undefined : await import('./wrun-row-lane-add-memo.util.js');
|
|
500
|
+
const memoFingerprint = addMemo === undefined ? '' : wrunRowLaneAddFingerprintOf(lane, extras, window);
|
|
501
|
+
const wholeRun = addMemo?.role === 'run' && opts.download === undefined;
|
|
502
|
+
if (wholeRun && memoUtil !== undefined && addMemo !== undefined)
|
|
503
|
+
memoUtil.forgetWrunRowLaneAdd(addMemo.key);
|
|
504
|
+
const memo = memoUtil === undefined || addMemo === undefined || wholeRun
|
|
505
|
+
? undefined
|
|
506
|
+
: memoUtil.wrunRowLaneAddMemoOf(addMemo.key, memoFingerprint);
|
|
507
|
+
const heldCut = memo === undefined ? [] : window.barOpens.filter((stampMs) => memo.cut.has(stampMs) && !memo.landed.has(stampMs));
|
|
508
|
+
const freshAsks = memo === undefined || memoUtil === undefined
|
|
509
|
+
? asks
|
|
510
|
+
: memoUtil.wrunRowLaneAsksOverBars(asks, (stampMs) => !memo.landed.has(stampMs) && !memo.cut.has(stampMs), window, sessionGrid);
|
|
511
|
+
const planPartial = heldCut.length === 0 ? partialBars : [...new Set([...partialBars, ...heldCut])].sort((a, b) => a - b);
|
|
343
512
|
// A row-budget lane's newest bars are asked first and on their own (wrun-row-lane-first-paint.util, off the boot path),
|
|
344
513
|
// and so are an instance's whose facets ask a per-bar word of the gateway (OPTLOAD G5: a surface pick, the strike kit
|
|
345
514
|
// fold), sized by the rows its answer holds; every other instance asks as the tier rule made it.
|
|
346
|
-
const sliceBudget =
|
|
347
|
-
|
|
515
|
+
const sliceBudget = rowBudget ?? wrunOptionLaneFirstPaintBudget(lane.sourceClass, extras, lane.width);
|
|
516
|
+
// A budgeted run of an add that already spent reads within what is left of the add's share.
|
|
517
|
+
const download = opts.download === undefined || memo === undefined
|
|
518
|
+
? opts.download
|
|
519
|
+
: { ...opts.download, share: Math.max(0, memo.shareBytes - memo.spentBytes) };
|
|
520
|
+
const firstPaint = sliceBudget === undefined && download === undefined ? undefined : await import('./wrun-row-lane-first-paint.util.js');
|
|
348
521
|
// The slice is cut on a trade date's first bar wherever the chart reads trade dates (`window.tradeDateOf`), so it
|
|
349
522
|
// holds whole sessions, on every run alike: a first paint asks the windows a later run asks (one cache entry each).
|
|
350
523
|
const split = firstPaint === undefined || sliceBudget === undefined
|
|
351
524
|
? undefined
|
|
352
|
-
: firstPaint.wrunRowLaneFirstPaintSplit(
|
|
353
|
-
const ordered = split === undefined ?
|
|
525
|
+
: firstPaint.wrunRowLaneFirstPaintSplit(freshAsks, window, sliceBudget, budgetAcquisition, sessionGrid, window.tradeDateOf);
|
|
526
|
+
const ordered = split === undefined ? freshAsks : [...split.first, ...split.older];
|
|
354
527
|
// The bars the slice's early answer holds back (`opts.onFirstSlice`), or undefined when it has none.
|
|
355
528
|
const coarserPass = landing.kind === 'snapshot' && landing.tiers !== undefined && landing.coarserWhenEmpty?.(extras) === true;
|
|
356
529
|
const heldBack = opts.onFirstSlice === undefined ||
|
|
530
|
+
download !== undefined ||
|
|
357
531
|
firstPaint === undefined ||
|
|
358
532
|
split === undefined ||
|
|
359
533
|
sliceBudget === undefined ||
|
|
360
534
|
sized.presentMask === false ||
|
|
361
535
|
coarserPass ||
|
|
362
|
-
wrunOptionLaneCarriesNext(lane.sourceClass, extras)
|
|
536
|
+
wrunOptionLaneCarriesNext(lane.sourceClass, extras) ||
|
|
537
|
+
!firstPaint.wrunRowLaneDrawsFirstSlice(lane.sourceClass, extras)
|
|
363
538
|
? undefined
|
|
364
539
|
: firstPaint.wrunRowLaneFirstSliceHeldBars(split, window, sliceBudget, budgetAcquisition, sessionGrid);
|
|
365
540
|
const fold = landing.fold;
|
|
366
|
-
//
|
|
367
|
-
const
|
|
368
|
-
|
|
541
|
+
// The bars of every ask the chart's fetch did not confirm whole (`ask`'s verdict): no memo admits them.
|
|
542
|
+
const unconfirmed = new Set();
|
|
543
|
+
// `askToMs` reads past the ask's own end (a kit fold's seam, below); only the ask's own bars ever land. `more`: the
|
|
544
|
+
// fields a budgeted read's ask names beside the payload (a browser fold's row cap, FE-FOLD-CAP).
|
|
545
|
+
const askAndLand = async (gridAsk, askToMs = gridAsk.toMs, more) => {
|
|
546
|
+
const payload = more === undefined ? extras : { ...extras, ...more };
|
|
547
|
+
const askExtras = gridAsk.tier === undefined ? payload : { ...payload, [WRUN_ROW_LANE_TIER_FIELD]: gridAsk.tier.key };
|
|
548
|
+
const heard = { whole: false };
|
|
549
|
+
const answer = await ask(askExtras, gridAsk.fromMs, askToMs, (answered) => {
|
|
550
|
+
heard.whole = answered;
|
|
551
|
+
});
|
|
552
|
+
if (!heard.whole) {
|
|
553
|
+
for (const stampMs of window.barOpens) {
|
|
554
|
+
const { fromMs } = wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
|
|
555
|
+
if (fromMs >= gridAsk.fromMs && fromMs < gridAsk.toMs)
|
|
556
|
+
unconfirmed.add(stampMs);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
369
559
|
// Rows stamped at or past the ask's end belong to a bar the plan did not ask (a skipped newest bar): never land
|
|
370
560
|
// them, whatever the control answered.
|
|
371
|
-
const rows =
|
|
561
|
+
const rows = answer.filter((row) => Number(row[0]) < gridAsk.toMs);
|
|
372
562
|
return wrunLandCellRowsOnHostBars(rows, landing.kind, { intervalMs: window.intervalMs, barGrid: window.barGrid, tierMs: gridAsk.tier?.ms, nowMs: window.nowMs }, fold === undefined ? undefined : (group) => fold(group, askExtras)).map((row) => wrunRowLanePlainRow(row, width));
|
|
373
563
|
};
|
|
374
564
|
const byBar = new Map();
|
|
565
|
+
// The add's landed bars come back as they landed (a copy: the memo's rows are never handed out to be written).
|
|
566
|
+
if (memo !== undefined) {
|
|
567
|
+
const inWindow = new Set(window.barOpens);
|
|
568
|
+
for (const [stampMs, row] of memo.landed) {
|
|
569
|
+
if (row !== undefined && inWindow.has(stampMs)) {
|
|
570
|
+
byBar.set(stampMs, row.map((cell) => (Array.isArray(cell) ? cell.slice() : cell)));
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
375
574
|
const landAll = (gridAsks) => Promise.all(gridAsks.map((gridAsk) => askAndLand(gridAsk)));
|
|
376
|
-
|
|
575
|
+
// The asks the read sent and the bars it reads partial: the plan's, unless a budgeted read left older bars unasked.
|
|
576
|
+
let sentAsks = freshAsks;
|
|
577
|
+
let readPartial = planPartial;
|
|
578
|
+
if (download !== undefined && firstPaint !== undefined && freshAsks.length === 0) {
|
|
579
|
+
// Every bar of the window is the add's already (landed or cut): nothing is asked.
|
|
580
|
+
sentAsks = [];
|
|
581
|
+
}
|
|
582
|
+
else if (download !== undefined && firstPaint !== undefined) {
|
|
583
|
+
// OPTLOAD W3 R2: the newest slice first and alone, then the newest older bars the read's share fits by the slice's
|
|
584
|
+
// own wire bytes, and no others (`landWithinDownloadShare`). No early handover: the older asks leave once the
|
|
585
|
+
// slice landed, so the whole answer is the first picture.
|
|
586
|
+
const carriesNext = wrunOptionLaneCarriesNext(lane.sourceClass, extras);
|
|
587
|
+
const landGroup = async (gridAsks, more) => {
|
|
588
|
+
if (!carriesNext) {
|
|
589
|
+
const answers = await Promise.all(gridAsks.map((gridAsk) => askAndLand(gridAsk, gridAsk.toMs, more)));
|
|
590
|
+
for (const landed of answers)
|
|
591
|
+
for (const row of landed)
|
|
592
|
+
byBar.set(Number(row[0]), row);
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
// A kit fold carrying the next bar: newest first, one at a time, each read through its seam (as below).
|
|
596
|
+
for (const gridAsk of [...gridAsks].sort((a, b) => b.fromMs - a.fromMs)) {
|
|
597
|
+
const end = wrunRowLaneSeamEndMs(gridAsk, byBar, window.intervalMs);
|
|
598
|
+
for (const row of await askAndLand(gridAsk, end, more))
|
|
599
|
+
byBar.set(Number(row[0]), row);
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
const within = await landWithinDownloadShare({
|
|
603
|
+
laneKey: lane.laneKey,
|
|
604
|
+
extras,
|
|
605
|
+
width,
|
|
606
|
+
window,
|
|
607
|
+
sessionGrid,
|
|
608
|
+
asks: freshAsks,
|
|
609
|
+
partialBars: planPartial,
|
|
610
|
+
budgetAcquisition,
|
|
611
|
+
sliceBudget,
|
|
612
|
+
download,
|
|
613
|
+
firstPaint,
|
|
614
|
+
land: landGroup,
|
|
615
|
+
landedData: (stampMs) => (byBar.get(stampMs) ?? [])
|
|
616
|
+
.slice(1)
|
|
617
|
+
.some((tuple) => Array.isArray(tuple) &&
|
|
618
|
+
tuple.length > 0 &&
|
|
619
|
+
(sized.presentMask === false || !wrunPresentIsPartial(Number(tuple[tuple.length - 1])))),
|
|
620
|
+
});
|
|
621
|
+
sentAsks = within.sent;
|
|
622
|
+
readPartial = within.partialBars;
|
|
623
|
+
}
|
|
624
|
+
else if (heldBack !== undefined && split !== undefined && opts.onFirstSlice !== undefined) {
|
|
377
625
|
// Every ask leaves at once, as below; the slice's answer is handed over first while an older ask is still out.
|
|
378
626
|
const onFirstSlice = opts.onFirstSlice;
|
|
379
627
|
// The slice's first bar: the first bar the cut keeps (every bar before it is held).
|
|
@@ -434,7 +682,7 @@ export async function fetchWrunRowLaneRows(lane, extras, window, fallback, ask,
|
|
|
434
682
|
// acquisition its lane says so of (`coarserWhenEmpty`: a CME surface's daily bar whose 5m tier holds no session
|
|
435
683
|
// yet reads its settlement DAY row, never nothing); a fallback row fills only a bar still empty.
|
|
436
684
|
if (landing.kind === 'snapshot' && landing.tiers !== undefined && landing.coarserWhenEmpty?.(extras) === true) {
|
|
437
|
-
for (let pending =
|
|
685
|
+
for (let pending = sentAsks;;) {
|
|
438
686
|
const fallback = wrunHostGridFallbackAsks({
|
|
439
687
|
tiers: landing.tiers,
|
|
440
688
|
asks: pending,
|
|
@@ -454,9 +702,296 @@ export async function fetchWrunRowLaneRows(lane, extras, window, fallback, ask,
|
|
|
454
702
|
}
|
|
455
703
|
}
|
|
456
704
|
const landed = [...byBar.entries()].sort((a, b) => a[0] - b[0]).map(([, row]) => row);
|
|
705
|
+
if (lane.rowBudget !== undefined) {
|
|
706
|
+
noteWrunRowLaneMeasured(lane.laneKey, extras, sentAsks, byBar, readPartial, window, sessionGrid, sized.presentMask);
|
|
707
|
+
}
|
|
708
|
+
const foldPartial = (download?.fold ?? lane.download?.fold) !== undefined && sized.presentMask !== false;
|
|
709
|
+
if (download !== undefined && opts.download !== undefined) {
|
|
710
|
+
// The download budget's cut, named once the asks landed: the bars the share left unread, and the bars a browser
|
|
711
|
+
// fold left partial under its cap (FE-FOLD-CAP), the source answer budget's own cut kept apart; the add's cut and
|
|
712
|
+
// its whole spend when a memo served the read.
|
|
713
|
+
const cut = wrunRowLaneDownloadCutOf({
|
|
714
|
+
laneKey: lane.laneKey,
|
|
715
|
+
width,
|
|
716
|
+
window,
|
|
717
|
+
sessionGrid,
|
|
718
|
+
asks,
|
|
719
|
+
before: partialBars,
|
|
720
|
+
after: readPartial,
|
|
721
|
+
byBar,
|
|
722
|
+
foldPartial,
|
|
723
|
+
spentBytes: (memo?.spentBytes ?? 0) + download.meter.spentBytes(),
|
|
724
|
+
shareBytes: opts.download.share,
|
|
725
|
+
});
|
|
726
|
+
if (cut.cutBars > 0)
|
|
727
|
+
reportWrunRowLaneBudgetCut(cut, window.intervalMs, opts.onBudgetCut);
|
|
728
|
+
}
|
|
729
|
+
// The asks the chart's fetch did not confirm whole, named once they all landed.
|
|
730
|
+
if (unconfirmed.size > 0)
|
|
731
|
+
opts.onUnconfirmed?.([...unconfirmed].sort((a, b) => a - b));
|
|
732
|
+
// The add's memo after this read: a budgeted run's leaves one, a replay's read too (a whole read or not), and a read
|
|
733
|
+
// the memo served brings it up to date; a bar an unconfirmed ask answered joins none (asked again by the next read).
|
|
734
|
+
if (memoUtil !== undefined &&
|
|
735
|
+
addMemo !== undefined &&
|
|
736
|
+
(opts.download !== undefined || memo !== undefined || addMemo.role === 'replay')) {
|
|
737
|
+
const asked = (stampMs) => {
|
|
738
|
+
const { fromMs } = wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
|
|
739
|
+
return sentAsks.some((gridAsk) => fromMs >= gridAsk.fromMs && fromMs < gridAsk.toMs);
|
|
740
|
+
};
|
|
741
|
+
const askedBars = window.barOpens.filter(asked);
|
|
742
|
+
memoUtil.rememberWrunRowLaneAdd(addMemo.key, memoUtil.wrunRowLaneAddMemoAfter({
|
|
743
|
+
previous: memo,
|
|
744
|
+
fingerprint: memoFingerprint,
|
|
745
|
+
window,
|
|
746
|
+
sessionGrid,
|
|
747
|
+
askedBars,
|
|
748
|
+
landedRows: byBar,
|
|
749
|
+
partialBars: new Set([...readPartial, ...unconfirmed]),
|
|
750
|
+
marked: (row) => foldPartial && wrunRowLaneRowMarkedPartial(row),
|
|
751
|
+
cutBars: opts.download === undefined
|
|
752
|
+
? []
|
|
753
|
+
: [
|
|
754
|
+
...readPartial,
|
|
755
|
+
...askedBars.filter((stampMs) => {
|
|
756
|
+
const row = byBar.get(stampMs);
|
|
757
|
+
return foldPartial && row !== undefined && wrunRowLaneRowMarkedPartial(row);
|
|
758
|
+
}),
|
|
759
|
+
],
|
|
760
|
+
spentBytes: download?.meter.spentBytes() ?? 0,
|
|
761
|
+
shareBytes: opts.download?.share,
|
|
762
|
+
}));
|
|
763
|
+
}
|
|
457
764
|
// A block with no `present` mask (its class's, or an instance's its facets widen) marks nothing: a partial bar asked
|
|
458
765
|
// nothing and reads an empty block.
|
|
459
|
-
return sized.presentMask === false ? landed : wrunCellRowsWithPartialBars(landed,
|
|
766
|
+
return sized.presentMask === false ? landed : wrunCellRowsWithPartialBars(landed, readPartial, width);
|
|
767
|
+
}
|
|
768
|
+
/** Whether a landed row carries a partial mark (bit 14 on a tuple's `present`, its last cell). */
|
|
769
|
+
function wrunRowLaneRowMarkedPartial(row) {
|
|
770
|
+
return row.slice(1).some((tuple) => Array.isArray(tuple) && wrunPresentIsPartial(Number(tuple[tuple.length - 1])));
|
|
771
|
+
}
|
|
772
|
+
/** The add memo's fingerprint (wrun-row-lane-add-memo.util): the lane, the acquisition without a per-ask field (the
|
|
773
|
+
* measured key's skips and the lane's fold cap) and the bar span. A run's extras and a reconcile's recorded acquisition
|
|
774
|
+
* of the same instance print the same. Never the bar grid's record: the live session's market names no
|
|
775
|
+
* `transformations` where the chart's metadata does (INT 2026-10-23: every reconcile missed the run's memo), and the
|
|
776
|
+
* memo's bars are matched by their stamps anyway. */
|
|
777
|
+
function wrunRowLaneAddFingerprintOf(lane, extras, window) {
|
|
778
|
+
const foldField = lane.download?.fold?.field;
|
|
779
|
+
const fields = {};
|
|
780
|
+
for (const [key, value] of Object.entries(extras))
|
|
781
|
+
if (key !== foldField)
|
|
782
|
+
fields[key] = value;
|
|
783
|
+
return measuredKeyOf(lane.laneKey, fields, undefined, window.intervalMs);
|
|
784
|
+
}
|
|
785
|
+
/** The newest projection a budgeted read measured (`landWithinDownloadShare`), by lane and acquisition: its wire bytes a
|
|
786
|
+
* millisecond of bars. In memory, the newest `MEASURED_KEPT`. */
|
|
787
|
+
const downloadDensity = new Map();
|
|
788
|
+
function rememberDownload(map, key, value) {
|
|
789
|
+
if (!(Number.isFinite(value) && value > 0))
|
|
790
|
+
return;
|
|
791
|
+
map.delete(key);
|
|
792
|
+
map.set(key, value);
|
|
793
|
+
while (map.size > MEASURED_KEPT)
|
|
794
|
+
map.delete(map.keys().next().value);
|
|
795
|
+
}
|
|
796
|
+
/** The first bar of the newest trade date the window reads (`window.tradeDateOf`), or undefined without one. */
|
|
797
|
+
function wrunRowLaneNewestSessionFromMs(window, sessionGrid) {
|
|
798
|
+
const { barOpens, tradeDateOf } = window;
|
|
799
|
+
const newest = barOpens[barOpens.length - 1];
|
|
800
|
+
if (tradeDateOf === undefined || newest === undefined)
|
|
801
|
+
return undefined;
|
|
802
|
+
const date = tradeDateOf(newest);
|
|
803
|
+
if (!Number.isFinite(date))
|
|
804
|
+
return undefined;
|
|
805
|
+
let fromMs;
|
|
806
|
+
for (let at = barOpens.length - 1; at >= 0 && tradeDateOf(barOpens[at]) === date; at -= 1) {
|
|
807
|
+
fromMs = wrunHostBarSpanOf(barOpens[at], window.intervalMs, sessionGrid).fromMs;
|
|
808
|
+
}
|
|
809
|
+
return fromMs;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* A budgeted read's asks (OPTLOAD W3 R2, `WrunRowLaneFetchOptions.download`), landed through `land`:
|
|
813
|
+
* 1. its NEWEST SLICE, first and alone: the first-paint split of its asks (wrun-row-lane-first-paint.util) under the
|
|
814
|
+
* lane's own row budget, else a per-bar word's first-paint budget, else the kit's declared rows a bar (one heavy bar
|
|
815
|
+
* alone); a read summing a whole session per row (`span` "session") slices on its newest session's first bar, so no
|
|
816
|
+
* older ask reads that session again;
|
|
817
|
+
* 2. once it landed, its wire bytes over the slice's elapsed span (a bar still forming counts its elapsed part, at least
|
|
818
|
+
* a minute) project each older bar by its span; a slice no stamp measured (a cache) reads the read's last measured
|
|
819
|
+
* projection, else the declared rows a bar;
|
|
820
|
+
* 3. the newest older bars whose projections fit the share left after the slice are asked, as one run of bars, and no
|
|
821
|
+
* others: every older bar it leaves unasked joins the partial bars, except a bar its lane projects at nothing (before
|
|
822
|
+
* today under `history` "today": it reads nothing either way);
|
|
823
|
+
* 4. FE-FOLD-CAP: a lane folding contract rows in the browser (`download.fold`) bounds the READ, never each ask: a
|
|
824
|
+
* group of its asks (the slice, the older asks) lands newest first, one ask at a time, each naming the rows the
|
|
825
|
+
* bytes its group may still spend buy at the row's cells (the fold plan's own unit); once the group spent its bytes,
|
|
826
|
+
* its older asks are not sent and their bars read partial. The slice's bytes are the share, never under the first
|
|
827
|
+
* paint's (so it reads its newest bars); the older asks', what the slice left.
|
|
828
|
+
* The sent asks and the bars the read reads partial come back; what the slice measured is remembered for the next read.
|
|
829
|
+
*/
|
|
830
|
+
async function landWithinDownloadShare(args) {
|
|
831
|
+
const { window, sessionGrid, asks, download, budgetAcquisition } = args;
|
|
832
|
+
const declared = download.declaredBarRows;
|
|
833
|
+
const sliceRows = args.sliceBudget ??
|
|
834
|
+
(declared !== undefined && declared > 0 ? { cellsPerRow: args.width, barRows: () => declared } : undefined);
|
|
835
|
+
const sessionFrom = args.extras.span === 'session' ? wrunRowLaneNewestSessionFromMs(window, sessionGrid) : undefined;
|
|
836
|
+
const split = sessionFrom !== undefined
|
|
837
|
+
? args.firstPaint.wrunRowLaneSplitAt(asks, sessionFrom)
|
|
838
|
+
: args.firstPaint.wrunRowLaneFirstPaintSplit(asks, window, sliceRows, budgetAcquisition, sessionGrid);
|
|
839
|
+
const memoryKey = measuredKeyOf(args.laneKey, args.extras, undefined, 0);
|
|
840
|
+
const fold = download.fold;
|
|
841
|
+
const spanOf = (stampMs) => wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
|
|
842
|
+
const askOf = (stampMs, gridAsks) => {
|
|
843
|
+
const { fromMs } = spanOf(stampMs);
|
|
844
|
+
return gridAsks.find((ask) => fromMs >= ask.fromMs && fromMs < ask.toMs);
|
|
845
|
+
};
|
|
846
|
+
const barsOf = (gridAsks) => window.barOpens.filter((stampMs) => askOf(stampMs, gridAsks) !== undefined);
|
|
847
|
+
// A group of asks within `bytes`: a lane with no fold lands it at once; a fold lands it newest first, one ask at a
|
|
848
|
+
// time, each naming the rows what is left of `bytes` buys at the row's cells, and sends no older ask once it is spent.
|
|
849
|
+
const landGroup = async (gridAsks, bytes) => {
|
|
850
|
+
if (fold === undefined) {
|
|
851
|
+
await args.land(gridAsks, undefined);
|
|
852
|
+
return { sent: [...gridAsks], unsent: [] };
|
|
853
|
+
}
|
|
854
|
+
const rowBytes = fold.cellsPerRow * KSCRIPT_SOURCE_CELL_BYTES;
|
|
855
|
+
const sent = [];
|
|
856
|
+
const unsent = [];
|
|
857
|
+
let left = bytes;
|
|
858
|
+
for (const gridAsk of [...gridAsks].sort((a, b) => b.fromMs - a.fromMs)) {
|
|
859
|
+
if (sent.length > 0 && left <= 0) {
|
|
860
|
+
unsent.push(gridAsk);
|
|
861
|
+
continue;
|
|
862
|
+
}
|
|
863
|
+
const before = download.meter.spentBytes();
|
|
864
|
+
await args.land([gridAsk], { [fold.field]: Math.max(1, Math.floor(Math.max(0, left) / rowBytes)) });
|
|
865
|
+
sent.push(gridAsk);
|
|
866
|
+
left -= Math.max(0, download.meter.spentBytes() - before);
|
|
867
|
+
}
|
|
868
|
+
return { sent, unsent };
|
|
869
|
+
};
|
|
870
|
+
const bytesBefore = download.meter.spentBytes();
|
|
871
|
+
// The slice reads at least its newest bars whatever the share: a fold's bytes there are never under the first paint's.
|
|
872
|
+
const sliceCap = Math.max(download.share, args.firstPaint.WRUN_ROW_LANE_FIRST_PAINT_BYTES);
|
|
873
|
+
const slice = await landGroup(split.first, sliceCap);
|
|
874
|
+
let sliceSent = slice.sent;
|
|
875
|
+
const sliceUnsent = barsOf(slice.unsent);
|
|
876
|
+
let olderPlan = split.older;
|
|
877
|
+
// A slice that landed no data (its newest bar holds none yet: a delayed route's first minutes of a session) reads the
|
|
878
|
+
// newest older bar beside it, once, so the first picture holds the newest bar with data and the older bars are
|
|
879
|
+
// projected from a measured bar (INT 2026-10-23 13:30Z: Spot Exposures' forming bar answered nothing, its 55 older
|
|
880
|
+
// bars were cut on the kit's declared rows, and the chart drew nothing).
|
|
881
|
+
if (olderPlan.length > 0 && !barsOf(slice.sent).some(args.landedData)) {
|
|
882
|
+
const newestOlder = barsOf(olderPlan).at(-1);
|
|
883
|
+
if (newestOlder !== undefined) {
|
|
884
|
+
const { fromMs, toMs } = spanOf(newestOlder);
|
|
885
|
+
const extension = olderPlan.flatMap((ask) => {
|
|
886
|
+
const askFrom = Math.max(ask.fromMs, fromMs);
|
|
887
|
+
const askTo = Math.min(ask.toMs, toMs);
|
|
888
|
+
return askFrom < askTo ? [{ ...ask, fromMs: askFrom, toMs: askTo }] : [];
|
|
889
|
+
});
|
|
890
|
+
const spent = Math.max(0, download.meter.spentBytes() - bytesBefore);
|
|
891
|
+
const extended = await landGroup(extension, Math.max(sliceCap - spent, args.firstPaint.WRUN_ROW_LANE_FIRST_PAINT_BYTES));
|
|
892
|
+
sliceSent = [...sliceSent, ...extended.sent];
|
|
893
|
+
sliceUnsent.push(...barsOf(extended.unsent));
|
|
894
|
+
olderPlan = olderPlan.flatMap((ask) => {
|
|
895
|
+
const askTo = Math.min(ask.toMs, fromMs);
|
|
896
|
+
return ask.fromMs < askTo ? [{ ...ask, toMs: askTo }] : [];
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
const sliceBytes = Math.max(0, download.meter.spentBytes() - bytesBefore);
|
|
901
|
+
if (olderPlan.length === 0) {
|
|
902
|
+
return { sent: sliceSent, partialBars: [...new Set([...args.partialBars, ...sliceUnsent])].sort((a, b) => a - b) };
|
|
903
|
+
}
|
|
904
|
+
// The slice's elapsed span over its bars that landed data (a bar still forming counts what has elapsed of it, at least
|
|
905
|
+
// a minute): a bar that answered nothing spent nothing, and counting it would price the older bars under what they cost.
|
|
906
|
+
let sliceMs = 0;
|
|
907
|
+
for (const stampMs of window.barOpens) {
|
|
908
|
+
if (askOf(stampMs, sliceSent) === undefined || !args.landedData(stampMs))
|
|
909
|
+
continue;
|
|
910
|
+
const span = spanOf(stampMs);
|
|
911
|
+
const whole = span.toMs - span.fromMs;
|
|
912
|
+
sliceMs += Math.max(Math.min(MINUTE_MS, whole), Math.min(span.toMs, window.nowMs) - span.fromMs);
|
|
913
|
+
}
|
|
914
|
+
if (sliceBytes > 0 && sliceMs > 0)
|
|
915
|
+
rememberDownload(downloadDensity, memoryKey, sliceBytes / sliceMs);
|
|
916
|
+
const density = sliceBytes > 0 && sliceMs > 0 ? sliceBytes / sliceMs : downloadDensity.get(memoryKey);
|
|
917
|
+
const declaredRowsOf = (stampMs, tier) => {
|
|
918
|
+
if (sliceRows === undefined)
|
|
919
|
+
return undefined;
|
|
920
|
+
const span = spanOf(stampMs);
|
|
921
|
+
const rows = sliceRows.barRows({ openMs: span.fromMs, endMs: span.toMs, tier }, window.nowMs, budgetAcquisition);
|
|
922
|
+
return Number.isFinite(rows) && rows > 0 ? rows : 0;
|
|
923
|
+
};
|
|
924
|
+
let left = download.share - sliceBytes;
|
|
925
|
+
let keptFrom = Number.POSITIVE_INFINITY;
|
|
926
|
+
let keptEnd = Number.NEGATIVE_INFINITY;
|
|
927
|
+
let stopped = false;
|
|
928
|
+
const cut = [];
|
|
929
|
+
const older = window.barOpens.filter((stampMs) => askOf(stampMs, olderPlan) !== undefined).sort((a, b) => b - a);
|
|
930
|
+
for (const stampMs of older) {
|
|
931
|
+
const tier = askOf(stampMs, olderPlan)?.tier;
|
|
932
|
+
const rows = declaredRowsOf(stampMs, tier);
|
|
933
|
+
// A bar its lane projects at nothing reads nothing: never cut, never asked on its own.
|
|
934
|
+
if (rows === 0)
|
|
935
|
+
continue;
|
|
936
|
+
const span = spanOf(stampMs);
|
|
937
|
+
const bytes = density !== undefined
|
|
938
|
+
? density * (span.toMs - span.fromMs)
|
|
939
|
+
: (rows ?? 0) * (sliceRows?.cellsPerRow ?? args.width) * KSCRIPT_SOURCE_CELL_BYTES;
|
|
940
|
+
if (stopped || bytes > left) {
|
|
941
|
+
stopped = true;
|
|
942
|
+
cut.push(stampMs);
|
|
943
|
+
continue;
|
|
944
|
+
}
|
|
945
|
+
left -= bytes;
|
|
946
|
+
keptFrom = Math.min(keptFrom, span.fromMs);
|
|
947
|
+
keptEnd = Math.max(keptEnd, span.toMs);
|
|
948
|
+
}
|
|
949
|
+
const olderAsks = olderPlan.flatMap((ask) => {
|
|
950
|
+
const fromMs = Math.max(ask.fromMs, keptFrom);
|
|
951
|
+
const toMs = Math.min(ask.toMs, keptEnd);
|
|
952
|
+
return fromMs < toMs ? [{ ...ask, fromMs, toMs }] : [];
|
|
953
|
+
});
|
|
954
|
+
const olderLanded = olderAsks.length > 0 ? await landGroup(olderAsks, download.share - sliceBytes) : undefined;
|
|
955
|
+
return {
|
|
956
|
+
sent: [...sliceSent, ...(olderLanded?.sent ?? [])],
|
|
957
|
+
partialBars: [...new Set([...args.partialBars, ...sliceUnsent, ...cut, ...barsOf(olderLanded?.unsent ?? [])])].sort((a, b) => a - b),
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* A budgeted read's cut once its asks landed (`WrunRowLaneBudgetCut`, `budget: 'download'`): of the bars the plan asked
|
|
962
|
+
* (`asks`, the tier rule's, the horizon's and the answer budget's), the ones read whole and the ones the download budget
|
|
963
|
+
* alone left partial: unasked (`after` beside `before`), or, for a browser fold under its cap (`foldPartial`), landed
|
|
964
|
+
* partial. The oldest kept bar is the oldest of the newest run of whole bars.
|
|
965
|
+
*/
|
|
966
|
+
function wrunRowLaneDownloadCutOf(args) {
|
|
967
|
+
const before = new Set(args.before);
|
|
968
|
+
const after = new Set(args.after);
|
|
969
|
+
const marked = (row) => row !== undefined && wrunRowLaneRowMarkedPartial(row);
|
|
970
|
+
const asked = args.window.barOpens.filter((stampMs) => {
|
|
971
|
+
const { fromMs } = wrunHostBarSpanOf(stampMs, args.window.intervalMs, args.sessionGrid);
|
|
972
|
+
return !before.has(stampMs) && args.asks.some((ask) => fromMs >= ask.fromMs && fromMs < ask.toMs);
|
|
973
|
+
});
|
|
974
|
+
const isCut = (stampMs) => after.has(stampMs) || (args.foldPartial && marked(args.byBar.get(stampMs)));
|
|
975
|
+
let keptFromTs;
|
|
976
|
+
for (let at = asked.length - 1; at >= 0; at -= 1) {
|
|
977
|
+
if (isCut(asked[at])) {
|
|
978
|
+
if (keptFromTs !== undefined)
|
|
979
|
+
break;
|
|
980
|
+
continue;
|
|
981
|
+
}
|
|
982
|
+
keptFromTs = asked[at];
|
|
983
|
+
}
|
|
984
|
+
const cutBars = asked.filter(isCut).length;
|
|
985
|
+
return {
|
|
986
|
+
laneKey: args.laneKey,
|
|
987
|
+
keptBars: asked.length - cutBars,
|
|
988
|
+
cutBars,
|
|
989
|
+
...(keptFromTs !== undefined ? { keptFromTs } : {}),
|
|
990
|
+
maxRows: wrunRowLaneMaxRows({ cellsPerRow: args.width }),
|
|
991
|
+
budget: 'download',
|
|
992
|
+
spentBytes: Math.round(args.spentBytes),
|
|
993
|
+
shareBytes: Math.round(args.shareBytes),
|
|
994
|
+
};
|
|
460
995
|
}
|
|
461
996
|
/**
|
|
462
997
|
* Where a kit fold page carrying the next bar's strikes is read to (the paging seam, OPTLOAD G5): through the end of the
|
|
@@ -595,6 +1130,129 @@ export function wrunRowLaneAsksWithinRowBudget(plan, window, budget, acquisition
|
|
|
595
1130
|
partialBars: [...new Set([...plan.partialBars, ...cut])].sort((a, b) => a - b),
|
|
596
1131
|
};
|
|
597
1132
|
}
|
|
1133
|
+
/**
|
|
1134
|
+
* What row-budget lanes' reads measured (`wrunRowLaneProjectedBarRows`): the bars a read landed whole and the tuples
|
|
1135
|
+
* they held, by lane, acquisition, tier and bar width, a running sum weighing at most `MEASURED_BARS` bars, so a newer
|
|
1136
|
+
* read moves it and a short one (a live reconcile's newest bars) never replaces a whole window's. In memory, the
|
|
1137
|
+
* newest `MEASURED_KEPT` kept.
|
|
1138
|
+
*/
|
|
1139
|
+
const measuredBars = new Map();
|
|
1140
|
+
const MEASURED_KEPT = 64;
|
|
1141
|
+
const MEASURED_BARS = 500;
|
|
1142
|
+
/** The ask's fields that never change what a bar holds: its tier (keyed apart), the routed tier and plane, the market
|
|
1143
|
+
* placeholders a recorded acquisition carries, today's first instant and the instance's own bound. */
|
|
1144
|
+
const MEASURED_SKIP = new Set([
|
|
1145
|
+
WRUN_ROW_LANE_TIER_FIELD,
|
|
1146
|
+
'servedTier',
|
|
1147
|
+
'wrunPlane',
|
|
1148
|
+
'symbol',
|
|
1149
|
+
'exchange',
|
|
1150
|
+
WRUN_OPTION_FLOW_TODAY_FIELD,
|
|
1151
|
+
'maxCells',
|
|
1152
|
+
]);
|
|
1153
|
+
function measuredKeyOf(laneKey, extras, tierKey, widthMs) {
|
|
1154
|
+
const fields = {};
|
|
1155
|
+
for (const [key, value] of Object.entries(extras))
|
|
1156
|
+
if (!MEASURED_SKIP.has(key))
|
|
1157
|
+
fields[key] = value;
|
|
1158
|
+
return `${laneKey}|${tierKey ?? ''}|${widthMs}|${stableJson(fields)}`;
|
|
1159
|
+
}
|
|
1160
|
+
/** Test seam: forget every measurement. */
|
|
1161
|
+
export function __resetWrunRowLaneMeasurementsForTests() {
|
|
1162
|
+
measuredBars.clear();
|
|
1163
|
+
downloadDensity.clear();
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* The rows a row-budget lane's next ask projects for one bar: its own projection (`rowBudget.barRows`: a proxy, the
|
|
1167
|
+
* strike flow's SPY bars at one width, the contract flow's SPY session at each tier) raised to the tuples a bar of the
|
|
1168
|
+
* same lane, acquisition, tier and width held in the reads that landed before, never past the instance's `maxCells`
|
|
1169
|
+
* (the most tuples a bar of it is read with, which option_strike_flow's facets name); a bar its projection reads
|
|
1170
|
+
* nothing for (before today under `history` "today") stays at nothing. A market busier than its proxy then reads fewer
|
|
1171
|
+
* bars on its next ask instead of an answer past the source answer budget, and a quieter one keeps the proxy. A
|
|
1172
|
+
* contract flow bar's measured tuples (its contracts) are no more than the raw rows it reads, so they only ever lift a
|
|
1173
|
+
* projection that was under them.
|
|
1174
|
+
*/
|
|
1175
|
+
export function wrunRowLaneProjectedBarRows(lane, extras, bar, nowMs, acquisition = extras) {
|
|
1176
|
+
const projected = lane.rowBudget?.barRows(bar, nowMs, acquisition) ?? 0;
|
|
1177
|
+
if (!(projected > 0))
|
|
1178
|
+
return projected;
|
|
1179
|
+
const held = measuredBars.get(measuredKeyOf(lane.laneKey, extras, bar.tier?.key, bar.endMs - bar.openMs));
|
|
1180
|
+
const measured = held === undefined ? 0 : Math.ceil(held.tuples / held.bars);
|
|
1181
|
+
const most = extras.maxCells;
|
|
1182
|
+
return Math.min(Math.max(projected, measured), typeof most === 'number' && most >= 1 ? most : Infinity);
|
|
1183
|
+
}
|
|
1184
|
+
/** A lane's row budget projecting each bar through `wrunRowLaneProjectedBarRows` for one read's `extras`. */
|
|
1185
|
+
function wrunRowLaneMeasuredBudget(lane, budget, extras) {
|
|
1186
|
+
return {
|
|
1187
|
+
cellsPerRow: budget.cellsPerRow,
|
|
1188
|
+
barRows: (bar, nowMs, acquisition) => wrunRowLaneProjectedBarRows(lane, extras, bar, nowMs, acquisition),
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* One read's landed bars into the measurements (`wrunRowLaneProjectedBarRows`): every bar it holds whole, closed by the
|
|
1193
|
+
* clock, none of the plan's partial bars and no tuple marked partial (a bar still forming, or served in part, holds a
|
|
1194
|
+
* floor of its tuples), its tuples counted under the tier its ask read and its width.
|
|
1195
|
+
*/
|
|
1196
|
+
function noteWrunRowLaneMeasured(laneKey, extras, asks, landed, partialBars, window, sessionGrid, presentMask) {
|
|
1197
|
+
const partial = new Set(partialBars);
|
|
1198
|
+
const marked = (tuple) => Array.isArray(tuple) && wrunPresentIsPartial(Number(tuple[tuple.length - 1]));
|
|
1199
|
+
const reads = new Map();
|
|
1200
|
+
for (const [stampMs, row] of landed) {
|
|
1201
|
+
const span = wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
|
|
1202
|
+
const tuples = row.slice(1);
|
|
1203
|
+
if (partial.has(stampMs) || span.toMs > window.nowMs || tuples.length === 0)
|
|
1204
|
+
continue;
|
|
1205
|
+
if (presentMask !== false && tuples.some(marked))
|
|
1206
|
+
continue;
|
|
1207
|
+
const tier = asks.find((ask) => span.fromMs >= ask.fromMs && span.fromMs < ask.toMs)?.tier;
|
|
1208
|
+
const key = measuredKeyOf(laneKey, extras, tier?.key, span.toMs - span.fromMs);
|
|
1209
|
+
const read = reads.get(key) ?? { bars: 0, tuples: 0 };
|
|
1210
|
+
reads.set(key, { bars: read.bars + 1, tuples: read.tuples + tuples.length });
|
|
1211
|
+
}
|
|
1212
|
+
for (const [key, read] of reads) {
|
|
1213
|
+
const held = measuredBars.get(key) ?? { bars: 0, tuples: 0 };
|
|
1214
|
+
const bars = held.bars + read.bars;
|
|
1215
|
+
const weight = Math.min(1, MEASURED_BARS / bars);
|
|
1216
|
+
measuredBars.delete(key);
|
|
1217
|
+
measuredBars.set(key, { bars: bars * weight, tuples: (held.tuples + read.tuples) * weight });
|
|
1218
|
+
while (measuredBars.size > MEASURED_KEPT)
|
|
1219
|
+
measuredBars.delete(measuredBars.keys().next().value);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
/** The cut a row budget made (`wrunRowLaneAsksWithinRowBudget` over `before`, answering `after`): the asked bars it
|
|
1223
|
+
* reads whole and the bars it alone left partial. */
|
|
1224
|
+
function wrunRowLaneBudgetCutOf(laneKey, budget, before, after, window, sessionGrid) {
|
|
1225
|
+
const partialBefore = new Set(before.partialBars);
|
|
1226
|
+
const kept = window.barOpens.filter((stampMs) => {
|
|
1227
|
+
const { fromMs } = wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
|
|
1228
|
+
return after.asks.some((ask) => fromMs >= ask.fromMs && fromMs < ask.toMs);
|
|
1229
|
+
});
|
|
1230
|
+
return {
|
|
1231
|
+
laneKey,
|
|
1232
|
+
keptBars: kept.length,
|
|
1233
|
+
cutBars: after.partialBars.filter((stampMs) => !partialBefore.has(stampMs)).length,
|
|
1234
|
+
...(kept.length > 0 ? { keptFromTs: kept[0] } : {}),
|
|
1235
|
+
maxRows: wrunRowLaneMaxRows(budget),
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
/** A budget cut to the debug ring and the caller. Both are advisory: a host with no ring, or a caller whose note
|
|
1239
|
+
* fails, costs the record, never the read. */
|
|
1240
|
+
function reportWrunRowLaneBudgetCut(cut, intervalMs, onBudgetCut) {
|
|
1241
|
+
try {
|
|
1242
|
+
const { diagnostics } = wrunChartHostEnv();
|
|
1243
|
+
if (diagnostics.debugEnabled())
|
|
1244
|
+
diagnostics.debug('wrun-row-lane-budget-cut', { ...cut, intervalMs });
|
|
1245
|
+
}
|
|
1246
|
+
catch {
|
|
1247
|
+
// No ring in this host.
|
|
1248
|
+
}
|
|
1249
|
+
try {
|
|
1250
|
+
onBudgetCut?.(cut);
|
|
1251
|
+
}
|
|
1252
|
+
catch {
|
|
1253
|
+
// The note is lost; the read goes on.
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
598
1256
|
function finiteOrUndefined(value) {
|
|
599
1257
|
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
600
1258
|
}
|