@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,471 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derived underlyings (SKYLIT-PARITY contract F): the `underlying` knob of `option_strikes` and `options_chain` reads
|
|
3
|
+
* another root's option chain than the chart's own (an ES chart reading SPX's), so a package can draw that root's levels
|
|
4
|
+
* on the chart. The rows keep their own `underlying` column (that root's spot or forward): the package derives each
|
|
5
|
+
* level with the ratio of the chart's close to it (the recipe's math, never the host's).
|
|
6
|
+
*
|
|
7
|
+
* - The knob (`wrunUnderlyingKnob`): "auto" (absent too) reads the chart's own chain, exactly as before; a root in
|
|
8
|
+
* capitals ("SPX", "QQQ", "ES", "BTC") reads that root's chain; "derived" reads the first root the mapping table lists
|
|
9
|
+
* for the chart's root (`defaultDerivedRoot`, `WRUN_DERIVED_ROOTS`, the kit's DERIVED_ROOTS row for row); a setting's
|
|
10
|
+
* name ("@root", or the name the sheet records for it) reads the word the setting's pick names
|
|
11
|
+
* (`resolveWrunUnderlyingSettingKnob`, read by the planners before a lane judges the knob).
|
|
12
|
+
* - The venue family that lists a root (`resolveWrunUnderlyingMarket`), from config and the listings alone: a crypto
|
|
13
|
+
* root reads the chart's own crypto venue when it lists the root (an OKX options chart reads OKX's BTC chain, as its
|
|
14
|
+
* "auto" does), else the root's own listing venue (Deribit for a coin Deribit lists: BTC, ETH, ...; on a crypto chart
|
|
15
|
+
* the first venue whose listing names it); a CME futures root (`CME_ROOT_SPECS`, with the exchange it lists on) the
|
|
16
|
+
* CME chain of its continuous alias; any other root a US root on the OPRA plane (the governed set's one exchange),
|
|
17
|
+
* read by coin as the plane's own chain is (O1): an index root (`OPRA_INDEX_ROOTS`) or a root the mapping table names
|
|
18
|
+
* at once, any other root once the plane's expiry directory lists it (a directory that does not answer refuses
|
|
19
|
+
* nothing before the read).
|
|
20
|
+
* - The read is the lane's own, planned against the root's market as if the chart were that market
|
|
21
|
+
* (`wrunUnderlyingLaneContext`): the same chain resolver, venue and book words, walls and refusals. An OPRA root is a
|
|
22
|
+
* governed OPRA read: the OPRA wall stands before any read (`opra-official-only:<class>`, official packages only),
|
|
23
|
+
* the `opra` flag's stop after it, the plane stamp, the routed tier and the provenance as on a stock chart; a CME root
|
|
24
|
+
* meets the CME display wall (`assertWrunLaneChainPlaneReadable`).
|
|
25
|
+
* - A root no family lists, and "derived" on a chart whose root the table maps to nothing, refuse by name
|
|
26
|
+
* (`wrun_underlying_unresolved:<root>`), seeded as a chart with no option chain (`no-options` / `chain`), so an input
|
|
27
|
+
* declaring `missing: "empty"` reads an empty block with a note, the planners' one rule.
|
|
28
|
+
* - A stock twin (a crypto or HIP-3 market whose search group is a US stock or ETF: BINANCE_FUTURES NVDAUSDT,
|
|
29
|
+
* HYPERLIQUID_HIP3 xyz:NVDA) reads its stock's OPRA chain while the `opra` flag is lit, through the same swap: the
|
|
30
|
+
* run decides its ONE options market at its head (`decideWrunRunOptionsMarket`, the options seam behind the gate
|
|
31
|
+
* port), and the twin's lane market (`wrunChartOptionsLaneMarket`, the OPRA root shape `resolveWrunUnderlyingMarket`
|
|
32
|
+
* builds, naming the chart market it stands in for) is the market its chain lanes are planned against
|
|
33
|
+
* (`wrunUnderlyingLaneContext`), exactly as an OPRA root's.
|
|
34
|
+
*
|
|
35
|
+
* Off the boot path: the planners import it, and the lane files never do. The resolver loads the chain and venue
|
|
36
|
+
* services, the gate, the market facts and pb-common lazily, inside its async helpers.
|
|
37
|
+
*/
|
|
38
|
+
import { wrunChartHostEnv } from '../../host-env.js';
|
|
39
|
+
import { OPRA_GOVERNED_EXCHANGES } from '../../constants/governed-exchanges.constants.js';
|
|
40
|
+
import { OPRA_INDEX_ROOTS, OPTION_VENUES } from '../../constants/option-venues.constants.js';
|
|
41
|
+
import { isCmeGoverned } from '../chart/cme-realtime.util.js';
|
|
42
|
+
import { governedContractCoin } from '../chart/governed-contract-coin.util.js';
|
|
43
|
+
import { mayReadOpra } from '../chart/opra-read-access.leaf.js';
|
|
44
|
+
import { optionVenueForExchange } from '../options/option-venue.util.js';
|
|
45
|
+
import { gateSessionHeldElsewhere } from '../v2/gate-session-latch.util.js';
|
|
46
|
+
import { decideWrunChartOptionsMarket, } from './run-schedule/wrun-chart-gate-reader.util.js';
|
|
47
|
+
import { assertWrunLaneChainPlaneReadable } from './sources/wrun-poll-lanes.util.js';
|
|
48
|
+
import { wrunParamChoices } from './wrun-color-settings.util.js';
|
|
49
|
+
import { WRUN_OPTIONS_CHAIN_CRYPTO_VENUE_IDS, } from './wrun-options-chain.util.js';
|
|
50
|
+
import { refuseWrunOptionKnob } from './wrun-option-knobs.util.js';
|
|
51
|
+
import { attachWrunRefusal } from './wrun-refusal.util.js';
|
|
52
|
+
/**
|
|
53
|
+
* Contract F's mapping table (the kit's DERIVED_ROOTS in options.ts, row for row): a chart root and the roots whose
|
|
54
|
+
* chains its derived levels read, the first one the default (`defaultDerivedRoot`).
|
|
55
|
+
*/
|
|
56
|
+
export const WRUN_DERIVED_ROOTS = Object.freeze({
|
|
57
|
+
ES: Object.freeze(['SPX', 'SPY']),
|
|
58
|
+
NQ: Object.freeze(['NDX', 'QQQ']),
|
|
59
|
+
GC: Object.freeze(['GLD']),
|
|
60
|
+
SI: Object.freeze(['SLV']),
|
|
61
|
+
YM: Object.freeze(['DIA']),
|
|
62
|
+
RTY: Object.freeze(['IWM']),
|
|
63
|
+
SPY: Object.freeze(['SPX']),
|
|
64
|
+
QQQ: Object.freeze(['NDX']),
|
|
65
|
+
});
|
|
66
|
+
/** The roots the table maps `chartRoot` to, the default first; none for a root off the table. */
|
|
67
|
+
export function wrunDerivedRootsOf(chartRoot) {
|
|
68
|
+
const key = chartRoot.trim().toUpperCase();
|
|
69
|
+
return Object.prototype.hasOwnProperty.call(WRUN_DERIVED_ROOTS, key) ? WRUN_DERIVED_ROOTS[key] : [];
|
|
70
|
+
}
|
|
71
|
+
/** The root `underlying: "derived"` reads on a chart of `chartRoot`: the table's first, undefined off the table. */
|
|
72
|
+
export function defaultDerivedRoot(chartRoot) {
|
|
73
|
+
return wrunDerivedRootsOf(chartRoot)[0];
|
|
74
|
+
}
|
|
75
|
+
/** The knob's name on a source. */
|
|
76
|
+
export const WRUN_UNDERLYING_KNOB = 'underlying';
|
|
77
|
+
/** The knob's default word: the chart's own chain. */
|
|
78
|
+
export const WRUN_UNDERLYING_AUTO = 'auto';
|
|
79
|
+
/** The knob's word for the table's default root of the chart's root. */
|
|
80
|
+
export const WRUN_UNDERLYING_DERIVED = 'derived';
|
|
81
|
+
/** The classes that take the knob (contract F). */
|
|
82
|
+
export const WRUN_UNDERLYING_CLASSES = Object.freeze(['option_strikes', 'options_chain']);
|
|
83
|
+
/** The stem of a root no venue family lists: `wrun_underlying_unresolved:<root>`. */
|
|
84
|
+
export const WRUN_UNDERLYING_UNRESOLVED_CODE = 'wrun_underlying_unresolved';
|
|
85
|
+
/** A root as the knob spells it: capitals and digits, one letter at least (SPX, QQQ, ES, 6E, BTC). */
|
|
86
|
+
const WRUN_UNDERLYING_ROOT_RE = /^(?=[A-Z0-9]*[A-Z])[A-Z0-9]{1,10}$/;
|
|
87
|
+
/** A setting's name as the sheet records it (om's WRUN_NAME_PATTERN), or as an author's handle names it. */
|
|
88
|
+
const WRUN_SETTING_NAME_RE = /^[a-z0-9][a-z0-9._-]*$/;
|
|
89
|
+
/** The words the knob takes, for a refusal. */
|
|
90
|
+
const WRUN_UNDERLYING_WORDS = '"auto" (the chart\'s own chain), "derived" (the first root the derived table maps the chart\'s root to), an ' +
|
|
91
|
+
'underlying root in capitals ("SPX", "QQQ", "ES", "BTC") or "@<param>" naming a select setting';
|
|
92
|
+
/** Whether `sourceClass` takes the knob. */
|
|
93
|
+
export function wrunTakesUnderlying(sourceClass) {
|
|
94
|
+
return WRUN_UNDERLYING_CLASSES.includes(sourceClass);
|
|
95
|
+
}
|
|
96
|
+
/** The knob's literal reading (absent is "auto"); undefined for a value that is no literal (a setting's name, a word
|
|
97
|
+
* outside the grammar). */
|
|
98
|
+
export function wrunUnderlyingKnobOf(value) {
|
|
99
|
+
if (value === undefined || value === WRUN_UNDERLYING_AUTO)
|
|
100
|
+
return { kind: 'auto' };
|
|
101
|
+
if (value === WRUN_UNDERLYING_DERIVED)
|
|
102
|
+
return { kind: 'derived' };
|
|
103
|
+
return typeof value === 'string' && WRUN_UNDERLYING_ROOT_RE.test(value) ? { kind: 'root', root: value } : undefined;
|
|
104
|
+
}
|
|
105
|
+
/** The setting a knob value names: an author's handle ("@root") or the name the sheet records ("root"); undefined for
|
|
106
|
+
* a literal and for anything else. */
|
|
107
|
+
export function wrunUnderlyingSettingName(value) {
|
|
108
|
+
if (typeof value !== 'string' || wrunUnderlyingKnobOf(value) !== undefined)
|
|
109
|
+
return undefined;
|
|
110
|
+
const name = value.startsWith('@') ? value.slice(1) : value;
|
|
111
|
+
return WRUN_SETTING_NAME_RE.test(name) ? name : undefined;
|
|
112
|
+
}
|
|
113
|
+
/** A source's knob, validated: its literal reading, or a refusal by name (`wrun_option_knob_invalid`, om's one name
|
|
114
|
+
* for an options knob outside its words; a setting's name the planners did not read lands here too). */
|
|
115
|
+
export function wrunUnderlyingKnob(source, ctx) {
|
|
116
|
+
const value = source[WRUN_UNDERLYING_KNOB];
|
|
117
|
+
return wrunUnderlyingKnobOf(value) ?? refuseWrunOptionKnob(ctx, WRUN_UNDERLYING_KNOB, value, WRUN_UNDERLYING_WORDS);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* A source whose `underlying` names a setting, read as the word the setting's pick names (the planners' read, before a
|
|
121
|
+
* lane judges the knob, as `resolveWrunOptionSettingKnobs` reads the kit's table): the setting must be a compute select
|
|
122
|
+
* of the sheet with a value this run read, its pick's word (its `style_values` entry when the select declares them,
|
|
123
|
+
* else its label) one of the knob's literals, else the input is refused by name (`wrun_option_knob_invalid`). A
|
|
124
|
+
* literal, a class that takes no knob, and every source of a run that read no setting values are left as they are.
|
|
125
|
+
*/
|
|
126
|
+
export function resolveWrunUnderlyingSettingKnob(ctx, source, params, values) {
|
|
127
|
+
if (!wrunTakesUnderlying(ctx.sourceClass) || values === undefined)
|
|
128
|
+
return source;
|
|
129
|
+
const declared = source[WRUN_UNDERLYING_KNOB];
|
|
130
|
+
const name = wrunUnderlyingSettingName(declared);
|
|
131
|
+
if (name === undefined)
|
|
132
|
+
return source;
|
|
133
|
+
const param = params.find((candidate) => candidate.name === name);
|
|
134
|
+
const value = Object.prototype.hasOwnProperty.call(values, name) ? values[name] : undefined;
|
|
135
|
+
if (param === undefined || param.style !== undefined || param.type !== 'select' || typeof value !== 'number') {
|
|
136
|
+
return refuseWrunOptionKnob(ctx, WRUN_UNDERLYING_KNOB, declared, `${WRUN_UNDERLYING_WORDS}, and '${name}' is no select compute setting of the sheet`);
|
|
137
|
+
}
|
|
138
|
+
const choices = wrunParamChoices(param);
|
|
139
|
+
const at = choices?.findIndex((choice) => choice.value === value) ?? -1;
|
|
140
|
+
const word = at < 0 ? undefined : Array.isArray(param.style_values) ? param.style_values[at] : choices?.[at]?.label;
|
|
141
|
+
if (typeof word !== 'string' || wrunUnderlyingKnobOf(word) === undefined) {
|
|
142
|
+
return refuseWrunOptionKnob(ctx, WRUN_UNDERLYING_KNOB, declared, `${WRUN_UNDERLYING_WORDS}, and '${name}' picks '${word ?? value}'`);
|
|
143
|
+
}
|
|
144
|
+
return { ...source, [WRUN_UNDERLYING_KNOB]: word };
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The chart's root as the mapping table keys it: a CME chart's futures root (its contract's, an option contract's
|
|
148
|
+
* underlying future's: ES for ES1!, ESZ6 and `ESZ6 C6000`), else the chart's coin (a stock or ETF ticker, an OPRA
|
|
149
|
+
* contract's underlying, a crypto coin), upper case; '' when the chart names none.
|
|
150
|
+
*/
|
|
151
|
+
export function wrunChartRootOf(chart) {
|
|
152
|
+
const coin = typeof chart.coin === 'string' ? chart.coin.trim().toUpperCase() : '';
|
|
153
|
+
if (typeof chart.exchange !== 'string' || !isCmeGoverned(chart.exchange) || typeof chart.symbol !== 'string') {
|
|
154
|
+
return coin;
|
|
155
|
+
}
|
|
156
|
+
const [contract] = chart.symbol.trim().split(/\s+/);
|
|
157
|
+
return governedContractCoin(contract)?.toUpperCase() ?? coin;
|
|
158
|
+
}
|
|
159
|
+
/** The refusal of a root no venue family lists (`wrun_underlying_unresolved:<root>`), seeded as a chart with no option
|
|
160
|
+
* chain (the record names the root), so a declared `missing: "empty"` reads an empty block, the planners' one rule. */
|
|
161
|
+
export function wrunUnderlyingUnresolvedError(ctx, root, why) {
|
|
162
|
+
const code = `${WRUN_UNDERLYING_UNRESOLVED_CODE}:${root}`;
|
|
163
|
+
return attachWrunRefusal(new Error(`Input '${ctx.inputName}' reads ${ctx.sourceClass} cells with underlying '${root}' (${code}): ${why}`), { cls: 'no-options', variant: 'chain', params: { market: root, coin: root } });
|
|
164
|
+
}
|
|
165
|
+
/** The root a knob reads: undefined for "auto" and for the chart's own root (`wrunChartRootOf`: the chart's own chain,
|
|
166
|
+
* read exactly as "auto" reads it, on its own venue); "derived" the table's default root of the chart's root, refused
|
|
167
|
+
* by name when the table maps it to none. */
|
|
168
|
+
export function wrunUnderlyingRootOf(knob, ctx) {
|
|
169
|
+
if (knob.kind === 'auto')
|
|
170
|
+
return undefined;
|
|
171
|
+
if (knob.kind === 'root')
|
|
172
|
+
return knob.root === wrunChartRootOf(ctx) ? undefined : knob.root;
|
|
173
|
+
const chartRoot = wrunChartRootOf(ctx);
|
|
174
|
+
const root = defaultDerivedRoot(chartRoot);
|
|
175
|
+
if (root !== undefined)
|
|
176
|
+
return root;
|
|
177
|
+
const named = chartRoot === '' ? 'the chart market' : chartRoot;
|
|
178
|
+
throw wrunUnderlyingUnresolvedError(ctx, chartRoot === '' ? WRUN_UNDERLYING_DERIVED : chartRoot, `underlying "derived" reads the first root the derived table maps the chart's root to, and it maps ${named} ` +
|
|
179
|
+
`to none (the table: ${Object.keys(WRUN_DERIVED_ROOTS).join(', ')}); declare a root, or missing: "empty" to ` +
|
|
180
|
+
'read nothing here');
|
|
181
|
+
}
|
|
182
|
+
/** The US roots the plane lists without a directory read: the index roots and every root the table maps to. */
|
|
183
|
+
const WRUN_UNDERLYING_OPRA_KNOWN_ROOTS = new Set([
|
|
184
|
+
...OPRA_INDEX_ROOTS,
|
|
185
|
+
...Object.values(WRUN_DERIVED_ROOTS).flat(),
|
|
186
|
+
]);
|
|
187
|
+
/** Every crypto venue word, in the options chain's order. */
|
|
188
|
+
const WRUN_CRYPTO_VENUE_WORDS = Object.keys(WRUN_OPTIONS_CHAIN_CRYPTO_VENUE_IDS);
|
|
189
|
+
/** The exchange a venue's chain lists on (the venue table's first of its row), '' for a venue off the table. */
|
|
190
|
+
function wrunVenueExchangeOf(venueId) {
|
|
191
|
+
return OPTION_VENUES.find((venue) => venue.id === venueId)?.exchanges[0] ?? '';
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The crypto venue the chart's own options chain lists on, as the chain decision's `auto` reads it: a plain venue's
|
|
195
|
+
* word (`okx` for an OKX option contract chart), `deribit` for a chart reading the coin's Deribit chain, undefined for a
|
|
196
|
+
* chart whose chain is no crypto chain (CME, OPRA) or that rides no crypto option venue. The chain is the run's when it
|
|
197
|
+
* holds one (`chartChain`), else the chart's own, resolved only for a chart on a crypto option venue (a local read of
|
|
198
|
+
* its contract, no directory); a resolution that fails reads none.
|
|
199
|
+
*/
|
|
200
|
+
async function wrunChartCryptoVenueWord(chart, chartChain) {
|
|
201
|
+
let chain = chartChain;
|
|
202
|
+
if (chain === undefined) {
|
|
203
|
+
if (optionVenueForExchange(chart.exchange)?.lane !== 'plain')
|
|
204
|
+
return undefined;
|
|
205
|
+
try {
|
|
206
|
+
const { resolveWrunLaneChartChain } = await import('./sources/opra-option-lanes.util.js');
|
|
207
|
+
chain = await resolveWrunLaneChartChain(chart);
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const source = chain.chartSource;
|
|
214
|
+
if (source?.venue === 'deribit')
|
|
215
|
+
return 'deribit';
|
|
216
|
+
if (source?.venue !== 'crypto')
|
|
217
|
+
return undefined;
|
|
218
|
+
const venueId = optionVenueForExchange(source.source.exchange)?.id;
|
|
219
|
+
return WRUN_CRYPTO_VENUE_WORDS.find((word) => WRUN_OPTIONS_CHAIN_CRYPTO_VENUE_IDS[word] === venueId);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* A crypto root's market, or undefined for a root no crypto venue lists on this chart: the chart's own crypto venue
|
|
223
|
+
* when its listing names the root (the venue's word rides along, `venue`), else the root's own listing venue: Deribit
|
|
224
|
+
* when it lists the root, and on a chart whose chain is a crypto one the first venue whose listing names it (the chain
|
|
225
|
+
* the venue decision's `auto` reads for the coin, `exchange` ''). The listing is asked once per coin, and only on a
|
|
226
|
+
* crypto chart (with the crypto-options gate on).
|
|
227
|
+
*/
|
|
228
|
+
async function wrunUnderlyingCryptoMarket(root, chart, chartChain) {
|
|
229
|
+
const [{ hasDeribitOptions }, word] = await Promise.all([
|
|
230
|
+
wrunChartHostEnv().market.loadDeribitOptions(),
|
|
231
|
+
wrunChartCryptoVenueWord(chart, chartChain),
|
|
232
|
+
]);
|
|
233
|
+
const listed = word === undefined
|
|
234
|
+
? undefined
|
|
235
|
+
: await (await wrunChartHostEnv().market.loadOptionsChainVenues()).resolveWrunOptionsChainCryptoVenues({
|
|
236
|
+
words: WRUN_CRYPTO_VENUE_WORDS,
|
|
237
|
+
chartSource: undefined,
|
|
238
|
+
chartCoin: root,
|
|
239
|
+
});
|
|
240
|
+
if (word !== undefined && word !== 'deribit' && listed?.sourceOf(word) !== undefined) {
|
|
241
|
+
const exchange = wrunVenueExchangeOf(WRUN_OPTIONS_CHAIN_CRYPTO_VENUE_IDS[word]);
|
|
242
|
+
return { family: 'crypto', exchange, symbol: root, coin: root, venue: word };
|
|
243
|
+
}
|
|
244
|
+
if (hasDeribitOptions(root))
|
|
245
|
+
return { family: 'crypto', exchange: wrunVenueExchangeOf('deribit'), symbol: root, coin: root };
|
|
246
|
+
if (listed !== undefined && WRUN_CRYPTO_VENUE_WORDS.some((venue) => listed.sourceOf(venue) !== undefined)) {
|
|
247
|
+
return { family: 'crypto', exchange: '', symbol: root, coin: root };
|
|
248
|
+
}
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* 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
|
|
253
|
+
* own crypto venue when it lists the root, else on the root's listing venue (`wrunUnderlyingCryptoMarket`), a CME root
|
|
254
|
+
* its continuous alias on the exchange it lists on (`CME_ROOT_SPECS`), any other root a US root on the OPRA plane. For
|
|
255
|
+
* an OPRA root and a run the plane is open to (`mayReadOpra`), the `opra` flag is read first (a bounded wait for its map)
|
|
256
|
+
* 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
|
|
257
|
+
* listed by the plane's expiry directory, or it refuses by name (`wrun_underlying_unresolved:<root>`). A run the plane is
|
|
258
|
+
* closed to reads nothing here: the caller's wall refuses it before any read. `chart` is the chart the input sits on,
|
|
259
|
+
* `chartChain` its chain when the caller already resolved it.
|
|
260
|
+
*/
|
|
261
|
+
export async function resolveWrunUnderlyingMarket(root, chart, run, chartChain) {
|
|
262
|
+
const ctx = { inputName: chart.inputName, sourceClass: chart.sourceClass };
|
|
263
|
+
const [crypto, { wrunCmeRootExchange }] = await Promise.all([
|
|
264
|
+
wrunUnderlyingCryptoMarket(root, chart, chartChain),
|
|
265
|
+
import('./wrun-chart-market-facts.util.js'),
|
|
266
|
+
]);
|
|
267
|
+
if (crypto !== undefined)
|
|
268
|
+
return crypto;
|
|
269
|
+
const cmeExchange = wrunCmeRootExchange(root);
|
|
270
|
+
if (cmeExchange !== undefined)
|
|
271
|
+
return { family: 'cme', exchange: cmeExchange, symbol: `${root}1!`, coin: root };
|
|
272
|
+
const opra = OPRA_GOVERNED_EXCHANGES[0];
|
|
273
|
+
const market = { family: 'opra', exchange: opra, symbol: root, coin: root };
|
|
274
|
+
if (!mayReadOpra(run))
|
|
275
|
+
return market;
|
|
276
|
+
const gate = await wrunChartHostEnv().market.loadOptionsGate();
|
|
277
|
+
await gate.awaitOpraFlagHydration();
|
|
278
|
+
const plane = { exchange: market.exchange, symbol: market.symbol, coin: market.coin };
|
|
279
|
+
if (gate.governedOptionPlane(plane) !== 'opra') {
|
|
280
|
+
return { ...market, opraStop: gate.opraOptionPlaneStop(plane) ?? 'flag-off' };
|
|
281
|
+
}
|
|
282
|
+
// A plane another screen holds the session of is read nowhere here: the chain resolution stops by that name.
|
|
283
|
+
if (WRUN_UNDERLYING_OPRA_KNOWN_ROOTS.has(root) || gateSessionHeldElsewhere('opra'))
|
|
284
|
+
return market;
|
|
285
|
+
if ((await wrunOpraRootListed(market.exchange, root)) === false) {
|
|
286
|
+
throw wrunUnderlyingUnresolvedError(ctx, root, `no options venue lists ${root}: it is no coin Deribit lists, no CME futures root, and the US option chain ` +
|
|
287
|
+
'directory lists no expiry for it; check the root');
|
|
288
|
+
}
|
|
289
|
+
return market;
|
|
290
|
+
}
|
|
291
|
+
/** Whether the OPRA plane's expiry directory lists a root (one expiry at least); undefined when it cannot be asked or
|
|
292
|
+
* did not answer (O1's rule: a directory failing refuses nothing before the read). */
|
|
293
|
+
async function wrunOpraRootListed(exchangeName, root) {
|
|
294
|
+
try {
|
|
295
|
+
const [{ optionChainServiceForExchange }, { Exchange }, { withWrunDeadline, WRUN_SOURCE_FETCH_DEADLINE_MS }] = await Promise.all([
|
|
296
|
+
wrunChartHostEnv().market.loadOptionChainService(),
|
|
297
|
+
import('@orangecharts/orange-v2-pb-common'),
|
|
298
|
+
import('./wrun-deadline.util.js'),
|
|
299
|
+
]);
|
|
300
|
+
const exchange = Exchange[exchangeName];
|
|
301
|
+
if (typeof exchange !== 'number')
|
|
302
|
+
return undefined;
|
|
303
|
+
const expiries = await withWrunDeadline(optionChainServiceForExchange(exchangeName).listOptionExpiries({ exchange, underlying: root }), WRUN_SOURCE_FETCH_DEADLINE_MS, `wrun underlying directory for ${exchangeName}:${root}`);
|
|
304
|
+
return expiries.length > 0;
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
console.warn(`[wrun] the ${exchangeName} option chain directory did not answer for ${root}: reading it`, error);
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/** The `venue` word an input reads a root's chain under: its own when it declares one, else the chart's crypto venue the
|
|
312
|
+
* root's market names (`WrunUnderlyingMarket.venue`), else as declared ("auto", or absent). */
|
|
313
|
+
export function wrunUnderlyingVenueWord(declared, market) {
|
|
314
|
+
return market.venue !== undefined && (declared === undefined || declared === 'auto') ? market.venue : declared;
|
|
315
|
+
}
|
|
316
|
+
/** A lane's context for a root's market (`resolveWrunUnderlyingMarket`, or a stock twin's lane market,
|
|
317
|
+
* `wrunChartOptionsLaneMarket`): the chart's, with the root's market in place of the chart's (no category: the root's
|
|
318
|
+
* market is no option contract), the OPRA plane named for an OPRA root (its chain is the plane's own by coin, no
|
|
319
|
+
* directory read), and a twin's chart market named (`stockTwinOf`: its crypto venue words still read their venues'
|
|
320
|
+
* chains) beside the run's one decision for it (`optionsDecision`, the twin's lane market being that decision's); any
|
|
321
|
+
* other root's market names neither, whatever the context it replaces named (the run decided the chart's market, not
|
|
322
|
+
* the root's). */
|
|
323
|
+
export function wrunUnderlyingLaneContext(ctx, market) {
|
|
324
|
+
const next = {
|
|
325
|
+
...ctx,
|
|
326
|
+
exchange: market.exchange,
|
|
327
|
+
symbol: market.symbol,
|
|
328
|
+
coin: market.coin,
|
|
329
|
+
opraPlane: market.family === 'opra',
|
|
330
|
+
};
|
|
331
|
+
delete next.category;
|
|
332
|
+
if (market.twinOf !== undefined) {
|
|
333
|
+
next.stockTwinOf = { ...market.twinOf };
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
delete next.stockTwinOf;
|
|
337
|
+
delete next.optionsDecision;
|
|
338
|
+
}
|
|
339
|
+
return next;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* The lane market a run's chain lanes read a stock twin's options as (the shape `resolveWrunUnderlyingMarket` builds for
|
|
343
|
+
* an OPRA root): the OPRA plane's one exchange, the stock's ticker as the symbol and the coin, and the chart market it
|
|
344
|
+
* stands in for (`twinOf`). Undefined for every other options market (the chart's own: no lane is swapped). The market is
|
|
345
|
+
* the run's one decision (`decideWrunRunOptionsMarket`): the seam names a twin's stock only while the `opra` flag is lit,
|
|
346
|
+
* so no stop is named.
|
|
347
|
+
*/
|
|
348
|
+
export function wrunChartOptionsLaneMarket(market) {
|
|
349
|
+
const twinOf = market?.twinOf;
|
|
350
|
+
const coin = typeof market?.coin === 'string' ? market.coin.trim().toUpperCase() : '';
|
|
351
|
+
if (twinOf === undefined || coin === '')
|
|
352
|
+
return undefined;
|
|
353
|
+
return {
|
|
354
|
+
family: 'opra',
|
|
355
|
+
exchange: OPRA_GOVERNED_EXCHANGES[0],
|
|
356
|
+
symbol: coin,
|
|
357
|
+
coin,
|
|
358
|
+
twinOf: { exchange: twinOf.exchange, symbol: twinOf.symbol },
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
/** The options market each chart market's latest browser run decided (its exchange and its plane), by `EXCHANGE|SYMBOL`
|
|
362
|
+
* as the chart spells them: the facts a host fill reads beside the run (a live tick's `market.option_multiplier()`)
|
|
363
|
+
* follow the run's market, and a host reruns a chart's options runs once the market its options resolve to moved off
|
|
364
|
+
* it (a late stock twin answer, the `opra` flag landing). */
|
|
365
|
+
const decidedOptionsMarkets = new Map();
|
|
366
|
+
function chartMarketKey(market) {
|
|
367
|
+
return typeof market.exchange === 'string' && typeof market.symbol === 'string'
|
|
368
|
+
? `${market.exchange}|${market.symbol}`
|
|
369
|
+
: undefined;
|
|
370
|
+
}
|
|
371
|
+
/** A chart's metadata as the options decisions take it: its market, coin and category (strings and the category). */
|
|
372
|
+
export function wrunChartOptionsMarketRefOf(chart) {
|
|
373
|
+
const text = (value) => (typeof value === 'string' ? value : undefined);
|
|
374
|
+
return {
|
|
375
|
+
exchange: text(chart?.exchange),
|
|
376
|
+
symbol: text(chart?.symbol),
|
|
377
|
+
...(typeof chart?.coin === 'string' ? { coin: chart.coin } : {}),
|
|
378
|
+
...(chart?.category !== undefined ? { category: chart.category } : {}),
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* The ONE options market a run reads, decided at its head after the bounded waits (run-schedule/wrun-chart-gate-reader.util
|
|
383
|
+
* `decideWrunChartOptionsMarket`: the `opra` flag where it decides the chart's options or the overlay is `stamped` with
|
|
384
|
+
* an OPRA read, the stock twin answer under a lit flag or a stamp), so a run that started under one answer never mixes
|
|
385
|
+
* planes: its planners, its options chain lane, its download plan and its host fill read this decision in place of the
|
|
386
|
+
* seam, and every chain lane resolves its chain under this decision's plane (`optionsDecision` on its context). A later
|
|
387
|
+
* twin answer, or the `opra` flag landing, reruns the chart's options runs once the market they resolve to moved off
|
|
388
|
+
* the decision a browser run noted (`noteWrunRunOptionsMarket`, the host's listeners read `wrunDecidedOptionsMarket`).
|
|
389
|
+
*/
|
|
390
|
+
export async function decideWrunRunOptionsMarket(chart, stamped = false) {
|
|
391
|
+
const decided = await decideWrunChartOptionsMarket(wrunChartOptionsMarketRefOf(chart), stamped);
|
|
392
|
+
const lane = wrunChartOptionsLaneMarket(decided.market);
|
|
393
|
+
return lane === undefined ? decided : { ...decided, lane };
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Note the decision a run the browser computes reads (the sandbox prepare, the browser lanes' own step), per chart
|
|
397
|
+
* market: the facts read beside the run (a live tick's `market.option_multiplier()`, `wrunDecidedOptionsExchange`)
|
|
398
|
+
* follow it, and the host reruns the chart's options runs once their market moved off it (`wrunDecidedOptionsMarket`).
|
|
399
|
+
* A batch the cloud computes notes nothing: the server reads the chain of the chart market it is sent.
|
|
400
|
+
*/
|
|
401
|
+
export function noteWrunRunOptionsMarket(chart, decided) {
|
|
402
|
+
const key = chart === null || chart === undefined ? undefined : chartMarketKey(chart);
|
|
403
|
+
const exchange = decided.market.exchange;
|
|
404
|
+
if (key !== undefined && typeof exchange === 'string') {
|
|
405
|
+
decidedOptionsMarkets.set(key, { exchange, plane: decided.plane });
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/** The options market the latest browser run on this chart market decided (`noteWrunRunOptionsMarket`), undefined
|
|
409
|
+
* before one noted. */
|
|
410
|
+
export function wrunDecidedOptionsMarket(market) {
|
|
411
|
+
const key = chartMarketKey(market);
|
|
412
|
+
return key === undefined ? undefined : decidedOptionsMarkets.get(key);
|
|
413
|
+
}
|
|
414
|
+
/** The options exchange the latest browser run on this chart market decided, undefined before one noted: the chart's
|
|
415
|
+
* own then. */
|
|
416
|
+
export function wrunDecidedOptionsExchange(market) {
|
|
417
|
+
return wrunDecidedOptionsMarket(market)?.exchange;
|
|
418
|
+
}
|
|
419
|
+
/** Spec seam: forget every decision noted. */
|
|
420
|
+
export function __resetWrunDecidedOptionsMarketsForTests() {
|
|
421
|
+
decidedOptionsMarkets.clear();
|
|
422
|
+
}
|
|
423
|
+
/** The label a root's market goes by in a chain decision's words. */
|
|
424
|
+
function wrunUnderlyingMarketLabel(market) {
|
|
425
|
+
return market.exchange === '' ? market.symbol : `${market.exchange}/${market.symbol}`;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* One `options_chain` input's chain decision when its `underlying` names a root (the run's options chain lane,
|
|
429
|
+
* wrun-overlay-run.util `wrunOptionsChainLaneExtrasFor`), or undefined for "auto": the setting it names read first
|
|
430
|
+
* (`resolveWrunUnderlyingSettingKnob`), the root's market resolved (`resolveWrunUnderlyingMarket`), then the ONE venue
|
|
431
|
+
* decision every chain class shares (opra-option-lanes.util `decideWrunLaneChainIdentity`) over that market's chain:
|
|
432
|
+
* an OPRA root's the plane's own by coin, with its stop or the session another screen holds named (the decision's OPRA
|
|
433
|
+
* 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,
|
|
434
|
+
* its crypto venue word's listing asked for that root. A crypto root the chart's own crypto venue lists reads that venue
|
|
435
|
+
* (the chart's chain is the run's, `chartChain`) unless the input declares a venue of its own. The decision names the
|
|
436
|
+
* root's chain (`chainUnderlying`), so two inputs reading two chains meet the one-venue rule.
|
|
437
|
+
*/
|
|
438
|
+
export async function wrunUnderlyingOptionsChainDecision(source, who, params, values, chartChain) {
|
|
439
|
+
const ctx = { inputName: who.inputName, sourceClass: 'options_chain' };
|
|
440
|
+
const chart = { ...ctx, exchange: who.exchange, symbol: who.symbol, coin: who.coin };
|
|
441
|
+
const knob = wrunUnderlyingKnob(resolveWrunUnderlyingSettingKnob(ctx, source, params, values), ctx);
|
|
442
|
+
const root = wrunUnderlyingRootOf(knob, chart);
|
|
443
|
+
if (root === undefined)
|
|
444
|
+
return undefined;
|
|
445
|
+
const market = await resolveWrunUnderlyingMarket(root, chart, who, chartChain);
|
|
446
|
+
// A CME root's chain is CME options data whatever the chart: the CME display wall before any read.
|
|
447
|
+
if (market.family === 'cme')
|
|
448
|
+
assertWrunLaneChainPlaneReadable('cme', market.exchange, who, ctx);
|
|
449
|
+
const [lanes, { hasDeribitOptions }] = await Promise.all([
|
|
450
|
+
import('./sources/opra-option-lanes.util.js'),
|
|
451
|
+
wrunChartHostEnv().market.loadDeribitOptions(),
|
|
452
|
+
]);
|
|
453
|
+
let chain;
|
|
454
|
+
if (market.family !== 'opra')
|
|
455
|
+
chain = await lanes.resolveWrunLaneChartChain(market);
|
|
456
|
+
else if (gateSessionHeldElsewhere('opra'))
|
|
457
|
+
chain = { heldElsewhere: 'opra' };
|
|
458
|
+
else {
|
|
459
|
+
const plane = lanes.wrunLaneOpraPlaneChain(root);
|
|
460
|
+
chain = market.opraStop === undefined ? plane : { ...plane, opraStop: market.opraStop };
|
|
461
|
+
}
|
|
462
|
+
const venue = wrunUnderlyingVenueWord(source.venue, market);
|
|
463
|
+
const cryptoVenues = await lanes.resolveWrunLaneCryptoVenues(chain, market.coin, venue === undefined ? [] : [venue]);
|
|
464
|
+
return lanes.decideWrunLaneChainIdentity({ chain, cryptoVenues, deribitListed: hasDeribitOptions }, venue, {
|
|
465
|
+
...who,
|
|
466
|
+
exchange: market.exchange,
|
|
467
|
+
symbol: market.symbol,
|
|
468
|
+
coin: market.coin,
|
|
469
|
+
marketLabel: wrunUnderlyingMarketLabel(market),
|
|
470
|
+
});
|
|
471
|
+
}
|
|
@@ -1,19 +1,54 @@
|
|
|
1
|
-
import type { WrunGateReaderIntentSurface, WrunGateReaderIntentWarm } from '../../../host-ports.types.js';
|
|
1
|
+
import type { OpraOptionPlaneStop, WrunChartOptionsMarket, WrunChartOptionsMarketRef, WrunGateProvider, WrunGateReaderIntentSurface, WrunGateReaderIntentWarm, WrunGateReaderReadKind } from '../../../host-ports.types.js';
|
|
2
2
|
/**
|
|
3
3
|
* The exchange a gate plane's lane reads name, the one the transport routes them by: an OPRA lane asks by the plane's
|
|
4
4
|
* own exchange whatever the chart's venue spelling (`wrunLaneOpraPlaneChain`, the stats lanes' `statsExchange`), a CME
|
|
5
5
|
* chain lane by the chart's own CME exchange.
|
|
6
6
|
*/
|
|
7
7
|
export declare function wrunGateReadExchangeOf(plane: 'cme' | 'opra', chartExchange: string): string;
|
|
8
|
+
/** A chart market as a door names it: the market itself, or, from a door that holds the exchange alone, the exchange
|
|
9
|
+
* (no market named: a stock twin is never seen there, its venue's own options are read). */
|
|
10
|
+
export type WrunGateReaderChart = WrunChartOptionsMarketRef | string;
|
|
11
|
+
/** One chart's options market, decided once (`decideWrunChartOptionsMarket`). */
|
|
12
|
+
export interface WrunChartOptionsMarketDecision {
|
|
13
|
+
/** The chart market the decision is for, as the caller named it. */
|
|
14
|
+
chart: WrunChartOptionsMarketRef;
|
|
15
|
+
/** The market whose options the chart reads: the chart's own, or a stock twin's US stock (`twinOf` names the chart). */
|
|
16
|
+
market: WrunChartOptionsMarket;
|
|
17
|
+
/** The gate plane those options ride (`governedOptionPlane` over `market`), null for none. */
|
|
18
|
+
plane: WrunGateProvider | null;
|
|
19
|
+
/** Off every plane, the known reason options that list on OPRA ride none (`opraOptionPlaneStop` over `market`). */
|
|
20
|
+
opraStop?: OpraOptionPlaneStop;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The market whose options a chart reads, its plane and its stop, decided ONCE (a run's head reads it, and both gate
|
|
24
|
+
* reader warms): the flag map first where the `opra` flag decides the chart's options (`opraFlagDecidesChartOptions`: a
|
|
25
|
+
* US stock, an OPRA contract or index chart, a known stock twin) or where `stamped` says the overlay read OPRA before,
|
|
26
|
+
* bounded (`awaitOpraFlagHydration`); then, under a lit flag or a stamp only, the chart's stock twin answer, bounded
|
|
27
|
+
* (the gate port's `awaitStockTwin`, which answers at once for a known answer and a market that cannot be a twin); then
|
|
28
|
+
* the market (the gate port's `chartOptionsMarket`), its plane and its stop in one synchronous step, so the three read
|
|
29
|
+
* one state of the seam. A host that binds neither twin port reads every chart's options off its own market. Rejects
|
|
30
|
+
* only when the options gate cannot load.
|
|
31
|
+
*/
|
|
32
|
+
export declare function decideWrunChartOptionsMarket(chart: WrunChartOptionsMarketRef, stamped?: boolean): Promise<WrunChartOptionsMarketDecision>;
|
|
8
33
|
/** The exchange the reads of a chart's options route by on their gate plane (see the module comment), or null for a
|
|
9
34
|
* chart whose options ride no plane. Rejects only when the options gate cannot load. */
|
|
10
|
-
export declare function wrunChartGateReadExchange(
|
|
35
|
+
export declare function wrunChartGateReadExchange(chart: WrunGateReaderChart): Promise<string | null>;
|
|
11
36
|
/**
|
|
12
37
|
* Warm the gate reader the chart's options are read on, for a surface whose open suspects an options add is coming:
|
|
13
38
|
* dialed through the transport only when no other tab of this browser holds that reader for this identity and tier,
|
|
14
39
|
* once per reader's life (a reader this tab already dials or holds is left alone), and under every guard of a dial (a
|
|
15
|
-
* guest, a terms wall, a refusal).
|
|
16
|
-
*
|
|
17
|
-
*
|
|
40
|
+
* guest, a terms wall, a refusal). `kind` names the reads it readies the reader for (the slot they ride: `candles` by
|
|
41
|
+
* default, `metadata` for the one-shot reads a native options add makes first). A reader no read ever uses is released
|
|
42
|
+
* by the transport's idle sweep. Resolves with what it did (`no-plane` for a chart whose options ride no gate plane,
|
|
43
|
+
* `failed` when a load or a port failed); never rejects.
|
|
44
|
+
*/
|
|
45
|
+
export declare function warmWrunChartGateReaderOnIntent(chart: WrunGateReaderChart | null | undefined, surface: WrunGateReaderIntentSurface, kind?: WrunGateReaderReadKind): Promise<WrunGateReaderIntentWarm>;
|
|
46
|
+
/**
|
|
47
|
+
* The add's own dial of the reader a chart's options data reads ride (V2Service `warmGateReaderFor`: the `candles`
|
|
48
|
+
* slot at the served tier, under every guard of an on-demand dial but no lease, since the add contests another tab's
|
|
49
|
+
* session exactly as its first read would). For an add the host has ADMITTED (web: chart.add-indicator, after its
|
|
50
|
+
* slot, duplicate and lock gates), never for an intent: a refused add must dial nothing. A chart whose options ride no
|
|
51
|
+
* plane dials nothing. `chart` is the chart's market (an exchange alone names no market: a stock twin is not seen
|
|
52
|
+
* there, and its venue's own plane is dialed). Resolves once the dial was asked for; never rejects.
|
|
18
53
|
*/
|
|
19
|
-
export declare function
|
|
54
|
+
export declare function dialWrunChartGateReaderForAdd(chart: WrunGateReaderChart | null | undefined): Promise<void>;
|