@orangecharts/wrun-chart-host 0.5.0 → 0.7.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 +17 -8
- package/dist/constants/feature-flags.constants.js +7 -2
- package/dist/constants/marketCapabilities.constants.d.ts +5 -0
- package/dist/constants/marketCapabilities.constants.js +16 -0
- package/dist/host-env.d.ts +3 -19
- package/dist/host-ports.types.d.ts +36 -17
- package/dist/index.d.ts +12 -1
- package/dist/index.js +12 -1
- package/dist/indicators/controls/tpo-session.util.js +42 -18
- package/dist/interfaces/wrun-runtime.interface.d.ts +88 -13
- package/dist/interfaces/wrun-runtime.interface.js +17 -3
- package/dist/market-data/billing.interface.d.ts +2 -1
- package/dist/settings-templates/indicator-fields.js +10 -0
- package/dist/utility/chart/chart-mount-epoch.util.d.ts +12 -0
- package/dist/utility/chart/chart-mount-epoch.util.js +32 -0
- package/dist/utility/chart/crypto-index.leaf.d.ts +16 -0
- package/dist/utility/chart/crypto-index.leaf.js +19 -0
- package/dist/utility/chart/index-mode-admission.util.js +9 -1
- package/dist/utility/chart/index-mode.util.d.ts +11 -5
- package/dist/utility/chart/index-mode.util.js +22 -10
- package/dist/utility/chart/kscript-source-answer-budget.leaf.d.ts +36 -0
- package/dist/utility/chart/kscript-source-answer-budget.leaf.js +39 -0
- package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +38 -1
- package/dist/utility/chart/kscript-source-degrade.leaf.js +39 -1
- package/dist/utility/chart/live-bucket.util.d.ts +2 -1
- package/dist/utility/chart/live-bucket.util.js +47 -15
- package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +15 -1
- package/dist/utility/chart/local-kscript-warmup-depth.util.js +9 -0
- package/dist/utility/chart/market-session-schedule.util.d.ts +3 -1
- package/dist/utility/chart/market-session-schedule.util.js +24 -2
- package/dist/utility/chart/marketKind.util.d.ts +12 -7
- package/dist/utility/chart/marketKind.util.js +15 -5
- package/dist/utility/chart/ny-calendar.util.d.ts +104 -0
- package/dist/utility/chart/ny-calendar.util.js +346 -0
- package/dist/utility/chart/om-panel.util.d.ts +14 -2
- package/dist/utility/chart/om-panel.util.js +108 -40
- package/dist/utility/chart/rth-session.util.d.ts +10 -7
- package/dist/utility/chart/rth-session.util.js +17 -22
- package/dist/utility/chart/trading-day.util.js +90 -18
- package/dist/utility/chart/us-equities-session.util.js +20 -67
- package/dist/utility/chart/wrun-bar-session-facts.util.js +14 -1
- package/dist/utility/common/time.util.d.ts +7 -1
- package/dist/utility/common/time.util.js +11 -41
- package/dist/utility/number-format.util.d.ts +17 -7
- package/dist/utility/number-format.util.js +18 -8
- package/dist/utility/options/option-symbol.util.js +13 -2
- package/dist/utility/symbol-selection/contract-expiry.util.js +9 -1
- package/dist/utility/watchlist/import/import-request.leaf.d.ts +4 -1
- package/dist/utility/watchlist/import/import-request.leaf.js +5 -2
- package/dist/utility/watchlist/import/tradingview-symbols.leaf.d.ts +25 -4
- package/dist/utility/watchlist/import/tradingview-symbols.leaf.js +62 -4
- package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +19 -0
- package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +57 -0
- package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +23 -0
- package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +90 -0
- package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.d.ts +39 -0
- package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.js +60 -0
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +77 -0
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +195 -0
- package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +56 -0
- package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +70 -0
- package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +53 -0
- package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +239 -0
- package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +16 -0
- package/dist/utility/wrun/sources/lanes/option_stats_10m.js +14 -0
- package/dist/utility/wrun/sources/lanes/options_flow.d.ts +43 -18
- package/dist/utility/wrun/sources/lanes/options_flow.js +209 -72
- package/dist/utility/wrun/sources/lanes/token_supply.js +5 -31
- package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +3 -18
- package/dist/utility/wrun/sources/opra-option-lanes.util.js +12 -57
- package/dist/utility/wrun/sources/row-lane-registry.d.ts +1 -1
- package/dist/utility/wrun/sources/row-lane-registry.js +22 -8
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +61 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +103 -8
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +5 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +24 -12
- package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +55 -0
- package/dist/utility/wrun/sources/row-lanes/option_prints.js +95 -18
- package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +15 -1
- package/dist/utility/wrun/sources/row-lanes/option_strikes.js +23 -8
- package/dist/utility/wrun/sources/row-lanes/option_surface.js +11 -11
- package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +14 -2
- package/dist/utility/wrun/sources/wrun-poll-lane.types.js +6 -3
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +43 -8
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +77 -11
- package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +31 -16
- package/dist/utility/wrun/sources/wrun-row-lane.types.js +2 -0
- package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +52 -12
- package/dist/utility/wrun/sources/wrun-row-lanes.util.js +110 -46
- package/dist/utility/wrun/wrun-bar-count.util.d.ts +17 -6
- package/dist/utility/wrun/wrun-bar-count.util.js +27 -12
- package/dist/utility/wrun/wrun-browser-sources.leaf.d.ts +10 -0
- package/dist/utility/wrun/wrun-browser-sources.leaf.js +12 -0
- package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +3 -3
- package/dist/utility/wrun/wrun-coin-lane-live.util.js +53 -18
- package/dist/utility/wrun/wrun-color-settings.util.d.ts +6 -0
- package/dist/utility/wrun/wrun-color-settings.util.js +45 -0
- package/dist/utility/wrun/wrun-draft-overlay.util.js +14 -8
- package/dist/utility/wrun/wrun-failure-cause.d.ts +1 -1
- package/dist/utility/wrun/wrun-failure-cause.js +14 -0
- package/dist/utility/wrun/wrun-frames.js +6 -2
- package/dist/utility/wrun/wrun-host.service.d.ts +131 -59
- package/dist/utility/wrun/wrun-host.service.js +391 -194
- package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +1 -1
- package/dist/utility/wrun/wrun-hosted-wire-caps.js +2 -0
- package/dist/utility/wrun/wrun-hover.util.d.ts +3 -0
- package/dist/utility/wrun/wrun-hover.util.js +25 -4
- package/dist/utility/wrun/wrun-input-requirements.leaf.js +7 -4
- package/dist/utility/wrun/wrun-kit-run-tables.util.d.ts +24 -0
- package/dist/utility/wrun/wrun-kit-run-tables.util.js +87 -0
- package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +2 -1
- package/dist/utility/wrun/wrun-live-tick.util.d.ts +8 -2
- package/dist/utility/wrun/wrun-live-tick.util.js +35 -16
- package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +40 -13
- package/dist/utility/wrun/wrun-opra-flow.leaf.js +39 -12
- package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +70 -21
- package/dist/utility/wrun/wrun-option-contract-flow.util.js +257 -112
- package/dist/utility/wrun/wrun-option-prints.util.d.ts +62 -22
- package/dist/utility/wrun/wrun-option-prints.util.js +148 -46
- package/dist/utility/wrun/wrun-option-views.util.d.ts +262 -0
- package/dist/utility/wrun/wrun-option-views.util.js +356 -0
- package/dist/utility/wrun/wrun-options-chain.util.d.ts +23 -2
- package/dist/utility/wrun/wrun-options-chain.util.js +37 -3
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +20 -5
- package/dist/utility/wrun/wrun-overlay-drivers.util.js +32 -7
- package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +9 -3
- package/dist/utility/wrun/wrun-overlay-recovery.util.js +146 -18
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +52 -8
- package/dist/utility/wrun/wrun-overlay-run.util.js +816 -243
- package/dist/utility/wrun/wrun-pack.util.d.ts +2 -1
- package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +5 -0
- package/dist/utility/wrun/wrun-pin-spelling.util.js +28 -12
- package/dist/utility/wrun/wrun-pin-venues.util.js +4 -6
- package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +1 -1
- package/dist/utility/wrun/wrun-prefix-cohort.util.js +1 -1
- package/dist/utility/wrun/wrun-present-bits.util.d.ts +9 -0
- package/dist/utility/wrun/wrun-present-bits.util.js +39 -0
- package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +3 -2
- package/dist/utility/wrun/wrun-refusal-surface.util.js +5 -4
- package/dist/utility/wrun/wrun-refusal.util.d.ts +66 -6
- package/dist/utility/wrun/wrun-refusal.util.js +335 -40
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
- package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +2 -2
- package/dist/utility/wrun/wrun-sha256.leaf.d.ts +13 -0
- package/dist/utility/wrun/wrun-sha256.leaf.js +84 -0
- package/dist/utility/wrun/wrun-source-rows.util.js +11 -0
- package/dist/utility/wrun/wrun-tier-grid.util.d.ts +28 -3
- package/dist/utility/wrun/wrun-tier-grid.util.js +79 -19
- package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +14 -3
- package/dist/utility/wrun/wrun-transient-rerun.util.js +33 -8
- package/dist/workers/wrun/wrun-abi-host.d.ts +15 -2
- package/dist/workers/wrun/wrun-abi-host.js +31 -12
- package/dist/workers/wrun/wrun-engine-handler.d.ts +11 -28
- package/dist/workers/wrun/wrun-engine-handler.js +181 -12
- package/package.json +5 -5
- package/dist/utility/wrun/wrun-opra-underlying.util.d.ts +0 -12
- package/dist/utility/wrun/wrun-opra-underlying.util.js +0 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reads a run left out at a lane's degrade budget, which the source ladder joins or adopts instead of asking the
|
|
3
|
+
* same window again (run scheduling, 2026-10-20).
|
|
4
|
+
*
|
|
5
|
+
* The degrade budget (kscript-source-degrade.leaf `resolveSecondarySourceBudgetMs`: 10 s plus 2.5 s per 1,000 rows)
|
|
6
|
+
* stays the authority for the chip: at it the run marks the lane degraded and paints without it. The lane's read is
|
|
7
|
+
* abandoned, never aborted, so it is still on the wire. The ladder's rung used to run the overlay again 15 s later,
|
|
8
|
+
* and its lane asked the same window a second time beside the first (Options Market Stats and Market Share at 1h,
|
|
9
|
+
* 2026-10-20: painted empty at 14 to 15 s, painted with data at 31 s). Now:
|
|
10
|
+
*
|
|
11
|
+
* - the run notes each read it abandoned (`noteWrunLateRead`), by overlay and lane, with the identity of the ask (the
|
|
12
|
+
* run's window, market, chart data generation and settings revision) and a reader of the acquisition the run
|
|
13
|
+
* recorded for the lane (the payload its live session asks the lane again with);
|
|
14
|
+
* - the dispatch of a later run that asks the same lane with the same identity takes it (`takeWrunLateRead`): a read
|
|
15
|
+
* still out is JOINED (the lane waits on it under its own budget, and no second ask leaves), a read that answered
|
|
16
|
+
* with rows is ADOPTED (its rows, no ask); a failed read, or one asked another way, is no read and the lane asks;
|
|
17
|
+
* - the source ladder (wrun-overlay-recovery.util) fires its rung the moment the reads it waits on answer with rows,
|
|
18
|
+
* and a rung that comes due while one is still out waits for it instead of asking again (`onWrunLateReadSettled`).
|
|
19
|
+
*
|
|
20
|
+
* A read that never answers is bounded by the fetch's own deadline (wrun-deadline.util
|
|
21
|
+
* `WRUN_SOURCE_FETCH_DEADLINE_MS`, 45 s from its send) and by the transport's watchdog: it then fails, leaves this
|
|
22
|
+
* registry, and the next rung asks the wire. The degrade budget is a paint deadline, never a stall verdict: those two
|
|
23
|
+
* are. A read is taken once (a run that joined it notes it again if its own budget runs out first), a failed read and
|
|
24
|
+
* an answered one past `WRUN_LATE_READ_ADOPT_MS` are dropped, and every read of an overlay goes with it (teardown,
|
|
25
|
+
* suspend: `forgetWrunLateReads`). Pure module state: nothing here reads the host env.
|
|
26
|
+
*/
|
|
27
|
+
/** How long an answered read stays adoptable: the source-row cache's freshness window (25 s), so an adopted read is
|
|
28
|
+
* never older than a row-cache hit would be. */
|
|
29
|
+
export const WRUN_LATE_READ_ADOPT_MS = 25_000;
|
|
30
|
+
/** The most reads the registry keeps across every overlay: the oldest noted goes first past it. An overlay's own reads
|
|
31
|
+
* are one per lane and leave with it (`forgetWrunLateReads` on its teardown); the cap bounds the rows held for an
|
|
32
|
+
* overlay no ladder ever watches. */
|
|
33
|
+
export const WRUN_LATE_READS_KEPT = 64;
|
|
34
|
+
const lateReads = new Map();
|
|
35
|
+
const settleListeners = new Map();
|
|
36
|
+
/** Every read in the order it was noted (entries a later note, a take or a forget already removed are skipped). */
|
|
37
|
+
let noteOrder = [];
|
|
38
|
+
/** Whether a noted read is still the registry's. */
|
|
39
|
+
function isKept(entry) {
|
|
40
|
+
return lateReads.get(entry.indicatorId)?.get(entry.lane) === entry.read;
|
|
41
|
+
}
|
|
42
|
+
/** Past `WRUN_LATE_READS_KEPT`, the oldest noted reads go first. */
|
|
43
|
+
function capWrunLateReads() {
|
|
44
|
+
noteOrder = noteOrder.filter(isKept);
|
|
45
|
+
while (noteOrder.length > WRUN_LATE_READS_KEPT) {
|
|
46
|
+
const oldest = noteOrder.shift();
|
|
47
|
+
if (oldest === undefined)
|
|
48
|
+
break;
|
|
49
|
+
const reads = lateReads.get(oldest.indicatorId);
|
|
50
|
+
reads?.delete(oldest.lane);
|
|
51
|
+
if (reads?.size === 0)
|
|
52
|
+
lateReads.delete(oldest.indicatorId);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function nowMs() {
|
|
56
|
+
return performance.now();
|
|
57
|
+
}
|
|
58
|
+
function notifySettled(indicatorId) {
|
|
59
|
+
for (const listener of [...(settleListeners.get(indicatorId) ?? [])])
|
|
60
|
+
listener();
|
|
61
|
+
}
|
|
62
|
+
/** Whether an answered read is past the adopt window (its rows are dropped, never adopted). */
|
|
63
|
+
function answeredTooLongAgo(read, now) {
|
|
64
|
+
return read.state === 'rows' && (read.answeredAt === undefined || now - read.answeredAt > WRUN_LATE_READ_ADOPT_MS);
|
|
65
|
+
}
|
|
66
|
+
/** Drop the overlay's answered reads past the adopt window: their rows are never held longer than a row-cache hit. */
|
|
67
|
+
function sweepWrunLateReads(indicatorId) {
|
|
68
|
+
const reads = lateReads.get(indicatorId);
|
|
69
|
+
if (reads === undefined)
|
|
70
|
+
return;
|
|
71
|
+
const now = nowMs();
|
|
72
|
+
for (const [lane, read] of reads)
|
|
73
|
+
if (answeredTooLongAgo(read, now))
|
|
74
|
+
reads.delete(lane);
|
|
75
|
+
if (reads.size === 0)
|
|
76
|
+
lateReads.delete(indicatorId);
|
|
77
|
+
}
|
|
78
|
+
/** Note a read the run left out at its lane's budget: the latest note of a lane replaces the one before it. */
|
|
79
|
+
export function noteWrunLateRead(note) {
|
|
80
|
+
sweepWrunLateReads(note.indicatorId);
|
|
81
|
+
let reads = lateReads.get(note.indicatorId);
|
|
82
|
+
if (reads === undefined) {
|
|
83
|
+
reads = new Map();
|
|
84
|
+
lateReads.set(note.indicatorId, reads);
|
|
85
|
+
}
|
|
86
|
+
const read = {
|
|
87
|
+
identity: note.identity,
|
|
88
|
+
answer: note.answer,
|
|
89
|
+
acquisition: note.acquisition ?? (() => undefined),
|
|
90
|
+
state: 'in-flight',
|
|
91
|
+
};
|
|
92
|
+
reads.delete(note.lane);
|
|
93
|
+
reads.set(note.lane, read);
|
|
94
|
+
noteOrder.push({ indicatorId: note.indicatorId, lane: note.lane, read });
|
|
95
|
+
capWrunLateReads();
|
|
96
|
+
const still = () => lateReads.get(note.indicatorId)?.get(note.lane) === read;
|
|
97
|
+
note.answer.then((rows) => {
|
|
98
|
+
read.state = 'rows';
|
|
99
|
+
read.rows = rows;
|
|
100
|
+
read.answeredAt = nowMs();
|
|
101
|
+
if (still())
|
|
102
|
+
notifySettled(note.indicatorId);
|
|
103
|
+
}, () => {
|
|
104
|
+
read.state = 'failed';
|
|
105
|
+
if (!still())
|
|
106
|
+
return;
|
|
107
|
+
lateReads.get(note.indicatorId)?.delete(note.lane);
|
|
108
|
+
notifySettled(note.indicatorId);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The read a run's dispatch joins or adopts for one lane: one with the same identity, still out (joined) or answered
|
|
113
|
+
* with rows inside the adopt window (adopted). Taken once: the entry leaves the registry either way. A read asked
|
|
114
|
+
* another way, failed or answered too long ago is dropped and answers undefined (the lane asks).
|
|
115
|
+
*/
|
|
116
|
+
export function takeWrunLateRead(indicatorId, lane, identity) {
|
|
117
|
+
const reads = lateReads.get(indicatorId);
|
|
118
|
+
const read = reads?.get(lane);
|
|
119
|
+
if (reads === undefined || read === undefined)
|
|
120
|
+
return undefined;
|
|
121
|
+
reads.delete(lane);
|
|
122
|
+
if (reads.size === 0)
|
|
123
|
+
lateReads.delete(indicatorId);
|
|
124
|
+
if (read.identity !== identity || read.state === 'failed')
|
|
125
|
+
return undefined;
|
|
126
|
+
if (read.state === 'in-flight')
|
|
127
|
+
return { kind: 'joined', rows: read.answer, acquisition: read.acquisition };
|
|
128
|
+
if (answeredTooLongAgo(read, nowMs()))
|
|
129
|
+
return undefined;
|
|
130
|
+
return { kind: 'adopted', rows: Promise.resolve(read.rows ?? []), acquisition: read.acquisition };
|
|
131
|
+
}
|
|
132
|
+
/** The lanes of `lanes` whose abandoned read is still out. */
|
|
133
|
+
export function wrunLateReadsOut(indicatorId, lanes) {
|
|
134
|
+
const reads = lateReads.get(indicatorId);
|
|
135
|
+
if (reads === undefined)
|
|
136
|
+
return [];
|
|
137
|
+
return [...lanes].filter((lane) => reads.get(lane)?.state === 'in-flight');
|
|
138
|
+
}
|
|
139
|
+
/** The lanes of `lanes` whose abandoned read answered with rows (adoptable now). */
|
|
140
|
+
export function wrunLateReadsAnswered(indicatorId, lanes) {
|
|
141
|
+
const reads = lateReads.get(indicatorId);
|
|
142
|
+
if (reads === undefined)
|
|
143
|
+
return [];
|
|
144
|
+
const now = nowMs();
|
|
145
|
+
return [...lanes].filter((lane) => {
|
|
146
|
+
const read = reads.get(lane);
|
|
147
|
+
return read?.state === 'rows' && !answeredTooLongAgo(read, now);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/** Called on every settle of one of the overlay's noted reads (answered or failed); answers the unsubscribe. */
|
|
151
|
+
export function onWrunLateReadSettled(indicatorId, listener) {
|
|
152
|
+
let listeners = settleListeners.get(indicatorId);
|
|
153
|
+
if (listeners === undefined) {
|
|
154
|
+
listeners = new Set();
|
|
155
|
+
settleListeners.set(indicatorId, listeners);
|
|
156
|
+
}
|
|
157
|
+
listeners.add(listener);
|
|
158
|
+
return () => {
|
|
159
|
+
const known = settleListeners.get(indicatorId);
|
|
160
|
+
known?.delete(listener);
|
|
161
|
+
if (known?.size === 0)
|
|
162
|
+
settleListeners.delete(indicatorId);
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Every read the overlay left out, and every listener on them, go with it (data-loading rule 3). */
|
|
166
|
+
export function forgetWrunLateReads(indicatorId) {
|
|
167
|
+
lateReads.delete(indicatorId);
|
|
168
|
+
settleListeners.delete(indicatorId);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* A run's lane thunks with every lane joining or adopting its late read first (`take`, the run's own lookup by its
|
|
172
|
+
* ask identity): a lane with one never runs its thunk, so no second ask leaves. The run's shape: the builtin lanes by
|
|
173
|
+
* name (a function or undefined) and the lists of `[lane id, thunk]` pairs (trades legs, poll lanes, row lanes);
|
|
174
|
+
* everything else is returned as it is.
|
|
175
|
+
*/
|
|
176
|
+
export function wrunJoinLateReads(thunks, take) {
|
|
177
|
+
const joined = (lane, run) => (abandoned) => take(lane) ?? run(abandoned);
|
|
178
|
+
const out = { ...thunks };
|
|
179
|
+
for (const [key, value] of Object.entries(out)) {
|
|
180
|
+
if (typeof value === 'function') {
|
|
181
|
+
out[key] = joined(key, value);
|
|
182
|
+
}
|
|
183
|
+
else if (Array.isArray(value)) {
|
|
184
|
+
out[key] = value.map((pair) => Array.isArray(pair) && typeof pair[0] === 'string' && typeof pair[1] === 'function'
|
|
185
|
+
? [pair[0], joined(pair[0], pair[1])]
|
|
186
|
+
: pair);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return out;
|
|
190
|
+
}
|
|
191
|
+
export function __resetWrunLateReadsForTests() {
|
|
192
|
+
lateReads.clear();
|
|
193
|
+
settleListeners.clear();
|
|
194
|
+
noteOrder = [];
|
|
195
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A run's candle ask for the chart's OWN series at the chart's OWN interval answers from the chart's rows, with no
|
|
3
|
+
* request (run scheduling, 2026-10-20).
|
|
4
|
+
*
|
|
5
|
+
* Why: the chart's main series IS that series: the candle lane fetched it from the same gateway series, the live
|
|
6
|
+
* feed writes the forming bar into it, and the polling lane corrects its tail. A wrun lane asked it again: a candles
|
|
7
|
+
* stream or a leg at the chart's interval on the chart's market, the forming pre-roll over bars a clamped window
|
|
8
|
+
* holds below its head. The kScript lane serves its own `ohlcv` source from the main rows inside the chart's fetch
|
|
9
|
+
* (kscript-source-rows-main-serve.util), but only on a timestamp-mode chart; every US stock and ETF chart (the
|
|
10
|
+
* options indicators' charts) is index mode, so the wrun ask went to the wire.
|
|
11
|
+
*
|
|
12
|
+
* The rule (`serveWrunOwnCandles`), judged before the ask leaves:
|
|
13
|
+
* - the ask: the candle lane (`ohlcv`), naming no other market (no payload extras but the chart's own exchange and
|
|
14
|
+
* symbol), at the chart's interval (no interval option, or the chart's), never a replay run's (its window reaches
|
|
15
|
+
* the replay's forward runway, past the rows the chart shows);
|
|
16
|
+
* - the window `[fromTs, toTs]` (the end an inclusive bar, as the chart's fetch reads it) held whole by the chart's
|
|
17
|
+
* bars (`held`: the chart's rows, copied, so the lane's buffer never shares the forming bar the live feed rewrites);
|
|
18
|
+
* anything else is null and the wire answers the window whole, exactly as before: a window opening before the
|
|
19
|
+
* chart's first bar (the chart holds no part older than its first bar, and the ask's shape stays the one the fetch
|
|
20
|
+
* caches and coalesces by), one reaching past the chart's newest bar, one the chart holds no bar of.
|
|
21
|
+
* - the rows: every chart row inside the window with a finite close (a missing bar the chart draws as a gap is no
|
|
22
|
+
* candle the wire answers).
|
|
23
|
+
*
|
|
24
|
+
* Pure: the caller reads the chart's rows and owns the ask (wrun-overlay-run.util `fetchLane`, the one door every
|
|
25
|
+
* lane of a run asks through). The call-site census (tests/utility/wrun/run-schedule/wrun-own-candles.census.spec.ts)
|
|
26
|
+
* fails a new source fetch door in the package that this rule does not stand in front of.
|
|
27
|
+
*/
|
|
28
|
+
export interface WrunOwnCandlesAsk {
|
|
29
|
+
/** The fetch type of the ask (`ohlcv` is the candle lane). */
|
|
30
|
+
type: string;
|
|
31
|
+
/** The payload extras of the ask beyond the current-market placeholders (a pinned market's exchange and symbol). */
|
|
32
|
+
payloadExtras?: Readonly<Record<string, unknown>>;
|
|
33
|
+
/** The interval the ask rides (undefined: the chart's own). */
|
|
34
|
+
interval?: string;
|
|
35
|
+
/** A replay run's ask: never the chart's rows. */
|
|
36
|
+
replay: boolean;
|
|
37
|
+
/** The ask's window: its first bar's open and its last bar's open (inclusive), in ms. */
|
|
38
|
+
fromTs: number;
|
|
39
|
+
toTs: number;
|
|
40
|
+
chart: {
|
|
41
|
+
exchange?: string;
|
|
42
|
+
symbol?: string;
|
|
43
|
+
/** The chart's interval key (`1h`). */
|
|
44
|
+
interval: string;
|
|
45
|
+
intervalMs: number;
|
|
46
|
+
/** The chart's loaded candle rows, ascending (`[ts, open, high, low, close, volume]`). */
|
|
47
|
+
rows: ReadonlyArray<ArrayLike<number>>;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Every bar of the window, from the chart's rows; null: the wire answers the window. */
|
|
51
|
+
export type WrunOwnCandlesServe = {
|
|
52
|
+
kind: 'held';
|
|
53
|
+
rows: number[][];
|
|
54
|
+
} | null;
|
|
55
|
+
/** The chart's own candles for an ask of the chart's series at its interval (the module note), or null. */
|
|
56
|
+
export declare function serveWrunOwnCandles(ask: WrunOwnCandlesAsk): WrunOwnCandlesServe;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A run's candle ask for the chart's OWN series at the chart's OWN interval answers from the chart's rows, with no
|
|
3
|
+
* request (run scheduling, 2026-10-20).
|
|
4
|
+
*
|
|
5
|
+
* Why: the chart's main series IS that series: the candle lane fetched it from the same gateway series, the live
|
|
6
|
+
* feed writes the forming bar into it, and the polling lane corrects its tail. A wrun lane asked it again: a candles
|
|
7
|
+
* stream or a leg at the chart's interval on the chart's market, the forming pre-roll over bars a clamped window
|
|
8
|
+
* holds below its head. The kScript lane serves its own `ohlcv` source from the main rows inside the chart's fetch
|
|
9
|
+
* (kscript-source-rows-main-serve.util), but only on a timestamp-mode chart; every US stock and ETF chart (the
|
|
10
|
+
* options indicators' charts) is index mode, so the wrun ask went to the wire.
|
|
11
|
+
*
|
|
12
|
+
* The rule (`serveWrunOwnCandles`), judged before the ask leaves:
|
|
13
|
+
* - the ask: the candle lane (`ohlcv`), naming no other market (no payload extras but the chart's own exchange and
|
|
14
|
+
* symbol), at the chart's interval (no interval option, or the chart's), never a replay run's (its window reaches
|
|
15
|
+
* the replay's forward runway, past the rows the chart shows);
|
|
16
|
+
* - the window `[fromTs, toTs]` (the end an inclusive bar, as the chart's fetch reads it) held whole by the chart's
|
|
17
|
+
* bars (`held`: the chart's rows, copied, so the lane's buffer never shares the forming bar the live feed rewrites);
|
|
18
|
+
* anything else is null and the wire answers the window whole, exactly as before: a window opening before the
|
|
19
|
+
* chart's first bar (the chart holds no part older than its first bar, and the ask's shape stays the one the fetch
|
|
20
|
+
* caches and coalesces by), one reaching past the chart's newest bar, one the chart holds no bar of.
|
|
21
|
+
* - the rows: every chart row inside the window with a finite close (a missing bar the chart draws as a gap is no
|
|
22
|
+
* candle the wire answers).
|
|
23
|
+
*
|
|
24
|
+
* Pure: the caller reads the chart's rows and owns the ask (wrun-overlay-run.util `fetchLane`, the one door every
|
|
25
|
+
* lane of a run asks through). The call-site census (tests/utility/wrun/run-schedule/wrun-own-candles.census.spec.ts)
|
|
26
|
+
* fails a new source fetch door in the package that this rule does not stand in front of.
|
|
27
|
+
*/
|
|
28
|
+
/** Whether an ask names the chart's own market: no market extras, or exactly the chart's exchange and symbol. */
|
|
29
|
+
function asksChartMarket(ask) {
|
|
30
|
+
const extras = ask.payloadExtras;
|
|
31
|
+
if (extras === undefined)
|
|
32
|
+
return true;
|
|
33
|
+
for (const [key, value] of Object.entries(extras)) {
|
|
34
|
+
if (value === undefined)
|
|
35
|
+
continue;
|
|
36
|
+
if (key === 'exchange' && value === ask.chart.exchange)
|
|
37
|
+
continue;
|
|
38
|
+
if (key === 'symbol' && value === ask.chart.symbol)
|
|
39
|
+
continue;
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
/** The chart's own candles for an ask of the chart's series at its interval (the module note), or null. */
|
|
45
|
+
export function serveWrunOwnCandles(ask) {
|
|
46
|
+
if (ask.type !== 'ohlcv' || ask.replay)
|
|
47
|
+
return null;
|
|
48
|
+
if (ask.interval !== undefined && ask.interval !== ask.chart.interval)
|
|
49
|
+
return null;
|
|
50
|
+
if (!asksChartMarket(ask))
|
|
51
|
+
return null;
|
|
52
|
+
const { rows, intervalMs } = ask.chart;
|
|
53
|
+
if (rows.length === 0 || !(intervalMs > 0) || !(ask.toTs >= ask.fromTs))
|
|
54
|
+
return null;
|
|
55
|
+
const firstTs = Number(rows[0][0]);
|
|
56
|
+
const lastTs = Number(rows[rows.length - 1][0]);
|
|
57
|
+
// Older than the chart's first bar, or past its newest one: not the chart's to answer.
|
|
58
|
+
if (!(firstTs <= ask.fromTs) || !(ask.toTs < lastTs + intervalMs))
|
|
59
|
+
return null;
|
|
60
|
+
const held = [];
|
|
61
|
+
for (const row of rows) {
|
|
62
|
+
const ts = Number(row[0]);
|
|
63
|
+
if (ts < ask.fromTs || ts > ask.toTs)
|
|
64
|
+
continue;
|
|
65
|
+
if (!Number.isFinite(Number(row[4])))
|
|
66
|
+
continue;
|
|
67
|
+
held.push(Array.from(row));
|
|
68
|
+
}
|
|
69
|
+
return held.length > 0 ? { kind: 'held', rows: held } : null;
|
|
70
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { WrunOverlayLiveContext } from '../wrun-overlay-drivers.util.js';
|
|
2
|
+
import type { WrunChartSourceRows } from '../wrun-source-rows.util.js';
|
|
3
|
+
import type { WrunPollLaneInstance } from '../sources/wrun-poll-lane.types.js';
|
|
4
|
+
import type { WrunRowLaneInstance } from '../sources/wrun-row-lane.types.js';
|
|
5
|
+
import { type WrunPrefixLaneClause, type WrunPrefixLaneEvidence, type WrunPrefixLanePages, type WrunPrefixLanePlan, type WrunPrefixLaneSplice } from '../wrun-prefix-lanes.util.js';
|
|
6
|
+
/** The clause that refuses a session (`lanes:<clause>`): the base rule's, or `row-budget` (the module note). */
|
|
7
|
+
export type WrunPrefixFeedClause = WrunPrefixLaneClause | 'row-budget';
|
|
8
|
+
/** What a page asks again: the base rule's lanes, the daily poll lanes, the row lanes asked by host bar, and the row
|
|
9
|
+
* lanes read empty on the page (a `latest` landing). */
|
|
10
|
+
export interface WrunPrefixFeedPlan extends WrunPrefixLanePlan {
|
|
11
|
+
daily: WrunPollLaneInstance[];
|
|
12
|
+
rows: WrunRowLaneInstance[];
|
|
13
|
+
emptyRows: WrunRowLaneInstance[];
|
|
14
|
+
}
|
|
15
|
+
/** The fetch-key suffix of a row lane instance's page ask: `rows-<instance id>`. */
|
|
16
|
+
export declare function wrunPrefixRowSuffix(instance: Pick<WrunRowLaneInstance, 'key'>): string;
|
|
17
|
+
/** The prefix feed rule (the module note): the clause that refuses, or what a page asks. */
|
|
18
|
+
export declare function planWrunPrefixFeeds(context: WrunOverlayLiveContext): {
|
|
19
|
+
refused: WrunPrefixFeedClause;
|
|
20
|
+
} | {
|
|
21
|
+
plan: WrunPrefixFeedPlan;
|
|
22
|
+
};
|
|
23
|
+
/** The feed rule's clause for a session, null when it admits (`planWrunPrefixFeeds`). */
|
|
24
|
+
export declare function wrunPrefixFeedClauseOf(context: WrunOverlayLiveContext): WrunPrefixFeedClause | null;
|
|
25
|
+
/** Whether a planned window reaches the session's live row while a lane that lands there alone holds a snapshot: the
|
|
26
|
+
* options chain (the base rule) or a row lane of a `latest` landing. */
|
|
27
|
+
export declare function wrunPrefixFeedsLiveRowRefused(context: WrunOverlayLiveContext, toMs: number): boolean;
|
|
28
|
+
/** The first row a daily lane's session buffer holds (its page asks the days before it), NaN when the buffer is empty. */
|
|
29
|
+
export declare function wrunPrefixDailyHeldFirstTs(context: WrunOverlayLiveContext, instance: WrunPollLaneInstance): number;
|
|
30
|
+
/**
|
|
31
|
+
* The window build's lane rows (the base rule's window split, `wrunPrefixWindowLanes`), and the daily and row lanes
|
|
32
|
+
* beside it: a daily lane reads its page, then every buffered day through the window's end; an asked row lane its page,
|
|
33
|
+
* then the session's rows over the overlap; a `latest` row lane reads empty. The lane evidence names every asked lane
|
|
34
|
+
* (the proof compares each inside the overlap, where both sides hold the session's own row objects).
|
|
35
|
+
*/
|
|
36
|
+
export declare function wrunPrefixFeedWindowLanes(context: WrunOverlayLiveContext, plan: WrunPrefixFeedPlan, pages: WrunPrefixLanePages, firstRowTs: number, toMs: number): {
|
|
37
|
+
sourceRows: Partial<WrunChartSourceRows>;
|
|
38
|
+
lanes: WrunPrefixLaneEvidence[];
|
|
39
|
+
};
|
|
40
|
+
/** The session's buffers of the lanes a window's evidence names, as they stand now: the proof's mounted side. */
|
|
41
|
+
export declare function wrunPrefixFeedHeldLanes(context: WrunOverlayLiveContext, plan: WrunPrefixFeedPlan): WrunPrefixLaneEvidence[];
|
|
42
|
+
/** The buffers a landed page leaves its session: the base rule's, the daily lanes' (the page, then the whole buffer) and
|
|
43
|
+
* the asked row lanes' (the page, then the session's rows from its first row on). */
|
|
44
|
+
export interface WrunPrefixFeedSplice {
|
|
45
|
+
base: WrunPrefixLaneSplice;
|
|
46
|
+
daily: Record<string, ArrayLike<number>[]>;
|
|
47
|
+
rows: Record<string, ReadonlyArray<ReadonlyArray<unknown>>>;
|
|
48
|
+
}
|
|
49
|
+
/** The commit's splice, all or none (`wrunPrefixLaneSplice`): null when an asked lane has no buffer to splice. */
|
|
50
|
+
export declare function wrunPrefixFeedSplice(context: WrunOverlayLiveContext, plan: WrunPrefixFeedPlan, pages: WrunPrefixLanePages, firstRowTs: number): WrunPrefixFeedSplice | null;
|
|
51
|
+
/** Write a splice onto its session (synchronous; the buffers as new records, the reseed and the tail builder read the
|
|
52
|
+
* context's own). */
|
|
53
|
+
export declare function applyWrunPrefixFeedSplice(context: WrunOverlayLiveContext, splice: WrunPrefixFeedSplice): void;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The feeds a pan-back prefix run computes over, the lanes rule widened to the daily-joined poll lanes and the row lanes
|
|
3
|
+
* (run scheduling, 2026-10-20). The rule this builds on (wrun-prefix-lanes.util `planWrunPrefixLanes`) refused both: a
|
|
4
|
+
* daily lane by its clause (`daily`) and every row lane as an input outside every admitted source (`input-source`). So
|
|
5
|
+
* the chart's first lazy history load (252 to 753 bars) re-ran an options indicator whole and re-asked every one of its
|
|
6
|
+
* sources (16 indicators, 25 cells on INT, 2026-10-20: Skew History at 1h blocked 10.1 s after its first paint). Here
|
|
7
|
+
* a page asks only what it adds:
|
|
8
|
+
*
|
|
9
|
+
* - A daily-joined poll lane (`join: { kind: 'daily' }`, the stock's daily options statistics, an economic series, a
|
|
10
|
+
* supply series): the page asks the days the session's buffer does not hold yet, from the lane's lookback before the
|
|
11
|
+
* page's first bar (`wrunPollLaneFetchFrom`, a whole run's own ask start for the wider window) up to the buffer's
|
|
12
|
+
* first row (cut strictly before it), and asks nothing when the buffer already reaches back that far. The window
|
|
13
|
+
* reads the page, then every buffered day through the window's end (a daily join reads the standing observation, the
|
|
14
|
+
* lookback days before the session's first row included); the splice lands the page before the whole buffer.
|
|
15
|
+
* - A row lane of a `flow` or `snapshot` landing (the per-bar options classes): the page asks the page's own host
|
|
16
|
+
* bars `[fromMs, firstRowTs)` through the lane's own host-grid read (sources/wrun-row-lanes.util
|
|
17
|
+
* `fetchWrunRowLaneRows`: the tier rule, the horizon and the partial bars decide per bar at the clock, as a whole
|
|
18
|
+
* run's asks do), with the acquisition a whole run would plan now; the window and the splice are the bar-joined
|
|
19
|
+
* lanes' (the page, then the session's rows from its first row on).
|
|
20
|
+
* - A row lane of a `latest` landing (the live bar only, the options chain's rule): no ask, its page rows read the empty
|
|
21
|
+
* block a whole run's older bars read; a window reaching the session's live row while the lane holds a snapshot is
|
|
22
|
+
* refused (`live-row`), as the options chain's is.
|
|
23
|
+
*
|
|
24
|
+
* Still refused, each by a named clause (`lanes:<clause>`): a row lane under a row budget (`row-budget`: a whole run
|
|
25
|
+
* keeps the NEWEST bars of its whole window that fit, a page would keep the page's own), a row lane this build does
|
|
26
|
+
* not know or holds no buffer of (`input-source`), a daily lane under a host-grid landing, or with no recorded ask or
|
|
27
|
+
* no buffer to stand on (`daily`), a primary under carry reading a daily lane (`primary-carry`), and any of these
|
|
28
|
+
* lanes on an index-mode chart unless it
|
|
29
|
+
* rides the native-rows path (`index-mode`: there the chart's fetch replaces an explicit window with the chart's whole
|
|
30
|
+
* span, which the native-rows path never does). Every other feed is the base rule's, unchanged: the base judges the
|
|
31
|
+
* session with these lanes set aside (their inputs read as undemanded, their instances and acquisitions out), and its
|
|
32
|
+
* refusal wins.
|
|
33
|
+
*
|
|
34
|
+
* Pure and synchronous: the asks ride the run pass's lane machinery (wrun-overlay-run.util `acquireWrunPrefixLanePages`).
|
|
35
|
+
*/
|
|
36
|
+
import { checkIsIndexMode } from '../../chart/index-mode.util.js';
|
|
37
|
+
import { wrunPollLaneByKey } from '../sources/registry.js';
|
|
38
|
+
import { wrunRowLaneByKey, wrunRowLaneOfClass } from '../sources/row-lane-registry.js';
|
|
39
|
+
import { wrunPollLaneFetchOptions } from '../sources/wrun-poll-lanes.util.js';
|
|
40
|
+
import { wrunRowLaneFetchOptions } from '../sources/wrun-row-lanes.util.js';
|
|
41
|
+
import { applyWrunPrefixLaneSplice, planWrunPrefixLanes, wrunPrefixHeldLanes, wrunPrefixLaneSplice, wrunPrefixLiveRowRefused, wrunPrefixWindowLanes, } from '../wrun-prefix-lanes.util.js';
|
|
42
|
+
/** The fetch-key suffix of a row lane instance's page ask: `rows-<instance id>`. */
|
|
43
|
+
export function wrunPrefixRowSuffix(instance) {
|
|
44
|
+
return `rows-${instance.key}`;
|
|
45
|
+
}
|
|
46
|
+
/** Whether a poll lane instance is daily-joined (its rows one per UTC day, landed by the daily rules). */
|
|
47
|
+
function isWrunDailyInstance(instance) {
|
|
48
|
+
const lane = wrunPollLaneByKey(instance.laneKey);
|
|
49
|
+
return lane !== undefined && lane.join !== 'bar';
|
|
50
|
+
}
|
|
51
|
+
/** The session with the daily poll lanes and the row lanes set aside: their inputs undemanded, their instances and their
|
|
52
|
+
* acquisitions out, so the base rule judges every other feed exactly as before. */
|
|
53
|
+
function wrunPrefixBaseContext(context, daily, rows) {
|
|
54
|
+
const sheet = context.metadata;
|
|
55
|
+
const setAside = new Set([
|
|
56
|
+
...daily.flatMap((instance) => instance.inputIndexes),
|
|
57
|
+
...rows.flatMap((instance) => instance.inputIndexes),
|
|
58
|
+
]);
|
|
59
|
+
const inputSources = { ...sheet.inputSources };
|
|
60
|
+
for (const input of sheet.inputs) {
|
|
61
|
+
const entry = sheet.inputSources[input.name];
|
|
62
|
+
// A row lane's class, read by no instance (the plan dropped it: a fill on every row), is no input-source either.
|
|
63
|
+
if (entry !== undefined && (setAside.has(input.index) || wrunRowLaneOfClass(entry.source) !== undefined)) {
|
|
64
|
+
inputSources[input.name] = { ...entry, undemanded: true };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const laneIds = new Set([...daily.map((instance) => instance.key), ...rows.map((instance) => instance.key)]);
|
|
68
|
+
const acquisition = Object.fromEntries(Object.entries(context.acquisition).filter(([lane]) => !laneIds.has(lane)));
|
|
69
|
+
return {
|
|
70
|
+
...context,
|
|
71
|
+
metadata: { ...sheet, inputSources },
|
|
72
|
+
acquisition,
|
|
73
|
+
pollLanes: (context.pollLanes ?? []).filter((instance) => !laneIds.has(instance.key)),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Whether a daily lane is read by the primary (input 0) under carry: its first page rows would carry from an
|
|
77
|
+
* observation the page's own ask may not reach (the base rule's `primary-carry`). */
|
|
78
|
+
function wrunDailyPrimaryCarries(sheet, instance) {
|
|
79
|
+
return sheet.inputs.some((input) => {
|
|
80
|
+
if (input.index !== 0 || !instance.inputIndexes.includes(0) || input.cellType === 'array')
|
|
81
|
+
return false;
|
|
82
|
+
const entry = sheet.inputSources[input.name];
|
|
83
|
+
return entry !== undefined && entry.missing !== 'nan' && entry.missing !== 'zero';
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/** The prefix feed rule (the module note): the clause that refuses, or what a page asks. */
|
|
87
|
+
export function planWrunPrefixFeeds(context) {
|
|
88
|
+
const refused = (clause) => ({ refused: clause });
|
|
89
|
+
const daily = (context.pollLanes ?? []).filter(isWrunDailyInstance);
|
|
90
|
+
const rowInstances = context.rowLanes ?? [];
|
|
91
|
+
const base = planWrunPrefixLanes(wrunPrefixBaseContext(context, daily, rowInstances));
|
|
92
|
+
if ('refused' in base)
|
|
93
|
+
return base;
|
|
94
|
+
const indexMode = checkIsIndexMode(context.market?.exchange);
|
|
95
|
+
const plan = { ...base.plan, daily: [], rows: [], emptyRows: [] };
|
|
96
|
+
for (const instance of daily) {
|
|
97
|
+
const lane = wrunPollLaneByKey(instance.laneKey);
|
|
98
|
+
// A daily lane the page cannot ask the way the session did: no recorded ask or no buffer to stand on.
|
|
99
|
+
if (lane === undefined || lane.barGrid !== undefined)
|
|
100
|
+
return refused('daily');
|
|
101
|
+
if (context.acquisition[instance.key] === undefined || context.pollLaneRows?.[instance.key] === undefined) {
|
|
102
|
+
return refused('daily');
|
|
103
|
+
}
|
|
104
|
+
if (wrunDailyPrimaryCarries(context.metadata, instance))
|
|
105
|
+
return refused('primary-carry');
|
|
106
|
+
if (indexMode && lane.fetch === undefined && wrunPollLaneFetchOptions(lane)?.nativeRows !== true) {
|
|
107
|
+
return refused('index-mode');
|
|
108
|
+
}
|
|
109
|
+
plan.daily.push(instance);
|
|
110
|
+
}
|
|
111
|
+
for (const instance of rowInstances) {
|
|
112
|
+
const lane = wrunRowLaneByKey(instance.laneKey);
|
|
113
|
+
if (lane === undefined || context.rowLaneRows?.[instance.key] === undefined)
|
|
114
|
+
return refused('input-source');
|
|
115
|
+
if (lane.landing.kind === 'latest') {
|
|
116
|
+
plan.emptyRows.push(instance);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (lane.rowBudget !== undefined)
|
|
120
|
+
return refused('row-budget');
|
|
121
|
+
if (context.acquisition[instance.key] === undefined)
|
|
122
|
+
return refused('input-source');
|
|
123
|
+
if (indexMode && lane.fetch === undefined && wrunRowLaneFetchOptions(lane)?.nativeRows !== true) {
|
|
124
|
+
return refused('index-mode');
|
|
125
|
+
}
|
|
126
|
+
plan.rows.push(instance);
|
|
127
|
+
}
|
|
128
|
+
return { plan };
|
|
129
|
+
}
|
|
130
|
+
/** The feed rule's clause for a session, null when it admits (`planWrunPrefixFeeds`). */
|
|
131
|
+
export function wrunPrefixFeedClauseOf(context) {
|
|
132
|
+
const verdict = planWrunPrefixFeeds(context);
|
|
133
|
+
return 'refused' in verdict ? verdict.refused : null;
|
|
134
|
+
}
|
|
135
|
+
/** Whether a planned window reaches the session's live row while a lane that lands there alone holds a snapshot: the
|
|
136
|
+
* options chain (the base rule) or a row lane of a `latest` landing. */
|
|
137
|
+
export function wrunPrefixFeedsLiveRowRefused(context, toMs) {
|
|
138
|
+
if (wrunPrefixLiveRowRefused(context, toMs))
|
|
139
|
+
return true;
|
|
140
|
+
if (toMs < context.lastRowTs)
|
|
141
|
+
return false;
|
|
142
|
+
return (context.rowLanes ?? []).some((instance) => wrunRowLaneByKey(instance.laneKey)?.landing.kind === 'latest' &&
|
|
143
|
+
(context.rowLaneRows?.[instance.key]?.length ?? 0) > 0);
|
|
144
|
+
}
|
|
145
|
+
/** The first row a daily lane's session buffer holds (its page asks the days before it), NaN when the buffer is empty. */
|
|
146
|
+
export function wrunPrefixDailyHeldFirstTs(context, instance) {
|
|
147
|
+
return Number(context.pollLaneRows?.[instance.key]?.[0]?.[0]);
|
|
148
|
+
}
|
|
149
|
+
/** A buffer's rows at or before `toMs`. */
|
|
150
|
+
function wrunRowsThrough(rows, toMs) {
|
|
151
|
+
return (rows ?? []).filter((row) => Number(row[0]) <= toMs);
|
|
152
|
+
}
|
|
153
|
+
/** A buffer's rows inside `[fromTs, toTs]`. */
|
|
154
|
+
function wrunRowsInside(rows, fromTs, toTs) {
|
|
155
|
+
return (rows ?? []).filter((row) => {
|
|
156
|
+
const ts = Number(row[0]);
|
|
157
|
+
return ts >= fromTs && ts <= toTs;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The window build's lane rows (the base rule's window split, `wrunPrefixWindowLanes`), and the daily and row lanes
|
|
162
|
+
* beside it: a daily lane reads its page, then every buffered day through the window's end; an asked row lane its page,
|
|
163
|
+
* then the session's rows over the overlap; a `latest` row lane reads empty. The lane evidence names every asked lane
|
|
164
|
+
* (the proof compares each inside the overlap, where both sides hold the session's own row objects).
|
|
165
|
+
*/
|
|
166
|
+
export function wrunPrefixFeedWindowLanes(context, plan, pages, firstRowTs, toMs) {
|
|
167
|
+
const base = wrunPrefixWindowLanes(context, plan, pages, firstRowTs, toMs);
|
|
168
|
+
const sourceRows = { ...base.sourceRows };
|
|
169
|
+
const lanes = [...base.lanes];
|
|
170
|
+
if (plan.daily.length > 0) {
|
|
171
|
+
const pollLaneRows = {
|
|
172
|
+
...(sourceRows.pollLaneRows ?? {}),
|
|
173
|
+
};
|
|
174
|
+
for (const instance of plan.daily) {
|
|
175
|
+
const rows = [...(pages.get(instance.key) ?? []), ...wrunRowsThrough(context.pollLaneRows?.[instance.key], toMs)];
|
|
176
|
+
pollLaneRows[instance.key] = rows;
|
|
177
|
+
lanes.push({ lane: instance.key, rows });
|
|
178
|
+
}
|
|
179
|
+
sourceRows.pollLanes = context.pollLanes ?? [];
|
|
180
|
+
sourceRows.pollLaneRows = pollLaneRows;
|
|
181
|
+
}
|
|
182
|
+
const rowInstances = context.rowLanes ?? [];
|
|
183
|
+
if (rowInstances.length > 0) {
|
|
184
|
+
const rowLaneRows = {};
|
|
185
|
+
for (const instance of plan.rows) {
|
|
186
|
+
const rows = [
|
|
187
|
+
...(pages.get(instance.key) ?? []),
|
|
188
|
+
...wrunRowsInside(context.rowLaneRows?.[instance.key], firstRowTs, toMs),
|
|
189
|
+
];
|
|
190
|
+
rowLaneRows[instance.key] = rows;
|
|
191
|
+
lanes.push({ lane: instance.key, rows });
|
|
192
|
+
}
|
|
193
|
+
for (const instance of plan.emptyRows)
|
|
194
|
+
rowLaneRows[instance.key] = [];
|
|
195
|
+
sourceRows.rowLanes = rowInstances;
|
|
196
|
+
sourceRows.rowLaneRows = rowLaneRows;
|
|
197
|
+
}
|
|
198
|
+
return { sourceRows: sourceRows, lanes };
|
|
199
|
+
}
|
|
200
|
+
/** The session's buffers of the lanes a window's evidence names, as they stand now: the proof's mounted side. */
|
|
201
|
+
export function wrunPrefixFeedHeldLanes(context, plan) {
|
|
202
|
+
return [
|
|
203
|
+
...wrunPrefixHeldLanes(context, plan),
|
|
204
|
+
...plan.daily.map((instance) => ({ lane: instance.key, rows: context.pollLaneRows?.[instance.key] ?? [] })),
|
|
205
|
+
...plan.rows.map((instance) => ({ lane: instance.key, rows: context.rowLaneRows?.[instance.key] ?? [] })),
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
/** The commit's splice, all or none (`wrunPrefixLaneSplice`): null when an asked lane has no buffer to splice. */
|
|
209
|
+
export function wrunPrefixFeedSplice(context, plan, pages, firstRowTs) {
|
|
210
|
+
const base = wrunPrefixLaneSplice(context, plan, pages, firstRowTs);
|
|
211
|
+
if (base === null)
|
|
212
|
+
return null;
|
|
213
|
+
const splice = { base, daily: {}, rows: {} };
|
|
214
|
+
for (const instance of plan.daily) {
|
|
215
|
+
const held = context.pollLaneRows?.[instance.key];
|
|
216
|
+
if (held === undefined)
|
|
217
|
+
return null;
|
|
218
|
+
splice.daily[instance.key] = [...(pages.get(instance.key) ?? []), ...held];
|
|
219
|
+
}
|
|
220
|
+
for (const instance of plan.rows) {
|
|
221
|
+
const held = context.rowLaneRows?.[instance.key];
|
|
222
|
+
if (held === undefined)
|
|
223
|
+
return null;
|
|
224
|
+
splice.rows[instance.key] = [
|
|
225
|
+
...(pages.get(instance.key) ?? []),
|
|
226
|
+
...held.filter((row) => Number(row[0]) >= firstRowTs),
|
|
227
|
+
];
|
|
228
|
+
}
|
|
229
|
+
return splice;
|
|
230
|
+
}
|
|
231
|
+
/** Write a splice onto its session (synchronous; the buffers as new records, the reseed and the tail builder read the
|
|
232
|
+
* context's own). */
|
|
233
|
+
export function applyWrunPrefixFeedSplice(context, splice) {
|
|
234
|
+
applyWrunPrefixLaneSplice(context, splice.base);
|
|
235
|
+
if (Object.keys(splice.daily).length > 0)
|
|
236
|
+
context.pollLaneRows = { ...context.pollLaneRows, ...splice.daily };
|
|
237
|
+
if (Object.keys(splice.rows).length > 0)
|
|
238
|
+
context.rowLaneRows = { ...context.rowLaneRows, ...splice.rows };
|
|
239
|
+
}
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
* as-of join, since a bar between two rows reads the input's `missing` policy (`carry` holds the last row). A stock
|
|
11
11
|
* chart's 09:30 New York bars, a crypto chart's and an OPRA contract chart's UTC bars alike.
|
|
12
12
|
*
|
|
13
|
+
* Its reach (`horizon`, `WRUN_OPTION_STATS_10M_HISTORY_MS`): OPTION_UNDERLYING_STATS keeps the ten-minute rows a year,
|
|
14
|
+
* so the asks start where that history does and a run over a longer window (a daily chart's years, a warm-up page)
|
|
15
|
+
* never asks what the table no longer holds; those bars read the input's `missing` policy. A horizon, never a tier: a
|
|
16
|
+
* ten-minute tier would leave every 1m, 5m and 15m bar unread (a tier fits only the bars its width divides).
|
|
17
|
+
*
|
|
13
18
|
* A CHAIN lane like `option_daily` (`planWrunOptionStatsInput`): the chart's chain on whichever plane it lists on (on
|
|
14
19
|
* the OPRA plane its own by coin, with no chain directory read), one book per input, a plane per instance, a continuous
|
|
15
20
|
* CME chart's lead contract (`acquisitionMoved`).
|
|
@@ -22,6 +27,17 @@
|
|
|
22
27
|
* `protocol-pending:OPTION_UNDERLYING_STATS` until the protocol release, and the chain's own refusals.
|
|
23
28
|
*/
|
|
24
29
|
import type { WrunPollLane } from '../wrun-poll-lane.types.js';
|
|
30
|
+
import type { WrunRowLaneHorizon } from '../wrun-row-lane.types.js';
|
|
25
31
|
/** The lane key (the refusal record's feed words, `wrun.refusal.feed.optionStats10m`). */
|
|
26
32
|
export declare const WRUN_OPTION_STATS_10M_LANE_KEY = "option_stats_10m";
|
|
33
|
+
/**
|
|
34
|
+
* How far back the ten-minute statistics reach, on every plane: OPTION_UNDERLYING_STATS' ten-minute table drops its
|
|
35
|
+
* four-week chunks after 365 days (`drop_after`) in a drop window that ends at 400 (`drop_before`), the same on every
|
|
36
|
+
* cluster (tsdb-gateway `charts/tsdb-gateway/schema/schema.{ore,cme,blk}.generated.yaml`,
|
|
37
|
+
* `option_underlying_stats_agg_10m`). The far edge of the drop window, so the asks reach every chunk the drop job may
|
|
38
|
+
* not have dropped yet (the `option_strikes` lane's rule).
|
|
39
|
+
*/
|
|
40
|
+
export declare const WRUN_OPTION_STATS_10M_HISTORY_MS: number;
|
|
41
|
+
/** The lane's `horizon` (`WrunRowLaneHorizon`): its rows start where the ten-minute history does at the clock. */
|
|
42
|
+
export declare function wrunOptionStats10mHorizon(_acquisition: Readonly<Record<string, unknown>>, nowMs: number): WrunRowLaneHorizon | undefined;
|
|
27
43
|
export declare const lane: WrunPollLane;
|