@orangecharts/wrun-chart-host 0.7.1 → 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 +27 -4
- package/dist/constants/feature-flags.constants.d.ts +5 -0
- package/dist/constants/feature-flags.constants.js +32 -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 +29 -6
- package/dist/constants/option-venues.constants.js +19 -2
- package/dist/constants/venue-presets.constants.d.ts +17 -3
- package/dist/constants/venue-presets.constants.js +17 -3
- package/dist/host-env.d.ts +34 -4
- package/dist/host-env.js +21 -0
- package/dist/host-ports.types.d.ts +51 -3
- package/dist/index.d.ts +17 -0
- package/dist/index.js +17 -0
- package/dist/indicators/controls/tpo-session.util.d.ts +40 -11
- package/dist/indicators/controls/tpo-session.util.js +138 -14
- package/dist/interfaces/opra-realtime.interface.d.ts +13 -11
- package/dist/interfaces/opra-realtime.interface.js +10 -10
- package/dist/interfaces/option-instrument.interface.d.ts +6 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +34 -13
- package/dist/kscript-data/controls/live-trades-merge.util.d.ts +57 -10
- package/dist/kscript-data/controls/live-trades-merge.util.js +85 -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/settings-templates/footprint-rows.d.ts +25 -0
- package/dist/settings-templates/footprint-rows.js +127 -0
- package/dist/settings-templates/form-rows.d.ts +56 -0
- package/dist/settings-templates/form-rows.js +19 -0
- package/dist/settings-templates/frvp-fields.js +14 -0
- package/dist/settings-templates/index.d.ts +10 -1
- package/dist/settings-templates/index.js +11 -2
- package/dist/settings-templates/indicator-fields.js +78 -0
- package/dist/settings-templates/tool-rules.d.ts +35 -9
- package/dist/settings-templates/tool-rules.js +42 -8
- package/dist/settings-templates/tool-tables.generated.js +13 -2
- package/dist/utility/chart/candle-volume-unit.leaf.d.ts +16 -0
- package/dist/utility/chart/candle-volume-unit.leaf.js +61 -0
- 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/footprint-columns.util.d.ts +74 -0
- package/dist/utility/chart/footprint-columns.util.js +106 -0
- package/dist/utility/chart/footprint-display-mode.util.d.ts +40 -0
- package/dist/utility/chart/footprint-display-mode.util.js +62 -0
- package/dist/utility/chart/footprint-sierra-look.util.d.ts +2 -0
- package/dist/utility/chart/footprint-sierra-look.util.js +37 -0
- 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 +34 -26
- 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.d.ts +11 -0
- package/dist/utility/chart/om-panel.util.js +65 -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/window-geometry.leaf.d.ts +23 -1
- package/dist/utility/chart/window-geometry.leaf.js +78 -6
- package/dist/utility/chart/window-owner.leaf.d.ts +13 -0
- package/dist/utility/chart/window-owner.leaf.js +5 -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/cme-options-root.util.d.ts +25 -0
- package/dist/utility/options/cme-options-root.util.js +40 -0
- package/dist/utility/options/option-book.util.d.ts +27 -0
- package/dist/utility/options/option-book.util.js +76 -0
- package/dist/utility/options/option-trade-date.util.d.ts +50 -0
- package/dist/utility/options/option-trade-date.util.js +120 -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/host-grid-landing.d.ts +4 -2
- package/dist/utility/wrun/sources/host-grid-landing.js +8 -0
- package/dist/utility/wrun/sources/lanes/options_flow.d.ts +40 -4
- package/dist/utility/wrun/sources/lanes/options_flow.js +115 -18
- package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +12 -9
- package/dist/utility/wrun/sources/opra-option-lanes.util.js +10 -7
- package/dist/utility/wrun/sources/row-lane-registry.js +10 -5
- package/dist/utility/wrun/sources/row-lanes/index.js +2 -0
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +3 -2
- package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +30 -5
- 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 +25 -1
- package/dist/utility/wrun/sources/row-lanes/option_prints.js +161 -30
- package/dist/utility/wrun/sources/row-lanes/option_strike_flow.d.ts +4 -0
- package/dist/utility/wrun/sources/row-lanes/option_strike_flow.js +65 -0
- package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +55 -1
- package/dist/utility/wrun/sources/row-lanes/option_strikes.js +83 -2
- package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +17 -1
- package/dist/utility/wrun/sources/row-lanes/option_surface.js +33 -2
- package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +7 -1
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +51 -5
- package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +136 -3
- package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +42 -0
- package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +146 -0
- package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +25 -5
- package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +111 -20
- package/dist/utility/wrun/sources/wrun-row-lanes.util.js +291 -48
- 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-cloud-record.leaf.d.ts +27 -0
- package/dist/utility/wrun/wrun-cloud-record.leaf.js +71 -0
- package/dist/utility/wrun/wrun-cloud-record.util.d.ts +4 -21
- package/dist/utility/wrun/wrun-cloud-record.util.js +5 -65
- 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 +22 -9
- package/dist/utility/wrun/wrun-color-settings.util.js +57 -23
- 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 +10 -3
- package/dist/utility/wrun/wrun-draft-overlay.util.js +63 -6
- 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 +11 -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-lane-refusal.leaf.d.ts +29 -3
- package/dist/utility/wrun/wrun-lane-refusal.leaf.js +33 -3
- 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.d.ts +4 -1
- package/dist/utility/wrun/wrun-live-tick.util.js +130 -44
- 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 +224 -0
- package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +342 -0
- package/dist/utility/wrun/wrun-market-size-defaults.util.d.ts +88 -0
- package/dist/utility/wrun/wrun-market-size-defaults.util.js +471 -0
- package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +43 -8
- package/dist/utility/wrun/wrun-opra-flow.leaf.js +37 -6
- package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +51 -10
- package/dist/utility/wrun/wrun-option-contract-flow.util.js +85 -33
- package/dist/utility/wrun/wrun-option-prints.util.d.ts +172 -3
- package/dist/utility/wrun/wrun-option-prints.util.js +394 -17
- package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +99 -0
- package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +218 -0
- package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +365 -0
- package/dist/utility/wrun/wrun-option-strike-flow.util.js +797 -0
- package/dist/utility/wrun/wrun-option-views.util.d.ts +231 -7
- package/dist/utility/wrun/wrun-option-views.util.js +643 -23
- package/dist/utility/wrun/wrun-options-chain.util.d.ts +6 -4
- package/dist/utility/wrun/wrun-options-chain.util.js +8 -5
- 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 +9 -1
- package/dist/utility/wrun/wrun-overlay-recovery.util.js +32 -3
- 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 +527 -180
- package/dist/utility/wrun/wrun-pack-widths.leaf.d.ts +15 -0
- package/dist/utility/wrun/wrun-pack-widths.leaf.js +22 -0
- package/dist/utility/wrun/wrun-pack.util.d.ts +13 -8
- package/dist/utility/wrun/wrun-pack.util.js +38 -21
- package/dist/utility/wrun/wrun-panel-mount.util.d.ts +4 -0
- package/dist/utility/wrun/wrun-panel-mount.util.js +62 -22
- package/dist/utility/wrun/wrun-panel-style.util.d.ts +41 -14
- package/dist/utility/wrun/wrun-panel-style.util.js +86 -26
- 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-pin-spelling.util.js +19 -10
- package/dist/utility/wrun/wrun-prefix-lanes.util.js +2 -2
- package/dist/utility/wrun/wrun-refusal.util.js +17 -2
- package/dist/utility/wrun/wrun-script-inputs.util.d.ts +20 -0
- package/dist/utility/wrun/wrun-script-inputs.util.js +43 -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 +133 -48
- package/dist/utility/wrun/wrun-tape-source.util.js +205 -62
- 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
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The size thresholds a built-in package declares as ONE number for every market, made to follow the market. Big
|
|
3
|
+
* Trades 0.5.0 floors its tape by Min size in each venue's raw stored unit (coins on Binance, contracts on gate.io
|
|
4
|
+
* futures), tuned on BTC, where 10 BTC is about $830k; on a market whose coin is worth a sliver of BTC the same number
|
|
5
|
+
* keeps a whole tape: 10 ETH (about $24k) kept 487,132 prints over its seven days of BINANCE_FUTURES ETHUSDT, past the
|
|
6
|
+
* trades worker's 300,000-print cap, so every attempt failed. A threshold that means "big" follows the market instead:
|
|
7
|
+
* the table below names the params that do (keyed by package and param name, never by a label, a hint or a pattern),
|
|
8
|
+
* and this leaf holds the rules; the run head applies them once per mount and market (wrun-market-size-defaults.util).
|
|
9
|
+
*
|
|
10
|
+
* Two rule families, one per unit a package floors in:
|
|
11
|
+
*
|
|
12
|
+
* - The DOLLAR rule (C-DOLLAR, Big Trades 0.6.0's Min value and Whale value, the floor every new package uses): the
|
|
13
|
+
* default is 0.01% of the market's daily DOLLAR volume, read from the chart's own candles (each candle's volume x
|
|
14
|
+
* its close x the market's dollar unit, `wrunDailyCandleDollarVolume`), rounded down to 1, 2 or 5 times a power of
|
|
15
|
+
* ten (`wrunNiceFloor`), and Whale value ten times that. The dollar unit is the market facts' (`market.point_value()`
|
|
16
|
+
* on a market quoted in dollars, wrun-chart-market-facts.util `wrunMarketDollarUnit`): 1 where a candle counts coins
|
|
17
|
+
* or shares, the CME root's point value where it counts contracts. ONE rule for every market: the verdict reads the
|
|
18
|
+
* candles and the unit, and never a venue list (a spec walks every venue the pb-common enum names). A market whose
|
|
19
|
+
* unit cannot be proven reads the package's defaults with a named reason (no point value, a quote that is no dollar),
|
|
20
|
+
* or moves nothing while the directory can still name its quote.
|
|
21
|
+
* - The COIN rule (Big Trades 0.5.0's Min size and Whale size, kept so a published 0.5.0 runs exactly as it did): on a
|
|
22
|
+
* market whose size unit is coins and whose candle volume is in base coins, Min size defaults to 0.01% of the daily
|
|
23
|
+
* base volume, rounded the same way, and Whale size to ten times that, so BTC keeps 10 and 100 (131.7K BTC a day)
|
|
24
|
+
* while ETH reads 200 and 2000 (3.13M ETH). Its facts are a venue's raw unit, so a market whose facts never yield a
|
|
25
|
+
* coin default reads the package's defaults: sized in contracts, placed by the directory in another unit (shares), or
|
|
26
|
+
* candles in another unit than the tape (candle-volume-unit.leaf). This is the raw-unit class the dollar rule ends.
|
|
27
|
+
*
|
|
28
|
+
* Big Trades 0.8.0's contracts floor (`min_contracts` and `whale_contracts`, Min size and Whale size on a market that
|
|
29
|
+
* counts contracts, the floor of its `tape_contracts` input) follows no market: CME keeps 0.5.0's flat 10 and 100
|
|
30
|
+
* contracts, the package's defaults, untouched rows included (Kyle 2026-10-23; an even-density rule is a follow-up).
|
|
31
|
+
* The twins guard exempts it by name.
|
|
32
|
+
*
|
|
33
|
+
* A run reads only the family its sheet declares (`wrunMarketScaledRulesOfSheet`). A market whose closed candles cover
|
|
34
|
+
* under an hour moves nothing: the next run asks again.
|
|
35
|
+
*
|
|
36
|
+
* Beside the volume rules, the OPTION rule (r11, Big Trades 0.7.0's Size shown as, `contracts-option`): a select whose
|
|
37
|
+
* default follows what the chart counts. On a chart that counts contracts (`wrunChartSizeUnit` contracts) whose dollar
|
|
38
|
+
* unit is proven, the rule's option (Contracts or coins: the bubble reads 25 NQ contracts, not $12M); everywhere else
|
|
39
|
+
* the package's own (Dollars). It reads no candles, and skips only while the dollar unit can still be proven, so it
|
|
40
|
+
* never keeps another market's option for good. The run head splits it off the volume rules first
|
|
41
|
+
* (`wrunMarketScaledFamilies`): each family has its own verdict and memo, so a volume rule waiting on its candles never
|
|
42
|
+
* holds the option back.
|
|
43
|
+
*
|
|
44
|
+
* Pure: the specs and the phone app read the same rules. Its one import is the import-free size unit table.
|
|
45
|
+
*/
|
|
46
|
+
import type { WrunScriptInputDeclaration } from './wrun-script-inputs.util.js';
|
|
47
|
+
/** How a market-scaled param's default follows the market. */
|
|
48
|
+
export type WrunMarketScaledRule =
|
|
49
|
+
/** A share of the market's daily base volume (the coin rule), rounded down to 1, 2 or 5 times a power of ten. */
|
|
50
|
+
{
|
|
51
|
+
readonly kind: 'daily-volume';
|
|
52
|
+
readonly share: number;
|
|
53
|
+
}
|
|
54
|
+
/** A share of the market's daily dollar volume (the dollar rule, C-DOLLAR), rounded the same way. `carriesFrom` names
|
|
55
|
+
* the raw-unit param a saved record of an older version held in its place: a value the user changed there is priced
|
|
56
|
+
* into this one once (the pin move keeps it pending, the run head prices it, `wrunCarriedDollarValue`). */
|
|
57
|
+
| {
|
|
58
|
+
readonly kind: 'daily-dollar-volume';
|
|
59
|
+
readonly share: number;
|
|
60
|
+
readonly carriesFrom?: string;
|
|
61
|
+
}
|
|
62
|
+
/** A multiple of another scaled param's market default (resolved after the ones read off the volume). */
|
|
63
|
+
| {
|
|
64
|
+
readonly kind: 'times';
|
|
65
|
+
readonly param: string;
|
|
66
|
+
readonly factor: number;
|
|
67
|
+
readonly carriesFrom?: string;
|
|
68
|
+
}
|
|
69
|
+
/** A select's option where the chart counts contracts and its dollar unit is proven, the package's own default
|
|
70
|
+
* everywhere else (`wrunMarketOptionVerdict`). An option is never a value carried from an older version. */
|
|
71
|
+
| {
|
|
72
|
+
readonly kind: 'contracts-option';
|
|
73
|
+
readonly option: number;
|
|
74
|
+
readonly carriesFrom?: never;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The params whose default follows the market, by package name, then param name (the sheet's own names). A built-in
|
|
78
|
+
* twin whose sheet binds a param to a trade floor lists it here or in the guard's exemptions with a reason
|
|
79
|
+
* (tests/utility/wrun/wrun-market-size-defaults.twins.spec.ts walks every proven twin's frozen sheet).
|
|
80
|
+
*/
|
|
81
|
+
export declare const WRUN_MARKET_SCALED_PARAMS: Readonly<Record<string, Readonly<Record<string, WrunMarketScaledRule>>>>;
|
|
82
|
+
/** The scaled params of a package, or undefined for a package that scales none. */
|
|
83
|
+
export declare function wrunMarketScaledParamsOf(packageName: string | undefined): Readonly<Record<string, WrunMarketScaledRule>> | undefined;
|
|
84
|
+
/** The scaled rules a sheet declares params for (a version of the package declares its own: 0.5.0 the coin rule,
|
|
85
|
+
* 0.6.0 the dollar rule, 0.7.0 and 0.8.0 the option rule beside it), or undefined when it declares none. */
|
|
86
|
+
export declare function wrunMarketScaledRulesOfSheet(rules: Readonly<Record<string, WrunMarketScaledRule>> | undefined, paramNames: Iterable<string>): Readonly<Record<string, WrunMarketScaledRule>> | undefined;
|
|
87
|
+
/** A package's scaled rules split by family: the VOLUME rules (`daily-volume`, `daily-dollar-volume` and the
|
|
88
|
+
* multiples of them, read off the candles) and the OPTION rules (`contracts-option`, read off the market's units).
|
|
89
|
+
* The run head reads each family with its own verdict and memo; a family the rules leave empty is absent. */
|
|
90
|
+
export interface WrunMarketScaledFamilies {
|
|
91
|
+
volume?: Readonly<Record<string, WrunMarketScaledRule>>;
|
|
92
|
+
options?: Readonly<Record<string, WrunMarketScaledRule>>;
|
|
93
|
+
}
|
|
94
|
+
/** The scaled rules split into their families (`WrunMarketScaledFamilies`): every option rule to `options`, every other
|
|
95
|
+
* rule to `volume`. */
|
|
96
|
+
export declare function wrunMarketScaledFamilies(rules: Readonly<Record<string, WrunMarketScaledRule>>): WrunMarketScaledFamilies;
|
|
97
|
+
/** A market's daily volume in its candles' unit (the coin rule's volume), `wrunDailyCandleSum` of each candle's
|
|
98
|
+
* volume. */
|
|
99
|
+
export declare function wrunDailyCandleVolume(rows: ReadonlyArray<ArrayLike<number>>, intervalMs?: number): number | undefined;
|
|
100
|
+
/** A market's daily dollar volume (the dollar rule's volume): `wrunDailyCandleSum` of each candle's volume x its close
|
|
101
|
+
* x `dollarUnit` (the US dollars one price unit times one candle-volume unit is worth). Undefined for a unit that is
|
|
102
|
+
* not finite and above zero. */
|
|
103
|
+
export declare function wrunDailyCandleDollarVolume(rows: ReadonlyArray<ArrayLike<number>>, dollarUnit: number, intervalMs?: number): number | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* 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
|
|
106
|
+
* a clean decimal; undefined for a value that is not finite and above zero.
|
|
107
|
+
*/
|
|
108
|
+
export declare function wrunNiceFloor(value: number): number | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Each scaled param's default on a market trading `dailyVolume` base units a day and `dailyDollarVolume` dollars a
|
|
111
|
+
* day: the volume rules first (each reads its own family's volume), then the multiples of them. Undefined when a rule's
|
|
112
|
+
* volume yields no default (absent, or not finite and above zero). An option rule is no volume rule and gets nothing
|
|
113
|
+
* here (its default is `wrunMarketOptionVerdict`'s).
|
|
114
|
+
*/
|
|
115
|
+
export declare function wrunMarketScaledDefaults(rules: Readonly<Record<string, WrunMarketScaledRule>>, dailyVolume: number | undefined, dailyDollarVolume?: number): Record<string, number> | undefined;
|
|
116
|
+
/** The dollar unit a market's facts prove (wrun-chart-market-facts.util `wrunMarketDollarUnit`, read by the head): the
|
|
117
|
+
* US dollars one price unit times one size unit is worth, or why it cannot be proven. */
|
|
118
|
+
export type WrunMarketSizeDollarUnit = {
|
|
119
|
+
kind: 'dollars';
|
|
120
|
+
unit: number;
|
|
121
|
+
} | {
|
|
122
|
+
kind: 'unproven';
|
|
123
|
+
reason: 'point-value' | 'quote';
|
|
124
|
+
transient: boolean;
|
|
125
|
+
};
|
|
126
|
+
/** The market facts the rules read: the size unit (`wrunChartSizeUnit`) and whether the candles' volume is in base
|
|
127
|
+
* coins (the venue's unit profile, candle-volume-unit.leaf) for the coin rule; the market's dollar unit for the dollar
|
|
128
|
+
* rule; the chart's own candle rows and its bar length for both. */
|
|
129
|
+
export interface WrunMarketSizeFacts {
|
|
130
|
+
sizeUnit: number;
|
|
131
|
+
candleVolumeInCoins: boolean;
|
|
132
|
+
/** The dollar rule's unit; absent on a chart whose candles are no market's (a formula chart), which reads the
|
|
133
|
+
* package's defaults (`candle-unit`). */
|
|
134
|
+
dollarUnit?: WrunMarketSizeDollarUnit;
|
|
135
|
+
rows: ReadonlyArray<ArrayLike<number>>;
|
|
136
|
+
intervalMs?: number;
|
|
137
|
+
}
|
|
138
|
+
/** What a market's facts make of the scaled params' defaults. */
|
|
139
|
+
export type WrunMarketSizeVerdict =
|
|
140
|
+
/** The market's own defaults: a market whose candles say how much it trades a day, in the rules' unit. */
|
|
141
|
+
{
|
|
142
|
+
kind: 'market';
|
|
143
|
+
defaults: Record<string, number>;
|
|
144
|
+
}
|
|
145
|
+
/** The package's declared defaults, on facts that never change for the market, so a record moves back to them
|
|
146
|
+
* instead of keeping another market's scaled default. The coin rule: sized in contracts (`contracts`: CME, every
|
|
147
|
+
* contract market), placed by the directory in another unit (`size-unit`: shares), candles in another unit than the
|
|
148
|
+
* tape (`candle-unit`: contracts on an inverse or an OKX swap, a formula chart's candles, which are no market's). The
|
|
149
|
+
* dollar rule: no point value (`point-value`: ICE, PLATTS, a CME root off the table), a quote that is no dollar
|
|
150
|
+
* (`quote`: KRW, a coin), a formula chart (`candle-unit`). */
|
|
151
|
+
| {
|
|
152
|
+
kind: 'package';
|
|
153
|
+
reason: 'contracts' | 'size-unit' | 'candle-unit' | 'point-value' | 'quote';
|
|
154
|
+
}
|
|
155
|
+
/** Nothing moves yet (the record keeps what it holds, and the next run asks again), on facts that can still change:
|
|
156
|
+
* a size unit not known yet (`size-unit`: the directory has not placed the market, or its lookup failed), a dollar
|
|
157
|
+
* quote the directory can still name (`quote`), closed candles covering under an hour or holding no volume
|
|
158
|
+
* (`cover`). */
|
|
159
|
+
| {
|
|
160
|
+
kind: 'skip';
|
|
161
|
+
reason: 'size-unit' | 'quote' | 'cover';
|
|
162
|
+
};
|
|
163
|
+
/** The verdict of a market's facts on a package's VOLUME rules (`allRules`, one volume family: a sheet declares one,
|
|
164
|
+
* and the head passes `wrunMarketScaledFamilies(...).volume`; an option rule among them is left out, never read as a
|
|
165
|
+
* dollar rule). A set holding both volume families reads the dollar rule only when the coin rule agrees to move (a
|
|
166
|
+
* mixed set is no shipped sheet's; the stricter verdict wins). */
|
|
167
|
+
export declare function wrunMarketSizeVerdict(allRules: Readonly<Record<string, WrunMarketScaledRule>>, facts: WrunMarketSizeFacts): WrunMarketSizeVerdict;
|
|
168
|
+
/**
|
|
169
|
+
* The verdict of a market's facts on a package's OPTION rules (`contracts-option`, the head passes
|
|
170
|
+
* `wrunMarketScaledFamilies(...).options`). It reads no candles: on a chart that counts contracts (`sizeUnit`) whose
|
|
171
|
+
* dollar unit is proven, each rule's option (`market`); the package's own defaults on facts that never change for the
|
|
172
|
+
* market (`package`: a formula chart, `candle-unit`; a dollar unit that can never be proven, its reason; any other size
|
|
173
|
+
* unit, `size-unit`); nothing while the dollar unit can still be proven (`skip`, `quote`), so it is never a skip for
|
|
174
|
+
* good and a record never keeps another market's option.
|
|
175
|
+
*/
|
|
176
|
+
export declare function wrunMarketOptionVerdict(rules: Readonly<Record<string, WrunMarketScaledRule>>, facts: WrunMarketSizeFacts): WrunMarketSizeVerdict;
|
|
177
|
+
/** What one unit of a market's STORED trade amount is worth in US dollars (wrun-chart-market-facts.util
|
|
178
|
+
* `wrunMarketStoredUnitDollars`, read by the head: the large-print writer's own price of one, off the market's newest
|
|
179
|
+
* TRADE_LARGE print), or why that cannot be proven (`transient` while a read can still answer it). */
|
|
180
|
+
export type WrunMarketSizeStoredUnit = {
|
|
181
|
+
kind: 'dollars';
|
|
182
|
+
perUnit: number;
|
|
183
|
+
} | {
|
|
184
|
+
kind: 'unproven';
|
|
185
|
+
reason: string;
|
|
186
|
+
transient: boolean;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* 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)
|
|
190
|
+
* priced in dollars once, for the dollar param that took its place: `raw` STORED units (the unit 0.5.0 floored by:
|
|
191
|
+
* contracts on gate.io futures and OKX swaps, USD contracts on an inverse market, contracts on CME) x the dollars one
|
|
192
|
+
* stored unit is worth at the market's price (`perStoredUnit`, `WrunMarketSizeStoredUnit`), held to 3 significant
|
|
193
|
+
* figures, the nearest. A user's own number is never moved on the market defaults' 1, 2 or 5 ladder (`wrunNiceFloor`):
|
|
194
|
+
* that floor cut 5 NQ contracts ($3,002,125) to $2,000,000, about 3.3 contracts, and 60,000 gate.io contracts
|
|
195
|
+
* ($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:
|
|
196
|
+
* 60,000 gate.io BTC_USDT contracts are 6 BTC, about $504,000, never 60,000 x the price. Undefined when either fact is
|
|
197
|
+
* not finite and above zero, or their product is not (the carry then waits, never guesses).
|
|
198
|
+
*/
|
|
199
|
+
export declare function wrunCarriedDollarValue(raw: unknown, perStoredUnit: number): number | undefined;
|
|
200
|
+
/**
|
|
201
|
+
* Whether a carry keeps the raw value under its old name after pricing it (BT-CME stopgap S0): on a market that counts
|
|
202
|
+
* contracts (`sizeUnit`, `wrunChartSizeUnit` contracts: the CME family) the raw value IS the market's own unit, the
|
|
203
|
+
* contract count a futures trader set, and the version that floors such a market in contracts restores it exactly, so
|
|
204
|
+
* it stays stored (its dollar row's `carriedValue` mark keeps it from pricing twice). Everywhere else the raw value is
|
|
205
|
+
* a venue's stored unit no later version reads, and the carry clears it.
|
|
206
|
+
*/
|
|
207
|
+
export declare function wrunCarryKeepsRawValue(sizeUnit: number | undefined): boolean;
|
|
208
|
+
/** A market default as its row holds it: a number row's value held to its bounds (undefined for one that is not
|
|
209
|
+
* finite); a select row's option string when `String(value)` is one of the row's options ("0", "1"), the row's own
|
|
210
|
+
* spelling, else undefined. */
|
|
211
|
+
export declare function wrunMarketDefaultWithinRow(row: Pick<WrunScriptInputDeclaration, 'type' | 'constraints' | 'options'>, value: unknown): number | string | undefined;
|
|
212
|
+
/**
|
|
213
|
+
* `rows` (the rows a sheet builds, `buildWrunScriptInputs`) with the market defaults a record holds: each scaled
|
|
214
|
+
* param's row takes the default its row in `held` (the record's own `scriptInputs`) carries, the one the run head last
|
|
215
|
+
* moved it to, so a rebuild of the rows from the sheet (a delivered sheet's reconcile, a pin move) never moves a market
|
|
216
|
+
* default back to the sheet's, and a value at it never reads as changed; and the carried value its held row marks
|
|
217
|
+
* (`carriedValue`, C-DOLLAR's carry), so a rebuild never turns a carried value into one the market defaults move. A
|
|
218
|
+
* 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
|
|
219
|
+
* offer (a select keeps the option it names, in its own spelling). The same array when nothing moves.
|
|
220
|
+
*/
|
|
221
|
+
export declare function wrunRowsKeepingMarketDefaults(rows: WrunScriptInputDeclaration[], held: unknown, packageName: string | undefined): WrunScriptInputDeclaration[];
|
|
222
|
+
/** Whether a settings row can hold the market default of `rule`: a select for an option rule (`contracts-option`), a
|
|
223
|
+
* number kind for every other rule and for no rule given; a sheet that retyped the param keeps its own. */
|
|
224
|
+
export declare function isWrunMarketScaledRow(row: Pick<WrunScriptInputDeclaration, 'type'>, rule?: WrunMarketScaledRule): boolean;
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { WRUN_MARKET_SIZE_UNITS } from './wrun-market-facts.util.js';
|
|
2
|
+
/**
|
|
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 floor lists it here or in the guard's exemptions with a reason
|
|
5
|
+
* (tests/utility/wrun/wrun-market-size-defaults.twins.spec.ts walks every proven twin's frozen sheet).
|
|
6
|
+
*/
|
|
7
|
+
export const WRUN_MARKET_SCALED_PARAMS = Object.freeze({
|
|
8
|
+
'@om-core/big-trades': Object.freeze({
|
|
9
|
+
// 0.5.0, the coin rule: the tape's raw floor (its `min_size` facet names it) and the bubbles' size unit.
|
|
10
|
+
min_size: Object.freeze({ kind: 'daily-volume', share: 0.0001 }),
|
|
11
|
+
// 0.5.0: the Whale buy and Whale sell signals' threshold, in Min size's unit: ten times its market default.
|
|
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).
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
/** The scaled params of a package, or undefined for a package that scales none. */
|
|
25
|
+
export function wrunMarketScaledParamsOf(packageName) {
|
|
26
|
+
if (packageName === undefined || !Object.hasOwn(WRUN_MARKET_SCALED_PARAMS, packageName))
|
|
27
|
+
return undefined;
|
|
28
|
+
return WRUN_MARKET_SCALED_PARAMS[packageName];
|
|
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
|
+
}
|
|
58
|
+
const HOUR_MS = 3_600_000;
|
|
59
|
+
const DAY_MS = 86_400_000;
|
|
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;
|
|
62
|
+
const VOLUME_COLUMN = 5;
|
|
63
|
+
/** `market.size_unit()`'s codes (the kit's table, wrun-market-facts.util). */
|
|
64
|
+
const UNKNOWN_SIZE_UNIT = WRUN_MARKET_SIZE_UNITS.indexOf('unknown');
|
|
65
|
+
const COINS_SIZE_UNIT = WRUN_MARKET_SIZE_UNITS.indexOf('coins');
|
|
66
|
+
const CONTRACTS_SIZE_UNIT = WRUN_MARKET_SIZE_UNITS.indexOf('contracts');
|
|
67
|
+
/**
|
|
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.
|
|
74
|
+
*/
|
|
75
|
+
function wrunDailyCandleSum(rows, intervalMs, barValue) {
|
|
76
|
+
const last = rows.length - 1;
|
|
77
|
+
if (last < 1)
|
|
78
|
+
return undefined;
|
|
79
|
+
const newestOpen = Number(rows[last][0]);
|
|
80
|
+
const lastClosedOpen = Number(rows[last - 1][0]);
|
|
81
|
+
if (!Number.isFinite(newestOpen) || !Number.isFinite(lastClosedOpen))
|
|
82
|
+
return undefined;
|
|
83
|
+
const barMs = intervalMs !== undefined && Number.isFinite(intervalMs) && intervalMs > 0 ? intervalMs : Infinity;
|
|
84
|
+
const lastSpan = Math.min(newestOpen - lastClosedOpen, barMs);
|
|
85
|
+
if (lastSpan > DAY_MS) {
|
|
86
|
+
const volume = barValue(rows[last - 1]);
|
|
87
|
+
return Number.isFinite(volume) && volume > 0 ? (volume * DAY_MS) / lastSpan : undefined;
|
|
88
|
+
}
|
|
89
|
+
const windowStart = newestOpen - DAY_MS;
|
|
90
|
+
let volume = 0;
|
|
91
|
+
for (let at = last - 1; at >= 0; at -= 1) {
|
|
92
|
+
if (!(Number(rows[at][0]) >= windowStart))
|
|
93
|
+
break;
|
|
94
|
+
const bar = barValue(rows[at]);
|
|
95
|
+
if (Number.isFinite(bar) && bar > 0)
|
|
96
|
+
volume += bar;
|
|
97
|
+
}
|
|
98
|
+
const covered = newestOpen - Math.max(windowStart, Number(rows[0][0]));
|
|
99
|
+
if (!(covered >= HOUR_MS) || !(volume > 0))
|
|
100
|
+
return undefined;
|
|
101
|
+
return (volume * DAY_MS) / covered;
|
|
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
|
+
}
|
|
116
|
+
/**
|
|
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
|
|
118
|
+
* a clean decimal; undefined for a value that is not finite and above zero.
|
|
119
|
+
*/
|
|
120
|
+
export function wrunNiceFloor(value) {
|
|
121
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
122
|
+
return undefined;
|
|
123
|
+
const scale = 10 ** Math.floor(Math.log10(value));
|
|
124
|
+
// A hair over the float quotient: 0.6 / 0.1 reads 5.999999999999999, and log10 can land a power of ten one
|
|
125
|
+
// exponent low (the mantissa then reads 10).
|
|
126
|
+
const mantissa = (value / scale) * (1 + 1e-9);
|
|
127
|
+
const step = mantissa >= 10 ? 10 : mantissa >= 5 ? 5 : mantissa >= 2 ? 2 : 1;
|
|
128
|
+
return Number((step * scale).toPrecision(1));
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
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).
|
|
135
|
+
*/
|
|
136
|
+
export function wrunMarketScaledDefaults(rules, dailyVolume, dailyDollarVolume) {
|
|
137
|
+
const defaults = {};
|
|
138
|
+
for (const [name, rule] of Object.entries(rules)) {
|
|
139
|
+
if (rule.kind !== 'daily-volume' && rule.kind !== 'daily-dollar-volume')
|
|
140
|
+
continue;
|
|
141
|
+
const volume = rule.kind === 'daily-volume' ? dailyVolume : dailyDollarVolume;
|
|
142
|
+
const value = volume === undefined ? undefined : wrunNiceFloor(volume * rule.share);
|
|
143
|
+
if (value === undefined)
|
|
144
|
+
return undefined;
|
|
145
|
+
defaults[name] = value;
|
|
146
|
+
}
|
|
147
|
+
for (const [name, rule] of Object.entries(rules)) {
|
|
148
|
+
if (rule.kind !== 'times')
|
|
149
|
+
continue;
|
|
150
|
+
const base = defaults[rule.param];
|
|
151
|
+
if (base === undefined)
|
|
152
|
+
return undefined;
|
|
153
|
+
defaults[name] = Number((base * rule.factor).toPrecision(12));
|
|
154
|
+
}
|
|
155
|
+
return defaults;
|
|
156
|
+
}
|
|
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) {
|
|
180
|
+
if (facts.sizeUnit === CONTRACTS_SIZE_UNIT)
|
|
181
|
+
return { kind: 'package', reason: 'contracts' };
|
|
182
|
+
if (facts.sizeUnit === UNKNOWN_SIZE_UNIT)
|
|
183
|
+
return { kind: 'skip', reason: 'size-unit' };
|
|
184
|
+
if (facts.sizeUnit !== COINS_SIZE_UNIT)
|
|
185
|
+
return { kind: 'package', reason: 'size-unit' };
|
|
186
|
+
if (!facts.candleVolumeInCoins)
|
|
187
|
+
return { kind: 'package', reason: 'candle-unit' };
|
|
188
|
+
const daily = wrunDailyCandleVolume(facts.rows, facts.intervalMs);
|
|
189
|
+
const defaults = daily === undefined ? undefined : wrunMarketScaledDefaults(rules, daily);
|
|
190
|
+
return defaults === undefined ? { kind: 'skip', reason: 'cover' } : { kind: 'market', defaults };
|
|
191
|
+
}
|
|
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. */
|
|
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
|
+
}
|
|
293
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
294
|
+
return undefined;
|
|
295
|
+
const { min, max } = row.constraints ?? {};
|
|
296
|
+
if (typeof min === 'number' && value < min)
|
|
297
|
+
return min;
|
|
298
|
+
if (typeof max === 'number' && value > max)
|
|
299
|
+
return max;
|
|
300
|
+
return value;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* `rows` (the rows a sheet builds, `buildWrunScriptInputs`) with the market defaults a record holds: each scaled
|
|
304
|
+
* param's row takes the default its row in `held` (the record's own `scriptInputs`) carries, the one the run head last
|
|
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
|
|
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.
|
|
310
|
+
*/
|
|
311
|
+
export function wrunRowsKeepingMarketDefaults(rows, held, packageName) {
|
|
312
|
+
const rules = wrunMarketScaledParamsOf(packageName);
|
|
313
|
+
if (rules === undefined || !Array.isArray(held))
|
|
314
|
+
return rows;
|
|
315
|
+
let moved = false;
|
|
316
|
+
const kept = rows.map((row) => {
|
|
317
|
+
if (!Object.hasOwn(rules, row.name) || !isWrunMarketScaledRow(row, rules[row.name]))
|
|
318
|
+
return row;
|
|
319
|
+
const own = held.find((candidate) => candidate !== null && typeof candidate === 'object' && candidate.name === row.name);
|
|
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)
|
|
326
|
+
return row;
|
|
327
|
+
moved = true;
|
|
328
|
+
return {
|
|
329
|
+
...row,
|
|
330
|
+
...(keepsDefault && value !== undefined ? { defaultValue: value } : {}),
|
|
331
|
+
...(keepsCarried ? { carriedValue: carried } : {}),
|
|
332
|
+
};
|
|
333
|
+
});
|
|
334
|
+
return moved ? kept : rows;
|
|
335
|
+
}
|
|
336
|
+
/** The row kinds a volume rule's param is: a number, int or price row (they store the same finite number). */
|
|
337
|
+
const WRUN_MARKET_SCALED_ROW_TYPES = new Set(['number', 'int', 'price']);
|
|
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);
|
|
342
|
+
}
|