@orangecharts/wrun-chart-host 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +2 -0
  2. package/dist/constants/feature-flags.constants.d.ts +1 -6
  3. package/dist/constants/feature-flags.constants.js +17 -87
  4. package/dist/host-env.d.ts +2 -0
  5. package/dist/host-ports.types.d.ts +10 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +2 -0
  8. package/dist/market-data/venues/index.d.ts +128 -143
  9. package/dist/market-data/venues/index.js +2 -2
  10. package/dist/market-data/venues/stocks.d.ts +1 -1
  11. package/dist/market-data/venues/stocks.js +2 -4
  12. package/dist/settings-templates/frvp-fields.js +28 -19
  13. package/dist/settings-templates/index.d.ts +25 -0
  14. package/dist/settings-templates/index.js +62 -2
  15. package/dist/settings-templates/indicator-fields.d.ts +35 -0
  16. package/dist/settings-templates/indicator-fields.js +261 -114
  17. package/dist/settings-templates/market-bound.d.ts +214 -0
  18. package/dist/settings-templates/market-bound.js +369 -0
  19. package/dist/utility/chart/cme-user-scripts-gate.util.d.ts +8 -8
  20. package/dist/utility/chart/cme-user-scripts-gate.util.js +8 -8
  21. package/dist/utility/chart/governed-lanes-gate.util.d.ts +6 -6
  22. package/dist/utility/chart/governed-lanes-gate.util.js +6 -6
  23. package/dist/utility/chart/index-otc.leaf.d.ts +13 -0
  24. package/dist/utility/chart/index-otc.leaf.js +18 -0
  25. package/dist/utility/chart/server-built-bars.util.d.ts +4 -0
  26. package/dist/utility/chart/server-built-bars.util.js +18 -0
  27. package/dist/utility/v2/gate-plane.util.d.ts +7 -0
  28. package/dist/utility/v2/gate-plane.util.js +6 -0
  29. package/dist/utility/wrun/wrun-dark-pool.util.js +1 -1
  30. package/dist/utility/wrun/wrun-declared-warmup.util.d.ts +1 -1
  31. package/dist/utility/wrun/wrun-lane-warmup.util.d.ts +10 -0
  32. package/dist/utility/wrun/wrun-lane-warmup.util.js +32 -0
  33. package/dist/utility/wrun/wrun-live-intake.util.d.ts +3 -0
  34. package/dist/utility/wrun/wrun-live-intake.util.js +6 -0
  35. package/dist/utility/wrun/wrun-live-tick.util.js +5 -0
  36. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +2 -0
  37. package/dist/utility/wrun/wrun-overlay-recovery.util.js +1 -1
  38. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +3 -1
  39. package/dist/utility/wrun/wrun-overlay-run.util.js +128 -21
  40. package/dist/utility/wrun/wrun-replay-lane.util.js +3 -1
  41. package/dist/utility/wrun/wrun-twin-lookback.util.d.ts +4 -0
  42. package/dist/utility/wrun/wrun-twin-lookback.util.js +17 -0
  43. package/package.json +7 -7
@@ -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';
@@ -2938,7 +2938,7 @@ async function prepareWrunSandboxRun(passTarget, tc, meta, refusal, computed, ow
2938
2938
  // context exists (D4): the run starts with a hidden head of W candles before its first landed row (a clamped
2939
2939
  // window's head included), the chart's own candles asked through the main candle request. Any `history_warmup`
2940
2940
  // key reaches the verdict (a torn stamp answers `warmup-invalid` there, never reads as no stamp; a converging one
2941
- // reads as no stamp there before anything else while `wrun-converging-prefix` is off, so no head is planned), and W
2941
+ // reads as no stamp there before anything else for a guest session, so no head is planned), and W
2942
2942
  // reads the settings the package computes with (`wrunWarmupSettings`: a run at another interval, and a twin whose
2943
2943
  // Timeframe is at or below the chart's, take their chart arm, as the init args below send them).
2944
2944
  const warmupVerdict = target.metadata.history_warmup === undefined
@@ -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
- const laneWarmupFromTs = laneWarmupRequest !== null ? wrunLaneWarmupFromMs(chartFirstTs, laneWarmupBars, chartIntervalMs) : undefined;
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 ('pending' in laneHeadTake) {
5261
- const waitFrom = performance.now();
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 = [exactHeadTake, laneHeadTake].flatMap((take) => take !== undefined && 'deferred' in take ? [take.deferred] : []);
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,
@@ -12118,7 +12212,7 @@ function wrunWarmupStampCorroborated(module, sheet) {
12118
12212
  * reason) and the capability line, where it used to read as no stamp at all (the roster's silent `not-audited`); it
12119
12213
  * still corroborates nothing (no W reads off it, and the per-bar stamp refuses any sheet carrying the key). A record
12120
12214
  * of another kind is a later round's stamp and reads as no stamp, as it always has (`wrunHistoryWarmupOf`), and so
12121
- * does a converging one while its flag is off: every caller asks `wrunConvergingStampDark` first (R2-13). */
12215
+ * does a converging one for a guest session: every caller asks `wrunConvergingStampDark` first (R2-13). */
12122
12216
  function wrunWarmupStampTorn(sheet) {
12123
12217
  if (sheet === null || typeof sheet !== 'object')
12124
12218
  return false;
@@ -12130,11 +12224,11 @@ function wrunWarmupStampTorn(sheet) {
12130
12224
  const kind = raw.kind;
12131
12225
  return (kind === 'exact' || kind === 'converges') && wrunWarmupStampOf(sheet) === undefined;
12132
12226
  }
12133
- /** Whether the chart honors a converging warm-up stamp (`FeatureFlag.WrunConvergingPrefix`, STAMPS round A, default
12134
- * off); a host whose flag store is not up reads off. */
12227
+ /** Whether the chart honors a converging warm-up stamp: a signed-in session; a host without `user.isSignedIn`, or whose
12228
+ * session is not up, reads off. */
12135
12229
  function wrunConvergingPrefixOn() {
12136
12230
  try {
12137
- return wrunChartHostEnv().user.isFeatureOn(FeatureFlag.WrunConvergingPrefix);
12231
+ return wrunChartHostEnv().user.isSignedIn?.() === true;
12138
12232
  }
12139
12233
  catch {
12140
12234
  return false;
@@ -12145,7 +12239,7 @@ function wrunWarmupStampConverges(sheet) {
12145
12239
  const raw = sheet !== null && typeof sheet === 'object' ? sheet.history_warmup : undefined;
12146
12240
  return (raw !== null && typeof raw === 'object' && !Array.isArray(raw) && raw.kind === 'converges');
12147
12241
  }
12148
- /** A converging stamp its flag leaves unread (STAMPS round A, R2-13): while `wrun-converging-prefix` is off, a
12242
+ /** A converging stamp a guest session leaves unread (STAMPS round A, R2-13): while `wrunConvergingPrefixOn` is off, a
12149
12243
  * `converges` record of ANY shape reads as no stamp, exactly as an unknown kind always has (never torn, never
12150
12244
  * planned, never admitted), so the run, its head, its rows and its admission are today's. Asked first by every reader
12151
12245
  * that plans or admits on a stamp, before any other reading of it (the torn check included). */
@@ -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
- return drawFirst ? { deferred: acquire() } : { pending: acquire() };
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
- outcome = await runUtil.reseedWrunOverlayFromBuffers(lane.indicatorId, 'replay-seek', {
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.17.0",
3
+ "version": "0.19.0",
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
+ }