@orangecharts/wrun-chart-host 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/constants/feature-flags.constants.d.ts +9 -0
- package/dist/constants/feature-flags.constants.js +67 -4
- package/dist/constants/governed-exchanges.constants.d.ts +12 -0
- package/dist/constants/governed-exchanges.constants.js +16 -0
- package/dist/constants/option-venues.constants.d.ts +2 -2
- package/dist/host-env.d.ts +1 -9
- package/dist/host-ports.types.d.ts +36 -7
- package/dist/index.d.ts +6 -1
- package/dist/index.js +6 -1
- package/dist/interfaces/cancel-reason.interface.d.ts +1 -1
- package/dist/interfaces/cme-realtime.interface.d.ts +16 -9
- package/dist/interfaces/cme-realtime.interface.js +6 -3
- package/dist/interfaces/kscript-diagnostics.interface.d.ts +6 -0
- package/dist/interfaces/opra-realtime.interface.d.ts +1 -5
- package/dist/interfaces/prediction-market.interface.d.ts +7 -0
- package/dist/interfaces/stocks-realtime.interface.d.ts +57 -0
- package/dist/interfaces/stocks-realtime.interface.js +32 -0
- package/dist/kscript-data/controls/live-trades-merge.util.d.ts +48 -117
- package/dist/kscript-data/controls/live-trades-merge.util.js +97 -207
- package/dist/market-data/billing.interface.d.ts +86 -12
- package/dist/market-data/billing.interface.js +23 -4
- package/dist/market-data/venue.d.ts +65 -2
- package/dist/market-data/venues/index.d.ts +135 -5
- package/dist/market-data/venues/index.js +2 -1
- package/dist/market-data/venues/opra.contract.copy.json +3 -2
- package/dist/market-data/venues/opra.d.ts +2 -2
- package/dist/market-data/venues/opra.js +5 -2
- package/dist/market-data/venues/stocks.contract.copy.json +64 -0
- package/dist/market-data/venues/stocks.d.ts +130 -0
- package/dist/market-data/venues/stocks.js +117 -0
- package/dist/settings-templates/footprint-rows.js +35 -2
- package/dist/settings-templates/form-rows.d.ts +2 -1
- package/dist/settings-templates/indicator-fields.js +34 -4
- package/dist/settings-templates/tool-rules.d.ts +12 -5
- package/dist/settings-templates/tool-rules.js +11 -5
- package/dist/settings-templates/tool-tables.generated.js +4 -0
- package/dist/utility/chart/cme-cache-context.util.d.ts +5 -3
- package/dist/utility/chart/cme-cache-context.util.js +10 -6
- package/dist/utility/chart/cme-realtime.util.js +10 -0
- package/dist/utility/chart/cme-user-scripts-gate.util.d.ts +83 -0
- package/dist/utility/chart/cme-user-scripts-gate.util.js +142 -0
- package/dist/utility/chart/effective-chart-session.util.d.ts +14 -0
- package/dist/utility/chart/effective-chart-session.util.js +39 -0
- package/dist/utility/chart/host-bar-placement.util.d.ts +28 -0
- package/dist/utility/chart/host-bar-placement.util.js +170 -30
- package/dist/utility/chart/index-host-tier.util.d.ts +3 -1
- package/dist/utility/chart/index-host-tier.util.js +7 -2
- package/dist/utility/chart/index-mode-admission.util.js +25 -11
- package/dist/utility/chart/kscript-apply-fingerprint.util.js +1 -1
- package/dist/utility/chart/kscript-live-coalesce.util.d.ts +6 -9
- package/dist/utility/chart/kscript-live-coalesce.util.js +8 -9
- package/dist/utility/chart/kscript-live-source-identity.util.d.ts +9 -0
- package/dist/utility/chart/kscript-live-source-identity.util.js +10 -1
- package/dist/utility/chart/kscript-provenance-keys.util.js +7 -0
- package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +3 -1
- package/dist/utility/chart/kscript-venue-policy.util.d.ts +115 -21
- package/dist/utility/chart/kscript-venue-policy.util.js +194 -40
- package/dist/utility/chart/live-bucket.util.d.ts +24 -8
- package/dist/utility/chart/live-bucket.util.js +85 -27
- package/dist/utility/chart/marketKind.util.js +5 -0
- package/dist/utility/chart/mixed-mode.util.d.ts +7 -0
- package/dist/utility/chart/mixed-mode.util.js +14 -0
- package/dist/utility/chart/opra-user-scripts-gate.util.d.ts +11 -16
- package/dist/utility/chart/opra-user-scripts-gate.util.js +12 -28
- package/dist/utility/chart/rth-session.util.d.ts +9 -8
- package/dist/utility/chart/rth-session.util.js +23 -20
- package/dist/utility/chart/trading-day.util.d.ts +17 -0
- package/dist/utility/chart/trading-day.util.js +59 -0
- package/dist/utility/chart/window-owner.leaf.d.ts +23 -2
- package/dist/utility/chart/window-owner.leaf.js +45 -3
- package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +33 -15
- package/dist/utility/chart/wrun-bar-session-facts.util.js +70 -20
- package/dist/utility/intl-locale.util.js +5 -0
- package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +2 -0
- package/dist/utility/v2/gate-plane.util.d.ts +12 -3
- package/dist/utility/v2/gate-plane.util.js +30 -4
- package/dist/utility/v2/gate-session-latch.util.js +1 -1
- package/dist/utility/v2/stocks-governed.util.d.ts +16 -0
- package/dist/utility/v2/stocks-governed.util.js +34 -0
- package/dist/utility/wrun/derived-roots.leaf.d.ts +13 -0
- package/dist/utility/wrun/derived-roots.leaf.js +27 -0
- package/dist/utility/wrun/derived-roots.util.d.ts +1 -9
- package/dist/utility/wrun/derived-roots.util.js +3 -23
- package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +4 -3
- package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +24 -3
- package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +46 -10
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +2 -0
- package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.d.ts +63 -16
- package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.js +58 -14
- package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +34 -11
- package/dist/utility/wrun/sources/wrun-row-lanes.util.js +106 -30
- package/dist/utility/wrun/wrun-browser-sources.leaf.js +1 -2
- package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +7 -4
- package/dist/utility/wrun/wrun-chart-market-facts.util.js +12 -8
- package/dist/utility/wrun/wrun-color-settings.util.d.ts +9 -0
- package/dist/utility/wrun/wrun-color-settings.util.js +33 -0
- package/dist/utility/wrun/wrun-handles.util.d.ts +7 -3
- package/dist/utility/wrun/wrun-handles.util.js +9 -8
- package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +68 -0
- package/dist/utility/wrun/wrun-input-requirements.leaf.js +163 -7
- package/dist/utility/wrun/wrun-leg-close.util.d.ts +59 -23
- package/dist/utility/wrun/wrun-leg-close.util.js +186 -28
- package/dist/utility/wrun/wrun-live-intake.util.d.ts +26 -12
- package/dist/utility/wrun/wrun-live-intake.util.js +219 -155
- package/dist/utility/wrun/wrun-live-tick.util.d.ts +9 -5
- package/dist/utility/wrun/wrun-live-tick.util.js +130 -94
- package/dist/utility/wrun/wrun-market-facts.util.d.ts +13 -3
- package/dist/utility/wrun/wrun-market-facts.util.js +13 -3
- package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +20 -10
- package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +10 -5
- package/dist/utility/wrun/wrun-option-book-rows.util.d.ts +56 -0
- package/dist/utility/wrun/wrun-option-book-rows.util.js +96 -0
- package/dist/utility/wrun/wrun-option-views.util.d.ts +281 -20
- package/dist/utility/wrun/wrun-option-views.util.js +391 -50
- package/dist/utility/wrun/wrun-options-chain.util.d.ts +3 -3
- package/dist/utility/wrun/wrun-options-chain.util.js +2 -0
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +15 -2
- package/dist/utility/wrun/wrun-overlay-drivers.util.js +13 -3
- package/dist/utility/wrun/wrun-overlay-recovery.util.js +3 -1
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +60 -11
- package/dist/utility/wrun/wrun-overlay-run.util.js +529 -113
- package/dist/utility/wrun/wrun-panel-mount.util.js +51 -6
- package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +15 -2
- package/dist/utility/wrun/wrun-pin-spelling.util.js +27 -3
- package/dist/utility/wrun/wrun-refusal.util.d.ts +3 -2
- package/dist/utility/wrun/wrun-refusal.util.js +22 -0
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +26 -0
- package/dist/utility/wrun/wrun-registry-errors.util.js +34 -0
- package/dist/utility/wrun/wrun-replay-lane.util.js +3 -2
- package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +20 -6
- package/dist/utility/wrun/wrun-run-interval-session.util.js +22 -7
- package/dist/utility/wrun/wrun-run-interval.util.d.ts +39 -7
- package/dist/utility/wrun/wrun-run-interval.util.js +49 -9
- package/dist/utility/wrun/wrun-socket-row-source.js +7 -2
- package/dist/utility/wrun/wrun-source-rows.util.d.ts +29 -22
- package/dist/utility/wrun/wrun-source-rows.util.js +62 -41
- package/dist/utility/wrun/wrun-tape-per-order.util.js +1 -20
- package/dist/utility/wrun/wrun-tape-source.util.d.ts +17 -9
- package/dist/utility/wrun/wrun-tape-source.util.js +20 -12
- package/dist/workers/constants/socket-slots.d.ts +91 -6
- package/dist/workers/constants/socket-slots.js +85 -6
- package/package.json +11 -11
- package/dist/kscript-data/controls/live-trades-order-gate.util.d.ts +0 -56
- package/dist/kscript-data/controls/live-trades-order-gate.util.js +0 -107
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `cme-user-scripts` gate as the venue policy reads it (kscript-venue-policy.util, the one decider of the governed
|
|
3
|
+
* walls: `isCmeUserScriptRun`), and the authorisation epoch every door that lands a CME user study's answer compares.
|
|
4
|
+
* Dependency-free on purpose (zero imports), the shape of the pre-retirement opra-user-scripts gate: the venue policy
|
|
5
|
+
* stays worker-safe and store-free, so the main thread hands it readers instead.
|
|
6
|
+
*
|
|
7
|
+
* The gate is open only while BOTH of its facts answer `true`, each read live on every call:
|
|
8
|
+
* - The flag. The flags store registers its override-aware `isOn` as the fallback when it is created, and publishes
|
|
9
|
+
* its reader again after every successful fetch. Until a fetch publishes, the fallback answers, so the dev and
|
|
10
|
+
* internal `kiyo.flag-overrides` lens reaches the walls before the map lands and through a failed fetch, exactly as
|
|
11
|
+
* it reaches every surface that reads `isOn`: the walls and the surfaces never disagree.
|
|
12
|
+
* - The viewer's CME entitlement. The web hands its `viewerMayReadCme()` reader: signed in, not a guest, the CME data
|
|
13
|
+
* terms not blocked. Delayed and real-time access both count: the tier a read rides is the gate plane's, decided per
|
|
14
|
+
* socket, never this answer's.
|
|
15
|
+
*
|
|
16
|
+
* Fail closed everywhere: in any context neither reader reached (a worker, a guest, a spec without a store), a reader
|
|
17
|
+
* that throws and a reader that answers anything but `true` read the gate closed, today's CME wall. The flag is never
|
|
18
|
+
* read server-side: kscript-backend denies CME to every user run whatever it says.
|
|
19
|
+
*
|
|
20
|
+
* The authorisation epoch (`cmeStudyAuthEpoch`, `bumpCmeStudyAuthEpoch`, `captureCmeStudyAuth`,
|
|
21
|
+
* `isCmeStudyAuthCurrent`): the generation model of the options chain's governed access
|
|
22
|
+
* (src/workers/indicators/options-chain-state.worker.util.ts `syncGovernedChainAccess`), moved to the main thread. The
|
|
23
|
+
* main-thread lifecycle watcher (web: `installCmeUserStudyLifecycle`, cme-user-scripts-lifecycle.util) bumps it
|
|
24
|
+
* whenever an input of a CME user study's authorisation moves: the account id, the CME data-terms state, the CME served
|
|
25
|
+
* access, the flag, a session expiry or a session swap. A run captures a token before it asks; every door that lands
|
|
26
|
+
* its answer (titan-charts' dataFetch result, the script engine's result, the wrun run's `isCurrent`) compares the
|
|
27
|
+
* token and drops an answer from a previous authorisation context, so a late answer never lands after access changed.
|
|
28
|
+
* A missing token is never current. The epoch is main-thread state: a worker's copy of this module never sees a bump,
|
|
29
|
+
* so a worker carries the captured token back and never judges it. Publishing a reader never moves the epoch (a flag
|
|
30
|
+
* fetch publishes after every fetch, moved or not): only the watcher bumps it, on a move it saw.
|
|
31
|
+
*
|
|
32
|
+
* The stopped-study register (`markCmeStudyStopped`, `clearCmeStudyStopped`, `cmeStudyStopReason`,
|
|
33
|
+
* `isCmeStudyStopped`): the studies the lifecycle watcher stopped in place when the gate closed (the viewer's access
|
|
34
|
+
* changed, or the flag went dark), keyed by chart index and overlay id. Main-thread state, never persisted: the
|
|
35
|
+
* workspace row and the editor tab keep their source and settings, the register only tells Door H which words to paint
|
|
36
|
+
* ("Access changed; the study stopped" or "CME chart studies are turned off") and the local-engine self-heal which rows
|
|
37
|
+
* to leave alone. The re-judgment that mounts a study again clears its row; a chart teardown clears the chart's rows.
|
|
38
|
+
*
|
|
39
|
+
* The remount stash (`stashCmeStudyRemount`, `cmeStudyRemountStash`): what a stopped study's remount needs that its
|
|
40
|
+
* workspace row does not carry, kept beside its register row and dropped with it by `clearCmeStudyStopped` (one clear,
|
|
41
|
+
* so a stash never outlives the stop it belongs to). An editor draft's source is the case: the add strips
|
|
42
|
+
* `settings.script` from the mounted config once the worker engine holds it, and a draft's row is session-only, so
|
|
43
|
+
* once its engine is destroyed nothing else on the page holds its code. Typed `unknown` here: the web lifecycle writes
|
|
44
|
+
* it, the web re-judgment reads it. Main-thread state, never persisted.
|
|
45
|
+
*/
|
|
46
|
+
let published = null;
|
|
47
|
+
let fallback = null;
|
|
48
|
+
let entitlement = null;
|
|
49
|
+
let authEpoch = 0;
|
|
50
|
+
const stopped = new Map();
|
|
51
|
+
const remountStash = new Map();
|
|
52
|
+
function stoppedKey(chartIndex, overlayId) {
|
|
53
|
+
return `${chartIndex}:${overlayId}`;
|
|
54
|
+
}
|
|
55
|
+
/** Record a study the lifecycle stopped in place (Door H paints the reason's words until it is cleared). */
|
|
56
|
+
export function markCmeStudyStopped(chartIndex, overlayId, reason) {
|
|
57
|
+
stopped.set(stoppedKey(chartIndex, overlayId), reason);
|
|
58
|
+
}
|
|
59
|
+
/** Forget one stopped study, or every stopped study of a chart when no overlay id is given, with its remount stash. */
|
|
60
|
+
export function clearCmeStudyStopped(chartIndex, overlayId) {
|
|
61
|
+
if (overlayId !== undefined) {
|
|
62
|
+
stopped.delete(stoppedKey(chartIndex, overlayId));
|
|
63
|
+
remountStash.delete(stoppedKey(chartIndex, overlayId));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const prefix = `${chartIndex}:`;
|
|
67
|
+
for (const store of [stopped, remountStash]) {
|
|
68
|
+
for (const key of Array.from(store.keys())) {
|
|
69
|
+
if (key.startsWith(prefix))
|
|
70
|
+
store.delete(key);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** Keep what a stopped study's remount needs and its row does not carry (the header); `clearCmeStudyStopped` drops it. */
|
|
75
|
+
export function stashCmeStudyRemount(chartIndex, overlayId, remount) {
|
|
76
|
+
remountStash.set(stoppedKey(chartIndex, overlayId), remount);
|
|
77
|
+
}
|
|
78
|
+
/** What the lifecycle kept for a stopped study's remount, or undefined when its row carries all it needs. */
|
|
79
|
+
export function cmeStudyRemountStash(chartIndex, overlayId) {
|
|
80
|
+
return remountStash.get(stoppedKey(chartIndex, overlayId));
|
|
81
|
+
}
|
|
82
|
+
/** The reason a study was stopped, or undefined for a study the lifecycle never stopped. */
|
|
83
|
+
export function cmeStudyStopReason(chartIndex, overlayId) {
|
|
84
|
+
return stopped.get(stoppedKey(chartIndex, overlayId));
|
|
85
|
+
}
|
|
86
|
+
/** Whether the lifecycle stopped this study and nothing has mounted it again since. */
|
|
87
|
+
export function isCmeStudyStopped(chartIndex, overlayId) {
|
|
88
|
+
return stopped.has(stoppedKey(chartIndex, overlayId));
|
|
89
|
+
}
|
|
90
|
+
/** Called by the flags store after a successful fetch (and by specs); null unpublishes. */
|
|
91
|
+
export function publishCmeUserScriptsFlag(next) {
|
|
92
|
+
published = next;
|
|
93
|
+
}
|
|
94
|
+
/** Called by the flags store when it is created: its override-aware `isOn`, read until a fetch publishes. */
|
|
95
|
+
export function setCmeUserScriptsFlagFallback(next) {
|
|
96
|
+
fallback = next;
|
|
97
|
+
}
|
|
98
|
+
/** Called by the web with its `viewerMayReadCme()` reader (signed in, not a guest, CME data terms not blocked); null
|
|
99
|
+
* unregisters, and no reader reads closed. */
|
|
100
|
+
export function setCmeUserScriptsEntitlementReader(next) {
|
|
101
|
+
entitlement = next;
|
|
102
|
+
}
|
|
103
|
+
/** Whether the `cme-user-scripts` flag is on for this session: the published answer, else the store's own; closed
|
|
104
|
+
* when neither can tell. The flag alone: the walls read `isCmeUserScriptsGateOpen`. */
|
|
105
|
+
export function isCmeUserScriptsFlagOn() {
|
|
106
|
+
try {
|
|
107
|
+
return (published ?? fallback)?.() === true;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** Whether the viewer's entitlement reader answers `true`; closed with no reader. */
|
|
114
|
+
function viewerMayReadCmeNow() {
|
|
115
|
+
try {
|
|
116
|
+
return entitlement?.() === true;
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** Whether the CME plane may open to a user run the browser executes: the flag lit AND the viewer entitled. */
|
|
123
|
+
export function isCmeUserScriptsGateOpen() {
|
|
124
|
+
return isCmeUserScriptsFlagOn() && viewerMayReadCmeNow();
|
|
125
|
+
}
|
|
126
|
+
/** The authorisation epoch now (see the header). */
|
|
127
|
+
export function cmeStudyAuthEpoch() {
|
|
128
|
+
return authEpoch;
|
|
129
|
+
}
|
|
130
|
+
/** Move the epoch on: every token captured before is no longer current. Returns the new epoch. */
|
|
131
|
+
export function bumpCmeStudyAuthEpoch() {
|
|
132
|
+
authEpoch += 1;
|
|
133
|
+
return authEpoch;
|
|
134
|
+
}
|
|
135
|
+
/** The token a run captures before it asks (frozen: a holder cannot move it forward). */
|
|
136
|
+
export function captureCmeStudyAuth() {
|
|
137
|
+
return Object.freeze({ epoch: authEpoch });
|
|
138
|
+
}
|
|
139
|
+
/** Whether a captured token is from the current authorisation context; a missing or malformed token is not. */
|
|
140
|
+
export function isCmeStudyAuthCurrent(token) {
|
|
141
|
+
return typeof token?.epoch === 'number' && token.epoch === authEpoch;
|
|
142
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type ChartSessionWord = 'regular' | 'extended';
|
|
2
|
+
/**
|
|
3
|
+
* The session the chart rides on this market at this interval. An absent or unknown word reads as the market's
|
|
4
|
+
* default. On a market with an RTH window the answer is 'regular' only while `isChartRthActive` holds for a
|
|
5
|
+
* 'regular' choice at `interval` (the chart's interval label or milliseconds; an unknown interval reads as
|
|
6
|
+
* inactive), else 'extended'. Every other market keeps the normalised word.
|
|
7
|
+
*/
|
|
8
|
+
export declare function effectiveChartSessionType(exchange: unknown, symbol: unknown, interval: unknown, sessionType: unknown): ChartSessionWord;
|
|
9
|
+
/**
|
|
10
|
+
* Whether the word only spells this market's default: it is absent (undefined or null) or equals
|
|
11
|
+
* `defaultChartSessionType(symbol, exchange)`. Writing such a word over an absent one changes the persisted document,
|
|
12
|
+
* never what the chart rides or what any request asks.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isSpelledChartSessionDefault(exchange: unknown, symbol: unknown, sessionType: unknown): boolean;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chart session every identity, key, compare and planner frame reads: what the chart RIDES, never how its
|
|
3
|
+
* persisted word is spelled.
|
|
4
|
+
*
|
|
5
|
+
* `metadata.sessionType` is a persisted choice: 'regular' (RTH), 'extended' (ETH), or absent, which every reader takes
|
|
6
|
+
* as the market's default (`defaultChartSessionType`: 'extended' on a future with an RTH window, 'regular' elsewhere).
|
|
7
|
+
* The chart rides RTH only while `isChartRthActive` holds: a 'regular' choice, an intraday interval and a root with an
|
|
8
|
+
* RTH window. Read verbatim, the word turned two no-ops into session flips: a spelled default (a settings confirm
|
|
9
|
+
* stamps the default onto a document that never carried the word) and a 'regular' a future keeps at daily and higher,
|
|
10
|
+
* where the chart rides the full session. Left out of an identity, a real flip went unseen.
|
|
11
|
+
*
|
|
12
|
+
* Markets without an RTH window (Polygon equities, crypto, unmapped CME roots) keep the normalised word: there
|
|
13
|
+
* 'regular' and 'extended' are the equities extended-hours flag, which this module never folds.
|
|
14
|
+
*
|
|
15
|
+
* A pure leaf: it imports the RTH predicates only (rth-session.util, worker-safe and store-free), so the store-free
|
|
16
|
+
* modules that read it (the pane planner, the wrun drivers registry) keep the chart store out of their eager graph.
|
|
17
|
+
*/
|
|
18
|
+
import { chartIntervalToMs, defaultChartSessionType, hasRthWindow, isChartRthActive } from './rth-session.util.js';
|
|
19
|
+
/**
|
|
20
|
+
* The session the chart rides on this market at this interval. An absent or unknown word reads as the market's
|
|
21
|
+
* default. On a market with an RTH window the answer is 'regular' only while `isChartRthActive` holds for a
|
|
22
|
+
* 'regular' choice at `interval` (the chart's interval label or milliseconds; an unknown interval reads as
|
|
23
|
+
* inactive), else 'extended'. Every other market keeps the normalised word.
|
|
24
|
+
*/
|
|
25
|
+
export function effectiveChartSessionType(exchange, symbol, interval, sessionType) {
|
|
26
|
+
const word = sessionType === 'regular' || sessionType === 'extended' ? sessionType : null;
|
|
27
|
+
const chosen = word ?? defaultChartSessionType(symbol, exchange);
|
|
28
|
+
if (chosen === 'extended' || !hasRthWindow(symbol, exchange))
|
|
29
|
+
return chosen;
|
|
30
|
+
return isChartRthActive(exchange, symbol, 'regular', chartIntervalToMs(interval)) ? 'regular' : 'extended';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether the word only spells this market's default: it is absent (undefined or null) or equals
|
|
34
|
+
* `defaultChartSessionType(symbol, exchange)`. Writing such a word over an absent one changes the persisted document,
|
|
35
|
+
* never what the chart rides or what any request asks.
|
|
36
|
+
*/
|
|
37
|
+
export function isSpelledChartSessionDefault(exchange, symbol, sessionType) {
|
|
38
|
+
return sessionType === undefined || sessionType === null || sessionType === defaultChartSessionType(symbol, exchange);
|
|
39
|
+
}
|
|
@@ -40,6 +40,14 @@ export interface IndexHostBars {
|
|
|
40
40
|
* from its own rows, with no bucket call.
|
|
41
41
|
*/
|
|
42
42
|
export declare function hostBarRowOf(barTs: number, rows: readonly number[][], merge: Exclude<IndexHostMerge, 'cells'>): number[];
|
|
43
|
+
/**
|
|
44
|
+
* A row's last instant (the last-instant placement's key): its bar's true end on the row's own grid less one
|
|
45
|
+
* (`rowVenue`, `liveBucketVenueOf` of the rows' market: a session's stub ends at its close, so a NYMEX RTH 4h row
|
|
46
|
+
* opening 13:00 New York lasts to 14:29:59, inside an ES RTH host's 13:30 bar, where its nominal span ran past the ES
|
|
47
|
+
* close and the row was dropped); the nominal span (`openMs + rowSpanMs - 1`) without a grid, or for a row that opens
|
|
48
|
+
* no bar on it.
|
|
49
|
+
*/
|
|
50
|
+
export declare function rowLastInstantMs(openMs: number, rowSpanMs: number, rowVenue?: LiveBucketVenue | null): number;
|
|
43
51
|
/** Options of `placeRowsInHostBars`. */
|
|
44
52
|
export interface PlaceRowsInHostBarsOptions {
|
|
45
53
|
/**
|
|
@@ -64,6 +72,14 @@ export interface PlaceRowsInHostBarsOptions {
|
|
|
64
72
|
* absent or null, no row takes it.
|
|
65
73
|
*/
|
|
66
74
|
formingBarTs?: number | null;
|
|
75
|
+
/**
|
|
76
|
+
* The rows' own bar grid at `rowSpanMs` (`liveBucketVenueOf` of their
|
|
77
|
+
* market, at the session their wire serves): a row's last instant is its
|
|
78
|
+
* bar's true end there (`rowLastInstantMs`: a session's stub ends at its
|
|
79
|
+
* close), not the nominal span, which overshoots a host's earlier close and
|
|
80
|
+
* dropped the row. Absent, the nominal span.
|
|
81
|
+
*/
|
|
82
|
+
rowVenue?: LiveBucketVenue | null;
|
|
67
83
|
}
|
|
68
84
|
/**
|
|
69
85
|
* Place every row in the host bar whose [open, close) holds its timestamp and
|
|
@@ -105,3 +121,15 @@ export declare function placeRowsInHostBars(rows: readonly number[][], bars: Ind
|
|
|
105
121
|
export declare function createHostBucketResolver(intervalMs: number, venue: LiveBucketVenue | null | undefined): (tsMs: number) => number | null;
|
|
106
122
|
/** The shared `createHostBucketResolver` of a host grid (every live door on that grid reuses its cached span). */
|
|
107
123
|
export declare function hostBucketResolverFor(intervalMs: number, venue: LiveBucketVenue | null | undefined): (tsMs: number) => number | null;
|
|
124
|
+
/**
|
|
125
|
+
* A live door's bar for a frame of a source on its own row grid (`rowSpanMs` rows on `rowVenue`): the bar the
|
|
126
|
+
* last-instant placement (`placeRowsInHostBars` with `rowSpanMs` and `rowVenue`, dataFetch's STEP 4) puts the row
|
|
127
|
+
* holding the frame's instant in, judged at `nowMs` as a fetch then would, so a fold and the next fetch of its row land
|
|
128
|
+
* in one bar. A row opening a host bar lands on it; any other keys on its last instant (`rowLastInstantMs`): in a bar
|
|
129
|
+
* opened by then it lands there (a replay, a frame late across a boundary), in a later bar it shows in the forming bar
|
|
130
|
+
* holding its open (the live edge), and with no bar (closing past the session close) nowhere, null, as with no row at
|
|
131
|
+
* the instant. Judged at the later of `nowMs` and the instant (a device clock inside the server-clock deadband).
|
|
132
|
+
*/
|
|
133
|
+
export declare function createSourceRowHostBarResolver(intervalMs: number, venue: LiveBucketVenue | null | undefined, rowSpanMs: number, rowVenue: LiveBucketVenue | null | undefined): (instantMs: number, nowMs: number) => number | null;
|
|
134
|
+
/** The shared `createSourceRowHostBarResolver` of a host grid and a row grid (every live door on the pair reuses it). */
|
|
135
|
+
export declare function sourceRowHostBarResolverFor(intervalMs: number, venue: LiveBucketVenue | null | undefined, rowSpanMs: number, rowVenue: LiveBucketVenue | null | undefined): (instantMs: number, nowMs: number) => number | null;
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
*
|
|
16
16
|
* Pure: the package's bucket function and session option, nothing else.
|
|
17
17
|
*/
|
|
18
|
-
import { liveBucketStartMs } from './live-bucket.util.js';
|
|
18
|
+
import { liveBucketBarsAreLabels, liveBucketStartMs } from './live-bucket.util.js';
|
|
19
19
|
import { usEquitiesSessionConfig } from './us-equities-session.util.js';
|
|
20
|
+
const MINUTE_MS = 60_000;
|
|
20
21
|
function isAscendingByTs(rows) {
|
|
21
22
|
for (let i = 1; i < rows.length; i++)
|
|
22
23
|
if (rows[i][0] < rows[i - 1][0])
|
|
@@ -124,9 +125,15 @@ function heldRowsAfterOpen(keyAt, from, to, barTs, intervalMs, venue, hint) {
|
|
|
124
125
|
* 12h, the last bar) asks the host's bucket function once per bar span
|
|
125
126
|
* (`heldRowsAfterOpen`). Keys before the first bar, off session or in a bar
|
|
126
127
|
* the host does not hold land nowhere. Returns where the keys the LAST bar
|
|
127
|
-
* does not hold begin (`count` when none is left past it).
|
|
128
|
+
* does not hold begin (`count` when none is left past it). On a grid whose
|
|
129
|
+
* stamps are labels, not opens (`liveBucketBarsAreLabels`), a bar spans no
|
|
130
|
+
* [stamp, next stamp) window at all: `sweepLabelledHostBars` books every key,
|
|
131
|
+
* and a bar whose keys are interleaved with keys it does not hold (a 3d bar's
|
|
132
|
+
* nights) gets one run each: `onBar` takes every run of a bar, in key order.
|
|
128
133
|
*/
|
|
129
134
|
function sweepHostBars(count, keyAt, main, intervalMs, venue, onBar) {
|
|
135
|
+
if (liveBucketBarsAreLabels(intervalMs, venue))
|
|
136
|
+
return sweepLabelledHostBars(count, keyAt, main, intervalMs, venue, onBar);
|
|
130
137
|
let next = 0;
|
|
131
138
|
let hint = 0;
|
|
132
139
|
let pastLastBar = count;
|
|
@@ -155,6 +162,44 @@ function sweepHostBars(count, keyAt, main, intervalMs, venue, onBar) {
|
|
|
155
162
|
}
|
|
156
163
|
return pastLastBar;
|
|
157
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* The sweep on a grid whose stamps are labels (`liveBucketBarsAreLabels`: the CME trade-date lattice from a day up, a
|
|
167
|
+
* regular-session stock's 3d group): every key lands on the mounted bar the host's own bucket function books it to
|
|
168
|
+
* (`hostBucketResolverFor`, one bucket call per bar span), the evening before a trade-date label included, a key
|
|
169
|
+
* stamped on a mounted label staying on it, so the placement and the live doors book an instant alike. Keys ascend and
|
|
170
|
+
* so do their bars, so each bar's keys are one run. Returns where the keys past the last bar begin: after the last key
|
|
171
|
+
* it holds, else at the first key booked past it (`count` when none is).
|
|
172
|
+
*/
|
|
173
|
+
function sweepLabelledHostBars(count, keyAt, main, intervalMs, venue, onBar) {
|
|
174
|
+
const barOf = hostBucketResolverFor(intervalMs, venue);
|
|
175
|
+
const indexOfBar = new Map();
|
|
176
|
+
for (let index = 0; index < main.length; index++)
|
|
177
|
+
indexOfBar.set(main[index][0], index);
|
|
178
|
+
const lastIndex = main.length - 1;
|
|
179
|
+
const lastBarTs = main[lastIndex][0];
|
|
180
|
+
let lastHeldEnd = -1;
|
|
181
|
+
let firstPast = count;
|
|
182
|
+
let runIndex = -1;
|
|
183
|
+
let runFrom = 0;
|
|
184
|
+
for (let k = 0; k < count; k++) {
|
|
185
|
+
const key = keyAt(k);
|
|
186
|
+
const bar = indexOfBar.has(key) ? key : barOf(key);
|
|
187
|
+
const index = bar === null ? -1 : (indexOfBar.get(bar) ?? -1);
|
|
188
|
+
if (index !== runIndex) {
|
|
189
|
+
if (runIndex >= 0)
|
|
190
|
+
onBar(runIndex, runFrom, k);
|
|
191
|
+
runIndex = index;
|
|
192
|
+
runFrom = k;
|
|
193
|
+
}
|
|
194
|
+
if (index === lastIndex)
|
|
195
|
+
lastHeldEnd = k + 1;
|
|
196
|
+
else if (firstPast === count && (bar === null ? key > lastBarTs : bar > lastBarTs))
|
|
197
|
+
firstPast = k;
|
|
198
|
+
}
|
|
199
|
+
if (runIndex >= 0)
|
|
200
|
+
onBar(runIndex, runFrom, count);
|
|
201
|
+
return lastHeldEnd >= 0 ? lastHeldEnd : firstPast;
|
|
202
|
+
}
|
|
158
203
|
/** The index of the mounted bar whose [open, close) holds `ms` (the sweep's own span rule), or -1. */
|
|
159
204
|
function barIndexHolding(main, ms, intervalMs, venue) {
|
|
160
205
|
let lo = 0;
|
|
@@ -169,40 +214,96 @@ function barIndexHolding(main, ms, intervalMs, venue) {
|
|
|
169
214
|
else
|
|
170
215
|
hi = mid - 1;
|
|
171
216
|
}
|
|
217
|
+
if (found >= 0 && ms === main[found][0])
|
|
218
|
+
return found;
|
|
219
|
+
if (liveBucketBarsAreLabels(intervalMs, venue)) {
|
|
220
|
+
// A label bar holds instants before its stamp (the evening before a trade date): the bucket function names it.
|
|
221
|
+
const bar = liveBucketStartMs(ms, intervalMs, venue);
|
|
222
|
+
if (bar === null)
|
|
223
|
+
return -1;
|
|
224
|
+
if (found >= 0 && main[found][0] === bar)
|
|
225
|
+
return found;
|
|
226
|
+
return main[found + 1]?.[0] === bar ? found + 1 : -1;
|
|
227
|
+
}
|
|
172
228
|
if (found < 0)
|
|
173
229
|
return -1;
|
|
174
230
|
const barTs = main[found][0];
|
|
175
|
-
if (
|
|
231
|
+
if (main[found + 1]?.[0] === barTs + intervalMs)
|
|
176
232
|
return found;
|
|
177
233
|
return liveBucketStartMs(ms, intervalMs, venue) === barTs ? found : -1;
|
|
178
234
|
}
|
|
235
|
+
/** Adds one run of a bar's keys (or rows) after its earlier runs: the sweep hands a bar each run in key order. */
|
|
236
|
+
function appendRun(groups, key, run) {
|
|
237
|
+
const held = groups.get(key);
|
|
238
|
+
if (held === undefined)
|
|
239
|
+
groups.set(key, run);
|
|
240
|
+
else
|
|
241
|
+
for (const item of run)
|
|
242
|
+
held.push(item);
|
|
243
|
+
}
|
|
179
244
|
function isAscendingNumbers(values) {
|
|
180
245
|
for (let i = 1; i < values.length; i++)
|
|
181
246
|
if (values[i] < values[i - 1])
|
|
182
247
|
return false;
|
|
183
248
|
return true;
|
|
184
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* The exclusive end of the bar opening at `openMs` on a venue's grid at `intervalMs` (`liveBucketStartMs`): the full
|
|
252
|
+
* interval where the bar holds its last instant, else the first minute past the open it does not hold (a session's
|
|
253
|
+
* stub ends at its close: an RTH 4h bar opening 13:00 New York on NYMEX ends 14:30), found by bisection on the minute
|
|
254
|
+
* grid every session boundary sits on.
|
|
255
|
+
*/
|
|
256
|
+
function venueBarEndMs(openMs, intervalMs, venue) {
|
|
257
|
+
const full = openMs + intervalMs;
|
|
258
|
+
if (liveBucketStartMs(full - 1, intervalMs, venue) === openMs)
|
|
259
|
+
return full;
|
|
260
|
+
let held = Math.floor(openMs / MINUTE_MS);
|
|
261
|
+
let notHeld = Math.floor((full - 1) / MINUTE_MS);
|
|
262
|
+
while (notHeld - held > 1) {
|
|
263
|
+
const mid = Math.floor((held + notHeld) / 2);
|
|
264
|
+
if (liveBucketStartMs(mid * MINUTE_MS, intervalMs, venue) === openMs)
|
|
265
|
+
held = mid;
|
|
266
|
+
else
|
|
267
|
+
notHeld = mid;
|
|
268
|
+
}
|
|
269
|
+
return Math.max(openMs + 1, notHeld * MINUTE_MS);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* A row's last instant (the last-instant placement's key): its bar's true end on the row's own grid less one
|
|
273
|
+
* (`rowVenue`, `liveBucketVenueOf` of the rows' market: a session's stub ends at its close, so a NYMEX RTH 4h row
|
|
274
|
+
* opening 13:00 New York lasts to 14:29:59, inside an ES RTH host's 13:30 bar, where its nominal span ran past the ES
|
|
275
|
+
* close and the row was dropped); the nominal span (`openMs + rowSpanMs - 1`) without a grid, or for a row that opens
|
|
276
|
+
* no bar on it.
|
|
277
|
+
*/
|
|
278
|
+
export function rowLastInstantMs(openMs, rowSpanMs, rowVenue) {
|
|
279
|
+
const venue = rowVenue ?? undefined;
|
|
280
|
+
if (venue !== undefined && liveBucketStartMs(openMs, rowSpanMs, venue) === openMs) {
|
|
281
|
+
return venueBarEndMs(openMs, rowSpanMs, venue) - 1;
|
|
282
|
+
}
|
|
283
|
+
return openMs + rowSpanMs - 1;
|
|
284
|
+
}
|
|
185
285
|
/**
|
|
186
286
|
* The last-instant placement (`PlaceRowsInHostBarsOptions.rowSpanMs`): every
|
|
187
|
-
* row keys on its last instant (`ts + rowSpanMs - 1
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* the
|
|
287
|
+
* row keys on its last instant (`rowLastInstantMs`: `ts + rowSpanMs - 1`, or
|
|
288
|
+
* its bar's true end on `rowVenue`) unless it is stamped on a mounted bar's
|
|
289
|
+
* open, the shared sweep lands the keys, and a row whose last instant only a
|
|
290
|
+
* bar after the last mounted one holds (the live edge) lands in the bar
|
|
291
|
+
* holding its open. Each bar's rows merge in timestamp order.
|
|
191
292
|
*/
|
|
192
|
-
function placeRowsByLastInstant(sorted, bars, rowSpanMs, formingBarTs, land) {
|
|
293
|
+
function placeRowsByLastInstant(sorted, bars, rowSpanMs, formingBarTs, land, rowVenue) {
|
|
193
294
|
const main = bars.mainRows;
|
|
194
295
|
const { intervalMs } = bars;
|
|
195
296
|
const venue = bars.venue ?? undefined;
|
|
196
297
|
const opens = new Set();
|
|
197
298
|
for (const bar of main)
|
|
198
299
|
opens.add(bar[0]);
|
|
199
|
-
const keys = sorted.map((row) => (opens.has(row[0]) ? row[0] : row[0]
|
|
300
|
+
const keys = sorted.map((row) => (opens.has(row[0]) ? row[0] : rowLastInstantMs(row[0], rowSpanMs, rowVenue)));
|
|
200
301
|
const order = keys.map((_, index) => index);
|
|
201
302
|
// Rows denser than their span can key out of order: sort by key, ties in timestamp order.
|
|
202
303
|
if (!isAscendingNumbers(keys))
|
|
203
304
|
order.sort((a, b) => keys[a] - keys[b] || a - b);
|
|
204
305
|
const groups = new Map();
|
|
205
|
-
const pastLastBar = sweepHostBars(order.length, (k) => keys[order[k]], main, intervalMs, venue, (barIndex, from, to) => groups
|
|
306
|
+
const pastLastBar = sweepHostBars(order.length, (k) => keys[order[k]], main, intervalMs, venue, (barIndex, from, to) => appendRun(groups, barIndex, order.slice(from, to)));
|
|
206
307
|
// The live edge: a row whose last instant falls in a bar the host has not
|
|
207
308
|
// printed yet is still forming, and the bar holding its open shows its
|
|
208
309
|
// latest value, but only when that bar is the one forming NOW
|
|
@@ -280,7 +381,7 @@ function placeCellsInHostBars(sorted, bars, out, onMade) {
|
|
|
280
381
|
if (!isAscendingNumbers(instants))
|
|
281
382
|
order.sort((a, b) => instants[a] - instants[b] || a - b);
|
|
282
383
|
const byBar = new Map();
|
|
283
|
-
sweepHostBars(order.length, (k) => instants[order[k]], main, bars.intervalMs, bars.venue ?? undefined, (barIndex, from, to) => byBar
|
|
384
|
+
sweepHostBars(order.length, (k) => instants[order[k]], main, bars.intervalMs, bars.venue ?? undefined, (barIndex, from, to) => appendRun(byBar, main[barIndex][0], order.slice(from, to)));
|
|
284
385
|
for (const barTs of bare.keys())
|
|
285
386
|
if (!byBar.has(barTs))
|
|
286
387
|
byBar.set(barTs, []);
|
|
@@ -343,10 +444,14 @@ export function placeRowsInHostBars(rows, bars, merge, onMade, opts) {
|
|
|
343
444
|
};
|
|
344
445
|
const rowSpanMs = opts?.rowSpanMs;
|
|
345
446
|
if (typeof rowSpanMs === 'number' && Number.isFinite(rowSpanMs) && rowSpanMs > 0) {
|
|
346
|
-
placeRowsByLastInstant(sorted, bars, rowSpanMs, opts?.formingBarTs ?? null, land);
|
|
447
|
+
placeRowsByLastInstant(sorted, bars, rowSpanMs, opts?.formingBarTs ?? null, land, opts?.rowVenue);
|
|
347
448
|
return out;
|
|
348
449
|
}
|
|
349
|
-
|
|
450
|
+
// A bar's runs (one, but on a label grid's interleaved bar) land together, the bars in order.
|
|
451
|
+
const runs = new Map();
|
|
452
|
+
sweepHostBars(sorted.length, (index) => sorted[index][0], main, bars.intervalMs, bars.venue ?? undefined, (barIndex, from, to) => appendRun(runs, barIndex, sorted.slice(from, to)));
|
|
453
|
+
for (const [barIndex, group] of runs)
|
|
454
|
+
land(main[barIndex][0], group);
|
|
350
455
|
return out;
|
|
351
456
|
}
|
|
352
457
|
/** The inputs `liveBucketStartMs` reads for a venue at an interval (the extended-hours option included). */
|
|
@@ -360,7 +465,6 @@ function gridKeyOf(intervalMs, venue) {
|
|
|
360
465
|
usEquitiesSessionConfig.extendedHoursEnabled,
|
|
361
466
|
].join('|');
|
|
362
467
|
}
|
|
363
|
-
const MINUTE_MS = 60_000;
|
|
364
468
|
/**
|
|
365
469
|
* A host's bucket function for a stream of instants (a live door's ticks):
|
|
366
470
|
* `liveBucketStartMs` over `venue` at `intervalMs`, asked only when an instant
|
|
@@ -397,22 +501,8 @@ export function createHostBucketResolver(intervalMs, venue) {
|
|
|
397
501
|
barEnds.set(bar, end);
|
|
398
502
|
return end;
|
|
399
503
|
};
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if (liveBucketStartMs(full - 1, intervalMs, v) === bar)
|
|
403
|
-
return full;
|
|
404
|
-
// A stub: the first minute past `bar` that the bar does not hold.
|
|
405
|
-
let held = Math.floor(bar / MINUTE_MS);
|
|
406
|
-
let notHeld = Math.floor((full - 1) / MINUTE_MS);
|
|
407
|
-
while (notHeld - held > 1) {
|
|
408
|
-
const mid = Math.floor((held + notHeld) / 2);
|
|
409
|
-
if (liveBucketStartMs(mid * MINUTE_MS, intervalMs, v) === bar)
|
|
410
|
-
held = mid;
|
|
411
|
-
else
|
|
412
|
-
notHeld = mid;
|
|
413
|
-
}
|
|
414
|
-
return Math.max(bar + 1, notHeld * MINUTE_MS);
|
|
415
|
-
};
|
|
504
|
+
// A stub's end is the first minute past `bar` that the bar does not hold.
|
|
505
|
+
const findBarEnd = (bar) => venueBarEndMs(bar, intervalMs, v);
|
|
416
506
|
return (tsMs) => {
|
|
417
507
|
if (!Number.isFinite(tsMs) || !(intervalMs > 0))
|
|
418
508
|
return null;
|
|
@@ -445,3 +535,53 @@ export function hostBucketResolverFor(intervalMs, venue) {
|
|
|
445
535
|
}
|
|
446
536
|
return resolve;
|
|
447
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* A live door's bar for a frame of a source on its own row grid (`rowSpanMs` rows on `rowVenue`): the bar the
|
|
540
|
+
* last-instant placement (`placeRowsInHostBars` with `rowSpanMs` and `rowVenue`, dataFetch's STEP 4) puts the row
|
|
541
|
+
* holding the frame's instant in, judged at `nowMs` as a fetch then would, so a fold and the next fetch of its row land
|
|
542
|
+
* in one bar. A row opening a host bar lands on it; any other keys on its last instant (`rowLastInstantMs`): in a bar
|
|
543
|
+
* opened by then it lands there (a replay, a frame late across a boundary), in a later bar it shows in the forming bar
|
|
544
|
+
* holding its open (the live edge), and with no bar (closing past the session close) nowhere, null, as with no row at
|
|
545
|
+
* the instant. Judged at the later of `nowMs` and the instant (a device clock inside the server-clock deadband).
|
|
546
|
+
*/
|
|
547
|
+
export function createSourceRowHostBarResolver(intervalMs, venue, rowSpanMs, rowVenue) {
|
|
548
|
+
// One span cache per lookup (rows, the bars a row keys into, the bar forming now); a row's bars once per row.
|
|
549
|
+
const rowAt = createHostBucketResolver(rowSpanMs, rowVenue);
|
|
550
|
+
const barAt = createHostBucketResolver(intervalMs, venue);
|
|
551
|
+
const barNow = createHostBucketResolver(intervalMs, venue);
|
|
552
|
+
let row = Number.NaN;
|
|
553
|
+
let openBar = null;
|
|
554
|
+
let keyBar = null;
|
|
555
|
+
return (instantMs, nowMs) => {
|
|
556
|
+
const rowOpen = rowAt(instantMs);
|
|
557
|
+
if (rowOpen === null)
|
|
558
|
+
return null;
|
|
559
|
+
if (rowOpen !== row) {
|
|
560
|
+
openBar = barAt(rowOpen);
|
|
561
|
+
keyBar = openBar === rowOpen ? rowOpen : barAt(rowLastInstantMs(rowOpen, rowSpanMs, rowVenue));
|
|
562
|
+
row = rowOpen;
|
|
563
|
+
}
|
|
564
|
+
if (openBar === rowOpen || keyBar === null)
|
|
565
|
+
return keyBar;
|
|
566
|
+
const atMs = Math.max(nowMs, instantMs);
|
|
567
|
+
if (keyBar <= atMs)
|
|
568
|
+
return keyBar;
|
|
569
|
+
const forming = barNow(atMs);
|
|
570
|
+
if (keyBar === forming)
|
|
571
|
+
return keyBar;
|
|
572
|
+
return openBar !== null && openBar === forming ? openBar : null;
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
const sourceRowResolvers = new Map();
|
|
576
|
+
/** The shared `createSourceRowHostBarResolver` of a host grid and a row grid (every live door on the pair reuses it). */
|
|
577
|
+
export function sourceRowHostBarResolverFor(intervalMs, venue, rowSpanMs, rowVenue) {
|
|
578
|
+
const key = `${gridKeyOf(intervalMs, venue)}#${gridKeyOf(rowSpanMs, rowVenue)}`;
|
|
579
|
+
let resolve = sourceRowResolvers.get(key);
|
|
580
|
+
if (!resolve) {
|
|
581
|
+
if (sourceRowResolvers.size >= RESOLVER_MEMO_MAX)
|
|
582
|
+
sourceRowResolvers.clear();
|
|
583
|
+
resolve = createSourceRowHostBarResolver(intervalMs, venue, rowSpanMs, rowVenue);
|
|
584
|
+
sourceRowResolvers.set(key, resolve);
|
|
585
|
+
}
|
|
586
|
+
return resolve;
|
|
587
|
+
}
|
|
@@ -26,6 +26,8 @@ export declare function indexHostFetchTierMs(intervalMs: number, hostVenue: Live
|
|
|
26
26
|
* Then the row closing first inside a host bar opens before that bar, so a
|
|
27
27
|
* fetch placed by last instant (`PlaceRowsInHostBarsOptions.rowSpanMs`) asks
|
|
28
28
|
* one source span early to hold the first bar's row. A source on the host's
|
|
29
|
-
* own grid, or a finer grid dividing it, never straddles
|
|
29
|
+
* own grid, or a finer grid dividing it, never straddles, and neither does a
|
|
30
|
+
* host bar no source row holds (a regular-session source's night under a 24/7
|
|
31
|
+
* host's 15m bars: no row opens before it).
|
|
30
32
|
*/
|
|
31
33
|
export declare function sourceRowsStraddleHostBars(intervalMs: number, hostVenue: LiveBucketVenue | null | undefined, rowSpanMs: number, sourceVenue: LiveBucketVenue | null | undefined): boolean;
|
|
@@ -100,7 +100,9 @@ const straddleByGrids = new Map();
|
|
|
100
100
|
* Then the row closing first inside a host bar opens before that bar, so a
|
|
101
101
|
* fetch placed by last instant (`PlaceRowsInHostBarsOptions.rowSpanMs`) asks
|
|
102
102
|
* one source span early to hold the first bar's row. A source on the host's
|
|
103
|
-
* own grid, or a finer grid dividing it, never straddles
|
|
103
|
+
* own grid, or a finer grid dividing it, never straddles, and neither does a
|
|
104
|
+
* host bar no source row holds (a regular-session source's night under a 24/7
|
|
105
|
+
* host's 15m bars: no row opens before it).
|
|
104
106
|
*/
|
|
105
107
|
export function sourceRowsStraddleHostBars(intervalMs, hostVenue, rowSpanMs, sourceVenue) {
|
|
106
108
|
if (!(intervalMs > 0) || !(rowSpanMs > 0))
|
|
@@ -110,7 +112,10 @@ export function sourceRowsStraddleHostBars(intervalMs, hostVenue, rowSpanMs, sou
|
|
|
110
112
|
const memo = straddleByGrids.get(memoKey);
|
|
111
113
|
if (memo !== undefined)
|
|
112
114
|
return memo;
|
|
113
|
-
const straddles = probeGrid(intervalMs, hostVenue, hostKey).opens.some((open) =>
|
|
115
|
+
const straddles = probeGrid(intervalMs, hostVenue, hostKey).opens.some((open) => {
|
|
116
|
+
const rowOpen = liveBucketStartMs(open, rowSpanMs, sourceVenue ?? undefined);
|
|
117
|
+
return rowOpen !== null && rowOpen !== open;
|
|
118
|
+
});
|
|
114
119
|
if (straddleByGrids.size >= TIER_MEMO_MAX)
|
|
115
120
|
straddleByGrids.clear();
|
|
116
121
|
straddleByGrids.set(memoKey, straddles);
|
|
@@ -15,13 +15,16 @@
|
|
|
15
15
|
* - the market-kind table: forex and commodities trade no volume the chart can split, keep no
|
|
16
16
|
* book and list no options, so they serve no volume profile, buy/sell volume, order book,
|
|
17
17
|
* implied volatility or skew, whatever the index-mode admission lets through; a US equity
|
|
18
|
-
* market
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* market of the tradfi kind (the listing venues, Polygon under both enum names) prints no
|
|
19
|
+
* aggressor side, so it serves no buy/sell volume either (the gateway writes every such trade
|
|
20
|
+
* row as side 0 and the lane keeps BUY and SELL rows only, so the lane is empty and a recipe's
|
|
21
|
+
* zero fill would draw that as flat flow), except the three consolidated tapes (`NASDAQ_TAPE`,
|
|
22
|
+
* `NYSE_TAPE`, `NYSE_ARCA_TAPE`), whose TRADE_AGG serves BUY and SELL envelopes; a crypto index
|
|
22
23
|
* (CRYPTOCAP, not index-mode: it fetches by period like crypto) serves its value candles and no
|
|
23
24
|
* other lane at all; a quote-priced perpetual market (Variational, also period-fetched) serves its
|
|
24
|
-
* quote candles, funding and open interest, and no trade, volume, book, profile or options lane;
|
|
25
|
+
* quote candles, funding and open interest, and no trade, volume, book, profile or options lane; a
|
|
26
|
+
* consolidated tape serves its trades alone (candles, sided volume, the profile, the size flow, the large
|
|
27
|
+
* prints) and no book, open interest, liquidations, funding or options summary;
|
|
25
28
|
* - the coin table: the option-summary lanes (implied volatility, skew) hold a series for the
|
|
26
29
|
* coins `WRUN_OPTION_SUMMARY_COINS` lists (BTC and ETH) and no other.
|
|
27
30
|
* The dispatcher's own admission (`isKScriptTypeServedOnIndexMode`) stays as it is.
|
|
@@ -30,6 +33,7 @@ import { checkIsCryptoIndex } from './crypto-index.leaf.js';
|
|
|
30
33
|
import { checkIsQuotePerp } from './quote-perp.leaf.js';
|
|
31
34
|
import { checkIsIndexMode } from './index-mode.util.js';
|
|
32
35
|
import { checkIsForexOrCommodity, getMarketKind } from './marketKind.util.js';
|
|
36
|
+
import { isStocksTapeGoverned } from '../v2/stocks-governed.util.js';
|
|
33
37
|
import { WRUN_OPTION_SUMMARY_COINS, WRUN_OPTION_SUMMARY_LANES } from '../wrun/wrun-option-summary-lane.util.js';
|
|
34
38
|
/** The kScript source types the dispatcher serves on an index-mode payload exchange. */
|
|
35
39
|
export function isKScriptTypeServedOnIndexMode(kScriptType) {
|
|
@@ -43,10 +47,18 @@ const FOREX_COMMODITY_UNSERVED_TYPES = new Set([
|
|
|
43
47
|
WRUN_OPTION_SUMMARY_LANES.implied_volatility.type,
|
|
44
48
|
WRUN_OPTION_SUMMARY_LANES.skew.type,
|
|
45
49
|
]);
|
|
46
|
-
/** The lane fetch types a US equity market never serves (the market-kind table): buy/sell volume. A
|
|
47
|
-
* carries no aggressor side, so the lane's BUY/SELL split is empty there; it is the one lane
|
|
48
|
-
* the index-mode admission lets through on a stock chart. */
|
|
50
|
+
/** The lane fetch types a US equity market never serves (the market-kind table): buy/sell volume. A Polygon or
|
|
51
|
+
* listing-venue print carries no aggressor side, so the lane's BUY/SELL split is empty there; it is the one lane
|
|
52
|
+
* needing a side that the index-mode admission lets through on a stock chart. The tapes are carved out below. */
|
|
49
53
|
const US_EQUITY_UNSERVED_TYPES = new Set(['buy_sell_volume']);
|
|
54
|
+
/** The lane fetch types a US stock tape serves (the stocks gate serves its trades alone): no book, OI or funding. */
|
|
55
|
+
const STOCK_TAPE_SERVED_TYPES = new Set([
|
|
56
|
+
'ohlcv',
|
|
57
|
+
'buy_sell_volume',
|
|
58
|
+
'volume_profile',
|
|
59
|
+
'trade_volume_by_size',
|
|
60
|
+
'trades',
|
|
61
|
+
]);
|
|
50
62
|
/** The one lane fetch type a crypto index market serves (the market-kind table): its value candles. */
|
|
51
63
|
const CRYPTO_INDEX_SERVED_TYPES = new Set(['ohlcv']);
|
|
52
64
|
/** The lane fetch types a quote-priced perpetual market serves (the market-kind table): its quote candles and the
|
|
@@ -73,9 +85,8 @@ export function wrunLaneServiceOnMarket({ type, exchange, coin, nativeRows, }) {
|
|
|
73
85
|
if (FOREX_COMMODITY_UNSERVED_TYPES.has(type) && checkIsForexOrCommodity(exchange)) {
|
|
74
86
|
return { served: false, reason: 'market-kind' };
|
|
75
87
|
}
|
|
76
|
-
// By the kind, not the index-mode set
|
|
77
|
-
|
|
78
|
-
if (US_EQUITY_UNSERVED_TYPES.has(type) && getMarketKind(exchange) === 'tradfi') {
|
|
88
|
+
// By the kind, not the index-mode set (listing venues outside that set included); a tape's TRADE_AGG is sided.
|
|
89
|
+
if (US_EQUITY_UNSERVED_TYPES.has(type) && getMarketKind(exchange) === 'tradfi' && !isStocksTapeGoverned(exchange)) {
|
|
79
90
|
return { served: false, reason: 'market-kind' };
|
|
80
91
|
}
|
|
81
92
|
if (!CRYPTO_INDEX_SERVED_TYPES.has(type) && checkIsCryptoIndex(exchange)) {
|
|
@@ -84,6 +95,9 @@ export function wrunLaneServiceOnMarket({ type, exchange, coin, nativeRows, }) {
|
|
|
84
95
|
if (!QUOTE_PERP_SERVED_TYPES.has(type) && checkIsQuotePerp(exchange)) {
|
|
85
96
|
return { served: false, reason: 'market-kind' };
|
|
86
97
|
}
|
|
98
|
+
if (!STOCK_TAPE_SERVED_TYPES.has(type) && isStocksTapeGoverned(exchange)) {
|
|
99
|
+
return { served: false, reason: 'market-kind' };
|
|
100
|
+
}
|
|
87
101
|
const coins = COIN_SERVED_TYPES[type];
|
|
88
102
|
const word = typeof coin === 'string' ? coin.trim().toUpperCase() : '';
|
|
89
103
|
if (coins !== undefined && word !== '' && !coins.includes(word))
|