@orangecharts/wrun-chart-host 0.7.1 → 0.8.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 (124) hide show
  1. package/README.md +25 -3
  2. package/dist/constants/feature-flags.constants.d.ts +1 -0
  3. package/dist/constants/feature-flags.constants.js +5 -0
  4. package/dist/constants/option-venues.constants.d.ts +18 -0
  5. package/dist/constants/option-venues.constants.js +14 -0
  6. package/dist/constants/venue-presets.constants.d.ts +17 -3
  7. package/dist/constants/venue-presets.constants.js +17 -3
  8. package/dist/host-env.d.ts +24 -0
  9. package/dist/host-env.js +21 -0
  10. package/dist/host-ports.types.d.ts +12 -0
  11. package/dist/index.d.ts +16 -0
  12. package/dist/index.js +16 -0
  13. package/dist/indicators/controls/tpo-session.util.d.ts +40 -11
  14. package/dist/indicators/controls/tpo-session.util.js +138 -14
  15. package/dist/interfaces/option-instrument.interface.d.ts +6 -0
  16. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +4 -0
  17. package/dist/kscript-data/controls/live-trades-merge.util.js +4 -0
  18. package/dist/settings-templates/footprint-rows.d.ts +25 -0
  19. package/dist/settings-templates/footprint-rows.js +127 -0
  20. package/dist/settings-templates/form-rows.d.ts +56 -0
  21. package/dist/settings-templates/form-rows.js +19 -0
  22. package/dist/settings-templates/frvp-fields.js +14 -0
  23. package/dist/settings-templates/index.d.ts +10 -1
  24. package/dist/settings-templates/index.js +11 -2
  25. package/dist/settings-templates/indicator-fields.js +78 -0
  26. package/dist/settings-templates/tool-rules.d.ts +35 -9
  27. package/dist/settings-templates/tool-rules.js +42 -8
  28. package/dist/settings-templates/tool-tables.generated.js +13 -2
  29. package/dist/utility/chart/candle-volume-unit.leaf.d.ts +16 -0
  30. package/dist/utility/chart/candle-volume-unit.leaf.js +61 -0
  31. package/dist/utility/chart/footprint-columns.util.d.ts +74 -0
  32. package/dist/utility/chart/footprint-columns.util.js +106 -0
  33. package/dist/utility/chart/footprint-display-mode.util.d.ts +40 -0
  34. package/dist/utility/chart/footprint-display-mode.util.js +62 -0
  35. package/dist/utility/chart/footprint-sierra-look.util.d.ts +2 -0
  36. package/dist/utility/chart/footprint-sierra-look.util.js +37 -0
  37. package/dist/utility/chart/kscript-venue-policy.util.js +4 -2
  38. package/dist/utility/chart/om-panel.util.d.ts +11 -0
  39. package/dist/utility/chart/om-panel.util.js +59 -0
  40. package/dist/utility/chart/window-geometry.leaf.d.ts +23 -1
  41. package/dist/utility/chart/window-geometry.leaf.js +78 -6
  42. package/dist/utility/chart/window-owner.leaf.d.ts +13 -0
  43. package/dist/utility/chart/window-owner.leaf.js +5 -0
  44. package/dist/utility/options/cme-options-root.util.d.ts +25 -0
  45. package/dist/utility/options/cme-options-root.util.js +40 -0
  46. package/dist/utility/options/option-book.util.d.ts +27 -0
  47. package/dist/utility/options/option-book.util.js +76 -0
  48. package/dist/utility/options/option-trade-date.util.d.ts +50 -0
  49. package/dist/utility/options/option-trade-date.util.js +120 -0
  50. package/dist/utility/wrun/sources/host-grid-landing.d.ts +4 -2
  51. package/dist/utility/wrun/sources/host-grid-landing.js +8 -0
  52. package/dist/utility/wrun/sources/lanes/options_flow.d.ts +40 -4
  53. package/dist/utility/wrun/sources/lanes/options_flow.js +115 -18
  54. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +12 -9
  55. package/dist/utility/wrun/sources/opra-option-lanes.util.js +10 -7
  56. package/dist/utility/wrun/sources/row-lane-registry.js +9 -5
  57. package/dist/utility/wrun/sources/row-lanes/index.js +2 -0
  58. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +3 -2
  59. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +30 -5
  60. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +14 -1
  61. package/dist/utility/wrun/sources/row-lanes/option_prints.js +100 -23
  62. package/dist/utility/wrun/sources/row-lanes/option_strike_flow.d.ts +4 -0
  63. package/dist/utility/wrun/sources/row-lanes/option_strike_flow.js +65 -0
  64. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +47 -1
  65. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +71 -2
  66. package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +14 -1
  67. package/dist/utility/wrun/sources/row-lanes/option_surface.js +30 -2
  68. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +7 -1
  69. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +45 -5
  70. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +115 -3
  71. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +10 -0
  72. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +57 -0
  73. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +60 -6
  74. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +160 -23
  75. package/dist/utility/wrun/wrun-cloud-record.leaf.d.ts +27 -0
  76. package/dist/utility/wrun/wrun-cloud-record.leaf.js +71 -0
  77. package/dist/utility/wrun/wrun-cloud-record.util.d.ts +4 -21
  78. package/dist/utility/wrun/wrun-cloud-record.util.js +5 -65
  79. package/dist/utility/wrun/wrun-color-settings.util.d.ts +7 -5
  80. package/dist/utility/wrun/wrun-color-settings.util.js +26 -11
  81. package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +4 -2
  82. package/dist/utility/wrun/wrun-draft-overlay.util.js +40 -3
  83. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +1 -1
  84. package/dist/utility/wrun/wrun-hosted-wire-caps.js +4 -0
  85. package/dist/utility/wrun/wrun-lane-refusal.leaf.d.ts +29 -3
  86. package/dist/utility/wrun/wrun-lane-refusal.leaf.js +33 -3
  87. package/dist/utility/wrun/wrun-live-tick.util.d.ts +4 -1
  88. package/dist/utility/wrun/wrun-live-tick.util.js +39 -6
  89. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +106 -0
  90. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +159 -0
  91. package/dist/utility/wrun/wrun-market-size-defaults.util.d.ts +44 -0
  92. package/dist/utility/wrun/wrun-market-size-defaults.util.js +213 -0
  93. package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +43 -8
  94. package/dist/utility/wrun/wrun-opra-flow.leaf.js +37 -6
  95. package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +51 -10
  96. package/dist/utility/wrun/wrun-option-contract-flow.util.js +85 -33
  97. package/dist/utility/wrun/wrun-option-prints.util.d.ts +133 -3
  98. package/dist/utility/wrun/wrun-option-prints.util.js +318 -8
  99. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +96 -0
  100. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +215 -0
  101. package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +342 -0
  102. package/dist/utility/wrun/wrun-option-strike-flow.util.js +742 -0
  103. package/dist/utility/wrun/wrun-option-views.util.d.ts +183 -3
  104. package/dist/utility/wrun/wrun-option-views.util.js +504 -7
  105. package/dist/utility/wrun/wrun-options-chain.util.d.ts +6 -4
  106. package/dist/utility/wrun/wrun-options-chain.util.js +8 -5
  107. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +2 -1
  108. package/dist/utility/wrun/wrun-overlay-recovery.util.js +7 -2
  109. package/dist/utility/wrun/wrun-overlay-run.util.js +120 -18
  110. package/dist/utility/wrun/wrun-pack-widths.leaf.d.ts +15 -0
  111. package/dist/utility/wrun/wrun-pack-widths.leaf.js +22 -0
  112. package/dist/utility/wrun/wrun-pack.util.d.ts +9 -8
  113. package/dist/utility/wrun/wrun-pack.util.js +21 -15
  114. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +4 -0
  115. package/dist/utility/wrun/wrun-panel-mount.util.js +62 -22
  116. package/dist/utility/wrun/wrun-panel-style.util.d.ts +17 -2
  117. package/dist/utility/wrun/wrun-panel-style.util.js +47 -9
  118. package/dist/utility/wrun/wrun-pin-spelling.util.js +19 -10
  119. package/dist/utility/wrun/wrun-refusal.util.js +7 -1
  120. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +13 -0
  121. package/dist/utility/wrun/wrun-script-inputs.util.js +43 -0
  122. package/dist/utility/wrun/wrun-tape-source.util.d.ts +9 -0
  123. package/dist/utility/wrun/wrun-tape-source.util.js +18 -0
  124. package/package.json +3 -3
