@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.
Files changed (210) hide show
  1. package/README.md +27 -4
  2. package/dist/constants/feature-flags.constants.d.ts +5 -0
  3. package/dist/constants/feature-flags.constants.js +32 -0
  4. package/dist/constants/marketCapabilities.constants.d.ts +14 -9
  5. package/dist/constants/marketCapabilities.constants.js +36 -13
  6. package/dist/constants/opra-compliance.constants.d.ts +14 -0
  7. package/dist/constants/opra-compliance.constants.js +14 -0
  8. package/dist/constants/option-venues.constants.d.ts +29 -6
  9. package/dist/constants/option-venues.constants.js +19 -2
  10. package/dist/constants/venue-presets.constants.d.ts +17 -3
  11. package/dist/constants/venue-presets.constants.js +17 -3
  12. package/dist/host-env.d.ts +34 -4
  13. package/dist/host-env.js +21 -0
  14. package/dist/host-ports.types.d.ts +51 -3
  15. package/dist/index.d.ts +17 -0
  16. package/dist/index.js +17 -0
  17. package/dist/indicators/controls/tpo-session.util.d.ts +40 -11
  18. package/dist/indicators/controls/tpo-session.util.js +138 -14
  19. package/dist/interfaces/opra-realtime.interface.d.ts +13 -11
  20. package/dist/interfaces/opra-realtime.interface.js +10 -10
  21. package/dist/interfaces/option-instrument.interface.d.ts +6 -0
  22. package/dist/interfaces/wrun-runtime.interface.d.ts +34 -13
  23. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +57 -10
  24. package/dist/kscript-data/controls/live-trades-merge.util.js +85 -16
  25. package/dist/market-data/billing.interface.d.ts +138 -17
  26. package/dist/market-data/billing.interface.js +25 -8
  27. package/dist/market-data/venues/index.d.ts +3 -3
  28. package/dist/market-data/venues/opra.contract.copy.json +5 -3
  29. package/dist/market-data/venues/opra.d.ts +3 -3
  30. package/dist/market-data/venues/opra.js +5 -4
  31. package/dist/replay/replayLadder.js +3 -1
  32. package/dist/settings-templates/footprint-rows.d.ts +25 -0
  33. package/dist/settings-templates/footprint-rows.js +127 -0
  34. package/dist/settings-templates/form-rows.d.ts +56 -0
  35. package/dist/settings-templates/form-rows.js +19 -0
  36. package/dist/settings-templates/frvp-fields.js +14 -0
  37. package/dist/settings-templates/index.d.ts +10 -1
  38. package/dist/settings-templates/index.js +11 -2
  39. package/dist/settings-templates/indicator-fields.js +78 -0
  40. package/dist/settings-templates/tool-rules.d.ts +35 -9
  41. package/dist/settings-templates/tool-rules.js +42 -8
  42. package/dist/settings-templates/tool-tables.generated.js +13 -2
  43. package/dist/utility/chart/candle-volume-unit.leaf.d.ts +16 -0
  44. package/dist/utility/chart/candle-volume-unit.leaf.js +61 -0
  45. package/dist/utility/chart/crypto-index.leaf.d.ts +2 -2
  46. package/dist/utility/chart/crypto-index.leaf.js +2 -2
  47. package/dist/utility/chart/footprint-columns.util.d.ts +74 -0
  48. package/dist/utility/chart/footprint-columns.util.js +106 -0
  49. package/dist/utility/chart/footprint-display-mode.util.d.ts +40 -0
  50. package/dist/utility/chart/footprint-display-mode.util.js +62 -0
  51. package/dist/utility/chart/footprint-sierra-look.util.d.ts +2 -0
  52. package/dist/utility/chart/footprint-sierra-look.util.js +37 -0
  53. package/dist/utility/chart/index-mode-admission.util.js +9 -1
  54. package/dist/utility/chart/index-mode.util.d.ts +5 -2
  55. package/dist/utility/chart/index-mode.util.js +23 -13
  56. package/dist/utility/chart/kscript-venue-policy.util.d.ts +28 -21
  57. package/dist/utility/chart/kscript-venue-policy.util.js +34 -26
  58. package/dist/utility/chart/marketKind.util.d.ts +12 -10
  59. package/dist/utility/chart/marketKind.util.js +17 -7
  60. package/dist/utility/chart/om-panel-push-style.util.d.ts +7 -7
  61. package/dist/utility/chart/om-panel-push-style.util.js +17 -15
  62. package/dist/utility/chart/om-panel.util.d.ts +11 -0
  63. package/dist/utility/chart/om-panel.util.js +65 -6
  64. package/dist/utility/chart/profile-block-size.util.d.ts +16 -0
  65. package/dist/utility/chart/profile-block-size.util.js +7 -0
  66. package/dist/utility/chart/quote-perp.leaf.d.ts +17 -0
  67. package/dist/utility/chart/quote-perp.leaf.js +20 -0
  68. package/dist/utility/chart/window-geometry.leaf.d.ts +23 -1
  69. package/dist/utility/chart/window-geometry.leaf.js +78 -6
  70. package/dist/utility/chart/window-owner.leaf.d.ts +13 -0
  71. package/dist/utility/chart/window-owner.leaf.js +5 -0
  72. package/dist/utility/chart/wrun-run-result.util.d.ts +5 -0
  73. package/dist/utility/chart/wrun-run-result.util.js +4 -1
  74. package/dist/utility/common/transformations.util.d.ts +7 -0
  75. package/dist/utility/common/transformations.util.js +11 -0
  76. package/dist/utility/options/cme-options-root.util.d.ts +25 -0
  77. package/dist/utility/options/cme-options-root.util.js +40 -0
  78. package/dist/utility/options/option-book.util.d.ts +27 -0
  79. package/dist/utility/options/option-book.util.js +76 -0
  80. package/dist/utility/options/option-trade-date.util.d.ts +50 -0
  81. package/dist/utility/options/option-trade-date.util.js +120 -0
  82. package/dist/utility/options/option-venue.util.d.ts +3 -3
  83. package/dist/utility/options/option-venue.util.js +3 -3
  84. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +1 -1
  85. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +2 -2
  86. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +2 -2
  87. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +5 -1
  88. package/dist/utility/wrun/sources/host-grid-landing.d.ts +4 -2
  89. package/dist/utility/wrun/sources/host-grid-landing.js +8 -0
  90. package/dist/utility/wrun/sources/lanes/options_flow.d.ts +40 -4
  91. package/dist/utility/wrun/sources/lanes/options_flow.js +115 -18
  92. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +12 -9
  93. package/dist/utility/wrun/sources/opra-option-lanes.util.js +10 -7
  94. package/dist/utility/wrun/sources/row-lane-registry.js +10 -5
  95. package/dist/utility/wrun/sources/row-lanes/index.js +2 -0
  96. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +3 -2
  97. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +30 -5
  98. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +9 -3
  99. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +13 -5
  100. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +25 -1
  101. package/dist/utility/wrun/sources/row-lanes/option_prints.js +161 -30
  102. package/dist/utility/wrun/sources/row-lanes/option_strike_flow.d.ts +4 -0
  103. package/dist/utility/wrun/sources/row-lanes/option_strike_flow.js +65 -0
  104. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +55 -1
  105. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +83 -2
  106. package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +17 -1
  107. package/dist/utility/wrun/sources/row-lanes/option_surface.js +33 -2
  108. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +7 -1
  109. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +51 -5
  110. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +136 -3
  111. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +42 -0
  112. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +146 -0
  113. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +25 -5
  114. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +111 -20
  115. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +291 -48
  116. package/dist/utility/wrun/wrun-batched-marks.util.d.ts +16 -3
  117. package/dist/utility/wrun/wrun-batched-marks.util.js +30 -19
  118. package/dist/utility/wrun/wrun-batched-readout.util.d.ts +37 -9
  119. package/dist/utility/wrun/wrun-batched-readout.util.js +61 -15
  120. package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +4 -0
  121. package/dist/utility/wrun/wrun-cell-capacity.leaf.d.ts +66 -0
  122. package/dist/utility/wrun/wrun-cell-capacity.leaf.js +86 -0
  123. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +147 -9
  124. package/dist/utility/wrun/wrun-chart-market-facts.util.js +345 -11
  125. package/dist/utility/wrun/wrun-cloud-record.leaf.d.ts +27 -0
  126. package/dist/utility/wrun/wrun-cloud-record.leaf.js +71 -0
  127. package/dist/utility/wrun/wrun-cloud-record.util.d.ts +4 -21
  128. package/dist/utility/wrun/wrun-cloud-record.util.js +5 -65
  129. package/dist/utility/wrun/wrun-color-facts.util.d.ts +19 -9
  130. package/dist/utility/wrun/wrun-color-facts.util.js +24 -14
  131. package/dist/utility/wrun/wrun-color-settings.util.d.ts +22 -9
  132. package/dist/utility/wrun/wrun-color-settings.util.js +57 -23
  133. package/dist/utility/wrun/wrun-dollar-unit-port.leaf.d.ts +17 -0
  134. package/dist/utility/wrun/wrun-dollar-unit-port.leaf.js +9 -0
  135. package/dist/utility/wrun/wrun-download-meter.util.d.ts +92 -0
  136. package/dist/utility/wrun/wrun-download-meter.util.js +122 -0
  137. package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +10 -3
  138. package/dist/utility/wrun/wrun-draft-overlay.util.js +63 -6
  139. package/dist/utility/wrun/wrun-frames.js +5 -5
  140. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +2 -2
  141. package/dist/utility/wrun/wrun-hosted-wire-caps.js +11 -0
  142. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +33 -17
  143. package/dist/utility/wrun/wrun-hud-looks.util.js +30 -16
  144. package/dist/utility/wrun/wrun-lane-refusal.leaf.d.ts +29 -3
  145. package/dist/utility/wrun/wrun-lane-refusal.leaf.js +33 -3
  146. package/dist/utility/wrun/wrun-lifecycle-runtime.util.d.ts +8 -6
  147. package/dist/utility/wrun/wrun-lifecycle-runtime.util.js +8 -6
  148. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +4 -2
  149. package/dist/utility/wrun/wrun-live-intake.util.d.ts +6 -2
  150. package/dist/utility/wrun/wrun-live-intake.util.js +136 -21
  151. package/dist/utility/wrun/wrun-live-tick.util.d.ts +4 -1
  152. package/dist/utility/wrun/wrun-live-tick.util.js +130 -44
  153. package/dist/utility/wrun/wrun-market-size-contract-carry.leaf.d.ts +53 -0
  154. package/dist/utility/wrun/wrun-market-size-contract-carry.leaf.js +162 -0
  155. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +224 -0
  156. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +342 -0
  157. package/dist/utility/wrun/wrun-market-size-defaults.util.d.ts +88 -0
  158. package/dist/utility/wrun/wrun-market-size-defaults.util.js +471 -0
  159. package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +43 -8
  160. package/dist/utility/wrun/wrun-opra-flow.leaf.js +37 -6
  161. package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +51 -10
  162. package/dist/utility/wrun/wrun-option-contract-flow.util.js +85 -33
  163. package/dist/utility/wrun/wrun-option-prints.util.d.ts +172 -3
  164. package/dist/utility/wrun/wrun-option-prints.util.js +394 -17
  165. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +99 -0
  166. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +218 -0
  167. package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +365 -0
  168. package/dist/utility/wrun/wrun-option-strike-flow.util.js +797 -0
  169. package/dist/utility/wrun/wrun-option-views.util.d.ts +231 -7
  170. package/dist/utility/wrun/wrun-option-views.util.js +643 -23
  171. package/dist/utility/wrun/wrun-options-chain.util.d.ts +6 -4
  172. package/dist/utility/wrun/wrun-options-chain.util.js +8 -5
  173. package/dist/utility/wrun/wrun-options-stop.util.d.ts +2 -1
  174. package/dist/utility/wrun/wrun-options-stop.util.js +3 -2
  175. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +3 -0
  176. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.d.ts +31 -14
  177. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.js +22 -0
  178. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +9 -1
  179. package/dist/utility/wrun/wrun-overlay-recovery.util.js +32 -3
  180. package/dist/utility/wrun/wrun-overlay-result.util.d.ts +7 -1
  181. package/dist/utility/wrun/wrun-overlay-result.util.js +2 -0
  182. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +34 -6
  183. package/dist/utility/wrun/wrun-overlay-run.util.js +527 -180
  184. package/dist/utility/wrun/wrun-pack-widths.leaf.d.ts +15 -0
  185. package/dist/utility/wrun/wrun-pack-widths.leaf.js +22 -0
  186. package/dist/utility/wrun/wrun-pack.util.d.ts +13 -8
  187. package/dist/utility/wrun/wrun-pack.util.js +38 -21
  188. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +4 -0
  189. package/dist/utility/wrun/wrun-panel-mount.util.js +62 -22
  190. package/dist/utility/wrun/wrun-panel-style.util.d.ts +41 -14
  191. package/dist/utility/wrun/wrun-panel-style.util.js +86 -26
  192. package/dist/utility/wrun/wrun-param-map.util.d.ts +7 -6
  193. package/dist/utility/wrun/wrun-param-map.util.js +8 -5
  194. package/dist/utility/wrun/wrun-param-values.util.d.ts +10 -2
  195. package/dist/utility/wrun/wrun-param-values.util.js +2 -0
  196. package/dist/utility/wrun/wrun-pin-spelling.util.js +19 -10
  197. package/dist/utility/wrun/wrun-prefix-lanes.util.js +2 -2
  198. package/dist/utility/wrun/wrun-refusal.util.js +17 -2
  199. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +20 -0
  200. package/dist/utility/wrun/wrun-script-inputs.util.js +43 -0
  201. package/dist/utility/wrun/wrun-source-rows.util.d.ts +4 -0
  202. package/dist/utility/wrun/wrun-source-rows.util.js +92 -40
  203. package/dist/utility/wrun/wrun-tape-source.util.d.ts +133 -48
  204. package/dist/utility/wrun/wrun-tape-source.util.js +205 -62
  205. package/dist/utility/wrun/wrun-volume-profile-lane.util.d.ts +7 -5
  206. package/dist/utility/wrun/wrun-volume-profile-lane.util.js +8 -6
  207. package/dist/workers/utils/volume-profile.worker.util.d.ts +4 -1
  208. package/dist/workers/utils/volume-profile.worker.util.js +5 -2
  209. package/dist/workers/wrun/wrun-abi-host.js +3 -2
  210. package/package.json +11 -11
