@orangecharts/wrun-chart-host 0.8.0 → 0.9.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 +2 -1
- package/dist/constants/feature-flags.constants.d.ts +4 -0
- package/dist/constants/feature-flags.constants.js +27 -0
- package/dist/constants/marketCapabilities.constants.d.ts +14 -9
- package/dist/constants/marketCapabilities.constants.js +36 -13
- package/dist/constants/opra-compliance.constants.d.ts +14 -0
- package/dist/constants/opra-compliance.constants.js +14 -0
- package/dist/constants/option-venues.constants.d.ts +11 -6
- package/dist/constants/option-venues.constants.js +5 -2
- package/dist/host-env.d.ts +10 -4
- package/dist/host-ports.types.d.ts +39 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces/opra-realtime.interface.d.ts +13 -11
- package/dist/interfaces/opra-realtime.interface.js +10 -10
- package/dist/interfaces/wrun-runtime.interface.d.ts +34 -13
- package/dist/kscript-data/controls/live-trades-merge.util.d.ts +53 -10
- package/dist/kscript-data/controls/live-trades-merge.util.js +81 -16
- package/dist/market-data/billing.interface.d.ts +138 -17
- package/dist/market-data/billing.interface.js +25 -8
- package/dist/market-data/venues/index.d.ts +3 -3
- package/dist/market-data/venues/opra.contract.copy.json +5 -3
- package/dist/market-data/venues/opra.d.ts +3 -3
- package/dist/market-data/venues/opra.js +5 -4
- package/dist/replay/replayLadder.js +3 -1
- package/dist/utility/chart/crypto-index.leaf.d.ts +2 -2
- package/dist/utility/chart/crypto-index.leaf.js +2 -2
- package/dist/utility/chart/index-mode-admission.util.js +9 -1
- package/dist/utility/chart/index-mode.util.d.ts +5 -2
- package/dist/utility/chart/index-mode.util.js +23 -13
- package/dist/utility/chart/kscript-venue-policy.util.d.ts +28 -21
- package/dist/utility/chart/kscript-venue-policy.util.js +30 -24
- package/dist/utility/chart/marketKind.util.d.ts +12 -10
- package/dist/utility/chart/marketKind.util.js +17 -7
- package/dist/utility/chart/om-panel-push-style.util.d.ts +7 -7
- package/dist/utility/chart/om-panel-push-style.util.js +17 -15
- package/dist/utility/chart/om-panel.util.js +6 -6
- package/dist/utility/chart/profile-block-size.util.d.ts +16 -0
- package/dist/utility/chart/profile-block-size.util.js +7 -0
- package/dist/utility/chart/quote-perp.leaf.d.ts +17 -0
- package/dist/utility/chart/quote-perp.leaf.js +20 -0
- package/dist/utility/chart/wrun-run-result.util.d.ts +5 -0
- package/dist/utility/chart/wrun-run-result.util.js +4 -1
- package/dist/utility/common/transformations.util.d.ts +7 -0
- package/dist/utility/common/transformations.util.js +11 -0
- package/dist/utility/options/option-venue.util.d.ts +3 -3
- package/dist/utility/options/option-venue.util.js +3 -3
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +1 -1
- package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +2 -2
- package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +2 -2
- package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +5 -1
- package/dist/utility/wrun/sources/row-lane-registry.js +3 -2
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +9 -3
- package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +13 -5
- package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +11 -0
- package/dist/utility/wrun/sources/row-lanes/option_prints.js +63 -9
- package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +8 -0
- package/dist/utility/wrun/sources/row-lanes/option_strikes.js +12 -0
- package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +5 -2
- package/dist/utility/wrun/sources/row-lanes/option_surface.js +5 -2
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +11 -5
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +31 -10
- package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +33 -1
- package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +95 -6
- package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +25 -5
- package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +55 -18
- package/dist/utility/wrun/sources/wrun-row-lanes.util.js +146 -40
- package/dist/utility/wrun/wrun-batched-marks.util.d.ts +16 -3
- package/dist/utility/wrun/wrun-batched-marks.util.js +30 -19
- package/dist/utility/wrun/wrun-batched-readout.util.d.ts +37 -9
- package/dist/utility/wrun/wrun-batched-readout.util.js +61 -15
- package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +4 -0
- package/dist/utility/wrun/wrun-cell-capacity.leaf.d.ts +66 -0
- package/dist/utility/wrun/wrun-cell-capacity.leaf.js +86 -0
- package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +147 -9
- package/dist/utility/wrun/wrun-chart-market-facts.util.js +345 -11
- package/dist/utility/wrun/wrun-color-facts.util.d.ts +19 -9
- package/dist/utility/wrun/wrun-color-facts.util.js +24 -14
- package/dist/utility/wrun/wrun-color-settings.util.d.ts +15 -4
- package/dist/utility/wrun/wrun-color-settings.util.js +31 -12
- package/dist/utility/wrun/wrun-dollar-unit-port.leaf.d.ts +17 -0
- package/dist/utility/wrun/wrun-dollar-unit-port.leaf.js +9 -0
- package/dist/utility/wrun/wrun-download-meter.util.d.ts +92 -0
- package/dist/utility/wrun/wrun-download-meter.util.js +122 -0
- package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +6 -1
- package/dist/utility/wrun/wrun-draft-overlay.util.js +23 -3
- package/dist/utility/wrun/wrun-frames.js +5 -5
- package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +2 -2
- package/dist/utility/wrun/wrun-hosted-wire-caps.js +7 -0
- package/dist/utility/wrun/wrun-hud-looks.util.d.ts +33 -17
- package/dist/utility/wrun/wrun-hud-looks.util.js +30 -16
- package/dist/utility/wrun/wrun-lifecycle-runtime.util.d.ts +8 -6
- package/dist/utility/wrun/wrun-lifecycle-runtime.util.js +8 -6
- package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +4 -2
- package/dist/utility/wrun/wrun-live-intake.util.d.ts +6 -2
- package/dist/utility/wrun/wrun-live-intake.util.js +136 -21
- package/dist/utility/wrun/wrun-live-tick.util.js +91 -38
- package/dist/utility/wrun/wrun-market-size-contract-carry.leaf.d.ts +53 -0
- package/dist/utility/wrun/wrun-market-size-contract-carry.leaf.js +162 -0
- package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +166 -48
- package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +216 -33
- package/dist/utility/wrun/wrun-market-size-defaults.util.d.ts +51 -7
- package/dist/utility/wrun/wrun-market-size-defaults.util.js +314 -56
- package/dist/utility/wrun/wrun-option-prints.util.d.ts +41 -2
- package/dist/utility/wrun/wrun-option-prints.util.js +80 -13
- package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +3 -0
- package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +3 -0
- package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +23 -0
- package/dist/utility/wrun/wrun-option-strike-flow.util.js +55 -0
- package/dist/utility/wrun/wrun-option-views.util.d.ts +51 -7
- package/dist/utility/wrun/wrun-option-views.util.js +151 -28
- package/dist/utility/wrun/wrun-options-stop.util.d.ts +2 -1
- package/dist/utility/wrun/wrun-options-stop.util.js +3 -2
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +3 -0
- package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.d.ts +31 -14
- package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.js +22 -0
- package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +7 -0
- package/dist/utility/wrun/wrun-overlay-recovery.util.js +25 -1
- package/dist/utility/wrun/wrun-overlay-result.util.d.ts +7 -1
- package/dist/utility/wrun/wrun-overlay-result.util.js +2 -0
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +34 -6
- package/dist/utility/wrun/wrun-overlay-run.util.js +416 -171
- package/dist/utility/wrun/wrun-pack-widths.leaf.d.ts +4 -4
- package/dist/utility/wrun/wrun-pack-widths.leaf.js +4 -4
- package/dist/utility/wrun/wrun-pack.util.d.ts +7 -3
- package/dist/utility/wrun/wrun-pack.util.js +20 -9
- package/dist/utility/wrun/wrun-panel-style.util.d.ts +27 -15
- package/dist/utility/wrun/wrun-panel-style.util.js +42 -20
- package/dist/utility/wrun/wrun-param-map.util.d.ts +7 -6
- package/dist/utility/wrun/wrun-param-map.util.js +8 -5
- package/dist/utility/wrun/wrun-param-values.util.d.ts +10 -2
- package/dist/utility/wrun/wrun-param-values.util.js +2 -0
- package/dist/utility/wrun/wrun-prefix-lanes.util.js +2 -2
- package/dist/utility/wrun/wrun-refusal.util.js +10 -1
- package/dist/utility/wrun/wrun-script-inputs.util.d.ts +7 -0
- package/dist/utility/wrun/wrun-source-rows.util.d.ts +4 -0
- package/dist/utility/wrun/wrun-source-rows.util.js +92 -40
- package/dist/utility/wrun/wrun-tape-source.util.d.ts +126 -50
- package/dist/utility/wrun/wrun-tape-source.util.js +193 -68
- package/dist/utility/wrun/wrun-volume-profile-lane.util.d.ts +7 -5
- package/dist/utility/wrun/wrun-volume-profile-lane.util.js +8 -6
- package/dist/workers/utils/volume-profile.worker.util.d.ts +4 -1
- package/dist/workers/utils/volume-profile.worker.util.js +5 -2
- package/dist/workers/wrun/wrun-abi-host.js +3 -2
- package/package.json +11 -11
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { WRUN_MARKET_SIZE_UNITS } from './wrun-market-facts.util.js';
|
|
2
2
|
/**
|
|
3
3
|
* The params whose default follows the market, by package name, then param name (the sheet's own names). A built-in
|
|
4
|
-
* twin whose sheet binds a param to a trade
|
|
4
|
+
* twin whose sheet binds a param to a trade floor lists it here or in the guard's exemptions with a reason
|
|
5
5
|
* (tests/utility/wrun/wrun-market-size-defaults.twins.spec.ts walks every proven twin's frozen sheet).
|
|
6
6
|
*/
|
|
7
7
|
export const WRUN_MARKET_SCALED_PARAMS = Object.freeze({
|
|
8
8
|
'@om-core/big-trades': Object.freeze({
|
|
9
|
-
//
|
|
9
|
+
// 0.5.0, the coin rule: the tape's raw floor (its `min_size` facet names it) and the bubbles' size unit.
|
|
10
10
|
min_size: Object.freeze({ kind: 'daily-volume', share: 0.0001 }),
|
|
11
|
-
//
|
|
11
|
+
// 0.5.0: the Whale buy and Whale sell signals' threshold, in Min size's unit: ten times its market default.
|
|
12
12
|
whale_size: Object.freeze({ kind: 'times', param: 'min_size', factor: 10 }),
|
|
13
|
+
// 0.6.0, the dollar rule: the tape's dollar floor (its `min_value` facet names it), 0.01% of a day's dollar volume.
|
|
14
|
+
min_value: Object.freeze({ kind: 'daily-dollar-volume', share: 0.0001, carriesFrom: 'min_size' }),
|
|
15
|
+
// 0.6.0: the whale threshold in dollars, ten times Min value's market default.
|
|
16
|
+
whale_value: Object.freeze({ kind: 'times', param: 'min_value', factor: 10, carriesFrom: 'whale_size' }),
|
|
17
|
+
// 0.7.0: Size shown as reads Contracts or coins (1) on a chart that counts contracts, the package's Dollars (0)
|
|
18
|
+
// elsewhere.
|
|
19
|
+
size_shown_as: Object.freeze({ kind: 'contracts-option', option: 1 }),
|
|
20
|
+
// 0.8.0's min_contracts and whale_contracts are not here: the package's flat 10 and 100 contracts (Kyle
|
|
21
|
+
// 2026-10-23).
|
|
13
22
|
}),
|
|
14
23
|
});
|
|
15
24
|
/** The scaled params of a package, or undefined for a package that scales none. */
|
|
@@ -18,23 +27,52 @@ export function wrunMarketScaledParamsOf(packageName) {
|
|
|
18
27
|
return undefined;
|
|
19
28
|
return WRUN_MARKET_SCALED_PARAMS[packageName];
|
|
20
29
|
}
|
|
30
|
+
/** The scaled rules a sheet declares params for (a version of the package declares its own: 0.5.0 the coin rule,
|
|
31
|
+
* 0.6.0 the dollar rule, 0.7.0 and 0.8.0 the option rule beside it), or undefined when it declares none. */
|
|
32
|
+
export function wrunMarketScaledRulesOfSheet(rules, paramNames) {
|
|
33
|
+
if (rules === undefined)
|
|
34
|
+
return undefined;
|
|
35
|
+
const declared = new Set(paramNames);
|
|
36
|
+
const kept = {};
|
|
37
|
+
for (const [name, rule] of Object.entries(rules))
|
|
38
|
+
if (declared.has(name))
|
|
39
|
+
kept[name] = rule;
|
|
40
|
+
return Object.keys(kept).length > 0 ? kept : undefined;
|
|
41
|
+
}
|
|
42
|
+
/** The scaled rules split into their families (`WrunMarketScaledFamilies`): every option rule to `options`, every other
|
|
43
|
+
* rule to `volume`. */
|
|
44
|
+
export function wrunMarketScaledFamilies(rules) {
|
|
45
|
+
const volume = {};
|
|
46
|
+
const options = {};
|
|
47
|
+
for (const [name, rule] of Object.entries(rules)) {
|
|
48
|
+
if (rule.kind === 'contracts-option')
|
|
49
|
+
options[name] = rule;
|
|
50
|
+
else
|
|
51
|
+
volume[name] = rule;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
...(Object.keys(volume).length > 0 ? { volume } : {}),
|
|
55
|
+
...(Object.keys(options).length > 0 ? { options } : {}),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
21
58
|
const HOUR_MS = 3_600_000;
|
|
22
59
|
const DAY_MS = 86_400_000;
|
|
23
|
-
/** The candle row's volume
|
|
60
|
+
/** The candle row's close and volume columns (`[ts, open, high, low, close, volume]`, the chart's main series rows). */
|
|
61
|
+
const CLOSE_COLUMN = 4;
|
|
24
62
|
const VOLUME_COLUMN = 5;
|
|
25
63
|
/** `market.size_unit()`'s codes (the kit's table, wrun-market-facts.util). */
|
|
26
64
|
const UNKNOWN_SIZE_UNIT = WRUN_MARKET_SIZE_UNITS.indexOf('unknown');
|
|
27
65
|
const COINS_SIZE_UNIT = WRUN_MARKET_SIZE_UNITS.indexOf('coins');
|
|
28
66
|
const CONTRACTS_SIZE_UNIT = WRUN_MARKET_SIZE_UNITS.indexOf('contracts');
|
|
29
67
|
/**
|
|
30
|
-
* A
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
68
|
+
* A candle-volume measure per day, from the chart's own candles (ascending, the newest the forming one, which is left
|
|
69
|
+
* out: its volume is partial): `barValue` of the closed candles opening in the 24 hours before the newest one's open,
|
|
70
|
+
* summed and scaled to a day by the span they cover (a fine chart loads less than a day: 500 one-minute candles count
|
|
71
|
+
* 499 minutes; a gap where nothing traded counts as covered time with no volume). One closed candle longer than a day
|
|
72
|
+
* (1W, 1M) is prorated by its length, the gap to the next open held to `intervalMs`. Undefined when the closed candles
|
|
73
|
+
* cover under an hour or hold no volume.
|
|
36
74
|
*/
|
|
37
|
-
|
|
75
|
+
function wrunDailyCandleSum(rows, intervalMs, barValue) {
|
|
38
76
|
const last = rows.length - 1;
|
|
39
77
|
if (last < 1)
|
|
40
78
|
return undefined;
|
|
@@ -45,7 +83,7 @@ export function wrunDailyCandleVolume(rows, intervalMs) {
|
|
|
45
83
|
const barMs = intervalMs !== undefined && Number.isFinite(intervalMs) && intervalMs > 0 ? intervalMs : Infinity;
|
|
46
84
|
const lastSpan = Math.min(newestOpen - lastClosedOpen, barMs);
|
|
47
85
|
if (lastSpan > DAY_MS) {
|
|
48
|
-
const volume =
|
|
86
|
+
const volume = barValue(rows[last - 1]);
|
|
49
87
|
return Number.isFinite(volume) && volume > 0 ? (volume * DAY_MS) / lastSpan : undefined;
|
|
50
88
|
}
|
|
51
89
|
const windowStart = newestOpen - DAY_MS;
|
|
@@ -53,7 +91,7 @@ export function wrunDailyCandleVolume(rows, intervalMs) {
|
|
|
53
91
|
for (let at = last - 1; at >= 0; at -= 1) {
|
|
54
92
|
if (!(Number(rows[at][0]) >= windowStart))
|
|
55
93
|
break;
|
|
56
|
-
const bar =
|
|
94
|
+
const bar = barValue(rows[at]);
|
|
57
95
|
if (Number.isFinite(bar) && bar > 0)
|
|
58
96
|
volume += bar;
|
|
59
97
|
}
|
|
@@ -62,6 +100,19 @@ export function wrunDailyCandleVolume(rows, intervalMs) {
|
|
|
62
100
|
return undefined;
|
|
63
101
|
return (volume * DAY_MS) / covered;
|
|
64
102
|
}
|
|
103
|
+
/** A market's daily volume in its candles' unit (the coin rule's volume), `wrunDailyCandleSum` of each candle's
|
|
104
|
+
* volume. */
|
|
105
|
+
export function wrunDailyCandleVolume(rows, intervalMs) {
|
|
106
|
+
return wrunDailyCandleSum(rows, intervalMs, (row) => Number(row[VOLUME_COLUMN]));
|
|
107
|
+
}
|
|
108
|
+
/** A market's daily dollar volume (the dollar rule's volume): `wrunDailyCandleSum` of each candle's volume x its close
|
|
109
|
+
* x `dollarUnit` (the US dollars one price unit times one candle-volume unit is worth). Undefined for a unit that is
|
|
110
|
+
* not finite and above zero. */
|
|
111
|
+
export function wrunDailyCandleDollarVolume(rows, dollarUnit, intervalMs) {
|
|
112
|
+
if (!(Number.isFinite(dollarUnit) && dollarUnit > 0))
|
|
113
|
+
return undefined;
|
|
114
|
+
return wrunDailyCandleSum(rows, intervalMs, (row) => Number(row[VOLUME_COLUMN]) * Number(row[CLOSE_COLUMN]) * dollarUnit);
|
|
115
|
+
}
|
|
65
116
|
/**
|
|
66
117
|
* The largest 1, 2 or 5 times a power of ten at or below `value` (5,000,000, 200, 10, then 0.5, 0.2, 0.1 below 1), as
|
|
67
118
|
* a clean decimal; undefined for a value that is not finite and above zero.
|
|
@@ -77,15 +128,18 @@ export function wrunNiceFloor(value) {
|
|
|
77
128
|
return Number((step * scale).toPrecision(1));
|
|
78
129
|
}
|
|
79
130
|
/**
|
|
80
|
-
* Each scaled param's default on a market trading `dailyVolume` base units a day
|
|
81
|
-
* the
|
|
131
|
+
* Each scaled param's default on a market trading `dailyVolume` base units a day and `dailyDollarVolume` dollars a
|
|
132
|
+
* day: the volume rules first (each reads its own family's volume), then the multiples of them. Undefined when a rule's
|
|
133
|
+
* volume yields no default (absent, or not finite and above zero). An option rule is no volume rule and gets nothing
|
|
134
|
+
* here (its default is `wrunMarketOptionVerdict`'s).
|
|
82
135
|
*/
|
|
83
|
-
export function wrunMarketScaledDefaults(rules, dailyVolume) {
|
|
136
|
+
export function wrunMarketScaledDefaults(rules, dailyVolume, dailyDollarVolume) {
|
|
84
137
|
const defaults = {};
|
|
85
138
|
for (const [name, rule] of Object.entries(rules)) {
|
|
86
|
-
if (rule.kind !== 'daily-volume')
|
|
139
|
+
if (rule.kind !== 'daily-volume' && rule.kind !== 'daily-dollar-volume')
|
|
87
140
|
continue;
|
|
88
|
-
const
|
|
141
|
+
const volume = rule.kind === 'daily-volume' ? dailyVolume : dailyDollarVolume;
|
|
142
|
+
const value = volume === undefined ? undefined : wrunNiceFloor(volume * rule.share);
|
|
89
143
|
if (value === undefined)
|
|
90
144
|
return undefined;
|
|
91
145
|
defaults[name] = value;
|
|
@@ -100,8 +154,29 @@ export function wrunMarketScaledDefaults(rules, dailyVolume) {
|
|
|
100
154
|
}
|
|
101
155
|
return defaults;
|
|
102
156
|
}
|
|
103
|
-
/**
|
|
104
|
-
|
|
157
|
+
/** Whether a set of rules is the dollar family's (a dollar volume rule, or a multiple of one). */
|
|
158
|
+
function readsDollarVolume(rules) {
|
|
159
|
+
return Object.values(rules).some((rule) => rule.kind === 'daily-dollar-volume');
|
|
160
|
+
}
|
|
161
|
+
/** Whether a set of rules is the coin family's. */
|
|
162
|
+
function readsCoinVolume(rules) {
|
|
163
|
+
return Object.values(rules).some((rule) => rule.kind === 'daily-volume');
|
|
164
|
+
}
|
|
165
|
+
/** The dollar rule's verdict: the candles' dollar volume over the market's proven dollar unit. Reads no venue: the unit
|
|
166
|
+
* is the market facts', and every other input is the chart's own candles. */
|
|
167
|
+
function wrunDollarVerdict(rules, facts) {
|
|
168
|
+
const unit = facts.dollarUnit;
|
|
169
|
+
if (unit === undefined)
|
|
170
|
+
return { kind: 'package', reason: 'candle-unit' };
|
|
171
|
+
if (unit.kind === 'unproven') {
|
|
172
|
+
return unit.transient ? { kind: 'skip', reason: 'quote' } : { kind: 'package', reason: unit.reason };
|
|
173
|
+
}
|
|
174
|
+
const daily = wrunDailyCandleDollarVolume(facts.rows, unit.unit, facts.intervalMs);
|
|
175
|
+
const defaults = daily === undefined ? undefined : wrunMarketScaledDefaults(rules, undefined, daily);
|
|
176
|
+
return defaults === undefined ? { kind: 'skip', reason: 'cover' } : { kind: 'market', defaults };
|
|
177
|
+
}
|
|
178
|
+
/** The coin rule's verdict (unchanged since 0.5.0's round): the candles' base volume on a coin market. */
|
|
179
|
+
function wrunCoinVerdict(rules, facts) {
|
|
105
180
|
if (facts.sizeUnit === CONTRACTS_SIZE_UNIT)
|
|
106
181
|
return { kind: 'package', reason: 'contracts' };
|
|
107
182
|
if (facts.sizeUnit === UNKNOWN_SIZE_UNIT)
|
|
@@ -114,8 +189,107 @@ export function wrunMarketSizeVerdict(rules, facts) {
|
|
|
114
189
|
const defaults = daily === undefined ? undefined : wrunMarketScaledDefaults(rules, daily);
|
|
115
190
|
return defaults === undefined ? { kind: 'skip', reason: 'cover' } : { kind: 'market', defaults };
|
|
116
191
|
}
|
|
117
|
-
/**
|
|
192
|
+
/** The verdict of a market's facts on a package's VOLUME rules (`allRules`, one volume family: a sheet declares one,
|
|
193
|
+
* and the head passes `wrunMarketScaledFamilies(...).volume`; an option rule among them is left out, never read as a
|
|
194
|
+
* dollar rule). A set holding both volume families reads the dollar rule only when the coin rule agrees to move (a
|
|
195
|
+
* mixed set is no shipped sheet's; the stricter verdict wins). */
|
|
196
|
+
export function wrunMarketSizeVerdict(allRules, facts) {
|
|
197
|
+
const rules = wrunMarketScaledFamilies(allRules).volume ?? {};
|
|
198
|
+
const dollar = readsDollarVolume(rules);
|
|
199
|
+
const coin = readsCoinVolume(rules);
|
|
200
|
+
if (dollar && !coin)
|
|
201
|
+
return wrunDollarVerdict(rules, facts);
|
|
202
|
+
if (coin && !dollar)
|
|
203
|
+
return wrunCoinVerdict(rules, facts);
|
|
204
|
+
const coinVerdict = wrunCoinVerdict(wrunRulesOfFamily(rules, 'daily-volume'), facts);
|
|
205
|
+
if (coinVerdict.kind !== 'market')
|
|
206
|
+
return coinVerdict;
|
|
207
|
+
const dollarVerdict = wrunDollarVerdict(wrunRulesOfFamily(rules, 'daily-dollar-volume'), facts);
|
|
208
|
+
if (dollarVerdict.kind !== 'market')
|
|
209
|
+
return dollarVerdict;
|
|
210
|
+
return { kind: 'market', defaults: { ...coinVerdict.defaults, ...dollarVerdict.defaults } };
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* The verdict of a market's facts on a package's OPTION rules (`contracts-option`, the head passes
|
|
214
|
+
* `wrunMarketScaledFamilies(...).options`). It reads no candles: on a chart that counts contracts (`sizeUnit`) whose
|
|
215
|
+
* dollar unit is proven, each rule's option (`market`); the package's own defaults on facts that never change for the
|
|
216
|
+
* market (`package`: a formula chart, `candle-unit`; a dollar unit that can never be proven, its reason; any other size
|
|
217
|
+
* unit, `size-unit`); nothing while the dollar unit can still be proven (`skip`, `quote`), so it is never a skip for
|
|
218
|
+
* good and a record never keeps another market's option.
|
|
219
|
+
*/
|
|
220
|
+
export function wrunMarketOptionVerdict(rules, facts) {
|
|
221
|
+
const unit = facts.dollarUnit;
|
|
222
|
+
if (unit === undefined)
|
|
223
|
+
return { kind: 'package', reason: 'candle-unit' };
|
|
224
|
+
if (unit.kind === 'unproven') {
|
|
225
|
+
return unit.transient ? { kind: 'skip', reason: 'quote' } : { kind: 'package', reason: unit.reason };
|
|
226
|
+
}
|
|
227
|
+
if (facts.sizeUnit !== CONTRACTS_SIZE_UNIT)
|
|
228
|
+
return { kind: 'package', reason: 'size-unit' };
|
|
229
|
+
const defaults = {};
|
|
230
|
+
for (const [name, rule] of Object.entries(rules)) {
|
|
231
|
+
if (rule.kind === 'contracts-option')
|
|
232
|
+
defaults[name] = rule.option;
|
|
233
|
+
}
|
|
234
|
+
return { kind: 'market', defaults };
|
|
235
|
+
}
|
|
236
|
+
/** The rules of one family: its volume rules and the multiples of them. */
|
|
237
|
+
function wrunRulesOfFamily(rules, family) {
|
|
238
|
+
const kept = {};
|
|
239
|
+
for (const [name, rule] of Object.entries(rules)) {
|
|
240
|
+
if (rule.kind === family)
|
|
241
|
+
kept[name] = rule;
|
|
242
|
+
}
|
|
243
|
+
for (const [name, rule] of Object.entries(rules)) {
|
|
244
|
+
if (rule.kind === 'times' && Object.hasOwn(kept, rule.param))
|
|
245
|
+
kept[name] = rule;
|
|
246
|
+
}
|
|
247
|
+
return kept;
|
|
248
|
+
}
|
|
249
|
+
/** The significant figures a carried value keeps (`wrunCarriedDollarValue`): at most 0.5% off its exact price. */
|
|
250
|
+
const CARRIED_VALUE_SIGNIFICANT_FIGURES = 3;
|
|
251
|
+
/**
|
|
252
|
+
* A raw-unit value the user changed on an older version (C-DOLLAR's carry: Big Trades 0.5.0's Min size or Whale size)
|
|
253
|
+
* priced in dollars once, for the dollar param that took its place: `raw` STORED units (the unit 0.5.0 floored by:
|
|
254
|
+
* contracts on gate.io futures and OKX swaps, USD contracts on an inverse market, contracts on CME) x the dollars one
|
|
255
|
+
* stored unit is worth at the market's price (`perStoredUnit`, `WrunMarketSizeStoredUnit`), held to 3 significant
|
|
256
|
+
* figures, the nearest. A user's own number is never moved on the market defaults' 1, 2 or 5 ladder (`wrunNiceFloor`):
|
|
257
|
+
* that floor cut 5 NQ contracts ($3,002,125) to $2,000,000, about 3.3 contracts, and 60,000 gate.io contracts
|
|
258
|
+
* ($495,078) to $200,000; held to 3 figures they carry $3,000,000 and $495,000. A raw floor is never priced as coins:
|
|
259
|
+
* 60,000 gate.io BTC_USDT contracts are 6 BTC, about $504,000, never 60,000 x the price. Undefined when either fact is
|
|
260
|
+
* not finite and above zero, or their product is not (the carry then waits, never guesses).
|
|
261
|
+
*/
|
|
262
|
+
export function wrunCarriedDollarValue(raw, perStoredUnit) {
|
|
263
|
+
const value = Number(raw);
|
|
264
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
265
|
+
return undefined;
|
|
266
|
+
if (!Number.isFinite(perStoredUnit) || perStoredUnit <= 0)
|
|
267
|
+
return undefined;
|
|
268
|
+
const dollars = value * perStoredUnit;
|
|
269
|
+
if (!Number.isFinite(dollars) || dollars <= 0)
|
|
270
|
+
return undefined;
|
|
271
|
+
return Number(dollars.toPrecision(CARRIED_VALUE_SIGNIFICANT_FIGURES));
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Whether a carry keeps the raw value under its old name after pricing it (BT-CME stopgap S0): on a market that counts
|
|
275
|
+
* contracts (`sizeUnit`, `wrunChartSizeUnit` contracts: the CME family) the raw value IS the market's own unit, the
|
|
276
|
+
* contract count a futures trader set, and the version that floors such a market in contracts restores it exactly, so
|
|
277
|
+
* it stays stored (its dollar row's `carriedValue` mark keeps it from pricing twice). Everywhere else the raw value is
|
|
278
|
+
* a venue's stored unit no later version reads, and the carry clears it.
|
|
279
|
+
*/
|
|
280
|
+
export function wrunCarryKeepsRawValue(sizeUnit) {
|
|
281
|
+
return sizeUnit === CONTRACTS_SIZE_UNIT;
|
|
282
|
+
}
|
|
283
|
+
/** A market default as its row holds it: a number row's value held to its bounds (undefined for one that is not
|
|
284
|
+
* finite); a select row's option string when `String(value)` is one of the row's options ("0", "1"), the row's own
|
|
285
|
+
* spelling, else undefined. */
|
|
118
286
|
export function wrunMarketDefaultWithinRow(row, value) {
|
|
287
|
+
if (row.type === 'select') {
|
|
288
|
+
if (typeof value !== 'number' && typeof value !== 'string')
|
|
289
|
+
return undefined;
|
|
290
|
+
const option = String(value);
|
|
291
|
+
return (row.options ?? []).includes(option) ? option : undefined;
|
|
292
|
+
}
|
|
119
293
|
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
120
294
|
return undefined;
|
|
121
295
|
const { min, max } = row.constraints ?? {};
|
|
@@ -129,8 +303,10 @@ export function wrunMarketDefaultWithinRow(row, value) {
|
|
|
129
303
|
* `rows` (the rows a sheet builds, `buildWrunScriptInputs`) with the market defaults a record holds: each scaled
|
|
130
304
|
* param's row takes the default its row in `held` (the record's own `scriptInputs`) carries, the one the run head last
|
|
131
305
|
* moved it to, so a rebuild of the rows from the sheet (a delivered sheet's reconcile, a pin move) never moves a market
|
|
132
|
-
* default back to the sheet's, and a value at it never reads as changed
|
|
133
|
-
*
|
|
306
|
+
* default back to the sheet's, and a value at it never reads as changed; and the carried value its held row marks
|
|
307
|
+
* (`carriedValue`, C-DOLLAR's carry), so a rebuild never turns a carried value into one the market defaults move. A
|
|
308
|
+
* held default that is not a number within the row's bounds stays the sheet's, and so does one a select row does not
|
|
309
|
+
* offer (a select keeps the option it names, in its own spelling). The same array when nothing moves.
|
|
134
310
|
*/
|
|
135
311
|
export function wrunRowsKeepingMarketDefaults(rows, held, packageName) {
|
|
136
312
|
const rules = wrunMarketScaledParamsOf(packageName);
|
|
@@ -138,22 +314,29 @@ export function wrunRowsKeepingMarketDefaults(rows, held, packageName) {
|
|
|
138
314
|
return rows;
|
|
139
315
|
let moved = false;
|
|
140
316
|
const kept = rows.map((row) => {
|
|
141
|
-
if (!Object.hasOwn(rules, row.name) || !isWrunMarketScaledRow(row))
|
|
317
|
+
if (!Object.hasOwn(rules, row.name) || !isWrunMarketScaledRow(row, rules[row.name]))
|
|
142
318
|
return row;
|
|
143
319
|
const own = held.find((candidate) => candidate !== null && typeof candidate === 'object' && candidate.name === row.name);
|
|
144
|
-
const value = own?.defaultValue;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
320
|
+
const value = own?.defaultValue === undefined ? undefined : wrunMarketDefaultWithinRow(row, own.defaultValue);
|
|
321
|
+
// A number within its row's bounds only (one held off them stays the sheet's); a select's option, as it spells it.
|
|
322
|
+
const keepsDefault = value !== undefined && (row.type === 'select' || value === own?.defaultValue) && value !== row.defaultValue;
|
|
323
|
+
const carried = own?.carriedValue;
|
|
324
|
+
const keepsCarried = typeof carried === 'number' && Number.isFinite(carried) && carried !== row.carriedValue;
|
|
325
|
+
if (!keepsDefault && !keepsCarried)
|
|
148
326
|
return row;
|
|
149
327
|
moved = true;
|
|
150
|
-
return {
|
|
328
|
+
return {
|
|
329
|
+
...row,
|
|
330
|
+
...(keepsDefault && value !== undefined ? { defaultValue: value } : {}),
|
|
331
|
+
...(keepsCarried ? { carriedValue: carried } : {}),
|
|
332
|
+
};
|
|
151
333
|
});
|
|
152
334
|
return moved ? kept : rows;
|
|
153
335
|
}
|
|
154
|
-
/** The row kinds a
|
|
336
|
+
/** The row kinds a volume rule's param is: a number, int or price row (they store the same finite number). */
|
|
155
337
|
const WRUN_MARKET_SCALED_ROW_TYPES = new Set(['number', 'int', 'price']);
|
|
156
|
-
/** Whether a settings row can hold
|
|
157
|
-
|
|
158
|
-
|
|
338
|
+
/** Whether a settings row can hold the market default of `rule`: a select for an option rule (`contracts-option`), a
|
|
339
|
+
* number kind for every other rule and for no rule given; a sheet that retyped the param keeps its own. */
|
|
340
|
+
export function isWrunMarketScaledRow(row, rule) {
|
|
341
|
+
return rule?.kind === 'contracts-option' ? row.type === 'select' : WRUN_MARKET_SCALED_ROW_TYPES.has(row.type);
|
|
159
342
|
}
|
|
@@ -1,20 +1,64 @@
|
|
|
1
1
|
import type { WrunIndicatorMetadata } from '../../interfaces/wrun-runtime.interface.js';
|
|
2
|
+
import { type WrunMarketScaledRule, type WrunMarketSizeStoredUnit } from './wrun-market-size-defaults.leaf.js';
|
|
3
|
+
import { type WrunScriptInputDeclaration } from './wrun-script-inputs.util.js';
|
|
4
|
+
/**
|
|
5
|
+
* Whether a market-scaled row holds a value the user chose (the market defaults never move it): a value off its row's
|
|
6
|
+
* default (the settings panel's reset test, `wrunRowValuesEqual` over `wrunRowValue`), or the value a carry priced into
|
|
7
|
+
* it (`carriedValue`, C-DOLLAR), which counts as chosen even where it equals the row's default: a 0.5.0 Min size of
|
|
8
|
+
* 5,000 Binance delivery contracts of $100 carries $500,000, the sheet's default, and must not follow the next market's
|
|
9
|
+
* default. Pure.
|
|
10
|
+
*/
|
|
11
|
+
export declare function wrunMarketScaledRowChanged(record: Readonly<Record<string, unknown>>, row: WrunScriptInputDeclaration): boolean;
|
|
2
12
|
/**
|
|
3
13
|
* The patch that moves a record (`settings`: its `scriptInputs` rows and each value flat under its row's name) to a
|
|
4
|
-
* market's `defaults`: every scaled row whose value
|
|
5
|
-
* (held to the row's bounds), value and `defaultValue` together.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
14
|
+
* market's `defaults`: every scaled row whose value the user never chose (`wrunMarketScaledRowChanged`) takes the
|
|
15
|
+
* market's default (held to the row's bounds, a select's as the option it names), value and `defaultValue` together.
|
|
16
|
+
* `rules` are the rules the defaults were read by: a select row moves under an option rule only (without them, number
|
|
17
|
+
* rows only, the volume families' kind). A changed value keeps both: the
|
|
18
|
+
* changed mark is the value against its own row's default, so a default moved under a kept value would read the value
|
|
19
|
+
* as never changed on the first market whose default equals it, and the next market would move it (SOL 200, then ETH
|
|
20
|
+
* whose default is 200, then SOL reset it to 1000). Its reset goes to the default of the market where the user changed
|
|
21
|
+
* it, a save whose run head then moves the unchanged value on. A carried value (`carriedValue`) is a changed one too,
|
|
22
|
+
* whatever its row's default. Undefined when the record already reads the defaults. Pure.
|
|
23
|
+
*/
|
|
24
|
+
export declare function wrunMarketSizeSettingsPatch(settings: unknown, defaults: Readonly<Record<string, number>>, rules?: Readonly<Record<string, WrunMarketScaledRule>>): Record<string, unknown> | undefined;
|
|
25
|
+
/** A pending carry: a dollar param (`to`) and the raw-unit value an older version's param (`from`) left for it. */
|
|
26
|
+
interface WrunPendingDollarCarry {
|
|
27
|
+
to: string;
|
|
28
|
+
from: string;
|
|
29
|
+
raw: number;
|
|
30
|
+
}
|
|
31
|
+
/** The carries a record holds for the scaled rules its sheet declares: a rule's `carriesFrom` name held flat on the
|
|
32
|
+
* record with a finite positive value while the sheet no longer declares it (the pin move left it there), and while
|
|
33
|
+
* the dollar row holds no carried mark: a carry prices once, so a raw value kept under its old name (a market that
|
|
34
|
+
* counts contracts, `wrunCarryKeepsRawValue`) never prices again, after a reload, a market switch or a reset alike
|
|
35
|
+
* (a reset writes values, never the rows, so the mark stays). */
|
|
36
|
+
export declare function wrunPendingDollarCarries(settings: unknown, rules: Readonly<Record<string, WrunMarketScaledRule>>, sheetParams: ReadonlySet<string>): WrunPendingDollarCarry[];
|
|
37
|
+
/**
|
|
38
|
+
* The patch that prices a record's pending carries once (C-DOLLAR's saved values): each carry's raw value in STORED
|
|
39
|
+
* units x the dollars one stored unit is worth at the market's price (`stored`, wrun-chart-market-facts.util
|
|
40
|
+
* `wrunMarketStoredUnitDollars`), held to 3 significant figures (`wrunCarriedDollarValue`) and to the dollar row's
|
|
41
|
+
* bounds, written flat under the dollar param, and the dollar row marked with it (`carriedValue`: a changed value
|
|
42
|
+
* whatever its row's default, `wrunMarketScaledRowChanged`; its row's default stays). The old name is cleared, except
|
|
43
|
+
* on a market that counts contracts (`sizeUnit`, `wrunCarryKeepsRawValue`), where it stays stored: the version that
|
|
44
|
+
* floors such a market in contracts restores the count exactly, and the mark keeps it from pricing twice (so a carry
|
|
45
|
+
* that keeps its old name and finds no dollar row to mark writes nothing yet). A stored unit that can never be proven
|
|
46
|
+
* (`unproven`, not transient: no large print of the market in the table's week, a quote that is no dollar, a CME
|
|
47
|
+
* contract with no point value) writes no value (the market's dollar default applies) and clears the old name, except
|
|
48
|
+
* on a market that counts contracts; a transient one writes nothing (the next run asks again). `sizeUnit` is required
|
|
49
|
+
* of every caller (undefined where the market's is not known: the old name is cleared), so the engine copy and the
|
|
50
|
+
* workspace row are always carried by one rule. Undefined when nothing moves. Pure.
|
|
10
51
|
*/
|
|
11
|
-
export declare function
|
|
52
|
+
export declare function wrunDollarCarryPatch(settings: unknown, pending: readonly WrunPendingDollarCarry[], stored: WrunMarketSizeStoredUnit | undefined, sizeUnit: number | undefined): Record<string, unknown> | undefined;
|
|
12
53
|
/** The chart market the run computes for, as the head reads it. */
|
|
13
54
|
interface WrunMarketSizeChart {
|
|
14
55
|
exchange?: unknown;
|
|
15
56
|
symbol?: unknown;
|
|
16
57
|
interval?: unknown;
|
|
17
58
|
transformations?: unknown;
|
|
59
|
+
normalizedSymbol?: unknown;
|
|
60
|
+
category?: unknown;
|
|
61
|
+
resolvedContract?: unknown;
|
|
18
62
|
}
|
|
19
63
|
/**
|
|
20
64
|
* Move an overlay's record to its chart market's scaled defaults (above), at the head of a full run, before the
|