@@ -166,9 +166,30 @@ export const WRUN_KSCRIPT_SOURCE_CLASSES = Object.freeze({
166
166
  // until the identity reaches the chart (wrun-browser-sources.leaf WRUN_BROWSER_REFUSED_CLASS_CODES).
167
167
  option_prints_v2: { type: null, payload: ['chain_venue', 'book'] },
168
168
  // The per-contract flow of the chart's chain (sources/row-lanes/option_contract_flow, a chain lane): one read per
169
- // chart market, venue word and book at the bars' tier; only `0dte` narrows it (nearest expiries, the strike window
170
- // and the volume floor fold on the chart).
171
- option_contract_flow: { type: null, payload: ['market', 'expiries', 'chain_venue', 'book'] },
169
+ // chart market, venue word and book at the bars' tier; `0dte`, the span, the history and the premium floor narrow it
170
+ // (the nearest expiries, the strike window and the volume floor fold on the chart).
171
+ option_contract_flow: {
172
+ type: null,
173
+ payload: ['market', 'expiries', 'chain_venue', 'book', 'span', 'flow_history', 'min_premium'],
174
+ },
175
+ // The flow by strike and expiry of the chart's chain (OPTLOAD G3): every knob value is a read of its own.
176
+ option_strike_flow: {
177
+ type: null,
178
+ payload: [
179
+ 'market',
180
+ 'chain_venue',
181
+ 'book',
182
+ 'group',
183
+ 'flow_expiries',
184
+ 'strike_window_pct',
185
+ 'strike_rows',
186
+ 'split_dte',
187
+ 'fold_types',
188
+ 'span',
189
+ 'flow_history',
190
+ 'min_volume',
191
+ ],
192
+ },
172
193
  series: { type: null, payload: ['ref'] },
173
194
  // The flow scope rows of the chart's chain (sources/lanes/options_flow, a chain lane read by `auto`, its `venue` a
174
195
  // scope's venue): one fetch per scope, dte, moneyness, venue and a ticker's book.
@@ -300,6 +321,22 @@ function payloadEntry(key, entry) {
300
321
  return ['currency', entry.currency === 'USD' ? 'USD' : 'Coin'];
301
322
  case 'ticks_per_bar':
302
323
  return ['ticks_per_bar', streamTicksPerBar(entry.ticks_per_bar)];
324
+ case 'flow_expiries':
325
+ return ['expiries', knobWord(entry.expiries) ?? 'all'];
326
+ case 'strike_window_pct':
327
+ case 'strike_rows':
328
+ case 'min_volume':
329
+ case 'min_premium': {
330
+ const value = entry[key];
331
+ return [key, typeof value === 'number' ? value : (knobWord(value) ?? null)];
332
+ }
333
+ case 'split_dte':
334
+ case 'fold_types':
335
+ return [key, entry[key] === true];
336
+ case 'span':
337
+ return ['span', knobWord(entry.span) ?? 'bar'];
338
+ case 'flow_history':
339
+ return ['history', knobWord(entry.history) ?? 'window'];
303
340
  default:
304
341
  return [key, knobWord(entry[key]) ?? null];
305
342
  }
@@ -341,7 +341,7 @@ export declare function wrunFrameRefusalMemory(text: string): 'window' | 'identi
341
341
  */
342
342
  export declare const WRUN_KIT_REFUSAL_STAGES: {
343
343
  readonly validate: readonly ["wrun_abi_unsupported", "wrun_pin_venue_unknown", "wrun_sheet_over_cap", "wrun_abi_channel_missing", "wrun_intrabar_interval_required", "wrun_intrabar_primary", "wrun_candles_interval_required", "wrun_candles_primary", "wrun_options_chain_venue", "wrun_options_chain_expiries", "wrun_options_chain_market_pinned", "wrun_offset_needs_view", "wrun_offset_count_required", "wrun_bars_needs_leg", "wrun_chart_interval_below_needs_candles", "wrun_chart_interval_below_primary", "wrun_chart_interval_below_forming", "wrun_pin_venue_refused", "wrun_pin_symbol_literal", "wrun_tape_history_unavailable", "wrun_strategy_feed_not_ohlcv", "wrun_strategy_slippage_model_unsupported", "wrun_strategy_reserved_output", "wrun_tape_min_size_invalid", "wrun_option_knob_invalid", "wrun_option_market_pinned", "wrun_option_prints_min_premium_required", "wrun_options_flow_venue_field", "wrun_options_flow_venue_required", "wrun_options_flow_venue_scope", "wrun_oi_candles_interval_required", "wrun_oi_candles_primary", "wrun_volume_profile_candles_interval_required", "wrun_volume_profile_candles_primary"];
344
- readonly plan: readonly ["wrun_options_coin_unknown", "wrun_source_unsupported", "wrun_not_in_10m_universe", "wrun_opra_lane_refused", "wrun_opra_official_only", "wrun_option_contract_flow_unsupported", "wrun_option_contract_state_unsupported", "wrun_option_daily_unsupported", "wrun_option_prints_one_acquisition", "wrun_option_prints_unsupported", "wrun_option_prints_v2_unsupported", "wrun_option_stats_10m_unsupported", "wrun_option_surface_unsupported", "wrun_options_flow_unsupported", "wrun_field_unsupported", "wrun_tenor_unsupported", "wrun_view_unsupported", "wrun_family_unsupported", "wrun_displacement_needs_cap", "wrun_options_chain_venue_unavailable", "wrun_options_chain_unavailable", "wrun_options_chain_one_venue", "wrun_lane_input_refused", "wrun_permission_denied", "wrun_coin_leg_unsupported", "wrun_coin_leg_unresolved", "wrun_pin_unsupported", "wrun_custom_interval_unsupported", "wrun_intrabar_leg_off_grid", "wrun_intrabar_ratio_over_cap", "wrun_intrabar_unsupported", "wrun_candles_bars_over_cap", "wrun_candles_ratio_over_cap", "wrun_oi_candles_unsupported", "wrun_volume_profile_candles_unsupported", "wrun_trade_volume_by_size_unsupported", "wrun_view_leg_off_grid", "wrun_view_leg_equal", "wrun_time_facts_unsupported", "wrun_etf_flow_unsupported", "wrun_volatility_index_unsupported", "wrun_long_short_ratio_unsupported", "wrun_options_oi_unsupported", "wrun_options_volume_unsupported", "wrun_ethena_positions_unsupported", "wrun_etf_holdings_unsupported", "wrun_etf_premium_unsupported", "wrun_economic_unsupported", "wrun_treasury_balance_unsupported", "wrun_bitfinex_funding_unsupported", "wrun_strategy_costs_in_sheet", "wrun_window_bars_invalid", "wrun_cells_unavailable", "wrun_tape_unavailable", "wrun_tape_interval_unsupported", "wrun_metric_source_missing_policy", "wrun_series_source_primary", "wrun_series_source_densification", "wrun_metric_pin_coarser_than_primary", "wrun_forming_primary_not_own_candles", "wrun_package_lock_invalid", "wrun_package_lock_missing", "wrun_package_not_installed", "wrun_package_lock_mismatch", "wrun_composition_cycle", "wrun_composition_depth", "wrun_options_chain_unsupported", "wrun_volume_profile_ticks_unsupported", "wrun_celled_metric_unsupported", "wrun_series_source_missing", "wrun_series_source_invalid", "wrun_params_invalid", "wrun_source_bindings_invalid", "wrun_output_displaced", "wrun_pin_unresolvable"];
344
+ readonly plan: readonly ["wrun_options_coin_unknown", "wrun_source_unsupported", "wrun_not_in_10m_universe", "wrun_opra_lane_refused", "wrun_opra_official_only", "wrun_option_contract_flow_unsupported", "wrun_option_contract_state_unsupported", "wrun_option_daily_unsupported", "wrun_option_prints_one_acquisition", "wrun_option_prints_unsupported", "wrun_option_prints_v2_unsupported", "wrun_option_stats_10m_unsupported", "wrun_option_strike_flow_unsupported", "wrun_option_surface_unsupported", "wrun_option_views_unserved", "wrun_options_flow_unsupported", "wrun_field_unsupported", "wrun_tenor_unsupported", "wrun_view_unsupported", "wrun_family_unsupported", "wrun_displacement_needs_cap", "wrun_options_chain_venue_unavailable", "wrun_options_chain_unavailable", "wrun_options_chain_one_venue", "wrun_lane_input_refused", "wrun_permission_denied", "wrun_coin_leg_unsupported", "wrun_coin_leg_unresolved", "wrun_pin_unsupported", "wrun_custom_interval_unsupported", "wrun_intrabar_leg_off_grid", "wrun_intrabar_ratio_over_cap", "wrun_intrabar_unsupported", "wrun_candles_bars_over_cap", "wrun_candles_ratio_over_cap", "wrun_oi_candles_unsupported", "wrun_volume_profile_candles_unsupported", "wrun_trade_volume_by_size_unsupported", "wrun_view_leg_off_grid", "wrun_view_leg_equal", "wrun_time_facts_unsupported", "wrun_etf_flow_unsupported", "wrun_volatility_index_unsupported", "wrun_long_short_ratio_unsupported", "wrun_options_oi_unsupported", "wrun_options_volume_unsupported", "wrun_ethena_positions_unsupported", "wrun_etf_holdings_unsupported", "wrun_etf_premium_unsupported", "wrun_economic_unsupported", "wrun_treasury_balance_unsupported", "wrun_bitfinex_funding_unsupported", "wrun_strategy_costs_in_sheet", "wrun_window_bars_invalid", "wrun_cells_unavailable", "wrun_tape_unavailable", "wrun_tape_interval_unsupported", "wrun_metric_source_missing_policy", "wrun_series_source_primary", "wrun_series_source_densification", "wrun_metric_pin_coarser_than_primary", "wrun_forming_primary_not_own_candles", "wrun_package_lock_invalid", "wrun_package_lock_missing", "wrun_package_not_installed", "wrun_package_lock_mismatch", "wrun_composition_cycle", "wrun_composition_depth", "wrun_options_chain_unsupported", "wrun_volume_profile_ticks_unsupported", "wrun_celled_metric_unsupported", "wrun_series_source_missing", "wrun_series_source_invalid", "wrun_params_invalid", "wrun_source_bindings_invalid", "wrun_output_displaced", "wrun_pin_unresolvable"];
345
345
  readonly shape: readonly ["wrun_draw_kind_limit", "wrun_draw_total_limit", "wrun_draw_polyline_too_large", "wrun_draw_calls_per_row", "wrun_render_result_too_large", "wrun_draw_kind_mismatch", "wrun_draw_handle_missing", "wrun_draw_label_slot_absent", "wrun_draw_non_finite", "wrun_draw_phase", "wrun_draw_id_negative", "wrun_draw_kind_undeclared", "wrun_draw_prop_unknown", "wrun_draw_prop_unsupported", "wrun_draw_style_out_of_range", "wrun_draw_polyline_empty", "wrun_draw_polyline_out_of_bounds", "wrun_draw_label_slot_undeclared", "wrun_draw_polyline_budget", "wrun_strategy_id_limit", "wrun_strategy_id_too_long", "wrun_strategy_id_invalid_utf8", "wrun_strategy_calls_per_row", "wrun_strategy_trade_limit", "wrun_strategy_non_finite", "wrun_strategy_bad_direction", "wrun_strategy_not_declared", "wrun_strategy_phase", "wrun_strategy_id_out_of_bounds", "wrun_text_param_phase", "wrun_text_param_memory", "wrun_bar_count_phase", "wrun_frame_invalid", "wrun_frame_phase", "wrun_frame_undeclared", "wrun_frame_length", "wrun_frame_too_large", "wrun_frame_run_too_large", "wrun_frame_memory", "wrun_frame_utf8"];
346
346
  readonly pack: readonly ["wrun_cell_block_invalid", "wrun_run_cells_too_large", "wrun_cell_block_too_large"];
347
347
  readonly align: readonly ["wrun_densify_empty_fetch", "wrun_densify_mixed_phase", "wrun_liquidation_side_unmatched", "wrun_bound_series_empty", "wrun_cell_data_malformed"];
@@ -536,7 +536,11 @@ export const WRUN_KIT_REFUSAL_STAGES = {
536
536
  // kit 0.88.0 (OPTIONS-PORT P7): the prints with their block and RFQ identity, a host that does not serve them.
537
537
  'wrun_option_prints_v2_unsupported',
538
538
  'wrun_option_stats_10m_unsupported',
539
+ // kit 0.89.0 (OPTLOAD G3): a host that does not serve the per-strike and per-expiry option flow.
540
+ 'wrun_option_strike_flow_unsupported',
539
541
  'wrun_option_surface_unsupported',
542
+ // kit 0.90.0 (OPTLOAD G5): a chain page view, surface pick or strike kit fold on a host that serves no view.
543
+ 'wrun_option_views_unserved',
540
544
  'wrun_options_flow_unsupported',
541
545
  'wrun_field_unsupported',
542
546
  'wrun_tenor_unsupported',
@@ -8,15 +8,41 @@
8
8
  * (`wrunLaneRefusedText`), and the main thread reads the code back off whatever error wraps that text on its way
9
9
  * (`wrunLaneRefusedCodeOf`: the transport keeps the worker's words);
10
10
  * - the run degrades the lane under its name, terminally (the chip says the source is missing and no ladder re-asks
11
- * it), in the record its lane declares for the code (`WrunPollLane.refusedAnswers`) when it declares one;
12
- * - a live reconcile reads it as an answer with no new rows: its window covered, the held rows kept, no warning, so
13
- * the session never widens its window or warns on every poll.
11
+ * it), in the record its lane declares for the code (`WrunPollLane.refusedAnswers`, a row-builder lane's in the run's
12
+ * own table: the tape over the trades worker's cap) when it declares one;
13
+ * - a run that holds on such a lane settles `held` with `WRUN_LANE_REFUSED_SETTLE_REASON`, so the chart store's
14
+ * settings reconcile shows the edit as not applied at once instead of running the same settings again;
15
+ * - a live reconcile reads it by what its code declares (`WRUN_LANE_REFUSALS`): a read the plane serves nothing for
16
+ * is an answer with no new rows (its window covered, the held rows kept, no warning, so the session never widens
17
+ * its window or warns on every poll); a window over the read's cap holds data the chart lacks, so it stays owed and
18
+ * the session hands the overlay back to a full run, whose record names the way out.
14
19
  *
15
20
  * Import-free: the worker twins and the main thread read the same mark.
16
21
  */
22
+ /** The reason a run that held on a lane refused by name settles with (`held`): the same settings ask the same read
23
+ * and are refused again, so the chart store's settings reconcile spends no rerun on them. */
24
+ export declare const WRUN_LANE_REFUSED_SETTLE_REASON = "lane-refused";
17
25
  /** The mark a named refusal's text carries before its code. */
18
26
  export declare const WRUN_LANE_REFUSED_MARK = "wrun-lane-refused:";
19
27
  /** The text a worker twin ends a refused read with: the mark, the code (lower case, digits and dashes), the detail. */
20
28
  export declare function wrunLaneRefusedText(code: string, detail: string): string;
21
29
  /** The code of a named refusal an error (or its text) carries, or undefined for any other failure. */
22
30
  export declare function wrunLaneRefusedCodeOf(error: unknown): string | undefined;
31
+ /** What a refusal by name says of the window it was asked for. */
32
+ export type WrunLaneRefusalMeaning =
33
+ /** The plane serves nothing for this read, on any ask (a switch keeps it off, a series it samples elsewhere only, a
34
+ * request this host does not read): the window holds nothing the chart lacks. */
35
+ 'nothing-served'
36
+ /** The window holds more than the read takes (the trades worker's cap): the data is there, so the window is not
37
+ * covered, and only another ask (a higher floor, a shorter window) can read it. */
38
+ | 'over-cap';
39
+ /**
40
+ * Every code a worker twin refuses by name, with what it says of the window (the codes' own modules name them:
41
+ * wrun-option-views.util, wrun-protocol-pending.util, wrun-opra-stats.leaf, wrun-opra-flow.leaf, wrun-tape-source.util
42
+ * and the twins' literal ask refusals). tests/utility/wrun/wrun-lane-refusal.leaf.spec.ts walks every
43
+ * `wrunLaneRefusedText` call in the workers and the package and fails on a code missing here, so a new refusal says
44
+ * whether a live reconcile may read its window as covered before it ships.
45
+ */
46
+ export declare const WRUN_LANE_REFUSALS: Readonly<Record<string, WrunLaneRefusalMeaning>>;
47
+ /** Whether a refusal by name leaves its window owed (`over-cap`): a live reconcile never reads it as covered. */
48
+ export declare function wrunLaneRefusalLeavesWindowOwed(code: string): boolean;
@@ -8,12 +8,20 @@
8
8
  * (`wrunLaneRefusedText`), and the main thread reads the code back off whatever error wraps that text on its way
9
9
  * (`wrunLaneRefusedCodeOf`: the transport keeps the worker's words);
10
10
  * - the run degrades the lane under its name, terminally (the chip says the source is missing and no ladder re-asks
11
- * it), in the record its lane declares for the code (`WrunPollLane.refusedAnswers`) when it declares one;
12
- * - a live reconcile reads it as an answer with no new rows: its window covered, the held rows kept, no warning, so
13
- * the session never widens its window or warns on every poll.
11
+ * it), in the record its lane declares for the code (`WrunPollLane.refusedAnswers`, a row-builder lane's in the run's
12
+ * own table: the tape over the trades worker's cap) when it declares one;
13
+ * - a run that holds on such a lane settles `held` with `WRUN_LANE_REFUSED_SETTLE_REASON`, so the chart store's
14
+ * settings reconcile shows the edit as not applied at once instead of running the same settings again;
15
+ * - a live reconcile reads it by what its code declares (`WRUN_LANE_REFUSALS`): a read the plane serves nothing for
16
+ * is an answer with no new rows (its window covered, the held rows kept, no warning, so the session never widens
17
+ * its window or warns on every poll); a window over the read's cap holds data the chart lacks, so it stays owed and
18
+ * the session hands the overlay back to a full run, whose record names the way out.
14
19
  *
15
20
  * Import-free: the worker twins and the main thread read the same mark.
16
21
  */
22
+ /** The reason a run that held on a lane refused by name settles with (`held`): the same settings ask the same read
23
+ * and are refused again, so the chart store's settings reconcile spends no rerun on them. */
24
+ export const WRUN_LANE_REFUSED_SETTLE_REASON = 'lane-refused';
17
25
  /** The mark a named refusal's text carries before its code. */
18
26
  export const WRUN_LANE_REFUSED_MARK = 'wrun-lane-refused:';
19
27
  const WRUN_LANE_REFUSED_RE = /wrun-lane-refused:([a-z0-9][a-z0-9-]*)/;
@@ -30,3 +38,25 @@ export function wrunLaneRefusedCodeOf(error) {
30
38
  return undefined;
31
39
  return WRUN_LANE_REFUSED_RE.exec(text)?.[1];
32
40
  }
41
+ /**
42
+ * Every code a worker twin refuses by name, with what it says of the window (the codes' own modules name them:
43
+ * wrun-option-views.util, wrun-protocol-pending.util, wrun-opra-stats.leaf, wrun-opra-flow.leaf, wrun-tape-source.util
44
+ * and the twins' literal ask refusals). tests/utility/wrun/wrun-lane-refusal.leaf.spec.ts walks every
45
+ * `wrunLaneRefusedText` call in the workers and the package and fails on a code missing here, so a new refusal says
46
+ * whether a live reconcile may read its window as covered before it ships.
47
+ */
48
+ export const WRUN_LANE_REFUSALS = Object.freeze({
49
+ 'option-views-ask': 'nothing-served',
50
+ 'option-views-unserved': 'nothing-served',
51
+ 'option-stats-ask': 'nothing-served',
52
+ 'not-in-10m-universe': 'nothing-served',
53
+ 'options-flow-ask': 'nothing-served',
54
+ 'options-flow-prints-unserved': 'nothing-served',
55
+ 'option-scope-reads-off': 'nothing-served',
56
+ 'protocol-pending': 'nothing-served',
57
+ 'tape-too-many-trades': 'over-cap',
58
+ });
59
+ /** Whether a refusal by name leaves its window owed (`over-cap`): a live reconcile never reads it as covered. */
60
+ export function wrunLaneRefusalLeavesWindowOwed(code) {
61
+ return Object.hasOwn(WRUN_LANE_REFUSALS, code) && WRUN_LANE_REFUSALS[code] === 'over-cap';
62
+ }
@@ -95,7 +95,10 @@
95
95
  * acquisition the lane would plan otherwise now (its `acquisitionMoved`: a
96
96
  * CME surface or a CME chain's statistics read off a continuous alias whose
97
97
  * lead rolled; the full run re-plans it and the fresh session holds none of
98
- * its old rows). A pan-back page left to its wave
98
+ * its old rows), or a reconcile lane whose window held more than its read
99
+ * takes (a refusal by name the leaf declares `over-cap`: the tape past the
100
+ * trades worker's cap), whose window stays owed while the session is held
101
+ * and hands ONE full run off (`handWrunLiveOverCapBack`). A pan-back page left to its wave
99
102
  * (contract C1: a verified backward extension under an owner pending or
100
103
  * landed over it, or on a prefix-capable session within the grace its wave
101
104
  * has to stamp one) moves no history: the wave lands the page's rows into
@@ -95,7 +95,10 @@
95
95
  * acquisition the lane would plan otherwise now (its `acquisitionMoved`: a
96
96
  * CME surface or a CME chain's statistics read off a continuous alias whose
97
97
  * lead rolled; the full run re-plans it and the fresh session holds none of
98
- * its old rows). A pan-back page left to its wave
98
+ * its old rows), or a reconcile lane whose window held more than its read
99
+ * takes (a refusal by name the leaf declares `over-cap`: the tape past the
100
+ * trades worker's cap), whose window stays owed while the session is held
101
+ * and hands ONE full run off (`handWrunLiveOverCapBack`). A pan-back page left to its wave
99
102
  * (contract C1: a verified backward extension under an owner pending or
100
103
  * landed over it, or on a prefix-capable session within the grace its wave
101
104
  * has to stamp one) moves no history: the wave lands the page's rows into
@@ -223,7 +226,7 @@ import { wrunLegNativeRowsOption } from './wrun-pin-venues.util.js';
223
226
  import { wrunSessionChartNamesOf } from './wrun-chart-context-names.util.js';
224
227
  import { wrunChartSizeUnit, wrunReadsMarketFacts } from './wrun-chart-market-facts.util.js';
225
228
  import { wrunReadsEarningsFacts } from './wrun-earnings-facts.util.js';
226
- import { wrunLaneRefusedCodeOf } from './wrun-lane-refusal.leaf.js';
229
+ import { wrunLaneRefusalLeavesWindowOwed, wrunLaneRefusedCodeOf } from './wrun-lane-refusal.leaf.js';
227
230
  import { WRUN_RUN_INTERVAL_ROWS_KEY, wrunRunIntervalComputeRows, wrunRunIntervalProjectionOf, wrunRunIntervalRowsThrough, wrunRunIntervalSentRow, wrunRunIntervalSessionOf, } from './wrun-run-interval-session.util.js';
228
231
  import { WRUN_NO_READY_ROWS_CODE, wrunNothingReadyRefusal, wrunRunHealthDiagnostics } from './wrun-run-health.util.js';
229
232
  import { attachWrunRefusal, serializeWrunRefusal, wrunOverlayEditable, wrunRefusalFor, } from './wrun-refusal.util.js';
@@ -1464,7 +1467,8 @@ export async function runWrunOverlayLiveTick(indicatorId) {
1464
1467
  : null;
1465
1468
  if (plan.kind === 'reconcile') {
1466
1469
  const verdict = await reconcileWrunOverlayLanes(context, ledger, plan, meta, mainClock, lastTs);
1467
- if (!wrunLiveContextCurrent(context, generation))
1470
+ // A window over its read's cap held the session and handed the overlay back to a full run: nothing more drains.
1471
+ if (!wrunLiveContextCurrent(context, generation) || verdict === 'handed-back')
1468
1472
  return;
1469
1473
  const owed = verdict === 'closed-bar-revised' || (context.dirtyFromTs !== null && reseedBudgetOpen(ledger));
1470
1474
  // A page ahead of the session holds the reseed (wrunPrefixHoldsReseed):
@@ -1837,6 +1841,21 @@ function suspendWrunLiveOnTapeRefusal(context, ledger, generation, error) {
1837
1841
  console.warn(`[wrun] live session suspended for '${context.indicatorId}' (${error.message})`);
1838
1842
  void noteWrunLiveTickRefusal(context, ledger, generation, error);
1839
1843
  }
1844
+ /**
1845
+ * A reconcile lane whose window held more than its read takes (wrunLaneRefusalLeavesWindowOwed: the tape held more
1846
+ * prints at its floor than the trades worker reads, `tape-too-many-trades`): its prints are there, so the window stays
1847
+ * owed, and the next poll would ask the same window at the same floor and meet the same cap. The session is held (no
1848
+ * drains, its picture kept) and hands the overlay back to the full run once, the handoff a reseed's failed reopen
1849
+ * makes: the full run asks the declared history at the same floor, which holds the window, so it meets the cap too
1850
+ * and shows the lane's record (the tape's: too much data, Open the settings), and a settings save with a higher floor
1851
+ * installs a fresh session. Like the budget holds it leaves `liveSuspendedBy` unset: a heal run over the same history
1852
+ * is refused again, so the heal ladder leaves the held session alone.
1853
+ */
1854
+ function handWrunLiveOverCapBack(context, ledger, lane, reason) {
1855
+ context.liveSuspended = true;
1856
+ console.warn(`[wrun] live reconcile lane '${lane}' for '${context.indicatorId}' held more than its read takes (its window stays owed); live suspended, rebuilding once through the full run:`, reason);
1857
+ noteWrunLiveRebuild(ledger, context.indicatorId);
1858
+ }
1840
1859
  /** A rebuild handoff to the full-run driver, counted here and in the intake's
1841
1860
  * stats. Its reason is 'live-rebuild': the session cannot extend, so the run
1842
1861
  * is never merged as a range refresh nor skipped as a duplicate range. */
@@ -2910,12 +2929,22 @@ lastMainTs) {
2910
2929
  let revisedFromTs = null;
2911
2930
  const liveCandleOnlyLegs = wrunLiveCandleOnlyLegKeys(context);
2912
2931
  const formingOpenLegs = wrunFormingOpenLegKeys(context);
2932
+ // The first lane whose window held more than its read takes (handed back below, once).
2933
+ let overCap;
2913
2934
  plan.lanes.forEach((lane, at) => {
2914
2935
  const outcome = settled[at];
2915
- // An answer the data plane refused by name (wrun-lane-refusal.leaf: a read switched off, a series it does not
2916
- // sample here) is refused the same way on every ask: read as an answer with no new rows (its window covered,
2936
+ const refusedCode = outcome.status === 'rejected' ? wrunLaneRefusedCodeOf(outcome.reason) : undefined;
2937
+ // A window over its read's cap (wrunLaneRefusalLeavesWindowOwed: the tape held more prints at its floor than
2938
+ // the trades worker reads) holds data the chart lacks: it keeps its obligation as a failed lane does (its fed
2939
+ // buckets outstanding, its coverage behind), and the session hands the overlay back to a full run below.
2940
+ if (outcome.status === 'rejected' && refusedCode !== undefined && wrunLaneRefusalLeavesWindowOwed(refusedCode)) {
2941
+ overCap ??= { lane, reason: outcome.reason };
2942
+ return;
2943
+ }
2944
+ // Any other answer the data plane refused by name (wrun-lane-refusal.leaf: a read switched off, a series it does
2945
+ // not sample here) is refused the same way on every ask: read as an answer with no new rows (its window covered,
2917
2946
  // the held rows kept), so the session neither warns nor widens its window on every poll.
2918
- const refused = outcome.status === 'rejected' && wrunLaneRefusedCodeOf(outcome.reason) !== undefined;
2947
+ const refused = refusedCode !== undefined;
2919
2948
  if (outcome.status === 'rejected' && !refused) {
2920
2949
  // A failed lane keeps its obligation: its fed buckets stay outstanding
2921
2950
  // and the next reconcile window reaches back to them.
@@ -3016,6 +3045,10 @@ lastMainTs) {
3016
3045
  });
3017
3046
  }
3018
3047
  }
3048
+ if (overCap !== undefined) {
3049
+ handWrunLiveOverCapBack(context, ledger, overCap.lane, overCap.reason);
3050
+ return 'handed-back';
3051
+ }
3019
3052
  if (revisedFromTs === null)
3020
3053
  return 'clean';
3021
3054
  // A revised closed bar is a committed bar the session evaluated on other
@@ -0,0 +1,106 @@
1
+ /**
2
+ * The size thresholds a built-in package declares in trade units (coins on crypto, contracts on futures) as ONE
3
+ * number for every market. Big Trades' Min size 10 was tuned on BTC, where 10 BTC is about $830k; on a market whose
4
+ * coin is worth a sliver of BTC the same number keeps a whole tape: 10 ETH (about $24k) kept 487,132 prints over its
5
+ * seven days of BINANCE_FUTURES ETHUSDT, past the trades worker's 300,000-print cap, so every attempt failed. A
6
+ * threshold that means "big" follows the market instead: the table below names the params that do (keyed by package
7
+ * and param name, never by a label, a hint or a pattern), and this leaf holds the rule; the run head applies it once
8
+ * per mount and market (wrun-market-size-defaults.util).
9
+ *
10
+ * The rule (product decision 2026-10-21): on a market whose size unit is coins and whose candle volume is in base
11
+ * coins, Min size defaults to 0.01% of the market's daily base volume rounded down to 1, 2 or 5 times a power of ten
12
+ * (`wrunNiceFloor`, below 1 too), and Whale size to ten times that, so BTC keeps 10 and 100 (131.7K BTC a day) while
13
+ * ETH reads 200 and 2000 (3.13M ETH). The daily volume comes from the chart's own candles (`wrunDailyCandleVolume`).
14
+ * A market whose facts never yield a market default reads the package's defaults, so a record never keeps the last
15
+ * coin market's scaled one there: sized in contracts (CME, every contract market), placed by the directory in another
16
+ * unit (shares), or candles in another unit than the tape (an inverse or OKX swap, a formula chart). A market whose
17
+ * size unit is not known yet and a chart whose closed candles cover under an hour move nothing: the next run asks
18
+ * again.
19
+ *
20
+ * Pure: the specs and the phone app read the same rule. Its one import is the import-free size unit table.
21
+ */
22
+ import type { WrunScriptInputDeclaration } from './wrun-script-inputs.util.js';
23
+ /** How a market-scaled param's default follows the market. */
24
+ export type WrunMarketScaledRule =
25
+ /** A share of the market's daily base volume, rounded down to 1, 2 or 5 times a power of ten. */
26
+ {
27
+ readonly kind: 'daily-volume';
28
+ readonly share: number;
29
+ }
30
+ /** A multiple of another scaled param's market default (resolved after the ones read off the volume). */
31
+ | {
32
+ readonly kind: 'times';
33
+ readonly param: string;
34
+ readonly factor: number;
35
+ };
36
+ /**
37
+ * The params whose default follows the market, by package name, then param name (the sheet's own names). A built-in
38
+ * twin whose sheet binds a param to a trade size floor lists it here or in the guard's exemptions with a reason
39
+ * (tests/utility/wrun/wrun-market-size-defaults.twins.spec.ts walks every proven twin's frozen sheet).
40
+ */
41
+ export declare const WRUN_MARKET_SCALED_PARAMS: Readonly<Record<string, Readonly<Record<string, WrunMarketScaledRule>>>>;
42
+ /** The scaled params of a package, or undefined for a package that scales none. */
43
+ export declare function wrunMarketScaledParamsOf(packageName: string | undefined): Readonly<Record<string, WrunMarketScaledRule>> | undefined;
44
+ /**
45
+ * A market's daily volume in its candles' unit, from the chart's own candles (ascending, the newest the forming
46
+ * one, which is left out: its volume is partial): the closed candles opening in the 24 hours before the newest one's
47
+ * open, summed and scaled to a day by the span they cover (a fine chart loads less than a day: 500 one-minute candles
48
+ * count 499 minutes; a gap where nothing traded counts as covered time with no volume). One closed candle longer than
49
+ * a day (1W, 1M) is prorated by its length, the gap to the next open held to `intervalMs`. Undefined when the closed
50
+ * candles cover under an hour or hold no volume.
51
+ */
52
+ export declare function wrunDailyCandleVolume(rows: ReadonlyArray<ArrayLike<number>>, intervalMs?: number): number | undefined;
53
+ /**
54
+ * 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
55
+ * a clean decimal; undefined for a value that is not finite and above zero.
56
+ */
57
+ export declare function wrunNiceFloor(value: number): number | undefined;
58
+ /**
59
+ * Each scaled param's default on a market trading `dailyVolume` base units a day: the daily-volume rules first, then
60
+ * the multiples of them. Undefined when the volume yields no default (not finite and above zero).
61
+ */
62
+ export declare function wrunMarketScaledDefaults(rules: Readonly<Record<string, WrunMarketScaledRule>>, dailyVolume: number): Record<string, number> | undefined;
63
+ /** The market facts the rule reads: the size unit (`wrunChartSizeUnit`), whether the candles' volume is in base
64
+ * coins (the venue's unit profile, candle-volume-unit.leaf), the chart's own candle rows and its bar length. */
65
+ export interface WrunMarketSizeFacts {
66
+ sizeUnit: number;
67
+ candleVolumeInCoins: boolean;
68
+ rows: ReadonlyArray<ArrayLike<number>>;
69
+ intervalMs?: number;
70
+ }
71
+ /** What a market's facts make of the scaled params' defaults. */
72
+ export type WrunMarketSizeVerdict =
73
+ /** The market's own defaults: a coin market whose candles say how much it trades a day. */
74
+ {
75
+ kind: 'market';
76
+ defaults: Record<string, number>;
77
+ }
78
+ /** The package's declared defaults, on facts that never change for the market, so a record moves back to them
79
+ * instead of keeping another market's scaled default: sized in contracts (`contracts`: CME, every contract
80
+ * market), placed by the directory in another unit (`size-unit`: shares), candles in another unit than the tape
81
+ * (`candle-unit`: contracts on an inverse or an OKX swap, a formula chart's candles, which are no market's). */
82
+ | {
83
+ kind: 'package';
84
+ reason: 'contracts' | 'size-unit' | 'candle-unit';
85
+ }
86
+ /** Nothing moves yet (the record keeps what it holds, and the next run asks again), on facts that can still change:
87
+ * a size unit not known yet (`size-unit`: the directory has not placed the market, or its lookup failed), closed
88
+ * candles covering under an hour or holding no volume (`cover`). */
89
+ | {
90
+ kind: 'skip';
91
+ reason: 'size-unit' | 'cover';
92
+ };
93
+ /** The verdict of a market's facts on a package's scaled params (`rules`). */
94
+ export declare function wrunMarketSizeVerdict(rules: Readonly<Record<string, WrunMarketScaledRule>>, facts: WrunMarketSizeFacts): WrunMarketSizeVerdict;
95
+ /** A number row's value held to its bounds, or undefined for one that is not finite. */
96
+ export declare function wrunMarketDefaultWithinRow(row: Pick<WrunScriptInputDeclaration, 'constraints'>, value: unknown): number | undefined;
97
+ /**
98
+ * `rows` (the rows a sheet builds, `buildWrunScriptInputs`) with the market defaults a record holds: each scaled
99
+ * param's row takes the default its row in `held` (the record's own `scriptInputs`) carries, the one the run head last
100
+ * moved it to, so a rebuild of the rows from the sheet (a delivered sheet's reconcile, a pin move) never moves a market
101
+ * default back to the sheet's, and a value at it never reads as changed. A held default that is not a number within
102
+ * the row's bounds stays the sheet's. The same array when nothing moves.
103
+ */
104
+ export declare function wrunRowsKeepingMarketDefaults(rows: WrunScriptInputDeclaration[], held: unknown, packageName: string | undefined): WrunScriptInputDeclaration[];
105
+ /** Whether a settings row can hold a market default (a number kind; a sheet that retyped the param keeps its own). */
106
+ export declare function isWrunMarketScaledRow(row: Pick<WrunScriptInputDeclaration, 'type'>): boolean;
@@ -0,0 +1,159 @@
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 size 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
+ // The tape's floor (its `min_size` facet names it) and the bubbles' size unit: 0.01% of a day's base volume.
10
+ min_size: Object.freeze({ kind: 'daily-volume', share: 0.0001 }),
11
+ // 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
+ }),
14
+ });
15
+ /** The scaled params of a package, or undefined for a package that scales none. */
16
+ export function wrunMarketScaledParamsOf(packageName) {
17
+ if (packageName === undefined || !Object.hasOwn(WRUN_MARKET_SCALED_PARAMS, packageName))
18
+ return undefined;
19
+ return WRUN_MARKET_SCALED_PARAMS[packageName];
20
+ }
21
+ const HOUR_MS = 3_600_000;
22
+ const DAY_MS = 86_400_000;
23
+ /** The candle row's volume column (`[ts, open, high, low, close, volume]`, the chart's main series rows). */
24
+ const VOLUME_COLUMN = 5;
25
+ /** `market.size_unit()`'s codes (the kit's table, wrun-market-facts.util). */
26
+ const UNKNOWN_SIZE_UNIT = WRUN_MARKET_SIZE_UNITS.indexOf('unknown');
27
+ const COINS_SIZE_UNIT = WRUN_MARKET_SIZE_UNITS.indexOf('coins');
28
+ const CONTRACTS_SIZE_UNIT = WRUN_MARKET_SIZE_UNITS.indexOf('contracts');
29
+ /**
30
+ * A market's daily volume in its candles' unit, from the chart's own candles (ascending, the newest the forming
31
+ * one, which is left out: its volume is partial): the closed candles opening in the 24 hours before the newest one's
32
+ * open, summed and scaled to a day by the span they cover (a fine chart loads less than a day: 500 one-minute candles
33
+ * count 499 minutes; a gap where nothing traded counts as covered time with no volume). One closed candle longer than
34
+ * a day (1W, 1M) is prorated by its length, the gap to the next open held to `intervalMs`. Undefined when the closed
35
+ * candles cover under an hour or hold no volume.
36
+ */
37
+ export function wrunDailyCandleVolume(rows, intervalMs) {
38
+ const last = rows.length - 1;
39
+ if (last < 1)
40
+ return undefined;
41
+ const newestOpen = Number(rows[last][0]);
42
+ const lastClosedOpen = Number(rows[last - 1][0]);
43
+ if (!Number.isFinite(newestOpen) || !Number.isFinite(lastClosedOpen))
44
+ return undefined;
45
+ const barMs = intervalMs !== undefined && Number.isFinite(intervalMs) && intervalMs > 0 ? intervalMs : Infinity;
46
+ const lastSpan = Math.min(newestOpen - lastClosedOpen, barMs);
47
+ if (lastSpan > DAY_MS) {
48
+ const volume = Number(rows[last - 1][VOLUME_COLUMN]);
49
+ return Number.isFinite(volume) && volume > 0 ? (volume * DAY_MS) / lastSpan : undefined;
50
+ }
51
+ const windowStart = newestOpen - DAY_MS;
52
+ let volume = 0;
53
+ for (let at = last - 1; at >= 0; at -= 1) {
54
+ if (!(Number(rows[at][0]) >= windowStart))
55
+ break;
56
+ const bar = Number(rows[at][VOLUME_COLUMN]);
57
+ if (Number.isFinite(bar) && bar > 0)
58
+ volume += bar;
59
+ }
60
+ const covered = newestOpen - Math.max(windowStart, Number(rows[0][0]));
61
+ if (!(covered >= HOUR_MS) || !(volume > 0))
62
+ return undefined;
63
+ return (volume * DAY_MS) / covered;
64
+ }
65
+ /**
66
+ * The largest 1, 2 or 5 times a power of ten at or below `value` (5,000,000, 200, 10, then 0.5, 0.2, 0.1 below 1), as
67
+ * a clean decimal; undefined for a value that is not finite and above zero.
68
+ */
69
+ export function wrunNiceFloor(value) {
70
+ if (!Number.isFinite(value) || value <= 0)
71
+ return undefined;
72
+ const scale = 10 ** Math.floor(Math.log10(value));
73
+ // A hair over the float quotient: 0.6 / 0.1 reads 5.999999999999999, and log10 can land a power of ten one
74
+ // exponent low (the mantissa then reads 10).
75
+ const mantissa = (value / scale) * (1 + 1e-9);
76
+ const step = mantissa >= 10 ? 10 : mantissa >= 5 ? 5 : mantissa >= 2 ? 2 : 1;
77
+ return Number((step * scale).toPrecision(1));
78
+ }
79
+ /**
80
+ * Each scaled param's default on a market trading `dailyVolume` base units a day: the daily-volume rules first, then
81
+ * the multiples of them. Undefined when the volume yields no default (not finite and above zero).
82
+ */
83
+ export function wrunMarketScaledDefaults(rules, dailyVolume) {
84
+ const defaults = {};
85
+ for (const [name, rule] of Object.entries(rules)) {
86
+ if (rule.kind !== 'daily-volume')
87
+ continue;
88
+ const value = wrunNiceFloor(dailyVolume * rule.share);
89
+ if (value === undefined)
90
+ return undefined;
91
+ defaults[name] = value;
92
+ }
93
+ for (const [name, rule] of Object.entries(rules)) {
94
+ if (rule.kind !== 'times')
95
+ continue;
96
+ const base = defaults[rule.param];
97
+ if (base === undefined)
98
+ return undefined;
99
+ defaults[name] = Number((base * rule.factor).toPrecision(12));
100
+ }
101
+ return defaults;
102
+ }
103
+ /** The verdict of a market's facts on a package's scaled params (`rules`). */
104
+ export function wrunMarketSizeVerdict(rules, facts) {
105
+ if (facts.sizeUnit === CONTRACTS_SIZE_UNIT)
106
+ return { kind: 'package', reason: 'contracts' };
107
+ if (facts.sizeUnit === UNKNOWN_SIZE_UNIT)
108
+ return { kind: 'skip', reason: 'size-unit' };
109
+ if (facts.sizeUnit !== COINS_SIZE_UNIT)
110
+ return { kind: 'package', reason: 'size-unit' };
111
+ if (!facts.candleVolumeInCoins)
112
+ return { kind: 'package', reason: 'candle-unit' };
113
+ const daily = wrunDailyCandleVolume(facts.rows, facts.intervalMs);
114
+ const defaults = daily === undefined ? undefined : wrunMarketScaledDefaults(rules, daily);
115
+ return defaults === undefined ? { kind: 'skip', reason: 'cover' } : { kind: 'market', defaults };
116
+ }
117
+ /** A number row's value held to its bounds, or undefined for one that is not finite. */
118
+ export function wrunMarketDefaultWithinRow(row, value) {
119
+ if (typeof value !== 'number' || !Number.isFinite(value))
120
+ return undefined;
121
+ const { min, max } = row.constraints ?? {};
122
+ if (typeof min === 'number' && value < min)
123
+ return min;
124
+ if (typeof max === 'number' && value > max)
125
+ return max;
126
+ return value;
127
+ }
128
+ /**
129
+ * `rows` (the rows a sheet builds, `buildWrunScriptInputs`) with the market defaults a record holds: each scaled
130
+ * param's row takes the default its row in `held` (the record's own `scriptInputs`) carries, the one the run head last
131
+ * moved it to, so a rebuild of the rows from the sheet (a delivered sheet's reconcile, a pin move) never moves a market
132
+ * default back to the sheet's, and a value at it never reads as changed. A held default that is not a number within
133
+ * the row's bounds stays the sheet's. The same array when nothing moves.
134
+ */
135
+ export function wrunRowsKeepingMarketDefaults(rows, held, packageName) {
136
+ const rules = wrunMarketScaledParamsOf(packageName);
137
+ if (rules === undefined || !Array.isArray(held))
138
+ return rows;
139
+ let moved = false;
140
+ const kept = rows.map((row) => {
141
+ if (!Object.hasOwn(rules, row.name) || !isWrunMarketScaledRow(row))
142
+ return row;
143
+ const own = held.find((candidate) => candidate !== null && typeof candidate === 'object' && candidate.name === row.name);
144
+ const value = own?.defaultValue;
145
+ if (typeof value !== 'number' || wrunMarketDefaultWithinRow(row, value) !== value)
146
+ return row;
147
+ if (value === row.defaultValue)
148
+ return row;
149
+ moved = true;
150
+ return { ...row, defaultValue: value };
151
+ });
152
+ return moved ? kept : rows;
153
+ }
154
+ /** The row kinds a scaled param is: a number, int or price row (they store the same finite number). */
155
+ const WRUN_MARKET_SCALED_ROW_TYPES = new Set(['number', 'int', 'price']);
156
+ /** Whether a settings row can hold a market default (a number kind; a sheet that retyped the param keeps its own). */
157
+ export function isWrunMarketScaledRow(row) {
158
+ return WRUN_MARKET_SCALED_ROW_TYPES.has(row.type);
159
+ }
@@ -0,0 +1,44 @@
1
+ import type { WrunIndicatorMetadata } from '../../interfaces/wrun-runtime.interface.js';
2
+ /**
3
+ * The patch that moves a record (`settings`: its `scriptInputs` rows and each value flat under its row's name) to a
4
+ * market's `defaults`: every scaled row whose value reads as its default (never changed) takes the market's default
5
+ * (held to the row's bounds), value and `defaultValue` together. A changed value keeps both: the changed mark is the
6
+ * value against its own row's default, so a default moved under a kept value would read the value as never changed on
7
+ * the first market whose default equals it, and the next market would move it (SOL 200, then ETH whose default is
8
+ * 200, then SOL reset it to 1000). Its reset goes to the default of the market where the user changed it, a save
9
+ * whose run head then moves the unchanged value on. Undefined when the record already reads the defaults. Pure.
10
+ */
11
+ export declare function wrunMarketSizeSettingsPatch(settings: unknown, defaults: Readonly<Record<string, number>>): Record<string, unknown> | undefined;
12
+ /** The chart market the run computes for, as the head reads it. */
13
+ interface WrunMarketSizeChart {
14
+ exchange?: unknown;
15
+ symbol?: unknown;
16
+ interval?: unknown;
17
+ transformations?: unknown;
18
+ }
19
+ /**
20
+ * Move an overlay's record to its chart market's scaled defaults (above), at the head of a full run, before the
21
+ * lanes read the settings. Resolves once the engine copy reads the defaults (the persist is the routing's own); a
22
+ * package that scales nothing returns at once, and nothing here ever throws over the run.
23
+ *
24
+ * Every fact is proven the keyed market's before it is kept or written: `market` is the market the run computes for
25
+ * (C4: the chart's market identity at the run head, `wrunChartMarketIdentity`, and the reader of the chart's metadata
26
+ * now), and `isCurrent` says the run is still the overlay's own (its chart and mount stand). After each await, in the
27
+ * task that keeps and writes, the chart still names that market (a switch during the directory's answer moves it, and
28
+ * neither the mount nor the refusal attempt sees a switch), and the verdict that reads the candles reads them only
29
+ * while they were loaded for it (`loadedMainIdentityOf`: the symbol pipeline stamps the new market's metadata before
30
+ * its rows replace the old market's). A fact it cannot prove reads as a transient skip: no memo, no write.
31
+ */
32
+ export declare function reconcileWrunMarketSizeDefaults(args: {
33
+ chartIndex: number;
34
+ indicatorId: string;
35
+ tc: unknown;
36
+ meta: Record<string, unknown>;
37
+ sheet: WrunIndicatorMetadata;
38
+ market: {
39
+ identity: string;
40
+ read: () => WrunMarketSizeChart | null | undefined;
41
+ };
42
+ isCurrent: () => boolean;
43
+ }): Promise<void>;
44
+ export {};