@@ -0,0 +1,88 @@
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;
12
+ /**
13
+ * The patch that moves a record (`settings`: its `scriptInputs` rows and each value flat under its row's name) to a
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.
51
+ */
52
+ export declare function wrunDollarCarryPatch(settings: unknown, pending: readonly WrunPendingDollarCarry[], stored: WrunMarketSizeStoredUnit | undefined, sizeUnit: number | undefined): Record<string, unknown> | undefined;
53
+ /** The chart market the run computes for, as the head reads it. */
54
+ interface WrunMarketSizeChart {
55
+ exchange?: unknown;
56
+ symbol?: unknown;
57
+ interval?: unknown;
58
+ transformations?: unknown;
59
+ normalizedSymbol?: unknown;
60
+ category?: unknown;
61
+ resolvedContract?: unknown;
62
+ }
63
+ /**
64
+ * Move an overlay's record to its chart market's scaled defaults (above), at the head of a full run, before the
65
+ * lanes read the settings. Resolves once the engine copy reads the defaults (the persist is the routing's own); a
66
+ * package that scales nothing returns at once, and nothing here ever throws over the run.
67
+ *
68
+ * Every fact is proven the keyed market's before it is kept or written: `market` is the market the run computes for
69
+ * (C4: the chart's market identity at the run head, `wrunChartMarketIdentity`, and the reader of the chart's metadata
70
+ * now), and `isCurrent` says the run is still the overlay's own (its chart and mount stand). After each await, in the
71
+ * task that keeps and writes, the chart still names that market (a switch during the directory's answer moves it, and
72
+ * neither the mount nor the refusal attempt sees a switch), and the verdict that reads the candles reads them only
73
+ * while they were loaded for it (`loadedMainIdentityOf`: the symbol pipeline stamps the new market's metadata before
74
+ * its rows replace the old market's). A fact it cannot prove reads as a transient skip: no memo, no write.
75
+ */
76
+ export declare function reconcileWrunMarketSizeDefaults(args: {
77
+ chartIndex: number;
78
+ indicatorId: string;
79
+ tc: unknown;
80
+ meta: Record<string, unknown>;
81
+ sheet: WrunIndicatorMetadata;
82
+ market: {
83
+ identity: string;
84
+ read: () => WrunMarketSizeChart | null | undefined;
85
+ };
86
+ isCurrent: () => boolean;
87
+ }): Promise<void>;
88
+ export {};
@@ -0,0 +1,471 @@
1
+ /**
2
+ * The run head's market-scaled size defaults (the rules and the table: wrun-market-size-defaults.leaf). A package that
3
+ * scales a param (Big Trades' Min value and Whale value, 0.5.0's Min size and Whale size) has its record moved to the
4
+ * chart market's defaults at the head of every full run, before the tape is resolved, so the run, the settings panel's
5
+ * value, the reset icon and its target, and the alert arm all read the one record:
6
+ *
7
+ * - The rules are the family the sheet declares (`wrunMarketScaledRulesOfSheet`: 0.6.0's dollar rule, 0.5.0's coin
8
+ * rule). The market's defaults are resolved once per mount, market and family (a page session's switch back to a
9
+ * market reads what it read there the first time), so a value never flaps inside a session: the chart's own candles
10
+ * give the daily volume, in dollars through the market's dollar unit (`wrunMarketDollarUnit`, the market facts, never
11
+ * a venue list) or in base coins on a coin market whose candles are in base coins (the directory row places the coin
12
+ * and names the quote, so a cold page waits for it once); a market whose facts never yield one (no point value, a
13
+ * quote that is no dollar, a formula chart keyed apart from its market; for the coin rule contracts, shares, candles
14
+ * in another unit) reads the package's declared defaults, so the record never keeps the last market's; a fact not
15
+ * known yet or too few candles resolves nothing (the record stays, the next run asks again).
16
+ * - A row moves while the user never changed it (the value reads as the row's default, the settings panel's reset
17
+ * test, `wrunRowValuesEqual` over `wrunRowValue`): its value and its `defaultValue` together. A changed value keeps
18
+ * both, so it reads as changed on every market after it; its reset goes to the default of the market where it was
19
+ * changed, and the run head of the save the reset is moves the now unchanged value to this market's.
20
+ * - The carry (C-DOLLAR's saved values): a raw-unit value the user changed on 0.5.0 (Min size, Whale size) rides the
21
+ * record under its old name after the pin move (wrun-twin-pin-move.util WRUN_PIN_CARRY_DOLLAR_CONVERSIONS), and the
22
+ * first head that proves what one STORED unit is worth there prices it once into the dollar param that took its
23
+ * place (raw stored units x the dollars per stored unit, the large-print writer's own price of one off the market's
24
+ * newest TRADE_LARGE print: wrun-chart-market-facts.util `wrunMarketStoredUnitDollars`; held to 3 significant
25
+ * figures, `wrunCarriedDollarValue`). The dollar row marks the carried value (`carriedValue`), so it counts as
26
+ * changed on this market and every one after it, even where it equals the row's default
27
+ * (`wrunMarketScaledRowChanged`), and a carry is pending only while its dollar row holds no mark, so it prices once.
28
+ * On a market that counts contracts (the CME family, `wrunCarryKeepsRawValue`) the old name stays stored, the
29
+ * contract count the version that floors CME in contracts restores exactly; everywhere else it is cleared. A market
30
+ * whose stored unit can never be proven writes no value (the market's dollar default applies) and drops the carry,
31
+ * the ring naming the market (`wrun-market-size-carry-dropped`), except on a market that counts contracts, where the
32
+ * raw value stays under its old name (`wrun-market-size-carry-kept`); one a read can still prove keeps it under its
33
+ * old name for the next run.
34
+ * - The engine copy takes the patch (titan merges it at once, so the run reads it) and the workspace row its own, with
35
+ * one reconcile persist (no gesture, no undo entry), the delivered sheet's reconcile's pattern
36
+ * (wrun-overlay-run.util `reconcileWrunSourceRecord`, which keeps the moved defaults when it rebuilds the rows).
37
+ * - The option family (r11, Big Trades 0.7.0's Size shown as, `contracts-option`): split off the volume rules
38
+ * (`wrunMarketScaledFamilies`) and resolved in the same warm block with its own verdict
39
+ * (`wrunMarketOptionVerdict`, no candles read) and its own memo key (`<market>#options`), so a volume rule that
40
+ * waits on its candles never holds the option back, nor the option the volume rules. Its select row moves while
41
+ * untouched like a number row (value and default together, in the row's own spelling), and the two families'
42
+ * defaults merge into one move patch.
43
+ * - The contracts carry (BT-CME, wrun-market-size-contract-carry.leaf, by param name): on a market that counts
44
+ * contracts, a 0.5.x count still the user's latest word (the dollar row unmarked, or still at its carried mark: S0
45
+ * kept the old name there) moves to Min size or Whale size exactly; else a changed dollar value (0.6.x or 0.7.x, a
46
+ * carried one included) counts `ceil(value / dollars per contract)` at the stored-unit price; the contracts row is
47
+ * marked, the old name cleared, the dollar row back to untouched (the market's dollar default then moves it). It runs
48
+ * before the dollar carry and takes its own raw names, so the dollar carry never prices them; ring
49
+ * `wrun-market-size-contract-carry`. The contracts params themselves follow no market (the package's flat 10 and
50
+ * 100 contracts, Kyle 2026-10-23): no rule of the table names them.
51
+ *
52
+ * Advisory: it never fails the run.
53
+ */
54
+ import { wrunChartHostEnv } from '../../host-env.js';
55
+ import { candleVolumeIsBaseCoins } from '../chart/candle-volume-unit.leaf.js';
56
+ import { normalizeTransformations, selfTransformationToken } from '../common/transformations.util.js';
57
+ import { wrunChartIntervalMsOf } from './wrun-chart-context.util.js';
58
+ import { warmWrunMarketDollarFacts, warmWrunMarketStoredUnit, wrunChartSizeUnit, wrunMarketDollarUnit, wrunMarketStoredUnitDollars, } from './wrun-chart-market-facts.util.js';
59
+ import { isWrunMarketScaledRow, wrunCarriedDollarValue, wrunCarryKeepsRawValue, wrunMarketDefaultWithinRow, wrunMarketOptionVerdict, wrunMarketScaledFamilies, wrunMarketScaledParamsOf, wrunMarketScaledRulesOfSheet, wrunMarketSizeVerdict, } from './wrun-market-size-defaults.leaf.js';
60
+ import { WRUN_CONTRACT_CARRY_PENDING, wrunContractCarryPatch, wrunContractCarrySettles, wrunPendingContractCarries, } from './wrun-market-size-contract-carry.leaf.js';
61
+ import { wrunChartMarketIdentity } from './wrun-overlay-drivers.util.js';
62
+ import { wrunRegistryRefOf } from './wrun-overlay-identity.util.js';
63
+ import { wrunRowValue, wrunRowValuesEqual, wrunValuesEqual, } from './wrun-script-inputs.util.js';
64
+ import { wrunChartCandleRows } from './wrun-source-rows.util.js';
65
+ function isRecord(value) {
66
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
67
+ }
68
+ /** A record with a patch merged over it (a carry's), the record itself as an object when there is none. */
69
+ function withPatch(settings, patch) {
70
+ return { ...(isRecord(settings) ? settings : {}), ...(patch ?? {}) };
71
+ }
72
+ /**
73
+ * Whether a market-scaled row holds a value the user chose (the market defaults never move it): a value off its row's
74
+ * default (the settings panel's reset test, `wrunRowValuesEqual` over `wrunRowValue`), or the value a carry priced into
75
+ * it (`carriedValue`, C-DOLLAR), which counts as chosen even where it equals the row's default: a 0.5.0 Min size of
76
+ * 5,000 Binance delivery contracts of $100 carries $500,000, the sheet's default, and must not follow the next market's
77
+ * default. Pure.
78
+ */
79
+ export function wrunMarketScaledRowChanged(record, row) {
80
+ const value = wrunRowValue(record, row);
81
+ if (!wrunRowValuesEqual(row, value, row.defaultValue))
82
+ return true;
83
+ return typeof row.carriedValue === 'number' && wrunRowValuesEqual(row, value, row.carriedValue);
84
+ }
85
+ /**
86
+ * The patch that moves a record (`settings`: its `scriptInputs` rows and each value flat under its row's name) to a
87
+ * market's `defaults`: every scaled row whose value the user never chose (`wrunMarketScaledRowChanged`) takes the
88
+ * market's default (held to the row's bounds, a select's as the option it names), value and `defaultValue` together.
89
+ * `rules` are the rules the defaults were read by: a select row moves under an option rule only (without them, number
90
+ * rows only, the volume families' kind). A changed value keeps both: the
91
+ * changed mark is the value against its own row's default, so a default moved under a kept value would read the value
92
+ * as never changed on the first market whose default equals it, and the next market would move it (SOL 200, then ETH
93
+ * whose default is 200, then SOL reset it to 1000). Its reset goes to the default of the market where the user changed
94
+ * it, a save whose run head then moves the unchanged value on. A carried value (`carriedValue`) is a changed one too,
95
+ * whatever its row's default. Undefined when the record already reads the defaults. Pure.
96
+ */
97
+ export function wrunMarketSizeSettingsPatch(settings, defaults, rules) {
98
+ const record = isRecord(settings) ? settings : {};
99
+ if (!Array.isArray(record.scriptInputs))
100
+ return undefined;
101
+ const patch = {};
102
+ let rowsMoved = false;
103
+ const scriptInputs = record.scriptInputs.map((held) => {
104
+ if (!isRecord(held) || typeof held.name !== 'string' || !Object.hasOwn(defaults, held.name))
105
+ return held;
106
+ const row = held;
107
+ if (!isWrunMarketScaledRow(row, rules?.[row.name]))
108
+ return held;
109
+ const target = wrunMarketDefaultWithinRow(row, defaults[row.name]);
110
+ if (target === undefined)
111
+ return held;
112
+ if (wrunMarketScaledRowChanged(record, row))
113
+ return held;
114
+ if (!wrunValuesEqual(record[row.name], target))
115
+ patch[row.name] = target;
116
+ if (wrunValuesEqual(row.defaultValue, target))
117
+ return held;
118
+ rowsMoved = true;
119
+ return { ...row, defaultValue: target };
120
+ });
121
+ if (rowsMoved)
122
+ patch.scriptInputs = scriptInputs;
123
+ return Object.keys(patch).length > 0 ? patch : undefined;
124
+ }
125
+ /** Whether a record's dollar row `name` holds a carried mark (`carriedValue`: a carry already priced into it). */
126
+ function wrunRowHoldsCarriedMark(record, name) {
127
+ const rows = Array.isArray(record.scriptInputs) ? record.scriptInputs : [];
128
+ return rows.some((row) => isRecord(row) && row.name === name && typeof row.carriedValue === 'number' && Number.isFinite(row.carriedValue));
129
+ }
130
+ /** The carries a record holds for the scaled rules its sheet declares: a rule's `carriesFrom` name held flat on the
131
+ * record with a finite positive value while the sheet no longer declares it (the pin move left it there), and while
132
+ * the dollar row holds no carried mark: a carry prices once, so a raw value kept under its old name (a market that
133
+ * counts contracts, `wrunCarryKeepsRawValue`) never prices again, after a reload, a market switch or a reset alike
134
+ * (a reset writes values, never the rows, so the mark stays). */
135
+ export function wrunPendingDollarCarries(settings, rules, sheetParams) {
136
+ const record = isRecord(settings) ? settings : {};
137
+ const pending = [];
138
+ for (const [to, rule] of Object.entries(rules)) {
139
+ if (rule.kind === 'daily-volume' || rule.carriesFrom === undefined)
140
+ continue;
141
+ const from = rule.carriesFrom;
142
+ if (sheetParams.has(from) || !Object.hasOwn(record, from) || wrunRowHoldsCarriedMark(record, to))
143
+ continue;
144
+ const raw = record[from];
145
+ if (typeof raw === 'number' && Number.isFinite(raw) && raw > 0)
146
+ pending.push({ to, from, raw });
147
+ }
148
+ return pending;
149
+ }
150
+ /**
151
+ * The patch that prices a record's pending carries once (C-DOLLAR's saved values): each carry's raw value in STORED
152
+ * units x the dollars one stored unit is worth at the market's price (`stored`, wrun-chart-market-facts.util
153
+ * `wrunMarketStoredUnitDollars`), held to 3 significant figures (`wrunCarriedDollarValue`) and to the dollar row's
154
+ * bounds, written flat under the dollar param, and the dollar row marked with it (`carriedValue`: a changed value
155
+ * whatever its row's default, `wrunMarketScaledRowChanged`; its row's default stays). The old name is cleared, except
156
+ * on a market that counts contracts (`sizeUnit`, `wrunCarryKeepsRawValue`), where it stays stored: the version that
157
+ * floors such a market in contracts restores the count exactly, and the mark keeps it from pricing twice (so a carry
158
+ * that keeps its old name and finds no dollar row to mark writes nothing yet). A stored unit that can never be proven
159
+ * (`unproven`, not transient: no large print of the market in the table's week, a quote that is no dollar, a CME
160
+ * contract with no point value) writes no value (the market's dollar default applies) and clears the old name, except
161
+ * on a market that counts contracts; a transient one writes nothing (the next run asks again). `sizeUnit` is required
162
+ * of every caller (undefined where the market's is not known: the old name is cleared), so the engine copy and the
163
+ * workspace row are always carried by one rule. Undefined when nothing moves. Pure.
164
+ */
165
+ export function wrunDollarCarryPatch(settings, pending, stored, sizeUnit) {
166
+ if (pending.length === 0 || stored === undefined)
167
+ return undefined;
168
+ const record = isRecord(settings) ? settings : {};
169
+ const rows = Array.isArray(record.scriptInputs) ? record.scriptInputs : [];
170
+ const keepsRawValue = wrunCarryKeepsRawValue(sizeUnit);
171
+ const patch = {};
172
+ const carried = new Map();
173
+ for (const carry of pending) {
174
+ if (stored.kind === 'unproven') {
175
+ if (!stored.transient && !keepsRawValue)
176
+ patch[carry.from] = undefined;
177
+ continue;
178
+ }
179
+ const priced = wrunCarriedDollarValue(carry.raw, stored.perUnit);
180
+ if (priced === undefined)
181
+ continue;
182
+ const row = rows.find((candidate) => isRecord(candidate) && candidate.name === carry.to);
183
+ // A kept raw value prices once only under its row's mark: no row to mark, no carry yet.
184
+ if (row === undefined && keepsRawValue)
185
+ continue;
186
+ const value = row === undefined ? priced : wrunMarketDefaultWithinRow(row, priced);
187
+ // A dollar row holds a number (a sheet that retyped it carries nothing).
188
+ if (typeof value !== 'number')
189
+ continue;
190
+ patch[carry.to] = value;
191
+ if (!keepsRawValue)
192
+ patch[carry.from] = undefined;
193
+ carried.set(carry.to, value);
194
+ }
195
+ if (carried.size > 0 && rows.length > 0) {
196
+ patch.scriptInputs = rows.map((row) => isRecord(row) && typeof row.name === 'string' && carried.has(row.name)
197
+ ? { ...row, carriedValue: carried.get(row.name) }
198
+ : row);
199
+ }
200
+ return Object.keys(patch).length > 0 ? patch : undefined;
201
+ }
202
+ /** Each mount's resolved defaults, by market (`exchange|symbol`, and a formula chart's formula after it: its candles
203
+ * are no market's, so it reads the package's defaults where its market reads its own) and the scaled params the sheet
204
+ * declares (a version that moves families reads its own): the engine meta is the mount. */
205
+ const wrunMarketSizeDefaultsByMount = new WeakMap();
206
+ /** The scaled params' defaults a sheet declares (the package's own: a `package` verdict's). */
207
+ function wrunDeclaredDefaults(sheet, names) {
208
+ const wanted = new Set(names);
209
+ const defaults = {};
210
+ for (const param of sheet.params ?? []) {
211
+ if (wanted.has(param.name) && typeof param.default === 'number' && Number.isFinite(param.default)) {
212
+ defaults[param.name] = param.default;
213
+ }
214
+ }
215
+ return defaults;
216
+ }
217
+ const WRUN_MARKET_SIZE_UNPROVEN = Object.freeze({ kind: 'skip', reason: 'unproven' });
218
+ /** The facts of a head that could not prove its reads the keyed market's: every declared family skips, nothing to
219
+ * price a carry with. */
220
+ function wrunMarketSizeUnprovenFacts(families) {
221
+ return {
222
+ ...(families.volume !== undefined ? { verdict: WRUN_MARKET_SIZE_UNPROVEN } : {}),
223
+ ...(families.options !== undefined ? { optionVerdict: WRUN_MARKET_SIZE_UNPROVEN } : {}),
224
+ };
225
+ }
226
+ /**
227
+ * Move an overlay's record to its chart market's scaled defaults (above), at the head of a full run, before the
228
+ * lanes read the settings. Resolves once the engine copy reads the defaults (the persist is the routing's own); a
229
+ * package that scales nothing returns at once, and nothing here ever throws over the run.
230
+ *
231
+ * Every fact is proven the keyed market's before it is kept or written: `market` is the market the run computes for
232
+ * (C4: the chart's market identity at the run head, `wrunChartMarketIdentity`, and the reader of the chart's metadata
233
+ * now), and `isCurrent` says the run is still the overlay's own (its chart and mount stand). After each await, in the
234
+ * task that keeps and writes, the chart still names that market (a switch during the directory's answer moves it, and
235
+ * neither the mount nor the refusal attempt sees a switch), and the verdict that reads the candles reads them only
236
+ * while they were loaded for it (`loadedMainIdentityOf`: the symbol pipeline stamps the new market's metadata before
237
+ * its rows replace the old market's). A fact it cannot prove reads as a transient skip: no memo, no write.
238
+ */
239
+ export async function reconcileWrunMarketSizeDefaults(args) {
240
+ const { chartIndex, indicatorId, tc, meta, sheet, market, isCurrent } = args;
241
+ const sheetParams = new Set((sheet.params ?? []).map((param) => param.name));
242
+ const packageName = wrunRegistryRefOf(meta.settings)?.package;
243
+ const rules = wrunMarketScaledRulesOfSheet(wrunMarketScaledParamsOf(packageName), sheetParams);
244
+ if (rules === undefined)
245
+ return;
246
+ // The volume rules and the option rules resolve apart: each its own verdict, memo key and ring line.
247
+ const families = wrunMarketScaledFamilies(rules);
248
+ const keyed = () => isCurrent() && wrunChartMarketIdentity(market.read()) === market.identity;
249
+ try {
250
+ if (!keyed())
251
+ return;
252
+ const chartMetadata = market.read() ?? undefined;
253
+ const exchange = typeof chartMetadata?.exchange === 'string' ? chartMetadata.exchange : '';
254
+ const symbol = typeof chartMetadata?.symbol === 'string' ? chartMetadata.symbol : '';
255
+ if (exchange === '' || symbol === '')
256
+ return;
257
+ const transformations = typeof chartMetadata?.transformations === 'string' ? chartMetadata.transformations : '';
258
+ const formula = wrunChartFormulaOf(exchange, symbol, transformations);
259
+ const family = families.volume === undefined ? undefined : Object.keys(families.volume).sort().join(',');
260
+ const marketKey = formula === undefined ? `${exchange}|${symbol}` : `${exchange}|${symbol}|${formula}`;
261
+ const volumeKey = family === undefined ? undefined : `${marketKey}#${family}`;
262
+ const optionKey = families.options === undefined ? undefined : `${marketKey}#options`;
263
+ let resolved = wrunMarketSizeDefaultsByMount.get(meta);
264
+ let volumeDefaults = volumeKey === undefined ? undefined : resolved?.get(volumeKey);
265
+ let optionDefaults = optionKey === undefined ? undefined : resolved?.get(optionKey);
266
+ const volumeOwed = volumeKey !== undefined && volumeDefaults === undefined;
267
+ const optionsOwed = optionKey !== undefined && optionDefaults === undefined;
268
+ // The contracts carry (BT-CME, wrun-market-size-contract-carry.leaf): on a market that counts contracts (its size
269
+ // unit never waits on a read) a saved count or a changed dollar value moves into the contracts params of a sheet
270
+ // declaring them, by name. The raw counts it takes are its own: the dollar carry never prices one of them.
271
+ const chartSizeUnit = wrunChartSizeUnit(chartMetadata);
272
+ const contractPending = wrunPendingContractCarries(meta.settings, packageName, sheetParams, chartSizeUnit);
273
+ const pending = wrunPendingDollarCarries(meta.settings, rules, sheetParams).filter((carry) => !contractPending.some((entry) => entry.raw === carry.from));
274
+ const pricesContracts = contractPending.some((entry) => entry.from === 'dollars');
275
+ let headFacts;
276
+ if (volumeOwed || optionsOwed || pending.length > 0 || contractPending.length > 0) {
277
+ // A crypto market's coin unit and quote are the directory row's (its asset class, its quote), a CME contract's
278
+ // point value the instrument registry's, and only with a raw floor to carry or a dollar value to count in
279
+ // contracts, what one stored unit is worth (the large-print writer's own rows): each asked once per market for
280
+ // the session, never rejects. The data loading module says whose candles the chart holds; a host that cannot
281
+ // load it proves nothing.
282
+ const [, , dataFetching] = await Promise.all([
283
+ warmWrunMarketDollarFacts(chartMetadata),
284
+ pending.length > 0 || pricesContracts ? warmWrunMarketStoredUnit(chartMetadata) : undefined,
285
+ Promise.resolve()
286
+ .then(() => wrunChartHostEnv().chart.loadDataFetching())
287
+ .catch(() => undefined),
288
+ ]);
289
+ headFacts = keyed()
290
+ ? wrunMarketSizeFactsNow(families, {
291
+ tc,
292
+ chartMetadata: market.read() ?? undefined,
293
+ identity: market.identity,
294
+ loaded: dataFetching?.loadedMainIdentityOf(chartIndex) ?? null,
295
+ ownCandles: formula === undefined,
296
+ exchange,
297
+ symbol,
298
+ })
299
+ : wrunMarketSizeUnprovenFacts(families);
300
+ }
301
+ /** Keep one family's resolution: its ring line, and its defaults unless it skipped (a fact that can still change,
302
+ * or one not proven the keyed market's: nothing kept, nothing moves, the next run asks again). */
303
+ const resolve = (key, verdict, familyRules, event, familyName) => {
304
+ if (wrunChartHostEnv().diagnostics.debugEnabled()) {
305
+ wrunChartHostEnv().diagnostics.debug(event, {
306
+ chartIndex,
307
+ indicatorId,
308
+ market: marketKey,
309
+ family: familyName,
310
+ verdict: verdict.kind,
311
+ ...(verdict.kind !== 'market' ? { reason: verdict.reason } : {}),
312
+ ...(verdict.kind === 'market' ? { defaults: verdict.defaults } : {}),
313
+ });
314
+ }
315
+ if (verdict.kind === 'skip')
316
+ return undefined;
317
+ const kept = verdict.kind === 'market' ? verdict.defaults : wrunDeclaredDefaults(sheet, Object.keys(familyRules ?? {}));
318
+ if (resolved === undefined) {
319
+ resolved = new Map();
320
+ wrunMarketSizeDefaultsByMount.set(meta, resolved);
321
+ }
322
+ resolved.set(key, kept);
323
+ return kept;
324
+ };
325
+ if (volumeOwed && volumeKey !== undefined && family !== undefined && headFacts?.verdict !== undefined) {
326
+ volumeDefaults = resolve(volumeKey, headFacts.verdict, families.volume, 'wrun-market-size-defaults', family);
327
+ }
328
+ if (optionsOwed && optionKey !== undefined && headFacts?.optionVerdict !== undefined) {
329
+ optionDefaults = resolve(optionKey, headFacts.optionVerdict, families.options, 'wrun-market-size-option-defaults', 'options');
330
+ }
331
+ if (!keyed())
332
+ return;
333
+ // The carries first (each value a marked changed one, `carriedValue`, so the move below keeps it): the contracts
334
+ // carry, then the dollar carry over what it left; then the market's defaults, both families' in one patch.
335
+ const storedUnit = headFacts?.storedUnit;
336
+ const sizeUnit = headFacts?.sizeUnit;
337
+ const defaults = volumeDefaults === undefined && optionDefaults === undefined
338
+ ? undefined
339
+ : { ...(volumeDefaults ?? {}), ...(optionDefaults ?? {}) };
340
+ // What one contract is worth: the large-print writer's own price of one stored unit (a CME contract).
341
+ const perContract = storedUnit?.kind === 'dollars' ? storedUnit.perUnit : undefined;
342
+ const contractCarry = wrunContractCarryPatch(meta.settings, contractPending, perContract);
343
+ if (contractCarry !== undefined && wrunChartHostEnv().diagnostics.debugEnabled()) {
344
+ wrunChartHostEnv().diagnostics.debug('wrun-market-size-contract-carry', {
345
+ chartIndex,
346
+ indicatorId,
347
+ market: marketKey,
348
+ carried: contractPending.map((entry) => ({ to: entry.to, from: entry.from })),
349
+ patch: contractCarry,
350
+ });
351
+ }
352
+ // A migration's stamp settles on the version's first head on any market (review of !10790, finding A): cleared
353
+ // beside the carries it ran, so a later switch to a market that counts contracts never converts a dollar value.
354
+ const settled = wrunContractCarrySettles(meta.settings, packageName, sheetParams, chartSizeUnit, contractPending, perContract)
355
+ ? { [WRUN_CONTRACT_CARRY_PENDING]: undefined }
356
+ : undefined;
357
+ if (settled !== undefined && wrunChartHostEnv().diagnostics.debugEnabled()) {
358
+ wrunChartHostEnv().diagnostics.debug('wrun-market-size-contract-carry-settled', {
359
+ chartIndex,
360
+ indicatorId,
361
+ market: marketKey,
362
+ carried: contractCarry !== undefined,
363
+ });
364
+ }
365
+ const carry = wrunDollarCarryPatch(withPatch(meta.settings, contractCarry), pending, storedUnit, sizeUnit);
366
+ const unpriced = pending.length > 0 && storedUnit?.kind === 'unproven' && !storedUnit.transient ? storedUnit : undefined;
367
+ if (wrunChartHostEnv().diagnostics.debugEnabled() && (carry !== undefined || unpriced !== undefined)) {
368
+ // A carry the market can never price is dropped by name (the market's dollar default applies), or kept by name
369
+ // on a market that counts contracts: the ring says which market and why, so a user's Min size is never silent.
370
+ const event = unpriced === undefined
371
+ ? 'wrun-market-size-carry'
372
+ : wrunCarryKeepsRawValue(sizeUnit)
373
+ ? 'wrun-market-size-carry-kept'
374
+ : 'wrun-market-size-carry-dropped';
375
+ wrunChartHostEnv().diagnostics.debug(event, {
376
+ chartIndex,
377
+ indicatorId,
378
+ market: marketKey,
379
+ carried: Object.fromEntries(pending.map((entry) => [entry.from, entry.raw])),
380
+ ...(unpriced !== undefined ? { reason: unpriced.reason } : { patch: carry }),
381
+ });
382
+ }
383
+ const settingsOf = (settings) => ({
384
+ ...withPatch(settings, contractCarry),
385
+ ...(carry ?? {}),
386
+ });
387
+ const movePatch = defaults === undefined ? undefined : wrunMarketSizeSettingsPatch(settingsOf(meta.settings), defaults, rules);
388
+ const enginePatch = settled === undefined && contractCarry === undefined && carry === undefined && movePatch === undefined
389
+ ? undefined
390
+ : { ...(settled ?? {}), ...(contractCarry ?? {}), ...(carry ?? {}), ...(movePatch ?? {}) };
391
+ if (enginePatch === undefined)
392
+ return;
393
+ const chart = tc;
394
+ if (typeof chart?.updateSettings === 'function')
395
+ chart.updateSettings(indicatorId, enginePatch);
396
+ else
397
+ meta.settings = { ...(isRecord(meta.settings) ? meta.settings : {}), ...enginePatch };
398
+ const { persistChart, resolveChart } = await wrunChartHostEnv().chart.loadChartRouting();
399
+ if (!keyed())
400
+ return;
401
+ const document = resolveChart(chartIndex);
402
+ const row = [...(document?.onchart ?? []), ...(document?.offchart ?? [])].find((candidate) => candidate?.id === indicatorId);
403
+ if (row === undefined)
404
+ return;
405
+ const rowContractCarry = contractCarry === undefined ? undefined : wrunContractCarryPatch(row.settings, contractPending, perContract);
406
+ const rowCarry = carry === undefined
407
+ ? undefined
408
+ : wrunDollarCarryPatch(withPatch(row.settings, rowContractCarry), pending, storedUnit, sizeUnit);
409
+ const rowSettings = { ...withPatch(row.settings, rowContractCarry), ...(rowCarry ?? {}) };
410
+ const rowMove = defaults === undefined ? undefined : wrunMarketSizeSettingsPatch(rowSettings, defaults, rules);
411
+ if (settled === undefined && rowContractCarry === undefined && rowCarry === undefined && rowMove === undefined) {
412
+ return;
413
+ }
414
+ row.settings = { ...rowSettings, ...(rowMove ?? {}), ...(settled ?? {}) };
415
+ persistChart(chartIndex, 'reconcile');
416
+ }
417
+ catch (error) {
418
+ console.warn(`[wrun] the market size defaults of '${indicatorId}' were not applied:`, error);
419
+ }
420
+ }
421
+ /** The formula a chart's candles are computed from (normalized), or undefined for a chart of the market's own candles
422
+ * (no transformations, or the market's own token). */
423
+ function wrunChartFormulaOf(exchange, symbol, transformations) {
424
+ const formula = normalizeTransformations(transformations);
425
+ return formula === '' || formula === normalizeTransformations(selfTransformationToken(exchange, symbol))
426
+ ? undefined
427
+ : formula;
428
+ }
429
+ /**
430
+ * The facts of the keyed market, read in the caller's task once the chart is proven on that market: the size unit once
431
+ * the directory placed it, the venue's candle volume unit (`ownCandles`: a formula chart's candles are no market's),
432
+ * the market's dollar unit (the market facts, `wrunMarketDollarUnit`), and the chart's own candles while they were
433
+ * loaded for the keyed market (`loaded`, the loaded-main identity, names its `identity`). Candles loaded for another
434
+ * market are never read: the volume verdict that would read them reads `unproven` (the candles not yet the market's
435
+ * own, never its own too few), and no carry prices with them. The option verdict reads no candles, so it stands then.
436
+ */
437
+ function wrunMarketSizeFactsNow(families, facts) {
438
+ const rowsOwn = facts.loaded !== null && wrunChartMarketIdentity(facts.loaded) === facts.identity;
439
+ const rows = rowsOwn && families.volume !== undefined
440
+ ? wrunChartCandleRows(facts.tc)
441
+ : [];
442
+ // A formula chart's candles are no market's: its dollar volume is no market's either, so the dollar rule reads the
443
+ // package's defaults there (`candle-unit`, as the coin rule does), and a pending carry waits for a run on the
444
+ // market's own candles (a formula's close is no price of the market's prints).
445
+ const dollarUnit = facts.ownCandles
446
+ ? wrunMarketDollarUnit(facts.chartMetadata)
447
+ : { kind: 'unproven', reason: 'quote', transient: true };
448
+ const sizeFacts = {
449
+ sizeUnit: wrunChartSizeUnit(facts.chartMetadata),
450
+ candleVolumeInCoins: facts.ownCandles && candleVolumeIsBaseCoins(facts.exchange, facts.symbol),
451
+ ...(facts.ownCandles ? { dollarUnit } : {}),
452
+ rows,
453
+ intervalMs: wrunChartIntervalMsOf(facts.chartMetadata?.interval),
454
+ };
455
+ const optionVerdict = families.options === undefined ? undefined : wrunMarketOptionVerdict(families.options, sizeFacts);
456
+ const options = optionVerdict === undefined ? {} : { optionVerdict };
457
+ if (families.volume === undefined)
458
+ return options;
459
+ const verdict = wrunMarketSizeVerdict(families.volume, sizeFacts);
460
+ // Only the verdict that reads the candles meets the rows held back, and no rows read as too few candles.
461
+ if (!rowsOwn && verdict.kind === 'skip' && verdict.reason === 'cover') {
462
+ return { verdict: WRUN_MARKET_SIZE_UNPROVEN, ...options };
463
+ }
464
+ // What a carried raw floor's stored unit is worth here: the large-print writer's own price of one (a formula chart
465
+ // is no market's: its carry waits for a run on the market's own chart), and the size unit that says whether the
466
+ // carry keeps the raw value under its old name.
467
+ const storedUnit = facts.ownCandles
468
+ ? wrunMarketStoredUnitDollars(facts.chartMetadata)
469
+ : { kind: 'unproven', reason: 'quote', transient: true };
470
+ return { verdict, ...options, storedUnit, sizeUnit: sizeFacts.sizeUnit };
471
+ }