@orangecharts/wrun-chart-host 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/constants/feature-flags.constants.d.ts +6 -1
- package/dist/constants/feature-flags.constants.js +67 -24
- package/dist/constants/opra-compliance.constants.d.ts +3 -2
- package/dist/constants/opra-compliance.constants.js +3 -2
- package/dist/constants/scriptEditor/builtin-script-snippets.d.ts +26 -0
- package/dist/constants/scriptEditor/builtin-script-snippets.js +6 -0
- package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +15 -0
- package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +17 -0
- package/dist/constants/venue-presets.constants.d.ts +20 -20
- package/dist/constants/venue-presets.constants.js +24 -26
- package/dist/host-env.d.ts +29 -5
- package/dist/host-env.js +6 -0
- package/dist/host-ports.types.d.ts +69 -15
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/interfaces/kscript-diagnostics.interface.d.ts +6 -0
- package/dist/interfaces/replay.interface.d.ts +8 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +18 -2
- package/dist/kscript-data/controls/live-trades-merge.util.d.ts +41 -4
- package/dist/kscript-data/controls/live-trades-merge.util.js +52 -7
- package/dist/kscript-data/controls/live-trades-order-gate.util.d.ts +56 -0
- package/dist/kscript-data/controls/live-trades-order-gate.util.js +107 -0
- package/dist/market-data/billing.interface.d.ts +95 -31
- package/dist/market-data/billing.interface.js +36 -5
- package/dist/market-data/venue.d.ts +88 -6
- package/dist/market-data/venues/cme.contract.copy.json +66 -0
- package/dist/market-data/venues/cme.d.ts +126 -0
- package/dist/market-data/venues/cme.js +133 -0
- package/dist/market-data/venues/index.d.ts +162 -5
- package/dist/market-data/venues/index.js +48 -6
- package/dist/settings-templates/index.js +7 -3
- package/dist/settings-templates/indicator-fields.d.ts +5 -4
- package/dist/settings-templates/indicator-fields.js +45 -6
- package/dist/settings-templates/tool-rules.d.ts +27 -17
- package/dist/settings-templates/tool-rules.js +27 -11
- package/dist/settings-templates/tool-tables.generated.js +91 -31
- package/dist/utility/chart/book-live-bucket.util.d.ts +15 -0
- package/dist/utility/chart/book-live-bucket.util.js +47 -0
- package/dist/utility/chart/index-mode-admission.util.js +15 -2
- package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +35 -11
- package/dist/utility/chart/kscript-drawing-safe-area.util.js +145 -35
- package/dist/utility/chart/kscript-live-coalesce.util.d.ts +7 -2
- package/dist/utility/chart/kscript-live-coalesce.util.js +9 -3
- package/dist/utility/chart/kscript-provenance-keys.util.js +6 -0
- package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +3 -1
- package/dist/utility/chart/kscript-titancharts-render-keys.constants.d.ts +32 -2
- package/dist/utility/chart/kscript-titancharts-render-keys.constants.js +45 -0
- package/dist/utility/chart/kscript-venue-policy.util.d.ts +54 -35
- package/dist/utility/chart/kscript-venue-policy.util.js +78 -42
- package/dist/utility/chart/market-session-schedule.util.d.ts +10 -0
- package/dist/utility/chart/market-session-schedule.util.js +16 -0
- package/dist/utility/chart/opra-read-access.leaf.d.ts +5 -3
- package/dist/utility/chart/opra-read-access.leaf.js +5 -3
- package/dist/utility/chart/rth-session.util.d.ts +3 -2
- package/dist/utility/chart/rth-session.util.js +2 -1
- package/dist/utility/chart/window-geometry.leaf.d.ts +8 -0
- package/dist/utility/chart/window-geometry.leaf.js +22 -6
- package/dist/utility/chart/wrun-run-result.util.d.ts +12 -0
- package/dist/utility/chart/wrun-run-result.util.js +141 -6
- package/dist/utility/options/option-bar-anchor.util.d.ts +145 -0
- package/dist/utility/options/option-bar-anchor.util.js +340 -0
- package/dist/utility/options/option-venue.util.d.ts +18 -0
- package/dist/utility/options/option-venue.util.js +27 -0
- package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +2 -0
- package/dist/utility/wrun/derived-roots.util.d.ts +213 -0
- package/dist/utility/wrun/derived-roots.util.js +471 -0
- package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +41 -6
- package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +89 -19
- package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +9 -4
- package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +47 -6
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +4 -2
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +4 -2
- package/dist/utility/wrun/sources/lanes/option_daily.js +5 -2
- package/dist/utility/wrun/sources/lanes/options_flow.js +5 -2
- package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +64 -19
- package/dist/utility/wrun/sources/opra-option-lanes.util.js +105 -35
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +2 -1
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +2 -1
- package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +3 -0
- package/dist/utility/wrun/sources/row-lanes/option_prints.js +19 -4
- package/dist/utility/wrun/sources/row-lanes/option_strike_flow.js +17 -4
- package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +52 -13
- package/dist/utility/wrun/sources/row-lanes/option_strikes.js +88 -19
- package/dist/utility/wrun/sources/row-lanes/option_surface.js +2 -1
- package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +19 -0
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +24 -9
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +39 -10
- package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.d.ts +64 -0
- package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.js +89 -0
- package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +15 -3
- package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +22 -3
- package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +31 -0
- package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +174 -13
- package/dist/utility/wrun/sources/wrun-row-lanes.util.js +685 -27
- package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +12 -0
- package/dist/utility/wrun/wrun-builtin-twin.util.js +21 -0
- package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +53 -12
- package/dist/utility/wrun/wrun-chart-market-facts.util.js +101 -53
- package/dist/utility/wrun/wrun-download-meter.util.d.ts +15 -0
- package/dist/utility/wrun/wrun-download-meter.util.js +14 -2
- package/dist/utility/wrun/wrun-download-plan.util.d.ts +99 -0
- package/dist/utility/wrun/wrun-download-plan.util.js +118 -0
- package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +11 -3
- package/dist/utility/wrun/wrun-draft-legend-note.util.js +26 -4
- package/dist/utility/wrun/wrun-frames.d.ts +27 -6
- package/dist/utility/wrun/wrun-frames.js +73 -10
- package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +7 -1
- package/dist/utility/wrun/wrun-hosted-wire.util.js +12 -2
- package/dist/utility/wrun/wrun-hud-looks.util.d.ts +18 -4
- package/dist/utility/wrun/wrun-hud-looks.util.js +45 -13
- package/dist/utility/wrun/wrun-latest-snapshot.d.ts +11 -0
- package/dist/utility/wrun/wrun-live-intake.util.d.ts +13 -7
- package/dist/utility/wrun/wrun-live-intake.util.js +82 -29
- package/dist/utility/wrun/wrun-live-tick.util.d.ts +4 -0
- package/dist/utility/wrun/wrun-live-tick.util.js +158 -14
- package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +49 -10
- package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +65 -5
- package/dist/utility/wrun/wrun-market-size-defaults.util.js +31 -5
- package/dist/utility/wrun/wrun-opra-lane.util.d.ts +17 -4
- package/dist/utility/wrun/wrun-opra-lane.util.js +6 -4
- package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.d.ts +31 -0
- package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.js +119 -0
- package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +23 -6
- package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +47 -11
- package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +86 -19
- package/dist/utility/wrun/wrun-option-strike-flow.util.js +168 -62
- package/dist/utility/wrun/wrun-option-views.util.d.ts +47 -13
- package/dist/utility/wrun/wrun-option-views.util.js +98 -26
- package/dist/utility/wrun/wrun-output-style.util.d.ts +6 -2
- package/dist/utility/wrun/wrun-output-style.util.js +20 -2
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +17 -0
- package/dist/utility/wrun/wrun-overlay-lifecycle.util.d.ts +10 -1
- package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +52 -4
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +100 -31
- package/dist/utility/wrun/wrun-overlay-run.util.js +733 -114
- package/dist/utility/wrun/wrun-pane-format.util.d.ts +2 -1
- package/dist/utility/wrun/wrun-pane-format.util.js +7 -3
- package/dist/utility/wrun/wrun-panel-mount.util.d.ts +9 -0
- package/dist/utility/wrun/wrun-panel-mount.util.js +63 -13
- package/dist/utility/wrun/wrun-panel-style.util.d.ts +10 -9
- package/dist/utility/wrun/wrun-panel-style.util.js +58 -9
- package/dist/utility/wrun/wrun-param-map.util.d.ts +14 -11
- package/dist/utility/wrun/wrun-param-map.util.js +10 -5
- package/dist/utility/wrun/wrun-param-values.util.d.ts +14 -4
- package/dist/utility/wrun/wrun-param-values.util.js +4 -0
- package/dist/utility/wrun/wrun-pin-spelling.util.js +12 -11
- package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +50 -0
- package/dist/utility/wrun/wrun-refusal-surface.util.js +68 -0
- package/dist/utility/wrun/wrun-refused-latest.util.d.ts +10 -0
- package/dist/utility/wrun/wrun-refused-latest.util.js +12 -0
- package/dist/utility/wrun/wrun-row-source.d.ts +11 -0
- package/dist/utility/wrun/wrun-run-interval.util.d.ts +4 -2
- package/dist/utility/wrun/wrun-run-interval.util.js +9 -6
- package/dist/utility/wrun/wrun-script-inputs.util.d.ts +45 -1
- package/dist/utility/wrun/wrun-script-inputs.util.js +112 -4
- package/dist/utility/wrun/wrun-setting-words.util.d.ts +7 -3
- package/dist/utility/wrun/wrun-setting-words.util.js +13 -5
- package/dist/utility/wrun/wrun-socket-row-source.d.ts +27 -2
- package/dist/utility/wrun/wrun-socket-row-source.js +113 -8
- package/dist/utility/wrun/wrun-source-rows.util.d.ts +5 -1
- package/dist/utility/wrun/wrun-source-rows.util.js +16 -3
- package/dist/utility/wrun/wrun-style-words.util.js +6 -4
- package/dist/utility/wrun/wrun-table-chrome.util.d.ts +3 -2
- package/dist/utility/wrun/wrun-table-chrome.util.js +19 -11
- package/dist/utility/wrun/wrun-tape-per-order.util.d.ts +2 -0
- package/dist/utility/wrun/wrun-tape-per-order.util.js +26 -0
- package/dist/utils/replay/replay-buffer-math.d.ts +53 -2
- package/dist/utils/replay/replay-buffer-math.js +227 -20
- package/package.json +11 -11
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bars a grouped option read lays (OPTLOAD-READ-CONTRACT 3.2 to 3.4): the app's ONE mirror of tsdb-gateway's anchor
|
|
3
|
+
* rules, read at origin/main d83cbbf20 (pkg/tsdb/selects/option_read_shape.go `barAnchorRules`, `optionReadAnchorReads`,
|
|
4
|
+
* `OptionReadGridOf` and each rule's `fitTier`, `bar`, `session`, `boundary`, `barEnd` and `lays`;
|
|
5
|
+
* option_print_agg_group.go `optionPrintAggCMESessionScopes`; trade_agg.go `cmeRegularSessionAnchor` and
|
|
6
|
+
* `cmeEnergySessionAnchor`; cme.go `cmeSessionDay`, `cmeSessionOpen`, `cmeCurrentSessionLabel` and `isCMEGroupExchange`).
|
|
7
|
+
* Every option read that names a `barAnchor` takes the anchors, their bars, the venues they lay and the reads that take
|
|
8
|
+
* them from here: the strike and contract flow groupings (wrun-option-strike-flow.util), the flow scopes' bars
|
|
9
|
+
* (option-print-agg-scope.worker.util), the prints' per-bar cut (k-option-print.worker), the surface pick
|
|
10
|
+
* (k-option-surface.worker) and the delayed bound's grid (option-read-grid.util). The rules are keyed by pb-common's
|
|
11
|
+
* `BarAnchor`, so an anchor the protocol adds fails the type check until it has a rule here, and the class guard
|
|
12
|
+
* (tests/utility/options/option-bar-anchor.class.spec.ts) fails by name on any other module that names an anchor.
|
|
13
|
+
*
|
|
14
|
+
* - UTC: bars on the Unix epoch, every row counted; its session is the UTC date.
|
|
15
|
+
* - US_EQUITY_RTH, CME_RTH and CME_ENERGY_RTH: a regular session on the New York wall clock (09:30 to 16:00; 09:30 to
|
|
16
|
+
* 16:15, the CME platform session the CME candles keep; 09:00 to 14:30, the energy pit session), weekdays only, bars
|
|
17
|
+
* open + k * width, only rows of [open, close) counted, the last bar of a day short; no holiday is modelled, as the
|
|
18
|
+
* charts model none. The two CME anchors lay bars over the CME group's rows alone, built from tiers dividing 15 and 30
|
|
19
|
+
* minutes; daylight saving comes from the tz database on both sides.
|
|
20
|
+
* - CME_SESSION: the Globex trade date (17:00 Chicago opens the next; a weekday holiday's session belongs to the next
|
|
21
|
+
* trade date on the CME calendar, a weekend day keeps its own date), each bar stamped at the 17:00 open of its first
|
|
22
|
+
* session day; a 604,800 s bar is the ISO week of a trade date. The CME group's alone, taken by OPTION_PRINT_AGG's
|
|
23
|
+
* COIN, MARKET, STRIKE, EXPIRY, EXPIRY_STRIKE and CONTRACT scopes alone, from a tier dividing an hour. It drops no
|
|
24
|
+
* row: an always-on root's weekend rows land on their own dates, as the chart's lattice books them.
|
|
25
|
+
*
|
|
26
|
+
* A decider proves an anchor's bars against the chart's own: a bucket the anchor lays no bar for may fall on a chart bar
|
|
27
|
+
* only where the chart's product holds no trading (`optionChartClosedAt`, its schedule), never because the anchor's own
|
|
28
|
+
* hours leave it out (a CME regular session's weekend on an always-on root).
|
|
29
|
+
*
|
|
30
|
+
* Pure and worker-safe: the zone clock (ny-calendar.util), the CME lattice's trade calendar (cme-session-bucket.util) and
|
|
31
|
+
* the CME products' schedules (market-session-schedule.util).
|
|
32
|
+
*/
|
|
33
|
+
import { BarAnchor, BarSpan } from '@orangecharts/orange-v2-pb-common';
|
|
34
|
+
import { cmeSessionBucketMs, isCmeSessionLatticeExchange } from '../chart/cme-session-bucket.util.js';
|
|
35
|
+
import { isGovernedFuturesSymbolOpenAt } from '../chart/market-session-schedule.util.js';
|
|
36
|
+
import { zoneWallMsAt, zoneWallToUtcMs } from '../chart/ny-calendar.util.js';
|
|
37
|
+
const MINUTE_MS = 60_000;
|
|
38
|
+
const HOUR_MS = 3_600_000;
|
|
39
|
+
const DAY_MS = 86_400_000;
|
|
40
|
+
const WEEK_MS = 7 * DAY_MS;
|
|
41
|
+
/** pb-common `BarAnchor` by name: the values a request names (the gateway decodes JSON enums as numbers). */
|
|
42
|
+
export const OPTION_BAR_ANCHOR = Object.freeze({
|
|
43
|
+
UTC: BarAnchor.UTC,
|
|
44
|
+
US_EQUITY_RTH: BarAnchor.US_EQUITY_RTH,
|
|
45
|
+
CME_SESSION: BarAnchor.CME_SESSION,
|
|
46
|
+
CME_RTH: BarAnchor.CME_RTH,
|
|
47
|
+
CME_ENERGY_RTH: BarAnchor.CME_ENERGY_RTH,
|
|
48
|
+
});
|
|
49
|
+
const floorMod = (value, width) => ((value % width) + width) % width;
|
|
50
|
+
/** `fitDayBars`: no bar wider than a day, a day bar from the DAY tier alone, and a whole number of the tier's buckets;
|
|
51
|
+
* a session is the anchor's own to fit. */
|
|
52
|
+
function fitDayBars(tierMs, barMs, session) {
|
|
53
|
+
if (session)
|
|
54
|
+
return true;
|
|
55
|
+
if (barMs > DAY_MS || (barMs === DAY_MS && tierMs !== DAY_MS))
|
|
56
|
+
return false;
|
|
57
|
+
return barMs % tierMs === 0;
|
|
58
|
+
}
|
|
59
|
+
/** `opensBar`: `tMs` opens the bar (or session) it lands in, or lands in none. */
|
|
60
|
+
function opensBar(rule, tMs, barMs, session) {
|
|
61
|
+
const open = session ? rule.sessionOpenMs(tMs) : rule.barOpenMs(tMs, barMs);
|
|
62
|
+
return open === null || open === tMs;
|
|
63
|
+
}
|
|
64
|
+
/** The latest boundary at or before `tMs` on a rule whose bars run unbroken from their open: the open of the bar (or
|
|
65
|
+
* session) holding it, else `tMs` itself (it lands in none). */
|
|
66
|
+
function floorOpensBar(rule, tMs, barMs, session) {
|
|
67
|
+
return (session ? rule.sessionOpenMs(tMs) : rule.barOpenMs(tMs, barMs)) ?? tMs;
|
|
68
|
+
}
|
|
69
|
+
const UTC_RULE = {
|
|
70
|
+
anchor: BarAnchor.UTC,
|
|
71
|
+
name: BarAnchor[BarAnchor.UTC],
|
|
72
|
+
tradeDate: { zone: 'UTC', offsetHours: 0 },
|
|
73
|
+
venues: 'every',
|
|
74
|
+
lays: () => true,
|
|
75
|
+
takes: () => true,
|
|
76
|
+
fitsTier: (tierMs, barMs, session) => tierMs > 0 && fitDayBars(tierMs, barMs, session) && (!session || DAY_MS % tierMs === 0),
|
|
77
|
+
barOpenMs: (tMs, barMs) => {
|
|
78
|
+
if (!Number.isFinite(tMs))
|
|
79
|
+
return null;
|
|
80
|
+
return barMs > 0 ? tMs - floorMod(tMs, barMs) : tMs;
|
|
81
|
+
},
|
|
82
|
+
sessionOpenMs: (tMs) => (Number.isFinite(tMs) ? tMs - floorMod(tMs, DAY_MS) : null),
|
|
83
|
+
isBoundary: (tMs, barMs, session) => opensBar(UTC_RULE, tMs, barMs, session),
|
|
84
|
+
floorBoundaryMs: (tMs, barMs, session) => floorOpensBar(UTC_RULE, tMs, barMs, session),
|
|
85
|
+
barEndMs: (openMs, barMs, session) => openMs + (session ? DAY_MS : barMs),
|
|
86
|
+
};
|
|
87
|
+
/** 1970-01-01, day 0, was a Thursday: a weekend day is a Saturday or a Sunday. */
|
|
88
|
+
const isWeekendDay = (day) => {
|
|
89
|
+
const weekday = floorMod(day + 4, 7);
|
|
90
|
+
return weekday === 0 || weekday === 6;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* `regularSessionAnchor`: each weekday's open in the session's zone, bars open + k * width, only rows of [open, close)
|
|
94
|
+
* of that weekday counted, the last bar of a day ending at the close; its session is one trade date of the zone. Built
|
|
95
|
+
* from tiers dividing `tierMs` (the coarsest bucket the open and the close both sit on).
|
|
96
|
+
*/
|
|
97
|
+
function regularSessionRule(anchor, session, tierMs, venues) {
|
|
98
|
+
const dayOf = (tMs) => Math.floor(zoneWallMsAt(session.zone, tMs) / DAY_MS);
|
|
99
|
+
const wallAt = (day, minutes) => zoneWallToUtcMs(session.zone, day * DAY_MS + minutes * MINUTE_MS);
|
|
100
|
+
/** `openOf`: the open of the session `tMs` trades in, null on a weekend or outside [open, close) of its day. */
|
|
101
|
+
const openOf = (tMs) => {
|
|
102
|
+
if (!Number.isFinite(tMs))
|
|
103
|
+
return null;
|
|
104
|
+
const day = dayOf(tMs);
|
|
105
|
+
if (!Number.isFinite(day) || isWeekendDay(day))
|
|
106
|
+
return null;
|
|
107
|
+
const open = wallAt(day, session.openMinutes);
|
|
108
|
+
return tMs >= open && tMs < wallAt(day, session.closeMinutes) ? open : null;
|
|
109
|
+
};
|
|
110
|
+
const rule = {
|
|
111
|
+
anchor,
|
|
112
|
+
name: BarAnchor[anchor],
|
|
113
|
+
tradeDate: { zone: session.zone, offsetHours: 0 },
|
|
114
|
+
session: Object.freeze({ ...session }),
|
|
115
|
+
venues,
|
|
116
|
+
lays: (exchange) => venues === 'every' || isCmeSessionLatticeExchange(exchange),
|
|
117
|
+
takes: () => true,
|
|
118
|
+
fitsTier: (tier, barMs, isSession) => tier > 0 && fitDayBars(tier, barMs, isSession) && tierMs % tier === 0,
|
|
119
|
+
barOpenMs: (tMs, barMs) => {
|
|
120
|
+
const open = openOf(tMs);
|
|
121
|
+
if (open === null)
|
|
122
|
+
return null;
|
|
123
|
+
return barMs > 0 ? open + Math.floor((tMs - open) / barMs) * barMs : tMs;
|
|
124
|
+
},
|
|
125
|
+
sessionOpenMs: openOf,
|
|
126
|
+
isBoundary: (tMs, barMs, isSession) => opensBar(rule, tMs, barMs, isSession),
|
|
127
|
+
floorBoundaryMs: (tMs, barMs, isSession) => floorOpensBar(rule, tMs, barMs, isSession),
|
|
128
|
+
barEndMs: (openMs, barMs, isSession) => {
|
|
129
|
+
const closing = wallAt(dayOf(openMs), session.closeMinutes);
|
|
130
|
+
const end = openMs + barMs;
|
|
131
|
+
return !isSession && end < closing ? end : closing;
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
return rule;
|
|
135
|
+
}
|
|
136
|
+
/** The CME Group's session clock (cme.go `cmeSessionTimezone`, `cmeSessionOpenHour`). */
|
|
137
|
+
const CME_SESSION_ZONE = 'America/Chicago';
|
|
138
|
+
const CME_SESSION_OPEN_HOUR = 17;
|
|
139
|
+
/** How far apart two session days of one bar lie (`cmeSessionReachDays`): a week bar from a Friday holiday booked
|
|
140
|
+
* into it to its Sunday, a day bar from a holiday to its trade date. */
|
|
141
|
+
const CME_SESSION_REACH_DAYS = 14;
|
|
142
|
+
/** `cmeSessionDay`: the calendar date (days since the epoch) of the session close `tMs` trades toward: the Chicago
|
|
143
|
+
* wall clock's date, moved on at the 17:00 open. */
|
|
144
|
+
const cmeSessionDayOf = (tMs) => Math.floor((zoneWallMsAt(CME_SESSION_ZONE, tMs) + (24 - CME_SESSION_OPEN_HOUR) * HOUR_MS) / DAY_MS);
|
|
145
|
+
/** `cmeSessionOpen`: the 17:00 Chicago open that starts session day `day`, on the calendar day before it. */
|
|
146
|
+
const cmeSessionOpenOf = (day) => zoneWallToUtcMs(CME_SESSION_ZONE, (day - 1) * DAY_MS + CME_SESSION_OPEN_HOUR * HOUR_MS);
|
|
147
|
+
/** `cmeSessionBarLabel`: the candle label (days since the epoch) of the bar holding session day `day`: its trade date
|
|
148
|
+
* (a weekend day its own), or the Monday of that date's week for a week bar. */
|
|
149
|
+
function cmeSessionLabelOf(day, barMs) {
|
|
150
|
+
const label = cmeSessionBucketMs(cmeSessionOpenOf(day), barMs === WEEK_MS ? WEEK_MS : DAY_MS);
|
|
151
|
+
return label === null ? Number.NaN : Math.round(label / DAY_MS);
|
|
152
|
+
}
|
|
153
|
+
/** `cmeSessionBarOpen`: the stamp of the bar holding session day `day`: the open of the first day of the run of
|
|
154
|
+
* session days booked to its label that ends on the label's own day. */
|
|
155
|
+
function cmeSessionBarOpenOf(day, barMs) {
|
|
156
|
+
const label = cmeSessionLabelOf(day, barMs);
|
|
157
|
+
let first = label;
|
|
158
|
+
for (let back = 0; back < CME_SESSION_REACH_DAYS && cmeSessionLabelOf(first - 1, barMs) === label; back += 1) {
|
|
159
|
+
first -= 1;
|
|
160
|
+
}
|
|
161
|
+
return cmeSessionOpenOf(first);
|
|
162
|
+
}
|
|
163
|
+
const CME_SESSION_READS = new Set([
|
|
164
|
+
'OPTION_PRINT_AGG/COIN',
|
|
165
|
+
'OPTION_PRINT_AGG/MARKET',
|
|
166
|
+
'OPTION_PRINT_AGG/STRIKE',
|
|
167
|
+
'OPTION_PRINT_AGG/EXPIRY',
|
|
168
|
+
'OPTION_PRINT_AGG/EXPIRY_STRIKE',
|
|
169
|
+
'OPTION_PRINT_AGG/CONTRACT',
|
|
170
|
+
]);
|
|
171
|
+
const CME_SESSION_RULE = {
|
|
172
|
+
anchor: BarAnchor.CME_SESSION,
|
|
173
|
+
name: BarAnchor[BarAnchor.CME_SESSION],
|
|
174
|
+
tradeDate: { zone: CME_SESSION_ZONE, offsetHours: 24 - CME_SESSION_OPEN_HOUR },
|
|
175
|
+
venues: 'cme',
|
|
176
|
+
lays: isCmeSessionLatticeExchange,
|
|
177
|
+
takes: (read) => CME_SESSION_READS.has(read),
|
|
178
|
+
// A trade date, a session span or a week, from a tier dividing an hour: the 17:00 open sits on the hour in both of
|
|
179
|
+
// Chicago's offsets.
|
|
180
|
+
fitsTier: (tierMs, barMs, session) => tierMs > 0 && (session || barMs === DAY_MS || barMs === WEEK_MS) && HOUR_MS % tierMs === 0,
|
|
181
|
+
barOpenMs: (tMs, barMs) => {
|
|
182
|
+
if (!Number.isFinite(tMs))
|
|
183
|
+
return null;
|
|
184
|
+
return barMs > 0 ? cmeSessionBarOpenOf(cmeSessionDayOf(tMs), barMs) : tMs;
|
|
185
|
+
},
|
|
186
|
+
sessionOpenMs: (tMs) => (Number.isFinite(tMs) ? cmeSessionBarOpenOf(cmeSessionDayOf(tMs), DAY_MS) : null),
|
|
187
|
+
// A session open no bar straddles: every bar of the session days before it differs from every bar of the days from
|
|
188
|
+
// it on (Christmas's session is Monday 12/28's, so no window starts or ends on the weekend opens between them).
|
|
189
|
+
isBoundary: (tMs, barMs, session) => {
|
|
190
|
+
const width = session ? DAY_MS : barMs;
|
|
191
|
+
if (!(width > 0))
|
|
192
|
+
return true;
|
|
193
|
+
if (!Number.isFinite(tMs))
|
|
194
|
+
return false;
|
|
195
|
+
const day = cmeSessionDayOf(tMs);
|
|
196
|
+
if (cmeSessionOpenOf(day) !== tMs)
|
|
197
|
+
return false;
|
|
198
|
+
const before = new Set();
|
|
199
|
+
for (let back = 1; back <= CME_SESSION_REACH_DAYS; back += 1)
|
|
200
|
+
before.add(cmeSessionLabelOf(day - back, width));
|
|
201
|
+
for (let ahead = 0; ahead < CME_SESSION_REACH_DAYS; ahead += 1) {
|
|
202
|
+
if (before.has(cmeSessionLabelOf(day + ahead, width)))
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
return true;
|
|
206
|
+
},
|
|
207
|
+
// Boundaries are session opens: the newest one at or before `tMs`, a session day at a time.
|
|
208
|
+
floorBoundaryMs: (tMs, barMs, session) => {
|
|
209
|
+
if (CME_SESSION_RULE.isBoundary(tMs, barMs, session) || !Number.isFinite(tMs))
|
|
210
|
+
return tMs;
|
|
211
|
+
let day = cmeSessionDayOf(tMs);
|
|
212
|
+
for (let back = 0; back <= 2 * CME_SESSION_REACH_DAYS; back += 1, day -= 1) {
|
|
213
|
+
const open = cmeSessionOpenOf(day);
|
|
214
|
+
if (open <= tMs && CME_SESSION_RULE.isBoundary(open, barMs, session))
|
|
215
|
+
return open;
|
|
216
|
+
}
|
|
217
|
+
return tMs;
|
|
218
|
+
},
|
|
219
|
+
// The open of the session day after the bar's last: its label's own day (a day bar), or its week's Sunday.
|
|
220
|
+
barEndMs: (openMs, barMs, session) => {
|
|
221
|
+
const width = session ? DAY_MS : barMs;
|
|
222
|
+
if (!(width > 0))
|
|
223
|
+
return openMs;
|
|
224
|
+
const label = cmeSessionLabelOf(cmeSessionDayOf(openMs), width);
|
|
225
|
+
return cmeSessionOpenOf(label + Math.round(width / DAY_MS));
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
const NEW_YORK = 'America/New_York';
|
|
229
|
+
/** Every anchor's rule, by pb-common's value (`barAnchorRules`): a value without a rule fails the type check. */
|
|
230
|
+
export const OPTION_BAR_ANCHOR_RULES = Object.freeze({
|
|
231
|
+
[BarAnchor.UTC]: UTC_RULE,
|
|
232
|
+
[BarAnchor.US_EQUITY_RTH]: regularSessionRule(BarAnchor.US_EQUITY_RTH, { zone: NEW_YORK, openMinutes: 9 * 60 + 30, closeMinutes: 16 * 60 }, 30 * MINUTE_MS, 'every'),
|
|
233
|
+
[BarAnchor.CME_SESSION]: CME_SESSION_RULE,
|
|
234
|
+
[BarAnchor.CME_RTH]: regularSessionRule(BarAnchor.CME_RTH, { zone: NEW_YORK, openMinutes: 9 * 60 + 30, closeMinutes: 16 * 60 + 15 }, 15 * MINUTE_MS, 'cme'),
|
|
235
|
+
[BarAnchor.CME_ENERGY_RTH]: regularSessionRule(BarAnchor.CME_ENERGY_RTH, { zone: NEW_YORK, openMinutes: 9 * 60, closeMinutes: 14 * 60 + 30 }, 30 * MINUTE_MS, 'cme'),
|
|
236
|
+
});
|
|
237
|
+
/** The rules in pb-common's order (UTC, US_EQUITY_RTH, CME_SESSION, CME_RTH, CME_ENERGY_RTH): the order deciders try. */
|
|
238
|
+
const RULES_IN_ORDER = Object.freeze(Object.values(OPTION_BAR_ANCHOR_RULES).sort((a, b) => a.anchor - b.anchor));
|
|
239
|
+
/** The rule of an anchor value, or undefined for a value no rule lays (the gateway refuses it by name). */
|
|
240
|
+
export function optionBarAnchorRuleOf(anchor) {
|
|
241
|
+
return typeof anchor === 'number' && Object.prototype.hasOwnProperty.call(OPTION_BAR_ANCHOR_RULES, anchor)
|
|
242
|
+
? OPTION_BAR_ANCHOR_RULES[anchor]
|
|
243
|
+
: undefined;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* The anchors a read takes on a venue, in pb-common's order: every anchor the read takes that lays every venue's rows,
|
|
247
|
+
* and one laid over a venue group's alone only when the read names a venue of that group (`exchange`, the chain's): the
|
|
248
|
+
* gateway refuses a CME anchor by name on any other venue (OPRA, Deribit) and on a read that names none.
|
|
249
|
+
*/
|
|
250
|
+
export function optionBarAnchorsTaken(read, exchange) {
|
|
251
|
+
return RULES_IN_ORDER.filter((rule) => rule.takes(read) && (rule.venues === 'every' || (exchange !== undefined && rule.lays(exchange))));
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Where a bar proof may drop a bucket the chart lays a bar for: only at an instant the chart's own product holds no
|
|
255
|
+
* trading at, by its schedule (market-session-schedule.util `isGovernedFuturesSymbolOpenAt`). This is the one drop
|
|
256
|
+
* exemption every decider proves an anchor's bars with (the strike and contract flow groupings, the flow scopes' bars,
|
|
257
|
+
* the prints' per-bar cut). An anchor's own hours are not it: a CME regular session lays no bar on a weekend day, which a
|
|
258
|
+
* weekday product's regular-hours chart lays empty bars for, while an always-on root (crypto since 2026-05-29, 1OZ since
|
|
259
|
+
* 2026-07-24) trades through it. So on an always-on root's chart the session lands on no bars that hold weekend rows,
|
|
260
|
+
* and the decider falls back (UTC bars where they land, else today's fold). A chart off the CME group has no schedule
|
|
261
|
+
* here, so nothing it lays may be dropped.
|
|
262
|
+
*/
|
|
263
|
+
export function optionChartClosedAt(grid) {
|
|
264
|
+
if (grid === null || grid === undefined || !isCmeSessionLatticeExchange(grid.exchange))
|
|
265
|
+
return () => false;
|
|
266
|
+
const symbol = grid.symbol;
|
|
267
|
+
return (tMs) => !isGovernedFuturesSymbolOpenAt(symbol, tMs);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* The anchor whose sessions are a chain's trade dates (contract 3.4), or undefined where none is: the first anchor the
|
|
271
|
+
* read takes on the venue whose session key (`tradeDate`) is the clock's own rule, a clock that moves its weekends to
|
|
272
|
+
* Monday matching none. New York's clock reads US_EQUITY_RTH's sessions, the UTC date UTC's, the Globex trade date
|
|
273
|
+
* (Chicago's wall clock plus 7 hours) CME_SESSION's on a CME group venue; a CME crypto root's clock (16:00 Chicago,
|
|
274
|
+
* weekends on Monday) is no anchor's.
|
|
275
|
+
*/
|
|
276
|
+
export function optionSessionAnchorOf(clock, read, exchange) {
|
|
277
|
+
if (clock.rule.weekendsToMonday === true)
|
|
278
|
+
return undefined;
|
|
279
|
+
return optionBarAnchorsTaken(read, exchange).find((rule) => rule.tradeDate.zone === clock.zone && rule.tradeDate.offsetHours === clock.rule.offsetHours);
|
|
280
|
+
}
|
|
281
|
+
const DAY_SECONDS = DAY_MS / 1000;
|
|
282
|
+
/**
|
|
283
|
+
* The grid an `optionRead` groups on (`OptionReadGridOf`), or null when it groups nothing (no `barSeconds`, span BAR). A
|
|
284
|
+
* day bar is a UTC day's row on UTC and US_EQUITY_RTH, and keeps its anchor on every other (a trade date on
|
|
285
|
+
* CME_SESSION).
|
|
286
|
+
*/
|
|
287
|
+
export function optionBarAnchorGridOf(shape) {
|
|
288
|
+
if (typeof shape !== 'object' || shape === null)
|
|
289
|
+
return null;
|
|
290
|
+
const fields = shape;
|
|
291
|
+
const barSeconds = Number(fields.barSeconds ?? 0);
|
|
292
|
+
const seconds = Number.isFinite(barSeconds) && barSeconds > 0 ? barSeconds : 0;
|
|
293
|
+
const session = Number(fields.span ?? BarSpan.BAR) === BarSpan.SESSION;
|
|
294
|
+
if (!session && seconds === 0)
|
|
295
|
+
return null;
|
|
296
|
+
let anchor = Number(fields.barAnchor ?? BarAnchor.UTC);
|
|
297
|
+
if (seconds === DAY_SECONDS && (anchor === BarAnchor.UTC || anchor === BarAnchor.US_EQUITY_RTH)) {
|
|
298
|
+
anchor = BarAnchor.UTC;
|
|
299
|
+
}
|
|
300
|
+
return { anchor, seconds, session };
|
|
301
|
+
}
|
|
302
|
+
/** The open of the bar (or session) holding `tMs` on a grid (`OptionReadGrid.Bar`), null where it lands in none or
|
|
303
|
+
* where no rule lays the grid's anchor. */
|
|
304
|
+
export function optionGridBarOpenMs(grid, tMs) {
|
|
305
|
+
const rule = optionBarAnchorRuleOf(grid.anchor);
|
|
306
|
+
if (rule === undefined)
|
|
307
|
+
return null;
|
|
308
|
+
return grid.session ? rule.sessionOpenMs(tMs) : rule.barOpenMs(tMs, grid.seconds * 1000);
|
|
309
|
+
}
|
|
310
|
+
/** Whether a window may start or end at `tMs` on a grid (`OptionReadGrid.Boundary`); an anchor no rule lays splits
|
|
311
|
+
* nothing. */
|
|
312
|
+
export function optionGridIsBoundary(grid, tMs) {
|
|
313
|
+
const rule = optionBarAnchorRuleOf(grid.anchor);
|
|
314
|
+
return rule === undefined || rule.isBoundary(tMs, grid.seconds * 1000, grid.session);
|
|
315
|
+
}
|
|
316
|
+
/** The latest instant at or before `tMs` a window may end at on a grid, so a window cut there ends with its last whole
|
|
317
|
+
* bar. */
|
|
318
|
+
export function optionGridFloorBoundaryMs(grid, tMs) {
|
|
319
|
+
const rule = optionBarAnchorRuleOf(grid.anchor);
|
|
320
|
+
return rule === undefined ? tMs : rule.floorBoundaryMs(tMs, grid.seconds * 1000, grid.session);
|
|
321
|
+
}
|
|
322
|
+
/** The first instant at or after `tMs` a window may start or end at on a grid (`OptionReadGrid.Ceil`): `tMs` on a
|
|
323
|
+
* boundary, else the end of the bar (or session) holding it, or of the bar after it, until one ends on a boundary. */
|
|
324
|
+
export function optionGridCeilBoundaryMs(grid, tMs) {
|
|
325
|
+
const rule = optionBarAnchorRuleOf(grid.anchor);
|
|
326
|
+
if (rule === undefined)
|
|
327
|
+
return tMs;
|
|
328
|
+
const barMs = grid.seconds * 1000;
|
|
329
|
+
let at = tMs;
|
|
330
|
+
for (let step = 0; step < 4 * CME_SESSION_REACH_DAYS && !rule.isBoundary(at, barMs, grid.session); step += 1) {
|
|
331
|
+
const open = optionGridBarOpenMs(grid, at);
|
|
332
|
+
if (open === null)
|
|
333
|
+
break;
|
|
334
|
+
const end = rule.barEndMs(open, barMs, grid.session);
|
|
335
|
+
if (!(end > at))
|
|
336
|
+
break;
|
|
337
|
+
at = end;
|
|
338
|
+
}
|
|
339
|
+
return at;
|
|
340
|
+
}
|
|
@@ -42,6 +42,15 @@ export declare function isOptionVenueVisible(venue: OptionVenue, gates?: OptionV
|
|
|
42
42
|
* futures and their options share exchange codes.
|
|
43
43
|
*/
|
|
44
44
|
export declare function optionVenueForUnderlyingExchange(exchange: Exchange | string): OptionVenue | null;
|
|
45
|
+
/**
|
|
46
|
+
* The provider whose options attach to the market the options seam answers as an underlying (POLYGON `NVDA/USD`
|
|
47
|
+
* resolves to OPRA): `optionVenueForUnderlyingExchange` over that market's exchange. Hand it the seam's market (web:
|
|
48
|
+
* opra-options-gate.util `chartOptionsMarket`), never a chart's own: a stock twin's own code is its crypto venue's, so
|
|
49
|
+
* only the seam knows that its options are its US stock's. Null for no market and for a market no provider lists.
|
|
50
|
+
*/
|
|
51
|
+
export declare function optionsMarketUnderlyingVenue(market: {
|
|
52
|
+
exchange?: Exchange | string | null;
|
|
53
|
+
} | null | undefined): OptionVenue | null;
|
|
45
54
|
/**
|
|
46
55
|
* The underlying key a venue's chain RPC expects for a parsed contract: the base asset for most
|
|
47
56
|
* venues, the catalog ticker (base plus quote, `BTCUSDT`) where the venue keys by it.
|
|
@@ -50,6 +59,15 @@ export declare function venueUnderlying(venue: OptionVenue, parsed: {
|
|
|
50
59
|
root: string;
|
|
51
60
|
quoteAsset?: string;
|
|
52
61
|
}): string;
|
|
62
|
+
/**
|
|
63
|
+
* The root coin a venue files a chain's prints and summaries under, read off the key its chain RPCs take: the inverse
|
|
64
|
+
* of `venueUnderlying`, and the one copy of the rule (tests/structure/venue-root-coin-one-rule.spec.ts). A venue that
|
|
65
|
+
* keys by the catalog ticker (`underlyingKey` 'assetTicker') drops the quote asset of the settlement family the key
|
|
66
|
+
* ends in (Binance Options: `BTCUSDT` reads `BTC`). Any other key already is the root (a Deribit coin, a CME futures
|
|
67
|
+
* contract, an OPRA ticker), and so is a key that ends in none of the venue's quote assets. The match ignores case; the
|
|
68
|
+
* root keeps the key's own.
|
|
69
|
+
*/
|
|
70
|
+
export declare function venueRootCoin(venue: OptionVenue, underlying: string): string;
|
|
53
71
|
/**
|
|
54
72
|
* Where a crypto options indicator reads. `exchange` is the pb-common `Exchange` member name.
|
|
55
73
|
* Summaries are filed under the root `coin`; trades under `tradeCoin`, which differs on venues
|
|
@@ -54,6 +54,18 @@ export function optionVenueForUnderlyingExchange(exchange) {
|
|
|
54
54
|
return null;
|
|
55
55
|
return OPTION_VENUES.find((venue) => venue.underlyingExchanges?.includes(name)) ?? null;
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The provider whose options attach to the market the options seam answers as an underlying (POLYGON `NVDA/USD`
|
|
59
|
+
* resolves to OPRA): `optionVenueForUnderlyingExchange` over that market's exchange. Hand it the seam's market (web:
|
|
60
|
+
* opra-options-gate.util `chartOptionsMarket`), never a chart's own: a stock twin's own code is its crypto venue's, so
|
|
61
|
+
* only the seam knows that its options are its US stock's. Null for no market and for a market no provider lists.
|
|
62
|
+
*/
|
|
63
|
+
export function optionsMarketUnderlyingVenue(market) {
|
|
64
|
+
const exchange = market?.exchange;
|
|
65
|
+
return exchange === undefined || exchange === null || exchange === ''
|
|
66
|
+
? null
|
|
67
|
+
: optionVenueForUnderlyingExchange(exchange);
|
|
68
|
+
}
|
|
57
69
|
/**
|
|
58
70
|
* The underlying key a venue's chain RPC expects for a parsed contract: the base asset for most
|
|
59
71
|
* venues, the catalog ticker (base plus quote, `BTCUSDT`) where the venue keys by it.
|
|
@@ -61,6 +73,21 @@ export function optionVenueForUnderlyingExchange(exchange) {
|
|
|
61
73
|
export function venueUnderlying(venue, parsed) {
|
|
62
74
|
return venue.underlyingKey === 'assetTicker' ? `${parsed.root}${parsed.quoteAsset ?? ''}` : parsed.root;
|
|
63
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* The root coin a venue files a chain's prints and summaries under, read off the key its chain RPCs take: the inverse
|
|
78
|
+
* of `venueUnderlying`, and the one copy of the rule (tests/structure/venue-root-coin-one-rule.spec.ts). A venue that
|
|
79
|
+
* keys by the catalog ticker (`underlyingKey` 'assetTicker') drops the quote asset of the settlement family the key
|
|
80
|
+
* ends in (Binance Options: `BTCUSDT` reads `BTC`). Any other key already is the root (a Deribit coin, a CME futures
|
|
81
|
+
* contract, an OPRA ticker), and so is a key that ends in none of the venue's quote assets. The match ignores case; the
|
|
82
|
+
* root keeps the key's own.
|
|
83
|
+
*/
|
|
84
|
+
export function venueRootCoin(venue, underlying) {
|
|
85
|
+
if (venue.underlyingKey !== 'assetTicker')
|
|
86
|
+
return underlying;
|
|
87
|
+
const key = underlying.toUpperCase();
|
|
88
|
+
const quote = venue.families?.find(({ quoteAsset }) => quoteAsset && key.length > quoteAsset.length && key.endsWith(quoteAsset.toUpperCase()))?.quoteAsset;
|
|
89
|
+
return quote ? underlying.slice(0, -quote.length) : underlying;
|
|
90
|
+
}
|
|
64
91
|
/**
|
|
65
92
|
* Where an ordinary chart's coin reads its chain on a plain crypto venue (one the metadata listing
|
|
66
93
|
* names for the coin): the venue's exchange, the root coin, and the trade key the venue files trades
|
|
@@ -270,6 +270,8 @@ export function normalizeRuntimeDiagnostics(value, options = {}) {
|
|
|
270
270
|
generation: positiveInteger(raw.generation),
|
|
271
271
|
type: optionalString(raw.type),
|
|
272
272
|
details: isObject(raw.details) ? { ...raw.details } : undefined,
|
|
273
|
+
// The row's OPRA mark (computed over OPRA data) survives every normalization: the store's choke point included.
|
|
274
|
+
...(raw.opra === true ? { opra: true } : {}),
|
|
273
275
|
},
|
|
274
276
|
];
|
|
275
277
|
});
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import type { OpraOptionPlaneStop, WrunChartOptionsMarket, WrunChartOptionsMarketRef, WrunGateProvider } from '../../host-ports.types.js';
|
|
2
|
+
import type { WrunMetadataParam } from '../../interfaces/wrun-runtime.interface.js';
|
|
3
|
+
import { type OpraReadFacts } from '../chart/opra-read-access.leaf.js';
|
|
4
|
+
import { type WrunChartOptionsMarketDecision } from './run-schedule/wrun-chart-gate-reader.util.js';
|
|
5
|
+
import type { WrunLaneChainDecider, WrunLaneChartChain } from './sources/opra-option-lanes.util.js';
|
|
6
|
+
import type { WrunPollLaneContext } from './sources/wrun-poll-lane.types.js';
|
|
7
|
+
import { type WrunOptionsChainCryptoVenueWord, type WrunOptionsChainDecision } from './wrun-options-chain.util.js';
|
|
8
|
+
/**
|
|
9
|
+
* Contract F's mapping table (the kit's DERIVED_ROOTS in options.ts, row for row): a chart root and the roots whose
|
|
10
|
+
* chains its derived levels read, the first one the default (`defaultDerivedRoot`).
|
|
11
|
+
*/
|
|
12
|
+
export declare const WRUN_DERIVED_ROOTS: Readonly<Record<string, readonly string[]>>;
|
|
13
|
+
/** The roots the table maps `chartRoot` to, the default first; none for a root off the table. */
|
|
14
|
+
export declare function wrunDerivedRootsOf(chartRoot: string): readonly string[];
|
|
15
|
+
/** The root `underlying: "derived"` reads on a chart of `chartRoot`: the table's first, undefined off the table. */
|
|
16
|
+
export declare function defaultDerivedRoot(chartRoot: string): string | undefined;
|
|
17
|
+
/** The knob's name on a source. */
|
|
18
|
+
export declare const WRUN_UNDERLYING_KNOB = "underlying";
|
|
19
|
+
/** The knob's default word: the chart's own chain. */
|
|
20
|
+
export declare const WRUN_UNDERLYING_AUTO = "auto";
|
|
21
|
+
/** The knob's word for the table's default root of the chart's root. */
|
|
22
|
+
export declare const WRUN_UNDERLYING_DERIVED = "derived";
|
|
23
|
+
/** The classes that take the knob (contract F). */
|
|
24
|
+
export declare const WRUN_UNDERLYING_CLASSES: readonly string[];
|
|
25
|
+
/** The stem of a root no venue family lists: `wrun_underlying_unresolved:<root>`. */
|
|
26
|
+
export declare const WRUN_UNDERLYING_UNRESOLVED_CODE = "wrun_underlying_unresolved";
|
|
27
|
+
/** What the knob says: the chart's own chain, the table's default root of the chart's root, or one root. */
|
|
28
|
+
export type WrunUnderlyingKnob = {
|
|
29
|
+
kind: 'auto';
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'derived';
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'root';
|
|
34
|
+
root: string;
|
|
35
|
+
};
|
|
36
|
+
/** Whether `sourceClass` takes the knob. */
|
|
37
|
+
export declare function wrunTakesUnderlying(sourceClass: string): boolean;
|
|
38
|
+
/** The knob's literal reading (absent is "auto"); undefined for a value that is no literal (a setting's name, a word
|
|
39
|
+
* outside the grammar). */
|
|
40
|
+
export declare function wrunUnderlyingKnobOf(value: unknown): WrunUnderlyingKnob | undefined;
|
|
41
|
+
/** The setting a knob value names: an author's handle ("@root") or the name the sheet records ("root"); undefined for
|
|
42
|
+
* a literal and for anything else. */
|
|
43
|
+
export declare function wrunUnderlyingSettingName(value: unknown): string | undefined;
|
|
44
|
+
/** A source's knob, validated: its literal reading, or a refusal by name (`wrun_option_knob_invalid`, om's one name
|
|
45
|
+
* for an options knob outside its words; a setting's name the planners did not read lands here too). */
|
|
46
|
+
export declare function wrunUnderlyingKnob(source: Readonly<Record<string, unknown>>, ctx: {
|
|
47
|
+
inputName: string;
|
|
48
|
+
sourceClass: string;
|
|
49
|
+
}): WrunUnderlyingKnob;
|
|
50
|
+
/**
|
|
51
|
+
* A source whose `underlying` names a setting, read as the word the setting's pick names (the planners' read, before a
|
|
52
|
+
* lane judges the knob, as `resolveWrunOptionSettingKnobs` reads the kit's table): the setting must be a compute select
|
|
53
|
+
* of the sheet with a value this run read, its pick's word (its `style_values` entry when the select declares them,
|
|
54
|
+
* else its label) one of the knob's literals, else the input is refused by name (`wrun_option_knob_invalid`). A
|
|
55
|
+
* literal, a class that takes no knob, and every source of a run that read no setting values are left as they are.
|
|
56
|
+
*/
|
|
57
|
+
export declare function resolveWrunUnderlyingSettingKnob<Source extends Readonly<Record<string, unknown>>>(ctx: {
|
|
58
|
+
inputName: string;
|
|
59
|
+
sourceClass: string;
|
|
60
|
+
}, source: Source, params: readonly WrunMetadataParam[], values: Readonly<Record<string, number>> | undefined): Source;
|
|
61
|
+
/**
|
|
62
|
+
* The chart's root as the mapping table keys it: a CME chart's futures root (its contract's, an option contract's
|
|
63
|
+
* underlying future's: ES for ES1!, ESZ6 and `ESZ6 C6000`), else the chart's coin (a stock or ETF ticker, an OPRA
|
|
64
|
+
* contract's underlying, a crypto coin), upper case; '' when the chart names none.
|
|
65
|
+
*/
|
|
66
|
+
export declare function wrunChartRootOf(chart: {
|
|
67
|
+
exchange?: unknown;
|
|
68
|
+
symbol?: unknown;
|
|
69
|
+
coin?: unknown;
|
|
70
|
+
}): string;
|
|
71
|
+
/** The refusal of a root no venue family lists (`wrun_underlying_unresolved:<root>`), seeded as a chart with no option
|
|
72
|
+
* chain (the record names the root), so a declared `missing: "empty"` reads an empty block, the planners' one rule. */
|
|
73
|
+
export declare function wrunUnderlyingUnresolvedError(ctx: {
|
|
74
|
+
inputName: string;
|
|
75
|
+
sourceClass: string;
|
|
76
|
+
}, root: string, why: string): Error;
|
|
77
|
+
/** The root a knob reads: undefined for "auto" and for the chart's own root (`wrunChartRootOf`: the chart's own chain,
|
|
78
|
+
* read exactly as "auto" reads it, on its own venue); "derived" the table's default root of the chart's root, refused
|
|
79
|
+
* by name when the table maps it to none. */
|
|
80
|
+
export declare function wrunUnderlyingRootOf(knob: WrunUnderlyingKnob, ctx: {
|
|
81
|
+
inputName: string;
|
|
82
|
+
sourceClass: string;
|
|
83
|
+
exchange: string;
|
|
84
|
+
symbol: string;
|
|
85
|
+
coin: string;
|
|
86
|
+
}): string | undefined;
|
|
87
|
+
/** The venue family that lists a root. */
|
|
88
|
+
export type WrunUnderlyingFamily = 'crypto' | 'cme' | 'opra';
|
|
89
|
+
/** The market a root's chain is read as (`resolveWrunUnderlyingMarket`): its family, and the chart market a chart of
|
|
90
|
+
* that root would be. A crypto root read on the chart's own crypto venue names that venue's word (`venue`: the input
|
|
91
|
+
* reads it where it declares no venue of its own); an OPRA root kept off the plane names the stop (`opraStop`: the
|
|
92
|
+
* `opra` flag dark). */
|
|
93
|
+
export interface WrunUnderlyingMarket {
|
|
94
|
+
family: WrunUnderlyingFamily;
|
|
95
|
+
exchange: string;
|
|
96
|
+
symbol: string;
|
|
97
|
+
coin: string;
|
|
98
|
+
venue?: WrunOptionsChainCryptoVenueWord;
|
|
99
|
+
opraStop?: OpraOptionPlaneStop;
|
|
100
|
+
/** A stock twin's lane market (`wrunChartOptionsLaneMarket`): the chart market whose options it stands in for. */
|
|
101
|
+
twinOf?: {
|
|
102
|
+
exchange: string;
|
|
103
|
+
symbol: string;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** The chart a root's family is judged beside: its market (the crypto venue its own chain lists on) and, when the run
|
|
107
|
+
* already resolved it, its chain (the options chain lane's). */
|
|
108
|
+
export interface WrunUnderlyingChart {
|
|
109
|
+
inputName: string;
|
|
110
|
+
sourceClass: string;
|
|
111
|
+
exchange: string;
|
|
112
|
+
symbol: string;
|
|
113
|
+
coin: string;
|
|
114
|
+
category?: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The market a root's chain is read as, by the venue family that lists it (the module doc): a crypto root on the chart's
|
|
118
|
+
* own crypto venue when it lists the root, else on the root's listing venue (`wrunUnderlyingCryptoMarket`), a CME root
|
|
119
|
+
* its continuous alias on the exchange it lists on (`CME_ROOT_SPECS`), any other root a US root on the OPRA plane. For
|
|
120
|
+
* an OPRA root and a run the plane is open to (`mayReadOpra`), the `opra` flag is read first (a bounded wait for its map)
|
|
121
|
+
* and a plane it keeps the account off of names its stop; then a root neither the index roots nor the table name must be
|
|
122
|
+
* listed by the plane's expiry directory, or it refuses by name (`wrun_underlying_unresolved:<root>`). A run the plane is
|
|
123
|
+
* closed to reads nothing here: the caller's wall refuses it before any read. `chart` is the chart the input sits on,
|
|
124
|
+
* `chartChain` its chain when the caller already resolved it.
|
|
125
|
+
*/
|
|
126
|
+
export declare function resolveWrunUnderlyingMarket(root: string, chart: WrunUnderlyingChart, run: OpraReadFacts | undefined, chartChain?: WrunLaneChartChain): Promise<WrunUnderlyingMarket>;
|
|
127
|
+
/** The `venue` word an input reads a root's chain under: its own when it declares one, else the chart's crypto venue the
|
|
128
|
+
* root's market names (`WrunUnderlyingMarket.venue`), else as declared ("auto", or absent). */
|
|
129
|
+
export declare function wrunUnderlyingVenueWord<Declared>(declared: Declared, market: Pick<WrunUnderlyingMarket, 'venue'>): Declared | WrunOptionsChainCryptoVenueWord;
|
|
130
|
+
/** A lane's context for a root's market (`resolveWrunUnderlyingMarket`, or a stock twin's lane market,
|
|
131
|
+
* `wrunChartOptionsLaneMarket`): the chart's, with the root's market in place of the chart's (no category: the root's
|
|
132
|
+
* market is no option contract), the OPRA plane named for an OPRA root (its chain is the plane's own by coin, no
|
|
133
|
+
* directory read), and a twin's chart market named (`stockTwinOf`: its crypto venue words still read their venues'
|
|
134
|
+
* chains) beside the run's one decision for it (`optionsDecision`, the twin's lane market being that decision's); any
|
|
135
|
+
* other root's market names neither, whatever the context it replaces named (the run decided the chart's market, not
|
|
136
|
+
* the root's). */
|
|
137
|
+
export declare function wrunUnderlyingLaneContext<Ctx extends WrunPollLaneContext>(ctx: Ctx, market: WrunUnderlyingMarket): Ctx;
|
|
138
|
+
/**
|
|
139
|
+
* The lane market a run's chain lanes read a stock twin's options as (the shape `resolveWrunUnderlyingMarket` builds for
|
|
140
|
+
* an OPRA root): the OPRA plane's one exchange, the stock's ticker as the symbol and the coin, and the chart market it
|
|
141
|
+
* stands in for (`twinOf`). Undefined for every other options market (the chart's own: no lane is swapped). The market is
|
|
142
|
+
* the run's one decision (`decideWrunRunOptionsMarket`): the seam names a twin's stock only while the `opra` flag is lit,
|
|
143
|
+
* so no stop is named.
|
|
144
|
+
*/
|
|
145
|
+
export declare function wrunChartOptionsLaneMarket(market: WrunChartOptionsMarket | undefined): WrunUnderlyingMarket | undefined;
|
|
146
|
+
/** A run's ONE options market (`decideWrunRunOptionsMarket`): the decision, and for a stock twin the lane market its
|
|
147
|
+
* chain lanes are planned against (`wrunChartOptionsLaneMarket`). */
|
|
148
|
+
export interface WrunRunOptionsMarket extends WrunChartOptionsMarketDecision {
|
|
149
|
+
lane?: WrunUnderlyingMarket;
|
|
150
|
+
}
|
|
151
|
+
/** A run's decided options market as noted (`wrunDecidedOptionsMarket`). */
|
|
152
|
+
export interface WrunDecidedOptionsMarket {
|
|
153
|
+
exchange: string;
|
|
154
|
+
plane: WrunGateProvider | null;
|
|
155
|
+
}
|
|
156
|
+
/** A chart's metadata as the options decisions take it: its market, coin and category (strings and the category). */
|
|
157
|
+
export declare function wrunChartOptionsMarketRefOf(chart: {
|
|
158
|
+
exchange?: unknown;
|
|
159
|
+
symbol?: unknown;
|
|
160
|
+
coin?: unknown;
|
|
161
|
+
category?: unknown;
|
|
162
|
+
} | null | undefined): WrunChartOptionsMarketRef;
|
|
163
|
+
/**
|
|
164
|
+
* The ONE options market a run reads, decided at its head after the bounded waits (run-schedule/wrun-chart-gate-reader.util
|
|
165
|
+
* `decideWrunChartOptionsMarket`: the `opra` flag where it decides the chart's options or the overlay is `stamped` with
|
|
166
|
+
* an OPRA read, the stock twin answer under a lit flag or a stamp), so a run that started under one answer never mixes
|
|
167
|
+
* planes: its planners, its options chain lane, its download plan and its host fill read this decision in place of the
|
|
168
|
+
* seam, and every chain lane resolves its chain under this decision's plane (`optionsDecision` on its context). A later
|
|
169
|
+
* twin answer, or the `opra` flag landing, reruns the chart's options runs once the market they resolve to moved off
|
|
170
|
+
* the decision a browser run noted (`noteWrunRunOptionsMarket`, the host's listeners read `wrunDecidedOptionsMarket`).
|
|
171
|
+
*/
|
|
172
|
+
export declare function decideWrunRunOptionsMarket(chart: {
|
|
173
|
+
exchange?: unknown;
|
|
174
|
+
symbol?: unknown;
|
|
175
|
+
coin?: unknown;
|
|
176
|
+
category?: unknown;
|
|
177
|
+
} | null | undefined, stamped?: boolean): Promise<WrunRunOptionsMarket>;
|
|
178
|
+
/**
|
|
179
|
+
* Note the decision a run the browser computes reads (the sandbox prepare, the browser lanes' own step), per chart
|
|
180
|
+
* market: the facts read beside the run (a live tick's `market.option_multiplier()`, `wrunDecidedOptionsExchange`)
|
|
181
|
+
* follow it, and the host reruns the chart's options runs once their market moved off it (`wrunDecidedOptionsMarket`).
|
|
182
|
+
* A batch the cloud computes notes nothing: the server reads the chain of the chart market it is sent.
|
|
183
|
+
*/
|
|
184
|
+
export declare function noteWrunRunOptionsMarket(chart: {
|
|
185
|
+
exchange?: unknown;
|
|
186
|
+
symbol?: unknown;
|
|
187
|
+
} | null | undefined, decided: Pick<WrunRunOptionsMarket, 'market' | 'plane'>): void;
|
|
188
|
+
/** The options market the latest browser run on this chart market decided (`noteWrunRunOptionsMarket`), undefined
|
|
189
|
+
* before one noted. */
|
|
190
|
+
export declare function wrunDecidedOptionsMarket(market: {
|
|
191
|
+
exchange?: unknown;
|
|
192
|
+
symbol?: unknown;
|
|
193
|
+
}): WrunDecidedOptionsMarket | undefined;
|
|
194
|
+
/** The options exchange the latest browser run on this chart market decided, undefined before one noted: the chart's
|
|
195
|
+
* own then. */
|
|
196
|
+
export declare function wrunDecidedOptionsExchange(market: {
|
|
197
|
+
exchange?: unknown;
|
|
198
|
+
symbol?: unknown;
|
|
199
|
+
}): string | undefined;
|
|
200
|
+
/** Spec seam: forget every decision noted. */
|
|
201
|
+
export declare function __resetWrunDecidedOptionsMarketsForTests(): void;
|
|
202
|
+
/**
|
|
203
|
+
* One `options_chain` input's chain decision when its `underlying` names a root (the run's options chain lane,
|
|
204
|
+
* wrun-overlay-run.util `wrunOptionsChainLaneExtrasFor`), or undefined for "auto": the setting it names read first
|
|
205
|
+
* (`resolveWrunUnderlyingSettingKnob`), the root's market resolved (`resolveWrunUnderlyingMarket`), then the ONE venue
|
|
206
|
+
* decision every chain class shares (opra-option-lanes.util `decideWrunLaneChainIdentity`) over that market's chain:
|
|
207
|
+
* an OPRA root's the plane's own by coin, with its stop or the session another screen holds named (the decision's OPRA
|
|
208
|
+
* wall, before any read, for a run the plane is closed to); a crypto or CME root's what a chart of that root resolves,
|
|
209
|
+
* its crypto venue word's listing asked for that root. A crypto root the chart's own crypto venue lists reads that venue
|
|
210
|
+
* (the chart's chain is the run's, `chartChain`) unless the input declares a venue of its own. The decision names the
|
|
211
|
+
* root's chain (`chainUnderlying`), so two inputs reading two chains meet the one-venue rule.
|
|
212
|
+
*/
|
|
213
|
+
export declare function wrunUnderlyingOptionsChainDecision(source: Readonly<Record<string, unknown>>, who: WrunLaneChainDecider, params: readonly WrunMetadataParam[], values: Readonly<Record<string, number>> | undefined, chartChain?: WrunLaneChartChain): Promise<WrunOptionsChainDecision | undefined>;
|