@orangecharts/wrun-chart-host 0.18.0 → 0.19.1
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 +2 -0
- package/dist/constants/feature-flags.constants.js +6 -5
- package/dist/host-ports.types.d.ts +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/settings-templates/frvp-fields.js +28 -19
- package/dist/settings-templates/index.d.ts +33 -0
- package/dist/settings-templates/index.js +91 -2
- package/dist/settings-templates/indicator-fields.d.ts +35 -0
- package/dist/settings-templates/indicator-fields.js +261 -114
- package/dist/settings-templates/market-bound.d.ts +215 -0
- package/dist/settings-templates/market-bound.js +386 -0
- package/dist/utility/v2/gate-plane.util.d.ts +7 -0
- package/dist/utility/v2/gate-plane.util.js +6 -0
- package/dist/utility/wrun/wrun-lane-warmup.util.d.ts +10 -0
- package/dist/utility/wrun/wrun-lane-warmup.util.js +32 -0
- package/dist/utility/wrun/wrun-live-tick.util.js +5 -0
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +2 -0
- package/dist/utility/wrun/wrun-overlay-recovery.util.js +1 -1
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +3 -1
- package/dist/utility/wrun/wrun-overlay-run.util.js +122 -15
- package/dist/utility/wrun/wrun-replay-lane.util.js +3 -1
- package/dist/utility/wrun/wrun-twin-lookback.util.d.ts +4 -0
- package/dist/utility/wrun/wrun-twin-lookback.util.js +17 -0
- package/package.json +7 -7
|
@@ -128,3 +128,35 @@ export function wrunLaneWarmupFromMs(fromMs, bars, intervalMs) {
|
|
|
128
128
|
const month = at.getUTCMonth();
|
|
129
129
|
return Date.UTC(at.getUTCFullYear(), month - (month % months) - bars * months, 1);
|
|
130
130
|
}
|
|
131
|
+
/** A 24-hour day of one-minute bars (1,440) with slack: the lanes' asks widen by the head, so its reach is bounded. */
|
|
132
|
+
export const WRUN_TRADE_DATE_HEAD_CAP_BARS = 1500;
|
|
133
|
+
const TRADE_DATE_HEAD_STEP_MS = 60_000;
|
|
134
|
+
/** The open of the trade date holding `firstBarMs`, to the minute; undefined past the cap, where a head short of the open leaves the total partial. */
|
|
135
|
+
export function wrunTradeDateHeadFromMs(firstBarMs, intervalMs, tradeDateOf, capBars = WRUN_TRADE_DATE_HEAD_CAP_BARS) {
|
|
136
|
+
if (!Number.isFinite(firstBarMs) || !(intervalMs > 0) || !(capBars > 0))
|
|
137
|
+
return undefined;
|
|
138
|
+
const date = tradeDateOf(firstBarMs);
|
|
139
|
+
if (!Number.isFinite(date))
|
|
140
|
+
return undefined;
|
|
141
|
+
const steps = Math.floor((capBars * intervalMs) / TRADE_DATE_HEAD_STEP_MS);
|
|
142
|
+
// Stepped on the minute grid: a seconds bar opening off the minute finds the date's first minute too.
|
|
143
|
+
const firstMinuteMs = Math.floor(firstBarMs / TRADE_DATE_HEAD_STEP_MS) * TRADE_DATE_HEAD_STEP_MS;
|
|
144
|
+
const at = (step) => firstMinuteMs - step * TRADE_DATE_HEAD_STEP_MS;
|
|
145
|
+
if (steps < 1 || tradeDateOf(at(steps)) === date)
|
|
146
|
+
return undefined;
|
|
147
|
+
// The trade date never decreases with time, so the furthest step back that reads the same date is its open.
|
|
148
|
+
let inside = 0;
|
|
149
|
+
let outside = steps;
|
|
150
|
+
while (outside - inside > 1) {
|
|
151
|
+
const mid = (inside + outside) >>> 1;
|
|
152
|
+
if (tradeDateOf(at(mid)) === date)
|
|
153
|
+
inside = mid;
|
|
154
|
+
else
|
|
155
|
+
outside = mid;
|
|
156
|
+
}
|
|
157
|
+
return at(inside);
|
|
158
|
+
}
|
|
159
|
+
/** False under any other option of the select (Continuous): that total depends on the first evaluated bar by definition. */
|
|
160
|
+
export function wrunTradeDateAnchorActive(anchor, paramValues) {
|
|
161
|
+
return paramValues[anchor.param] === anchor.value && anchor.rows.some((name) => paramValues[name] === 1);
|
|
162
|
+
}
|
|
@@ -4915,6 +4915,11 @@ async function reseedWrunOverlay(context, ledger, reason, mainClock) {
|
|
|
4915
4915
|
}
|
|
4916
4916
|
return;
|
|
4917
4917
|
}
|
|
4918
|
+
if (result === 'head-owed' && !context.liveSuspended) {
|
|
4919
|
+
// The reseed would evaluate a trade-date total from the first loaded bar: the full run takes the head first.
|
|
4920
|
+
noteWrunLiveRebuild(ledger, indicatorId);
|
|
4921
|
+
return;
|
|
4922
|
+
}
|
|
4918
4923
|
if (result === 'skipped' && (reason === 'session-lost' || reason === 'order-error') && !context.liveSuspended) {
|
|
4919
4924
|
// The session is gone or wedged and the reseed could not reopen it: the
|
|
4920
4925
|
// full-run driver re-opens it over the current window. A reopen the
|
|
@@ -531,6 +531,8 @@ export interface WrunLaneWarmupHead {
|
|
|
531
531
|
fromTs: number;
|
|
532
532
|
rows: ReadonlyArray<ReadonlyArray<number>>;
|
|
533
533
|
dataGen: number;
|
|
534
|
+
/** Opens at its trade date's open. */
|
|
535
|
+
tradeDate?: true;
|
|
534
536
|
}
|
|
535
537
|
/** The live guest's warmth record (round A). */
|
|
536
538
|
export interface WrunWarmRun {
|
|
@@ -953,7 +953,7 @@ async function reseedWrunCasualty(casualty) {
|
|
|
953
953
|
]);
|
|
954
954
|
const result = await reseedWrunOverlayFromBuffers(indicatorId, 'session-lost');
|
|
955
955
|
ring('wrun-casualty-reseed', { chartIndex, indicatorId, result });
|
|
956
|
-
if (result !== 'skipped' || !hasWrunOverlayDriver(indicatorId))
|
|
956
|
+
if ((result !== 'skipped' && result !== 'head-owed') || !hasWrunOverlayDriver(indicatorId))
|
|
957
957
|
return;
|
|
958
958
|
// The buffers could not reopen the session: the full-run driver rebuilds
|
|
959
959
|
// it over the current window, unless a hold says nothing may run now.
|
|
@@ -703,7 +703,7 @@ export declare function reseedWrunOverlayFromBuffers(indicatorId: string, reason
|
|
|
703
703
|
* cutoff with the window's head, or the run bars as of it; the session rebuilds over them
|
|
704
704
|
* instead of the chart's current candles. */
|
|
705
705
|
ohlcvRows?: ReadonlyArray<ArrayLike<number>>;
|
|
706
|
-
}): Promise<'reseeded' | 'refused' | 'skipped'>;
|
|
706
|
+
}): Promise<'reseeded' | 'refused' | 'skipped' | 'head-owed'>;
|
|
707
707
|
type WrunLaneRows = ArrayLike<number>[];
|
|
708
708
|
/** The row builder's own lanes, one optional thunk each. */
|
|
709
709
|
type WrunBuiltinLaneThunks = {
|
|
@@ -1250,6 +1250,8 @@ export declare function integrateWrunOutputRows(options: WrunIntegrateOptions):
|
|
|
1250
1250
|
* refuses.
|
|
1251
1251
|
*/
|
|
1252
1252
|
export declare function integrateWrunRunThroughRoute(options: WrunIntegrateOptions): WrunIntegrateOutcome;
|
|
1253
|
+
/** The longest a first paint waits for a trade-date head: past it the run paints from the loaded bars and reruns when the head lands. */
|
|
1254
|
+
export declare const WRUN_TRADE_DATE_HEAD_FIRST_PAINT_WAIT_MS = 2000;
|
|
1253
1255
|
/** Why a pan wave runs whole instead of as a prefix run (C1 v3's skip reasons). */
|
|
1254
1256
|
export type WrunPrefixSkipReason = 'no-context' | 'not-backward-extension' | 'not-audited' | 'version-outside-audit' | `unsupported-outputs:${string}` | 'replay' | 'clamped' | 'htf' | `lanes:${WrunPrefixFeedClause}` | 'whole-range-script' | 'prefix-unsafe' | 'no-closed-book-observation' | WrunWarmupMiss | 'warmup-cold' | 'warmup-gaps' | 'prefix-costlier' | 'candle-revised';
|
|
1255
1257
|
/**
|
|
@@ -225,9 +225,9 @@ import { isWrunReplayRunCurrent, noteWrunReplayRun, wrunReplayRunPlanOf, } from
|
|
|
225
225
|
import { cutWrunReplayRowsAfterApply } from './wrun-replay-rows.util.js';
|
|
226
226
|
import { builtinPortOf } from './wrun-builtin-twin.util.js';
|
|
227
227
|
import { WRUN_HISTORY_WARMUP_MAX_BARS, wrunDeclaredWarmupBars, wrunDeclaredWarmupCovered, wrunDeclaredWarmupEndTs, wrunHistoryStampExactColumns, wrunHistoryWarmupBars, } from './wrun-declared-warmup.util.js';
|
|
228
|
-
import { wrunLaneWarmupBars, wrunLaneWarmupFromMs } from './wrun-lane-warmup.util.js';
|
|
228
|
+
import { wrunLaneWarmupBars, wrunLaneWarmupFromMs, wrunTradeDateAnchorActive, wrunTradeDateHeadFromMs, } from './wrun-lane-warmup.util.js';
|
|
229
229
|
import { orderWrunFirstRunHistory } from './wrun-first-run-depth.util.js';
|
|
230
|
-
import { wrunTwinOriginalLookbackBars } from './wrun-twin-lookback.util.js';
|
|
230
|
+
import { wrunTwinOriginalLookbackBars, wrunTwinTradeDateAnchor } from './wrun-twin-lookback.util.js';
|
|
231
231
|
import { overlayWrunRunInterval, wrunSettingsForRunInterval, wrunTimeframeIsChartOrFiner, wrunTwinLookbackBars, } from './wrun-run-interval.util.js';
|
|
232
232
|
import { planWrunRunIntervalRows, rememberWrunRunIntervalSession, wrunRunIntervalComputeRows, wrunRunIntervalCoverageKey, wrunRunIntervalProjectionOf, wrunRunIntervalRowsThrough, wrunRunIntervalSentRow, wrunRunIntervalSessionOf, } from './wrun-run-interval-session.util.js';
|
|
233
233
|
import { isWrunBandedBookSource } from './wrun-book-bands.leaf.js';
|
|
@@ -3134,7 +3134,20 @@ async function prepareWrunSandboxRun(passTarget, tc, meta, refusal, computed, ow
|
|
|
3134
3134
|
// The cloud's warm-up head (the depth judged above), none for a run its budget clamped.
|
|
3135
3135
|
const laneWarmupBars = retainedWindow === undefined ? laneWarmupBarsAsked : 0;
|
|
3136
3136
|
const laneWarmupRequest = laneWarmupBars > 0 ? await wrunWarmupHeadRequestOf(chartMetadata) : null;
|
|
3137
|
-
|
|
3137
|
+
// A trade-date total adds up the rows the run evaluates: starting at the date's open keeps a bar's total off the loaded window.
|
|
3138
|
+
const tradeDateAnchor = laneWarmupRequest !== null ? await wrunTwinTradeDateAnchor(view.settings, target.metadata) : null;
|
|
3139
|
+
const tradeDateVenue = tradeDateAnchor !== null &&
|
|
3140
|
+
wrunTradeDateAnchorActive(tradeDateAnchor, wrunParamValuesFromSettings(target.metadata, view.settings))
|
|
3141
|
+
? wrunBarVenueOf(chartMetadata, chartIntervalMs)
|
|
3142
|
+
: undefined;
|
|
3143
|
+
const tradeDateFacts = tradeDateVenue !== undefined ? wrunBarSessionFactsResolver(tradeDateVenue) : undefined;
|
|
3144
|
+
const tradeDateAnchored = tradeDateFacts !== undefined;
|
|
3145
|
+
const tradeDateHeadFromTs = tradeDateFacts !== undefined
|
|
3146
|
+
? wrunTradeDateHeadFromMs(chartFirstTs, chartIntervalMs, (atMs) => tradeDateFacts(atMs).tradeDateSec)
|
|
3147
|
+
: undefined;
|
|
3148
|
+
const laneWarmupFromTs = laneWarmupRequest !== null
|
|
3149
|
+
? Math.min(wrunLaneWarmupFromMs(chartFirstTs, laneWarmupBars, chartIntervalMs), tradeDateHeadFromTs ?? Number.POSITIVE_INFINITY)
|
|
3150
|
+
: undefined;
|
|
3138
3151
|
const laneHeadArgs = laneWarmupRequest !== null && laneWarmupFromTs !== undefined
|
|
3139
3152
|
? {
|
|
3140
3153
|
chartIndex: target.chartIndex,
|
|
@@ -3148,7 +3161,11 @@ async function prepareWrunSandboxRun(passTarget, tc, meta, refusal, computed, ow
|
|
|
3148
3161
|
}
|
|
3149
3162
|
: undefined;
|
|
3150
3163
|
const laneHeadTake = laneHeadArgs !== undefined
|
|
3151
|
-
? takeWrunRunHead(peekWrunLaneWarmupHead(laneHeadArgs), () => acquireWrunLaneWarmupHead(laneHeadArgs), drawFirst
|
|
3164
|
+
? takeWrunRunHead(peekWrunLaneWarmupHead(laneHeadArgs), () => acquireWrunLaneWarmupHead(laneHeadArgs), drawFirst,
|
|
3165
|
+
// A trade-date head moves every bar of the first landed date, the bars on screen: a first paint gives it a bounded wait.
|
|
3166
|
+
tradeDateHeadFromTs !== undefined && tradeDateHeadFromTs < chartFirstTs
|
|
3167
|
+
? WRUN_TRADE_DATE_HEAD_FIRST_PAINT_WAIT_MS
|
|
3168
|
+
: undefined)
|
|
3152
3169
|
: undefined;
|
|
3153
3170
|
// The ETF lane's plan (wrun-etf-flow-lane.util), before any fetch: the
|
|
3154
3171
|
// chart's coin picks the ETF family (refused by name off the covered-coin
|
|
@@ -5256,25 +5273,39 @@ async function prepareWrunSandboxRun(passTarget, tc, meta, refusal, computed, ow
|
|
|
5256
5273
|
// The cloud's warm-up head (row 53), asked beside the lanes above: a head that cannot be had (or holds no candle)
|
|
5257
5274
|
// runs cold, as before; a deferred one is the rerun's to take.
|
|
5258
5275
|
let laneHead;
|
|
5276
|
+
// A bounded take that lands inside its bound is the head; one that does not is the rerun's to take, like a deferred one.
|
|
5277
|
+
let laneHeadLate;
|
|
5278
|
+
let laneHeadLanded;
|
|
5279
|
+
if (laneHeadTake !== undefined && !('deferred' in laneHeadTake)) {
|
|
5280
|
+
const waitFrom = performance.now();
|
|
5281
|
+
if ('pending' in laneHeadTake)
|
|
5282
|
+
laneHeadLanded = await laneHeadTake.pending;
|
|
5283
|
+
else {
|
|
5284
|
+
laneHeadLanded = (await laneHeadTake.within)?.head;
|
|
5285
|
+
if (laneHeadLanded === undefined)
|
|
5286
|
+
laneHeadLate = laneHeadTake.late;
|
|
5287
|
+
}
|
|
5288
|
+
headWaitMs += performance.now() - waitFrom;
|
|
5289
|
+
}
|
|
5259
5290
|
if (laneHeadTake !== undefined) {
|
|
5260
|
-
if (
|
|
5261
|
-
const
|
|
5262
|
-
const acquired = await laneHeadTake.pending;
|
|
5263
|
-
headWaitMs += performance.now() - waitFrom;
|
|
5291
|
+
if (laneHeadLanded !== undefined) {
|
|
5292
|
+
const acquired = laneHeadLanded;
|
|
5264
5293
|
ringWrunPrefix('wrun-lane-warmup', {
|
|
5265
5294
|
chartIndex: target.chartIndex,
|
|
5266
5295
|
indicatorId: target.indicatorId,
|
|
5267
5296
|
run: reason,
|
|
5268
5297
|
warmupBars: laneWarmupBars,
|
|
5269
5298
|
fromTs: laneWarmupFromTs,
|
|
5299
|
+
...(tradeDateHeadFromTs !== undefined ? { tradeDateFromTs: tradeDateHeadFromTs } : {}),
|
|
5270
5300
|
warmupRows: acquired.rows.length,
|
|
5271
5301
|
pages: acquired.pages,
|
|
5272
5302
|
...(acquired.wall ? { wall: true } : {}),
|
|
5273
5303
|
...(acquired.reused ? { reused: true } : {}),
|
|
5274
5304
|
...(acquired.shared ? { shared: true } : {}),
|
|
5275
5305
|
});
|
|
5306
|
+
const opensTradeDate = tradeDateHeadFromTs !== undefined && tradeDateHeadFromTs < chartFirstTs;
|
|
5276
5307
|
if (acquired.rows.length > 0)
|
|
5277
|
-
laneHead = acquired;
|
|
5308
|
+
laneHead = opensTradeDate ? { ...acquired, tradeDate: true } : acquired;
|
|
5278
5309
|
}
|
|
5279
5310
|
else {
|
|
5280
5311
|
ringWrunPrefix('wrun-lane-warmup', {
|
|
@@ -5293,7 +5324,10 @@ async function prepareWrunSandboxRun(passTarget, tc, meta, refusal, computed, ow
|
|
|
5293
5324
|
if (attemptToken)
|
|
5294
5325
|
wrunChartHostEnv().diagnostics.noteAttemptStageMs(attemptToken, 'warmupWaitMs', Math.round(headWaitMs));
|
|
5295
5326
|
}
|
|
5296
|
-
const deferredHeads = [
|
|
5327
|
+
const deferredHeads = [
|
|
5328
|
+
...[exactHeadTake, laneHeadTake].flatMap((take) => take !== undefined && 'deferred' in take ? [take.deferred] : []),
|
|
5329
|
+
...(laneHeadLate !== undefined ? [laneHeadLate] : []),
|
|
5330
|
+
];
|
|
5297
5331
|
if (deferredHeads.length > 0 && headStore !== undefined) {
|
|
5298
5332
|
refineWrunRunWhenHeadLands({
|
|
5299
5333
|
owner,
|
|
@@ -5330,6 +5364,16 @@ async function prepareWrunSandboxRun(passTarget, tc, meta, refusal, computed, ow
|
|
|
5330
5364
|
const computeOhlcvRows = hiddenHead !== undefined && hiddenHead.rows.length > 0
|
|
5331
5365
|
? wrunChartCandleRowsAfterHead(hiddenHead.rows, chartRows)
|
|
5332
5366
|
: ohlcvRows;
|
|
5367
|
+
ringWrunPrefix('wrun-run-evaluated', {
|
|
5368
|
+
chartIndex: target.chartIndex,
|
|
5369
|
+
indicatorId: target.indicatorId,
|
|
5370
|
+
op: 'run',
|
|
5371
|
+
run: reason,
|
|
5372
|
+
firstEvaluatedTs: Number(computeOhlcvRows[0]?.[0]),
|
|
5373
|
+
firstLandedTs: chartFirstTs,
|
|
5374
|
+
headRows: hiddenHead?.rows.length ?? 0,
|
|
5375
|
+
tradeDate: laneHead?.tradeDate === true,
|
|
5376
|
+
});
|
|
5333
5377
|
const sourceRows = {
|
|
5334
5378
|
ohlcvRows,
|
|
5335
5379
|
bookRows,
|
|
@@ -5598,6 +5642,7 @@ async function prepareWrunSandboxRun(passTarget, tc, meta, refusal, computed, ow
|
|
|
5598
5642
|
target,
|
|
5599
5643
|
textParams,
|
|
5600
5644
|
to,
|
|
5645
|
+
tradeDateAnchored,
|
|
5601
5646
|
tradeLegRows,
|
|
5602
5647
|
tradeVolumeBySizeRows,
|
|
5603
5648
|
twinAtChart,
|
|
@@ -6315,7 +6360,7 @@ async function integrateWrunRunAsk(runTarget, tc, meta, refusal, computed, owner
|
|
|
6315
6360
|
await integrateWrunRowSourceBatch(runTarget, tc, meta, refusal, computed, owner, head, ask, batch);
|
|
6316
6361
|
return;
|
|
6317
6362
|
}
|
|
6318
|
-
const { acquisitionByLane, writeOpraProvenance, readsOpraPlane, bookRows, buySellVolumeRows, buySellVolumeUsdRows, carryAtBuild, chartExchange, chartFirstTs, chartInterval, chartIntervalMs, chartMetadata, chartNames, chartRows, clampedLegs, clock, compositionToken, computeIdentity, computeSourceRows, cryptoVenue, degraded, emptyLegs, etfFlowRows, evaluatedCandles, fetchedRunBars, fillingFrom, fillingLanes, formingPreRoll, from, fundingRateRows, generationAtStart, hasGoodResult, hasIntrabarLegs, hasLiveCandleLegs, hasPinnedLegs, headWarm, heldCoverage, impliedVolatilityRows, initArgs, intrabarRows, laneHead, laneRun, legs, liquidationRows, live, loadedRows, marketIdentity, missingFeeds, ohlcvRows, openInterestRows, optionsChainRows, paramValues, pinnedCandleRows, pinnedLaneRows, pinnedLiveCandleRows, planGeneration, pollLaneRows, pollLanes, rowLaneRows, rowLanes, projection, reason, replay, replayChartRows, replayHeadRows, retainedRowsCap, retainedWindow, rows, run, runBars, runBlockRowsCap, runKey, runRowsPlan, skewRows, strategy, tapeRows, target, textParams, to, tradeLegRows, tradeVolumeBySizeRows, twinAtChart, unservedLanes, unservedLegs, unservedTradeLegs, unsettledLanes, volumeProfileRows, warmupBarsNow, warmupHead, warmupMiss, warmupWall, window, headsDeferred, epoch: generation, pinNotes, respelledPins, rowBudgetCuts, downloadBudgetCut, } = prepared;
|
|
6363
|
+
const { acquisitionByLane, writeOpraProvenance, readsOpraPlane, bookRows, buySellVolumeRows, buySellVolumeUsdRows, carryAtBuild, chartExchange, chartFirstTs, chartInterval, chartIntervalMs, chartMetadata, chartNames, chartRows, clampedLegs, clock, compositionToken, computeIdentity, computeSourceRows, cryptoVenue, degraded, emptyLegs, etfFlowRows, evaluatedCandles, fetchedRunBars, fillingFrom, fillingLanes, formingPreRoll, from, fundingRateRows, generationAtStart, hasGoodResult, hasIntrabarLegs, hasLiveCandleLegs, hasPinnedLegs, headWarm, heldCoverage, impliedVolatilityRows, initArgs, intrabarRows, laneHead, laneRun, legs, liquidationRows, live, loadedRows, marketIdentity, missingFeeds, ohlcvRows, openInterestRows, optionsChainRows, paramValues, pinnedCandleRows, pinnedLaneRows, pinnedLiveCandleRows, planGeneration, pollLaneRows, pollLanes, rowLaneRows, rowLanes, projection, reason, replay, replayChartRows, replayHeadRows, retainedRowsCap, retainedWindow, rows, run, runBars, runBlockRowsCap, runKey, runRowsPlan, skewRows, strategy, tapeRows, target, textParams, to, tradeDateAnchored, tradeLegRows, tradeVolumeBySizeRows, twinAtChart, unservedLanes, unservedLegs, unservedTradeLegs, unsettledLanes, volumeProfileRows, warmupBarsNow, warmupHead, warmupMiss, warmupWall, window, headsDeferred, epoch: generation, pinNotes, respelledPins, rowBudgetCuts, downloadBudgetCut, } = prepared;
|
|
6319
6364
|
// The filling chip (`fillingLanes`, a first-slice picture): raised right before the integrate, lowered if the run
|
|
6320
6365
|
// fails after it.
|
|
6321
6366
|
const fillingGuardKey = overlayExecutionGuardKey(target.chartIndex, target.indicatorId);
|
|
@@ -6862,6 +6907,7 @@ async function integrateWrunRunAsk(runTarget, tc, meta, refusal, computed, owner
|
|
|
6862
6907
|
fromTs: laneHead.fromTs,
|
|
6863
6908
|
rows: laneHead.rows,
|
|
6864
6909
|
dataGen: laneHead.dataGen,
|
|
6910
|
+
...(laneHead.tradeDate === true ? { tradeDate: true } : {}),
|
|
6865
6911
|
},
|
|
6866
6912
|
}
|
|
6867
6913
|
: {}),
|
|
@@ -6900,6 +6946,8 @@ async function integrateWrunRunAsk(runTarget, tc, meta, refusal, computed, owner
|
|
|
6900
6946
|
// The context this one replaces: an owner change while the run computed revised it, not this one.
|
|
6901
6947
|
const replacedDirtyFromTs = getWrunOverlayLiveContext(target.indicatorId)?.dirtyFromTs ?? null;
|
|
6902
6948
|
setWrunOverlayLiveContext(liveContext);
|
|
6949
|
+
if (tradeDateAnchored)
|
|
6950
|
+
wrunTradeDateSessions.add(liveContext);
|
|
6903
6951
|
// The host's session changed owner while the run computed (a hand-back, a new seam): its rows read a
|
|
6904
6952
|
// composition that is no longer the overlay's, so the revision the replaced context owed is carried onto this
|
|
6905
6953
|
// one (the whole window when it owed none): the drain reseeds over the composition as it stands.
|
|
@@ -9164,7 +9212,7 @@ export async function reseedWrunOverlayFromBuffers(indicatorId, reason, options
|
|
|
9164
9212
|
return 'skipped';
|
|
9165
9213
|
// The cloud's warm-up head (row 53) runs first the same way, while it still precedes what this reseed lands under
|
|
9166
9214
|
// the chart's current data generation; a head left behind (a page loaded since, a refetch) goes, and the reseed
|
|
9167
|
-
// lands cold until the next full run takes a new one
|
|
9215
|
+
// lands cold until the next full run takes a new one, a trade-date head apart: its session answers `head-owed`.
|
|
9168
9216
|
const laneReseedHeadAsked = reseedHead === undefined &&
|
|
9169
9217
|
options.ohlcvRows === undefined &&
|
|
9170
9218
|
runSession === undefined &&
|
|
@@ -9175,10 +9223,32 @@ export async function reseedWrunOverlayFromBuffers(indicatorId, reason, options
|
|
|
9175
9223
|
wrunRunRetainedHeadFits(ohlcvRows, laneReseedHeadAsked.length, context.runBlockRowsCap)
|
|
9176
9224
|
? laneReseedHeadAsked
|
|
9177
9225
|
: undefined;
|
|
9178
|
-
if (laneReseedHead === undefined && context.laneWarmupHead !== undefined)
|
|
9226
|
+
if (laneReseedHead === undefined && context.laneWarmupHead !== undefined) {
|
|
9227
|
+
if (!wrunTradeDateHeadOwed.has(context) && wrunSessionOpensInsideTradeDate(context, Number(sessionRows[0][0]))) {
|
|
9228
|
+
wrunTradeDateHeadOwed.set(context, 'owed');
|
|
9229
|
+
}
|
|
9179
9230
|
delete context.laneWarmupHead;
|
|
9231
|
+
}
|
|
9232
|
+
// A trade-date total evaluated from the first loaded bar reads short: the full run asks the head again, once a session.
|
|
9233
|
+
if (laneReseedHead === undefined &&
|
|
9234
|
+
options.ohlcvRows === undefined &&
|
|
9235
|
+
wrunTradeDateHeadOwed.get(context) === 'owed') {
|
|
9236
|
+
wrunTradeDateHeadOwed.set(context, 'asked');
|
|
9237
|
+
ringWrunPrefix('wrun-reseed-head-owed', { chartIndex: context.chartIndex, indicatorId, reason });
|
|
9238
|
+
return 'head-owed';
|
|
9239
|
+
}
|
|
9180
9240
|
const headRows = reseedHead?.rows ?? laneReseedHead;
|
|
9181
9241
|
const computeOhlcvRows = headRows !== undefined && headRows.length > 0 ? wrunChartCandleRowsAfterHead(headRows, sessionRows) : ohlcvRows;
|
|
9242
|
+
ringWrunPrefix('wrun-run-evaluated', {
|
|
9243
|
+
chartIndex: context.chartIndex,
|
|
9244
|
+
indicatorId,
|
|
9245
|
+
op: 'reseed',
|
|
9246
|
+
run: reason,
|
|
9247
|
+
firstEvaluatedTs: Number(computeOhlcvRows[0]?.[0]),
|
|
9248
|
+
firstLandedTs: Number(sessionRows[0][0]),
|
|
9249
|
+
headRows: headRows?.length ?? 0,
|
|
9250
|
+
tradeDate: laneReseedHead !== undefined && context.laneWarmupHead?.tradeDate === true,
|
|
9251
|
+
});
|
|
9182
9252
|
// The host session's composition, as the full run reads it (wrun-session-composition.util): the reseed rebuilds
|
|
9183
9253
|
// over the buffers composed as the session stands now, so an owner change since the run lands on every bar.
|
|
9184
9254
|
const composition = composeWrunSessionSources({
|
|
@@ -10937,6 +11007,21 @@ function wrunParkedBarsOf(rows) {
|
|
|
10937
11007
|
lastTs: Number(rows[rows.length - 1][0]),
|
|
10938
11008
|
};
|
|
10939
11009
|
}
|
|
11010
|
+
/** A session without the trade-date head its run took: `owed` hands its next reseed to the full run, `asked` once that run is requested. */
|
|
11011
|
+
const wrunTradeDateHeadOwed = new WeakMap();
|
|
11012
|
+
/** The sessions whose run reads a total that restarts each trade date under its settings (the roster's anchor, active). */
|
|
11013
|
+
const wrunTradeDateSessions = new WeakSet();
|
|
11014
|
+
/** Whether a session that reads a trade-date total would evaluate its first date short from `firstTs`: the date opens before it, inside the head's reach. */
|
|
11015
|
+
function wrunSessionOpensInsideTradeDate(context, firstTs) {
|
|
11016
|
+
if (!wrunTradeDateSessions.has(context))
|
|
11017
|
+
return false;
|
|
11018
|
+
const venue = wrunBarVenueOf(context.market, context.intervalMs);
|
|
11019
|
+
if (venue === undefined)
|
|
11020
|
+
return false;
|
|
11021
|
+
const facts = wrunBarSessionFactsResolver(venue);
|
|
11022
|
+
const open = wrunTradeDateHeadFromMs(firstTs, context.intervalMs, (atMs) => facts(atMs).tradeDateSec);
|
|
11023
|
+
return open !== undefined && open < firstTs;
|
|
11024
|
+
}
|
|
10940
11025
|
/** Cut an adopted session to the chart's rows from `firstTs` on: its first row and its output rows, and every fact a
|
|
10941
11026
|
* prefix run would read about the bars before (its guest evaluated them: no prefix proof stands over the cut). */
|
|
10942
11027
|
function trimWrunAdoptedSession(context, firstTs) {
|
|
@@ -10951,6 +11036,9 @@ function trimWrunAdoptedSession(context, firstTs) {
|
|
|
10951
11036
|
delete context.candleEvidence;
|
|
10952
11037
|
delete context.warmupHead;
|
|
10953
11038
|
delete context.warmRun;
|
|
11039
|
+
// A cut that lands on a trade date's open leaves the date whole: a reseed from there is exact and owes nothing.
|
|
11040
|
+
if (wrunSessionOpensInsideTradeDate(context, firstTs))
|
|
11041
|
+
wrunTradeDateHeadOwed.set(context, 'owed');
|
|
10954
11042
|
delete context.laneWarmupHead;
|
|
10955
11043
|
}
|
|
10956
11044
|
/** The overlay provenance writers (the env's loader), or undefined when they cannot load. */
|
|
@@ -11125,6 +11213,10 @@ export async function adoptWrunParkedLiveSession(parked, target) {
|
|
|
11125
11213
|
}
|
|
11126
11214
|
if (trim)
|
|
11127
11215
|
trimWrunAdoptedSession(context, chartFirstTs);
|
|
11216
|
+
else if (context.laneWarmupHead !== undefined) {
|
|
11217
|
+
// The adoption judges these bars the session's own, so its head rides the chart's new data generation: a reseed runs it first.
|
|
11218
|
+
context.laneWarmupHead = { ...context.laneWarmupHead, dataGen: getChartDataFetchGeneration(chartIndex) };
|
|
11219
|
+
}
|
|
11128
11220
|
// The session is this chart's now, under a fresh generation: frames and drains of its old chart are discarded.
|
|
11129
11221
|
// The worker's series keeps the epoch it was opened under, which a later park names it by.
|
|
11130
11222
|
context.chartIndex = chartIndex;
|
|
@@ -11269,6 +11361,8 @@ export async function adoptWrunParkedLiveSession(parked, target) {
|
|
|
11269
11361
|
adopted: true,
|
|
11270
11362
|
path,
|
|
11271
11363
|
...(trim ? { trimmedToTs: chartFirstTs } : {}),
|
|
11364
|
+
...(context.laneWarmupHead !== undefined ? { headFromTs: context.laneWarmupHead.fromTs } : {}),
|
|
11365
|
+
...(wrunTradeDateHeadOwed.has(context) ? { tradeDateHeadOwed: true } : {}),
|
|
11272
11366
|
...(ownerLeft ? { ownerLeft: true } : {}),
|
|
11273
11367
|
rows: context.outputRows.length,
|
|
11274
11368
|
parkedForMs: Date.now() - parked.parkedAt,
|
|
@@ -12704,15 +12798,28 @@ function ringWrunWarmupHead(chartIndex, indicatorId, run, warmupBars, acquired)
|
|
|
12704
12798
|
...('rows' in acquired && acquired.shared ? { shared: true } : {}),
|
|
12705
12799
|
});
|
|
12706
12800
|
}
|
|
12801
|
+
/** The longest a first paint waits for a trade-date head: past it the run paints from the loaded bars and reruns when the head lands. */
|
|
12802
|
+
export const WRUN_TRADE_DATE_HEAD_FIRST_PAINT_WAIT_MS = 2000;
|
|
12707
12803
|
/** THE decision whether a run waits on a hidden head: a head in hand (own rows, the wall, the held head, the chart's
|
|
12708
12804
|
* head store) is taken at once; one that needs a fetch is deferred when the run draws first, else awaited. The
|
|
12709
12805
|
* acquisition starts here either way, so the head is fetched beside the lanes. Pinned by the "draw first" cases of
|
|
12710
12806
|
* tests/utility/wrun/wrun-overlay-run.warmup-prefix.spec.ts, and tests/utility/wrun/wrun-overlay-run.head-wait.spec.ts
|
|
12711
12807
|
* reds a head acquisition called anywhere but here and the pan-back prefix (which runs over mounted rows). */
|
|
12712
|
-
function takeWrunRunHead(inHand, acquire, drawFirst) {
|
|
12808
|
+
function takeWrunRunHead(inHand, acquire, drawFirst, withinMs) {
|
|
12713
12809
|
if (inHand !== undefined)
|
|
12714
12810
|
return { pending: Promise.resolve(inHand) };
|
|
12715
|
-
|
|
12811
|
+
if (!drawFirst)
|
|
12812
|
+
return { pending: acquire() };
|
|
12813
|
+
if (withinMs === undefined)
|
|
12814
|
+
return { deferred: acquire() };
|
|
12815
|
+
// The clock starts with the acquisition, beside the lanes: the bound is on the paint, not on the await that reads it.
|
|
12816
|
+
const late = acquire();
|
|
12817
|
+
let timer;
|
|
12818
|
+
const bound = new Promise((resolve) => {
|
|
12819
|
+
timer = setTimeout(() => resolve(undefined), withinMs);
|
|
12820
|
+
});
|
|
12821
|
+
const within = Promise.race([late.then((head) => ({ head })), bound]).finally(() => clearTimeout(timer));
|
|
12822
|
+
return { within, late };
|
|
12716
12823
|
}
|
|
12717
12824
|
/** The chart's candle identity a head store key carries: market, interval and transformation
|
|
12718
12825
|
* (wrunChartMarketIdentity), the run clock's interval, and the session and adjustment the main candle request asks. */
|
|
@@ -417,10 +417,12 @@ async function stepWrunReplayLane(lane) {
|
|
|
417
417
|
outcome = await liveTick.advanceWrunReplaySession(lane.indicatorId, ohlcvRows);
|
|
418
418
|
}
|
|
419
419
|
if (outcome === 'reseed') {
|
|
420
|
-
|
|
420
|
+
const reseed = await runUtil.reseedWrunOverlayFromBuffers(lane.indicatorId, 'replay-seek', {
|
|
421
421
|
ohlcvRows,
|
|
422
422
|
eligible: () => isWrunReplayLaneCurrent(lane) && replaySessionOf(lane) === context,
|
|
423
423
|
});
|
|
424
|
+
// A replay's reseed brings its own rows and owes no head.
|
|
425
|
+
outcome = reseed === 'head-owed' ? 'skipped' : reseed;
|
|
424
426
|
}
|
|
425
427
|
if (!isWrunReplayLaneCurrent(lane) || replaySessionOf(lane) !== context)
|
|
426
428
|
return;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { WrunTwinTradeDateAnchor } from '../../host-ports.types.js';
|
|
2
|
+
import type { WrunIndicatorMetadata } from '../../interfaces/wrun-runtime.interface.js';
|
|
1
3
|
/**
|
|
2
4
|
* The original's declared lookback for a mounted twin (its `wrunRegistryRef` package), folded at
|
|
3
5
|
* `intervalMs` and capped like the kScript lane's read; null for an overlay that is no such twin
|
|
@@ -8,3 +10,5 @@
|
|
|
8
10
|
* (wrun-twins.util), loaded through `chart.loadTwinsRoster()`.
|
|
9
11
|
*/
|
|
10
12
|
export declare function wrunTwinOriginalLookbackBars(settings: unknown, intervalMs: number): Promise<number | null>;
|
|
13
|
+
/** The sheet is read first: a package with no `time.trade_date` input never loads the roster for this. */
|
|
14
|
+
export declare function wrunTwinTradeDateAnchor(settings: unknown, sheet: Pick<WrunIndicatorMetadata, 'inputSources'>): Promise<WrunTwinTradeDateAnchor | null>;
|
|
@@ -41,3 +41,20 @@ export async function wrunTwinOriginalLookbackBars(settings, intervalMs) {
|
|
|
41
41
|
return null;
|
|
42
42
|
return Math.min(KSCRIPT_LOOKBACK_ANCHOR_CAP_BARS, foldAnchorSpanIntoLookbackBars(declared.minimumBars, declared.anchorMinSpanMs, intervalMs));
|
|
43
43
|
}
|
|
44
|
+
/** The sheet is read first: a package with no `time.trade_date` input never loads the roster for this. */
|
|
45
|
+
export async function wrunTwinTradeDateAnchor(settings, sheet) {
|
|
46
|
+
const ref = wrunRegistryRefOf(settings);
|
|
47
|
+
if (!ref)
|
|
48
|
+
return null;
|
|
49
|
+
const readsTradeDate = Object.values(sheet.inputSources ?? {}).some((source) => {
|
|
50
|
+
const read = source;
|
|
51
|
+
return read?.source === 'time' && read.field === 'trade_date';
|
|
52
|
+
});
|
|
53
|
+
if (!readsTradeDate)
|
|
54
|
+
return null;
|
|
55
|
+
// A roster that fails to load reads as no anchor: the run computes from the planner's start.
|
|
56
|
+
const roster = await wrunChartHostEnv()
|
|
57
|
+
.chart.loadTwinsRoster()
|
|
58
|
+
.catch(() => null);
|
|
59
|
+
return roster?.wrunTwinTradeDateAnchorInfo?.(ref.package, ref.version) ?? null;
|
|
60
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orangecharts/wrun-chart-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.1",
|
|
4
4
|
"description": "The wrun chart-host layer shared by the kiyotaka web app and the mobile app: the wrun result reader and painter model, cut from the web app (its reference implementation).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
"default": "./dist/*.js"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "node scripts/generate-tool-tables.mjs && rm -rf dist && tsc -p tsconfig.build.json && node scripts/esm-dist.mjs dist",
|
|
27
|
+
"consumer-check": "node scripts/consumer-check.mjs",
|
|
28
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
29
|
+
},
|
|
25
30
|
"peerDependencies": {
|
|
26
31
|
"@orangecharts/indicator-kit": "0.121.0",
|
|
27
32
|
"@orangecharts/orange-v2-pb-common": "12.86.0",
|
|
@@ -35,10 +40,5 @@
|
|
|
35
40
|
"dayjs": "1.11.23",
|
|
36
41
|
"lodash-es": "4.18.1",
|
|
37
42
|
"typescript": "5.9.3"
|
|
38
|
-
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "node scripts/generate-tool-tables.mjs && rm -rf dist && tsc -p tsconfig.build.json && node scripts/esm-dist.mjs dist",
|
|
41
|
-
"consumer-check": "node scripts/consumer-check.mjs",
|
|
42
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
43
43
|
}
|
|
44
|
-
}
|
|
44
|
+
}
|