dexbot 1.6.10 → 1.6.12

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 (365) hide show
  1. package/CHANGELOG.md +50 -3
  2. package/README.md +3 -1
  3. package/analysis/README.md +51 -11
  4. package/analysis/bot_fitting/README.md +12 -0
  5. package/analysis/tradingview/README.md +3 -3
  6. package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +11 -37
  7. package/analysis/trend_detection/README.md +31 -0
  8. package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
  9. package/claw/modules/chain_broadcast.ts +7 -1
  10. package/claw/modules/claw_launcher.ts +1 -1
  11. package/claw/modules/launcher_mode_detector.ts +9 -2
  12. package/claw/package.json +1 -1
  13. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  14. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  15. package/dist/analysis/account_resolver.d.ts +1 -1
  16. package/dist/analysis/account_resolver.js +15 -2
  17. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +3 -4
  18. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +2 -7
  19. package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
  20. package/dist/analysis/ama_fitting/fetch_lp_candles.js +4 -4
  21. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +20 -4
  22. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +9 -6
  23. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +16 -12
  24. package/dist/analysis/analyze_args.d.ts +31 -0
  25. package/dist/analysis/analyze_args.js +41 -0
  26. package/dist/analysis/analyze_dynamic_weight.js +7 -20
  27. package/dist/analysis/analyze_kalman.js +7 -17
  28. package/dist/analysis/analyze_regime.js +7 -17
  29. package/dist/analysis/analyze_regime_windows.js +8 -18
  30. package/dist/analysis/analyze_risk_profile.js +8 -18
  31. package/dist/analysis/analyze_trade_heatmap.js +7 -17
  32. package/dist/analysis/analyze_volatility.js +7 -17
  33. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +220 -12
  34. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +55 -10
  35. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
  36. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +72 -66
  37. package/dist/analysis/bot_fitting/backtest_lookback_drawdown.d.ts +21 -0
  38. package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +315 -0
  39. package/dist/analysis/bot_fitting/shared_utils.d.ts +7 -7
  40. package/dist/analysis/bot_fitting/shared_utils.js +2 -2
  41. package/dist/analysis/bot_key_utils.d.ts +18 -10
  42. package/dist/analysis/bot_key_utils.js +10 -17
  43. package/dist/analysis/bot_usage/discover_bot_accounts.js +44 -47
  44. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -21
  45. package/dist/analysis/chain_pool.d.ts +3 -1
  46. package/dist/analysis/chart_ui.d.ts +5 -2
  47. package/dist/analysis/chart_ui.js +6 -3
  48. package/dist/analysis/chart_utils.d.ts +5 -5
  49. package/dist/analysis/chart_utils.js +9 -0
  50. package/dist/analysis/fills_cache.d.ts +64 -0
  51. package/dist/analysis/fills_cache.js +254 -0
  52. package/dist/analysis/fills_source.d.ts +2 -2
  53. package/dist/analysis/fills_source.js +19 -14
  54. package/dist/analysis/grid_correction_check.d.ts +1 -1
  55. package/dist/analysis/grid_correction_check.js +12 -11
  56. package/dist/analysis/math_utils.d.ts +7 -6
  57. package/dist/analysis/math_utils.js +5 -8
  58. package/dist/analysis/pnl_report.d.ts +39 -0
  59. package/dist/analysis/pnl_report.js +325 -0
  60. package/dist/analysis/price_sources.d.ts +8 -8
  61. package/dist/analysis/price_sources.js +5 -4
  62. package/dist/analysis/resolve_bot_accounts.js +2 -2
  63. package/dist/analysis/resolve_source.d.ts +1 -2
  64. package/dist/analysis/trade_profitability.d.ts +32 -2
  65. package/dist/analysis/trade_profitability.js +232 -106
  66. package/dist/analysis/tradingview/analyze_tradingview.d.ts +17 -6
  67. package/dist/analysis/tradingview/analyze_tradingview.js +9 -10
  68. package/dist/analysis/tradingview/grid_reset_config.d.ts +42 -31
  69. package/dist/analysis/tradingview/grid_reset_config.js +35 -6
  70. package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -8
  71. package/dist/analysis/tradingview/grid_reset_sim.js +42 -5
  72. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
  73. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +20 -20
  74. package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +102 -0
  75. package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +725 -0
  76. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
  77. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +27 -112
  78. package/dist/analysis/trend_detection/huber_scale_variants.d.ts +40 -0
  79. package/dist/analysis/trend_detection/huber_scale_variants.js +176 -0
  80. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +30 -1
  81. package/dist/analysis/trend_detection/kalman_chart_generator.js +3 -3
  82. package/dist/analysis/trend_detection/regime_chart_generator.d.ts +31 -1
  83. package/dist/analysis/trend_detection/regime_chart_generator.js +2 -2
  84. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +33 -1
  85. package/dist/credential-daemon.js +34 -20
  86. package/dist/dexbot.js +17 -14
  87. package/dist/market_adapter/candle_utils.d.ts +22 -18
  88. package/dist/market_adapter/candle_utils.js +24 -20
  89. package/dist/market_adapter/core/asymmetric_bounds.d.ts +13 -4
  90. package/dist/market_adapter/core/config_normalizers.d.ts +3 -3
  91. package/dist/market_adapter/core/kibana_candles.d.ts +53 -18
  92. package/dist/market_adapter/core/kibana_candles.js +9 -7
  93. package/dist/market_adapter/core/kibana_client.d.ts +9 -1
  94. package/dist/market_adapter/core/kibana_client.js +8 -7
  95. package/dist/market_adapter/core/kibana_market_candles.d.ts +3 -2
  96. package/dist/market_adapter/core/market_adapter_service.d.ts +297 -115
  97. package/dist/market_adapter/core/market_adapter_service.js +184 -101
  98. package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
  99. package/dist/market_adapter/core/strategies/ama.js +7 -32
  100. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +14 -1
  101. package/dist/market_adapter/core/strategies/ama_slope_model.js +12 -34
  102. package/dist/market_adapter/core/strategies/atr/calculator.d.ts +7 -2
  103. package/dist/market_adapter/core/strategies/atr/calculator.js +2 -34
  104. package/dist/market_adapter/core/strategies/collateral_manager.d.ts +7 -1
  105. package/dist/market_adapter/core/strategies/collateral_manager.js +0 -22
  106. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +36 -8
  107. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +9 -9
  108. package/dist/market_adapter/core/strategies/regime_gate.d.ts +24 -15
  109. package/dist/market_adapter/core/strategies/regime_gate.js +4 -31
  110. package/dist/market_adapter/core/strategies/regime_interp.d.ts +7 -1
  111. package/dist/market_adapter/core/strategies/regime_interp.js +14 -22
  112. package/dist/market_adapter/core/strategies/volatility_shift.d.ts +11 -1
  113. package/dist/market_adapter/core/strategies/volatility_shift.js +0 -13
  114. package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +29 -0
  115. package/dist/market_adapter/inputs/cex_candle_parsing.js +52 -0
  116. package/dist/market_adapter/inputs/fetch_book_data.d.ts +20 -4
  117. package/dist/market_adapter/inputs/fetch_book_data.js +3 -1
  118. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +97 -226
  119. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +42 -7
  120. package/dist/market_adapter/inputs/fetch_lp_data.js +22 -15
  121. package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
  122. package/dist/market_adapter/inputs/kibana_feed_source.js +29 -22
  123. package/dist/market_adapter/inputs/kibana_source.d.ts +25 -3
  124. package/dist/market_adapter/inputs/kibana_source.js +2 -2
  125. package/dist/market_adapter/inputs/window_cache.d.ts +99 -94
  126. package/dist/market_adapter/inputs/window_cache.js +8 -8
  127. package/dist/market_adapter/interval_utils.d.ts +4 -4
  128. package/dist/market_adapter/log_format.d.ts +6 -6
  129. package/dist/market_adapter/log_format.js +28 -22
  130. package/dist/market_adapter/lp_chart_core.d.ts +22 -1
  131. package/dist/market_adapter/lp_chart_core.js +26 -192
  132. package/dist/market_adapter/lp_chart_runner.d.ts +7 -7
  133. package/dist/market_adapter/lp_chart_strategy_loader.d.ts +41 -6
  134. package/dist/market_adapter/lp_chart_strategy_loader.js +8 -7
  135. package/dist/market_adapter/market_adapter.d.ts +94 -33
  136. package/dist/market_adapter/market_adapter.js +69 -75
  137. package/dist/market_adapter/utils/adapter_client.d.ts +3 -3
  138. package/dist/market_adapter/utils/adapter_client.js +2 -2
  139. package/dist/market_adapter/utils/atomic_write.d.ts +8 -1
  140. package/dist/market_adapter/utils/chain.d.ts +50 -41
  141. package/dist/market_adapter/utils/chain.js +40 -46
  142. package/dist/market_adapter/utils/data_discovery.d.ts +4 -1
  143. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +12 -3
  144. package/dist/market_adapter/utils/file_json_cache.d.ts +2 -2
  145. package/dist/market_adapter/utils/file_lock.d.ts +28 -14
  146. package/dist/market_adapter/utils/file_lock.js +36 -32
  147. package/dist/market_adapter/utils/native_history.d.ts +9 -2
  148. package/dist/market_adapter/utils/native_history.js +35 -28
  149. package/dist/modules/account_bots.d.ts +577 -21
  150. package/dist/modules/account_bots.js +182 -158
  151. package/dist/modules/account_orders.d.ts +66 -30
  152. package/dist/modules/account_orders.js +22 -20
  153. package/dist/modules/authority_resolver.d.ts +12 -2
  154. package/dist/modules/authority_resolver.js +15 -8
  155. package/dist/modules/bitshares-native/chain_client.d.ts +38 -3
  156. package/dist/modules/bitshares-native/chain_client.js +45 -46
  157. package/dist/modules/bitshares-native/crypto/ecc.browser.js +11 -171
  158. package/dist/modules/bitshares-native/crypto/ecc.js +13 -176
  159. package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +33 -0
  160. package/dist/modules/bitshares-native/crypto/ecc_core.js +213 -0
  161. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -1
  162. package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -13
  163. package/dist/modules/bitshares-native/index.d.ts +1 -1
  164. package/dist/modules/bitshares-native/lru_cache.d.ts +7 -7
  165. package/dist/modules/bitshares-native/resolvers.d.ts +18 -6
  166. package/dist/modules/bitshares-native/serial/lazy_buffer.d.ts +4 -0
  167. package/dist/modules/bitshares-native/serial/lazy_buffer.js +21 -0
  168. package/dist/modules/bitshares-native/serial/operations.d.ts +1 -1
  169. package/dist/modules/bitshares-native/serial/serializer.d.ts +16 -12
  170. package/dist/modules/bitshares-native/serial/serializer.js +7 -13
  171. package/dist/modules/bitshares-native/serial/types.d.ts +25 -16
  172. package/dist/modules/bitshares-native/serial/types.js +55 -62
  173. package/dist/modules/bitshares-native/signing_client.d.ts +32 -2
  174. package/dist/modules/bitshares-native/signing_client.js +19 -14
  175. package/dist/modules/bitshares-native/subscriptions.d.ts +81 -1
  176. package/dist/modules/bitshares-native/subscriptions.js +12 -12
  177. package/dist/modules/bitshares-native/transport.d.ts +5 -4
  178. package/dist/modules/bitshares-native/transport.js +5 -4
  179. package/dist/modules/bitshares-native/tx/builder.d.ts +40 -5
  180. package/dist/modules/bitshares-native/tx/builder.js +4 -3
  181. package/dist/modules/bitshares-native/tx/tx_cache.d.ts +4 -4
  182. package/dist/modules/bitshares_client.d.ts +45 -13
  183. package/dist/modules/bitshares_client.js +28 -19
  184. package/dist/modules/bot_defaults.d.ts +6 -15
  185. package/dist/modules/bot_defaults.js +1 -5
  186. package/dist/modules/bot_settings.d.ts +44 -10
  187. package/dist/modules/bot_settings.js +11 -8
  188. package/dist/modules/bots_file_lock.d.ts +6 -6
  189. package/dist/modules/bots_file_lock.js +16 -12
  190. package/dist/modules/broadcast_failure.d.ts +2 -2
  191. package/dist/modules/broadcast_failure.js +5 -4
  192. package/dist/modules/chain_keys.d.ts +42 -40
  193. package/dist/modules/chain_keys.js +53 -45
  194. package/dist/modules/chain_orders.d.ts +93 -59
  195. package/dist/modules/chain_orders.js +31 -23
  196. package/dist/modules/constants.d.ts +530 -32
  197. package/dist/modules/constants.js +52 -60
  198. package/dist/modules/cr_planner.d.ts +40 -2
  199. package/dist/modules/credential_policy.d.ts +68 -8
  200. package/dist/modules/credential_policy.js +37 -31
  201. package/dist/modules/credential_session_cache.d.ts +2 -2
  202. package/dist/modules/credit_pricing.d.ts +42 -6
  203. package/dist/modules/credit_pricing.js +44 -30
  204. package/dist/modules/credit_runtime.d.ts +276 -118
  205. package/dist/modules/credit_runtime.js +462 -165
  206. package/dist/modules/crypto/browser_provider.js +6 -4
  207. package/dist/modules/crypto/node_provider.js +1 -1
  208. package/dist/modules/crypto/pure_scrypt.js +35 -4
  209. package/dist/modules/crypto/pure_secp256k1.js +72 -26
  210. package/dist/modules/crypto/sync.d.ts +9 -9
  211. package/dist/modules/crypto/sync.js +16 -9
  212. package/dist/modules/dexbot_class.d.ts +195 -139
  213. package/dist/modules/dexbot_class.js +78 -28
  214. package/dist/modules/dexbot_cow_runtime.d.ts +167 -87
  215. package/dist/modules/dexbot_cow_runtime.js +248 -206
  216. package/dist/modules/dexbot_credential_client.d.ts +19 -11
  217. package/dist/modules/dexbot_fill_runtime.d.ts +63 -48
  218. package/dist/modules/dexbot_fill_runtime.js +48 -41
  219. package/dist/modules/dexbot_maintenance_runtime.d.ts +109 -70
  220. package/dist/modules/dexbot_maintenance_runtime.js +117 -80
  221. package/dist/modules/dexbot_startup_runtime.d.ts +11 -10
  222. package/dist/modules/dexbot_startup_runtime.js +43 -43
  223. package/dist/modules/dexbot_state_recovery.d.ts +13 -12
  224. package/dist/modules/dexbot_state_recovery.js +18 -13
  225. package/dist/modules/fund_registry.d.ts +4 -2
  226. package/dist/modules/fund_registry.js +10 -10
  227. package/dist/modules/general_settings.d.ts +30 -4
  228. package/dist/modules/graceful_shutdown.d.ts +3 -3
  229. package/dist/modules/graceful_shutdown.js +2 -2
  230. package/dist/modules/grid_price_source.d.ts +1 -1
  231. package/dist/modules/key_store.d.ts +14 -8
  232. package/dist/modules/key_store.js +7 -6
  233. package/dist/modules/launcher/adapter_requirement.d.ts +11 -5
  234. package/dist/modules/launcher/adapter_requirement.js +5 -5
  235. package/dist/modules/launcher/bot_supervisor.d.ts +106 -24
  236. package/dist/modules/launcher/bot_supervisor.js +12 -11
  237. package/dist/modules/launcher/credential_bootstrap.d.ts +1 -1
  238. package/dist/modules/launcher/credential_bootstrap.js +1 -1
  239. package/dist/modules/launcher/credential_daemon.d.ts +4 -4
  240. package/dist/modules/launcher/credential_daemon.js +2 -2
  241. package/dist/modules/launcher/credential_secret.d.ts +1 -1
  242. package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -2
  243. package/dist/modules/launcher/market_adapter_runtime.d.ts +61 -6
  244. package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -2
  245. package/dist/modules/launcher/market_adapter_watchdog.js +4 -0
  246. package/dist/modules/launcher/monolithic_runtime.d.ts +18 -16
  247. package/dist/modules/launcher/status_reporting.d.ts +22 -14
  248. package/dist/modules/launcher/supervisor_control.d.ts +8 -1
  249. package/dist/modules/launcher/supervisor_control.js +4 -2
  250. package/dist/modules/market_adapter_whitelist.d.ts +9 -3
  251. package/dist/modules/market_adapter_whitelist.js +15 -3
  252. package/dist/modules/node_manager.d.ts +41 -11
  253. package/dist/modules/node_manager.js +5 -4
  254. package/dist/modules/order/accounting.d.ts +53 -24
  255. package/dist/modules/order/accounting.js +40 -14
  256. package/dist/modules/order/async_lock.d.ts +5 -2
  257. package/dist/modules/order/async_lock.js +1 -1
  258. package/dist/modules/order/export.d.ts +7 -6
  259. package/dist/modules/order/export.js +1 -7
  260. package/dist/modules/order/format.d.ts +39 -19
  261. package/dist/modules/order/format.js +62 -16
  262. package/dist/modules/order/genesis_policy.d.ts +21 -18
  263. package/dist/modules/order/genesis_policy.js +12 -8
  264. package/dist/modules/order/grid.d.ts +142 -36
  265. package/dist/modules/order/grid.js +148 -123
  266. package/dist/modules/order/grid_reconcile.d.ts +21 -20
  267. package/dist/modules/order/grid_reconcile.js +13 -12
  268. package/dist/modules/order/grid_reconcile_internal.d.ts +85 -72
  269. package/dist/modules/order/grid_reconcile_internal.js +28 -19
  270. package/dist/modules/order/index.d.ts +263 -1
  271. package/dist/modules/order/logger.d.ts +45 -11
  272. package/dist/modules/order/logger.js +38 -40
  273. package/dist/modules/order/logger_state.d.ts +4 -4
  274. package/dist/modules/order/manager.d.ts +226 -180
  275. package/dist/modules/order/manager.js +101 -83
  276. package/dist/modules/order/processed_fill_store.d.ts +18 -3
  277. package/dist/modules/order/processed_fill_store.js +16 -27
  278. package/dist/modules/order/strategy.d.ts +21 -13
  279. package/dist/modules/order/strategy.js +5 -6
  280. package/dist/modules/order/sync_engine.d.ts +91 -33
  281. package/dist/modules/order/sync_engine.js +99 -54
  282. package/dist/modules/order/utils/math.d.ts +157 -102
  283. package/dist/modules/order/utils/math.js +77 -38
  284. package/dist/modules/order/utils/order.d.ts +326 -106
  285. package/dist/modules/order/utils/order.js +200 -99
  286. package/dist/modules/order/utils/slot.d.ts +1 -1
  287. package/dist/modules/order/utils/system.d.ts +176 -26
  288. package/dist/modules/order/utils/system.js +86 -69
  289. package/dist/modules/order/utils/validate.d.ts +89 -41
  290. package/dist/modules/order/utils/validate.js +24 -22
  291. package/dist/modules/order/utils/withPoolRef.d.ts +4 -3
  292. package/dist/modules/order/utils/withPoolRef.js +18 -12
  293. package/dist/modules/order/working_grid.d.ts +14 -13
  294. package/dist/modules/paths.d.ts +3 -4
  295. package/dist/modules/paths.js +3 -27
  296. package/dist/modules/process_discovery.d.ts +1 -1
  297. package/dist/modules/process_discovery.js +2 -1
  298. package/dist/modules/runtime.d.ts +7 -3
  299. package/dist/modules/runtime.js +4 -3
  300. package/dist/modules/runtime_settings.d.ts +15 -10
  301. package/dist/modules/runtime_settings.js +30 -24
  302. package/dist/modules/settings_merge.d.ts +29 -3
  303. package/dist/modules/settings_merge.js +56 -78
  304. package/dist/modules/socket_json_client.d.ts +7 -4
  305. package/dist/modules/storage/browser_adapter.d.ts +38 -53
  306. package/dist/modules/storage/browser_adapter.js +7 -30
  307. package/dist/modules/storage/index.d.ts +1 -1
  308. package/dist/modules/storage/node_adapter.d.ts +45 -27
  309. package/dist/modules/storage/node_adapter.js +9 -9
  310. package/dist/modules/storage/types.d.ts +5 -4
  311. package/dist/modules/types.d.ts +1071 -2
  312. package/dist/modules/types.js +4 -1
  313. package/dist/modules/utils/asset_symbols.d.ts +2 -1
  314. package/dist/modules/utils/asset_symbols.js +2 -1
  315. package/dist/modules/utils/errors.d.ts +9 -0
  316. package/dist/modules/utils/errors.js +23 -1
  317. package/dist/modules/utils/time_range.d.ts +4 -0
  318. package/dist/modules/utils/time_range.js +18 -0
  319. package/dist/modules/validate_profiles.js +53 -43
  320. package/dist/modules/version_notice.d.ts +14 -3
  321. package/dist/modules/version_notice.js +6 -4
  322. package/dist/pm2.d.ts +29 -27
  323. package/dist/pm2.js +5 -5
  324. package/dist/scripts/analyze-credit.d.ts +2 -1
  325. package/dist/scripts/analyze-credit.js +23 -24
  326. package/dist/scripts/analyze-orders.d.ts +77 -9
  327. package/dist/scripts/analyze-orders.js +66 -84
  328. package/dist/scripts/chart_command.d.ts +27 -18
  329. package/dist/scripts/chart_command.js +16 -15
  330. package/dist/scripts/check_any.d.ts +18 -0
  331. package/dist/scripts/check_any.js +126 -0
  332. package/dist/scripts/diagnose-pool-history.js +12 -7
  333. package/dist/scripts/pnl.d.ts +3 -0
  334. package/dist/scripts/pnl.js +40 -0
  335. package/dist/scripts/print_grid.js +0 -1
  336. package/dist/scripts/run-tests.js +39 -7
  337. package/dist/scripts/runner.js +1 -1
  338. package/dist/scripts/test-credit-renewal.js +30 -21
  339. package/dist/scripts/update.d.ts +10 -5
  340. package/dist/scripts/update.js +168 -103
  341. package/dist/scripts/update_dist_freshness.js +1 -0
  342. package/dist/scripts/update_layout.d.ts +61 -0
  343. package/dist/scripts/update_layout.js +180 -0
  344. package/dist/scripts/validate_bots.js +2 -1
  345. package/dist/scripts/verify-browser-bundle.js +8 -0
  346. package/dist/unlock.d.ts +28 -3
  347. package/dist/unlock.js +72 -10
  348. package/docs/BITSHARES_ONBOARDING.md +2 -0
  349. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
  350. package/docs/COW_INVARIANTS.md +13 -6
  351. package/docs/DEXBOT_COMPARISON.md +8 -8
  352. package/docs/EVOLUTION.md +12 -10
  353. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
  354. package/docs/GRID_RECALCULATION.md +15 -16
  355. package/docs/GRID_RECONCILE.md +14 -3
  356. package/docs/LIFECYCLE.md +11 -11
  357. package/docs/MPA_CREDIT_USAGE.md +22 -3
  358. package/docs/README.md +15 -4
  359. package/docs/WORKFLOW.md +1 -0
  360. package/docs/architecture.md +12 -9
  361. package/docs/developer_guide.md +6 -6
  362. package/market_adapter/README.md +9 -26
  363. package/modules/README.md +4 -1
  364. package/package.json +4 -1
  365. package/scripts/README.md +14 -0
@@ -3,8 +3,8 @@ declare function parseArgs(): {
3
3
  source: {
4
4
  type: string;
5
5
  config: {
6
- filePath: any;
7
- botKey?: any;
6
+ filePath?: string;
7
+ botKey?: string;
8
8
  };
9
9
  };
10
10
  chartFile: string;
@@ -30,11 +30,22 @@ declare function parseArgs(): {
30
30
  quiet: boolean;
31
31
  listBots: boolean;
32
32
  };
33
- declare function loadJsonMeta(filePath: any): {
34
- candles: any;
35
- meta: any;
33
+ declare function loadJsonMeta(filePath: string | null | undefined): import("../math_utils.js").CandleFile | {
34
+ meta: null;
35
+ candles: null;
36
36
  };
37
- declare function inferTitle(meta: any, fallback: string): string;
37
+ declare function inferTitle(meta: {
38
+ pool?: unknown;
39
+ intervalSeconds?: unknown;
40
+ assetA?: {
41
+ symbol?: unknown;
42
+ id?: unknown;
43
+ };
44
+ assetB?: {
45
+ symbol?: unknown;
46
+ id?: unknown;
47
+ };
48
+ } | null | undefined, fallback: string): string;
38
49
  declare function main(): Promise<void>;
39
50
  export { main, parseArgs, loadJsonMeta, inferTitle };
40
51
  //# sourceMappingURL=analyze_tradingview.d.ts.map
@@ -201,7 +201,7 @@ function inferTitle(meta, fallback) {
201
201
  const b = meta?.assetB?.symbol || meta?.assetB?.id || null;
202
202
  const pair = a && b ? `${a}/${b}` : fallback;
203
203
  const label = pool || pair;
204
- const interval = Number(meta?.intervalSeconds) > 0 ? toIntervalLabel(meta.intervalSeconds) : '1h';
204
+ const interval = Number(meta?.intervalSeconds) > 0 ? toIntervalLabel(Number(meta?.intervalSeconds)) : '1h';
205
205
  return `${label} · ${interval} · TradingView`;
206
206
  }
207
207
  async function main() {
@@ -237,15 +237,16 @@ async function main() {
237
237
  // Bot grid bounds for the range highlight: mirrors the runtime grid
238
238
  // (center = AMA, min "Nx" = center/N, max "Nx" = center*N) with the
239
239
  // live asymmetric tilt. Null when no bot key (width% fallback in-page).
240
+ const asym = botMeta?.asymmetricBounds;
240
241
  const grid = botMeta?.minPrice != null && botMeta?.maxPrice != null ? {
241
242
  minPrice: botMeta.minPrice,
242
243
  maxPrice: botMeta.maxPrice,
243
244
  incrementPercent: Number(botMeta.incrementPercent) > 0 ? Number(botMeta.incrementPercent) : null,
244
- maxAsymmetryFactor: Number.isFinite(Number(botMeta?.asymmetricBounds?.maxAsymmetryFactor))
245
- ? Number(botMeta.asymmetricBounds.maxAsymmetryFactor)
245
+ maxAsymmetryFactor: Number.isFinite(Number(asym?.maxAsymmetryFactor))
246
+ ? Number(asym?.maxAsymmetryFactor)
246
247
  : null,
247
- minScaleSlots: Number.isFinite(Number(botMeta?.asymmetricBounds?.minScaleSlots))
248
- ? Number(botMeta.asymmetricBounds.minScaleSlots)
248
+ minScaleSlots: Number.isFinite(Number(asym?.minScaleSlots))
249
+ ? Number(asym?.minScaleSlots)
249
250
  : null,
250
251
  } : null;
251
252
  // Order overlay (canonical profiles/orders/<botKey>.json; silent when absent)
@@ -286,11 +287,9 @@ async function main() {
286
287
  },
287
288
  smaPeriod: config.smaPeriod,
288
289
  amaDefaults: {
289
- // Intentionally the 3-param AMA (er/fast/slow) only: the in-page
290
- // recomputation has no erSmoothPeriod input by decision — `dexbot tv`
291
- // stays a plain candle chart. The dw research chart and the live
292
- // adapter are the mirrors of the full bot AMA config (incl.
293
- // ama.erSmoothPeriod); the knob is inert by default (global 0).
290
+ // Canonical 3-param AMA (er/fast/slow). The in-page AMA
291
+ // recomputation mirrors the live adapter exactly; `dexbot tv`
292
+ // stays a plain candle chart.
294
293
  erPeriod: config.amaErPeriod ?? amaConfig.erPeriod,
295
294
  fastPeriod: config.amaFastPeriod ?? amaConfig.fastPeriod,
296
295
  slowPeriod: config.amaSlowPeriod ?? amaConfig.slowPeriod,
@@ -5,22 +5,32 @@
5
5
  * @param {Object|null} input.ama Resolved AMA config (er/fast/slow) the chart runs with.
6
6
  * @param {Object} [input.overrides] CLI overrides {priceDeltaThresholdPercent, slopeDeltaThresholdPercent, enabled}.
7
7
  */
8
- declare function resolveGridResetSimConfig({ botKey, bot, ama, overrides }?: any): {
8
+ declare function resolveGridResetSimConfig({ botKey, bot, ama, overrides }?: {
9
+ botKey?: string | null;
10
+ bot?: Record<string, unknown> | null;
11
+ ama?: {
12
+ erPeriod?: number;
13
+ fastPeriod?: number;
14
+ slowPeriod?: number;
15
+ } | null;
16
+ overrides?: Record<string, unknown>;
17
+ }): {
9
18
  enabled: boolean;
10
- botKey: any;
11
- priceDeltaThresholdPercent: any;
12
- priceSource: any;
13
- slopeDeltaThresholdPercent: any;
14
- slopeSource: any;
19
+ botKey: string | null;
20
+ priceDeltaThresholdPercent: number;
21
+ priceSource: string;
22
+ slopeDeltaThresholdPercent: number;
23
+ slopeSource: string;
15
24
  slopeEnabled: boolean;
16
25
  dynamicWeightEnabled: boolean;
17
- lookbackBars: any;
18
- maxSlopePct: any;
26
+ lookbackBars: number;
27
+ slopePersistBars: number;
28
+ maxSlopePct: number;
19
29
  neutralZonePct: number;
20
- maxSlopeOffset: any;
30
+ maxSlopeOffset: number;
21
31
  clipPercentile: number;
22
- maxAsymmetryFactor: any;
23
- minScaleSlots: any;
32
+ maxAsymmetryFactor: number;
33
+ minScaleSlots: number;
24
34
  incrementPercent: number | null;
25
35
  erPeriod: number;
26
36
  warmupBars: number;
@@ -33,29 +43,30 @@ declare function resolveGridResetSimConfig({ botKey, bot, ama, overrides }?: any
33
43
  * Flatten the resolved config for the chart payload, dropping anything the page
34
44
  * must not see (e.g. Infinity from a disabled threshold).
35
45
  */
36
- declare function toGridSimPayload(cfg: any): {
46
+ declare function toGridSimPayload(cfg: Record<string, unknown> | null): {
37
47
  enabled: boolean;
38
- botKey: any;
39
- priceDeltaThresholdPercent: any;
40
- priceSource: any;
41
- slopeDeltaThresholdPercent: any;
42
- slopeSource: any;
48
+ botKey: {} | null;
49
+ priceDeltaThresholdPercent: unknown;
50
+ priceSource: {};
51
+ slopeDeltaThresholdPercent: unknown;
52
+ slopeSource: {};
43
53
  slopeEnabled: boolean;
44
54
  dynamicWeightEnabled: boolean;
45
- lookbackBars: any;
46
- maxSlopePct: any;
47
- neutralZonePct: any;
48
- maxSlopeOffset: any;
49
- clipPercentile: any;
50
- maxAsymmetryFactor: any;
51
- minScaleSlots: any;
52
- incrementPercent: any;
53
- erPeriod: any;
54
- warmupBars: any;
55
- warmupBarsOverride: any;
56
- clampMin: any;
57
- clampMax: any;
58
- notes: any;
55
+ lookbackBars: unknown;
56
+ slopePersistBars: unknown;
57
+ maxSlopePct: unknown;
58
+ neutralZonePct: unknown;
59
+ maxSlopeOffset: unknown;
60
+ clipPercentile: unknown;
61
+ maxAsymmetryFactor: unknown;
62
+ minScaleSlots: unknown;
63
+ incrementPercent: unknown;
64
+ erPeriod: unknown;
65
+ warmupBars: unknown;
66
+ warmupBarsOverride: unknown;
67
+ clampMin: unknown;
68
+ clampMax: unknown;
69
+ notes: any[];
59
70
  } | null;
60
71
  export { resolveGridResetSimConfig, toGridSimPayload };
61
72
  //# sourceMappingURL=grid_reset_config.d.ts.map
@@ -93,8 +93,11 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
93
93
  // ── 2. market_adapter_settings.json (globals → pair → bot)
94
94
  const botCfg = bot ? resolveBotCfg(bot, baseCfg) : baseCfg;
95
95
  const settings = loadMarketAdapterSettings();
96
- const pair = bot ? findPairForBot(bot, settings?.pairs) : null;
97
- const botOverride = pair?.botOverrides?.[bot?.name] || null;
96
+ const pair = bot ? findPairForBot(bot, Array.isArray(settings?.pairs) ? settings.pairs : []) : null;
97
+ const pairObj = pair;
98
+ const botOverride = pairObj?.botOverrides
99
+ ? (pairObj.botOverrides[String(bot?.name)] || null)
100
+ : null;
98
101
  const layers = [
99
102
  { name: SOURCE_ADAPTER_BOT, value: botOverride, keys: [['deltaThresholdPercent']] },
100
103
  { name: SOURCE_ADAPTER_PAIR, value: pair?.marketAdapterSettings, keys: [['deltaThresholdPercent']] },
@@ -143,9 +146,33 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
143
146
  }
144
147
  const erPeriod = firstPositive([ama?.erPeriod, botCfg?.erPeriod], MARKET_ADAPTER.AMAS.AMA3.erPeriod);
145
148
  const lookbackBars = firstPositive([botCfg?.amaSlope?.lookbackBars], MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_LOOKBACK_BARS);
149
+ // Slope-delta persistence gate: mirror resolveAmaSlopePersistBars in the
150
+ // adapter service so the chart replay fires the same Δs resets production
151
+ // does. Per-bot override wins; else the global enable + value; else legacy 1.
152
+ const resolveSlopePersistBars = () => {
153
+ // Mirror resolveAmaSlopePersistBars (market_adapter_service): explicit
154
+ // `persistBars >= 1` wins, `0` disables, and `persistEnabled: false` is a
155
+ // real tri-state override that must beat the global `true`.
156
+ const rawBars = botCfg?.amaSlope?.persistBars ?? botCfg?.amaSlopePersistBars;
157
+ const explicit = (rawBars === null || rawBars === undefined) ? NaN : Number(rawBars);
158
+ if (Number.isFinite(explicit)) {
159
+ if (explicit >= 1)
160
+ return Math.round(explicit);
161
+ if (explicit === 0)
162
+ return 1;
163
+ }
164
+ const override = botCfg?.amaSlope?.persistEnabled ?? botCfg?.amaSlopePersistEnabled;
165
+ const enabled = override === false ? false
166
+ : override === true ? true
167
+ : MARKET_ADAPTER.AMA_SLOPE_PERSIST_ENABLED === true;
168
+ if (!enabled)
169
+ return 1;
170
+ const bars = Number(MARKET_ADAPTER.AMA_SLOPE_PERSIST_BARS);
171
+ return Number.isFinite(bars) && bars >= 1 ? Math.round(bars) : 1;
172
+ };
146
173
  let warmupBars = 0;
147
174
  try {
148
- warmupBars = getAmaWarmupBars(erPeriod, firstPositive([ama?.slowPeriod], MARKET_ADAPTER.AMAS.AMA3.slowPeriod), lookbackBars, firstPositive([ama?.fastPeriod], MARKET_ADAPTER.AMAS.AMA3.fastPeriod), Number(ama?.erSmoothPeriod) > 0 ? Number(ama.erSmoothPeriod) : 0);
175
+ warmupBars = getAmaWarmupBars(erPeriod, firstPositive([ama?.slowPeriod], MARKET_ADAPTER.AMAS.AMA3.slowPeriod), lookbackBars, firstPositive([ama?.fastPeriod], MARKET_ADAPTER.AMAS.AMA3.fastPeriod));
149
176
  }
150
177
  catch (_err) {
151
178
  // getAmaWarmupBars validates strictly; a research-only AMA tweak must
@@ -162,7 +189,7 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
162
189
  return null;
163
190
  try {
164
191
  const bound = resolveConfiguredPriceBound(raw, fallback, 1, mode);
165
- return Number.isFinite(bound) && bound > 0 ? Number(bound) : null;
192
+ return bound != null && Number.isFinite(bound) && bound > 0 ? Number(bound) : null;
166
193
  }
167
194
  catch (_err) {
168
195
  return null;
@@ -180,9 +207,10 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
180
207
  slopeEnabled,
181
208
  dynamicWeightEnabled,
182
209
  lookbackBars,
210
+ slopePersistBars: resolveSlopePersistBars(),
183
211
  maxSlopePct: firstPositive([botCfg?.amaSlope?.maxSlopePct], MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_MAX_SLOPE_PCT),
184
212
  neutralZonePct: Number.isFinite(Number(botCfg?.amaSlope?.neutralZonePct))
185
- ? Number(botCfg.amaSlope.neutralZonePct)
213
+ ? Number(botCfg?.amaSlope?.neutralZonePct)
186
214
  : MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_NEUTRAL_ZONE_PCT,
187
215
  maxSlopeOffset: firstPositive([botCfg?.maxSlopeOffset], MARKET_ADAPTER.DYNAMIC_WEIGHT_ASYMMETRIC_OFFSET_CLAMP),
188
216
  clipPercentile: Number.isFinite(Number(botCfg?.clipPercentile))
@@ -190,7 +218,7 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
190
218
  : MARKET_ADAPTER.DYNAMIC_WEIGHT_CLIP_PERCENTILE,
191
219
  maxAsymmetryFactor: firstPositive([bot?.asymmetricBounds?.maxAsymmetryFactor, botCfg?.asymmetricBounds?.maxAsymmetryFactor], MARKET_ADAPTER.ASYMMETRIC_BOUNDS_MAX_ASYMMETRY_FACTOR),
192
220
  minScaleSlots: firstPositive([botCfg?.asymmetricBounds?.minScaleSlots], MARKET_ADAPTER.ASYMMETRIC_BOUNDS_MIN_SCALE_SLOTS),
193
- incrementPercent: Number.isFinite(Number(bot?.incrementPercent)) ? Number(bot.incrementPercent) : null,
221
+ incrementPercent: Number.isFinite(Number(bot?.incrementPercent)) ? Number(bot?.incrementPercent) : null,
194
222
  erPeriod: Math.ceil(erPeriod),
195
223
  warmupBars,
196
224
  warmupBarsOverride: Number.isFinite(Number(opts.warmupBars)) && Number(opts.warmupBars) >= 0 ? Math.ceil(Number(opts.warmupBars)) : null,
@@ -216,6 +244,7 @@ function toGridSimPayload(cfg) {
216
244
  slopeEnabled: cfg.slopeEnabled === true,
217
245
  dynamicWeightEnabled: cfg.dynamicWeightEnabled === true,
218
246
  lookbackBars: cfg.lookbackBars,
247
+ slopePersistBars: cfg.slopePersistBars,
219
248
  maxSlopePct: cfg.maxSlopePct,
220
249
  neutralZonePct: cfg.neutralZonePct,
221
250
  maxSlopeOffset: cfg.maxSlopeOffset,
@@ -1,16 +1,82 @@
1
+ /**
2
+ * Grid-reset simulation for the TradingView exporter.
3
+ *
4
+ * Replays the market adapter's two grid-recentering triggers over the chart's
5
+ * AMA series, exactly as `market_adapter/core/market_adapter_service.ts`
6
+ * decides them per cycle (see docs/GRID_RECALCULATION.md §3 and §4):
7
+ *
8
+ * A — AMA price delta (`market_adapter_delta_threshold`): the accepted
9
+ * center ratchets only when the AMA moves
10
+ * `|AMA − gridCenterPrice| / gridCenterPrice × 100 >= deltaThresholdPercent`
11
+ * (`deltaThresholdPercent` in the resolved adapter cfg).
12
+ *
13
+ * B — AMA slope delta (`market_adapter_ama_slope_delta_threshold`): gated
14
+ * behind the per-bot `asymmetricBounds` whitelist, fires when
15
+ * `|slopePct − gridRangeScalingAmaSlope.slopePct| >= amaSlopeThresholdPercent`
16
+ * (per-bar %, see `buildAmaSlopeResetDetails`).
17
+ *
18
+ * Ratchet semantics (both triggers): on a reset the accepted center moves to
19
+ * the current AMA **and** the accepted slope baseline is re-seeded to the
20
+ * current slope — the `advanceTriggeredBotState` chain in the service. The
21
+ * price trigger is evaluated first and the slope trigger only runs when no
22
+ * price trigger fired in the same bar, matching the service's if/if-else
23
+ * ordering. This is the same model the OHLC backtest uses
24
+ * (analysis/bot_fitting/backtest_bot_fitting.ts, `simulateForParams`).
25
+ *
26
+ * Deliberate scope limits (the chart replays the *decision*, not the runtime):
27
+ * - one evaluation per 1h bar, no staleness/gap/candle-count suppression
28
+ * gates (fresh closed candles are the norm in a candle file);
29
+ * - the accepted center is the value the grid would be built around, so the
30
+ * simulated range band is frozen between resets and re-tilts from the
31
+ * accepted slope at every reset;
32
+ * - the band is a faithful replay of the grid-build *bounds pipeline*
33
+ * (applyAsymmetricBounds → applyNarrowingSideGuard), but the narrowing
34
+ * guard is centered on the accepted AMA center rather than the live
35
+ * market/start price the runtime uses; the gap is bounded by the reset
36
+ * threshold and only shifts the tightening side by its slot floor;
37
+ * - RMS divergence, available-funds resizes and manual triggers are not
38
+ * simulated (out of scope for a candle chart).
39
+ *
40
+ * The functions below are embedded verbatim into the generated HTML via
41
+ * `embedFunctionSources`, so they may only reference module imports that are
42
+ * embedded alongside them (`computeAverageAmaSlopePct`,
43
+ * `createAmaSlopeClipTracker`, `percentileFromSorted`, `clamp`).
44
+ */
45
+ import { computeHuberWindowSlopePct } from '../../market_adapter/core/strategies/dynamic_weight_series.js';
1
46
  declare const GRID_RESET_NONE = 0;
2
47
  declare const GRID_RESET_BOOTSTRAP = 1;
48
+ interface GridResetEvent {
49
+ index: number;
50
+ reason?: unknown;
51
+ [key: string]: unknown;
52
+ }
53
+ interface GridSimCfg {
54
+ clampMin?: number | null;
55
+ clampMax?: number | null;
56
+ clipPercentile?: number | null;
57
+ erPeriod?: number;
58
+ lookbackBars?: number;
59
+ maxSlopeOffset?: number;
60
+ maxSlopePct?: number;
61
+ neutralZonePct?: number;
62
+ priceDeltaThresholdPercent?: number;
63
+ slopeDeltaThresholdPercent?: number;
64
+ slopeEnabled?: boolean;
65
+ slopePersistBars?: number;
66
+ warmupBars?: number;
67
+ slopeEstimator?: ((amaValues: unknown, index: number, lookbackBars: unknown) => number | null) | null;
68
+ }
3
69
  declare const GRID_RESET_PRICE = 2;
4
70
  declare const GRID_RESET_SLOPE = 3;
5
- declare function gridSimPositiveNumber(value: any, fallback: any): any;
6
- declare function gridSimNonNegativeInt(value: any, fallback: any): any;
71
+ declare function gridSimPositiveNumber(value: unknown, fallback: number): number;
72
+ declare function gridSimNonNegativeInt(value: unknown, fallback: number): number;
7
73
  /**
8
74
  * Average AMA slope in %/bar plus the trend/offset the grid build would use
9
75
  * for that bar, mirroring `computeAmaSlopeWeights` steps 2b–3 (percentile clip
10
76
  * → neutral zone → trend → slopeOffset). The delta trigger itself compares the
11
77
  * UNCLIPPED `slopePct`; the clipped value only feeds the range tilt.
12
78
  */
13
- declare function gridSimSlopeSignal(slopePct: any, clipThreshold: any, cfg: any): {
79
+ declare function gridSimSlopeSignal(slopePct: unknown, clipThreshold: unknown, cfg: GridSimCfg): {
14
80
  slopePct: null;
15
81
  clippedSlopePct: null;
16
82
  trend: null;
@@ -35,7 +101,7 @@ declare function gridSimSlopeSignal(slopePct: any, clipThreshold: any, cfg: any)
35
101
  * model without touching this module — it takes the whole series plus the index
36
102
  * because windowed estimators need the window, not just the two endpoints.
37
103
  */
38
- declare function gridSimResolveSlopeEstimator(cfg: any): any;
104
+ declare function gridSimResolveSlopeEstimator(cfg: GridSimCfg): typeof computeHuberWindowSlopePct;
39
105
  /**
40
106
  * Replay the two market-adapter grid-recentering triggers over `amaSeries`
41
107
  * (the chart's 1h AMA series, already in display orientation).
@@ -47,7 +113,7 @@ declare function gridSimResolveSlopeEstimator(cfg: any): any;
47
113
  * maxSlopeOffset, clipPercentile, clampMin, clampMax.
48
114
  * @returns per-bar series (same length as `amaSeries`) + `events` + `stats`.
49
115
  */
50
- declare function simulateGridResetSeries(amaSeries: any, cfg: any): {
116
+ declare function simulateGridResetSeries(amaSeries: unknown, cfg: GridSimCfg): {
51
117
  center: any[];
52
118
  reason: any[];
53
119
  driftPct: any[];
@@ -56,20 +122,21 @@ declare function simulateGridResetSeries(amaSeries: any, cfg: any): {
56
122
  acceptedSlopePct: any[];
57
123
  acceptedSlopeOffset: any[];
58
124
  acceptedTrend: any[];
59
- events: any[];
125
+ events: GridResetEvent[];
60
126
  stats: {
61
127
  bars: number;
62
128
  resets: number;
63
129
  resetsTotal: number;
64
130
  priceResets: number;
65
131
  slopeResets: number;
66
- bootstrapIndex: any;
132
+ bootstrapIndex: number | null;
67
133
  lastResetIndex: number | null;
68
134
  barsSinceLastReset: number | null;
69
135
  avgBarsBetweenResets: number | null;
70
- warmupBars: any;
136
+ warmupBars: number;
71
137
  priceDeltaThresholdPercent: number | null;
72
138
  slopeDeltaThresholdPercent: number | null;
139
+ slopePersistBars: number;
73
140
  slopeTriggerArmed: boolean;
74
141
  };
75
142
  };
@@ -120,7 +120,8 @@ function gridSimResolveSlopeEstimator(cfg) {
120
120
  * @returns per-bar series (same length as `amaSeries`) + `events` + `stats`.
121
121
  */
122
122
  function simulateGridResetSeries(amaSeries, cfg) {
123
- const n = Array.isArray(amaSeries) ? amaSeries.length : 0;
123
+ const amaArr = Array.isArray(amaSeries) ? amaSeries : [];
124
+ const n = amaArr.length;
124
125
  const priceThreshold = Number(cfg?.priceDeltaThresholdPercent);
125
126
  const priceTriggerArmed = Number.isFinite(priceThreshold) && priceThreshold > 0;
126
127
  const slopeThreshold = Number(cfg?.slopeDeltaThresholdPercent);
@@ -135,6 +136,10 @@ function simulateGridResetSeries(amaSeries, cfg) {
135
136
  const clipPercentile = Number(cfg?.clipPercentile);
136
137
  const clampMinValue = Number(cfg?.clampMin);
137
138
  const clampMaxValue = Number(cfg?.clampMax);
139
+ // Persistence gate on the slope-delta trigger (trigger B): consecutive
140
+ // confirming bars required before it fires. 1 = legacy behavior (fire on the
141
+ // first threshold crossing); >1 filters short-lived slope excursions.
142
+ const slopePersistBars = gridSimNonNegativeInt(cfg?.slopePersistBars, 1);
138
143
  // Mirrors clampGridPriceToBounds: only absolute bot bounds pin the center,
139
144
  // and each side binds independently (a mixed absolute/"Nx" config clamps
140
145
  // only on the absolute side).
@@ -174,6 +179,7 @@ function simulateGridResetSeries(amaSeries, cfg) {
174
179
  warmupBars,
175
180
  priceDeltaThresholdPercent: priceTriggerArmed ? priceThreshold : null,
176
181
  slopeDeltaThresholdPercent: slopeTriggerArmed ? slopeThreshold : null,
182
+ slopePersistBars,
177
183
  slopeTriggerArmed,
178
184
  },
179
185
  };
@@ -189,8 +195,11 @@ function simulateGridResetSeries(amaSeries, cfg) {
189
195
  let resetCount = 0;
190
196
  let priceResets = 0;
191
197
  let slopeResets = 0;
198
+ // Persistence-gate state for trigger B.
199
+ let slopePersistCount = 0;
200
+ let slopePersistDir = 0;
192
201
  for (let i = 0; i < n; i++) {
193
- const ama = Number(amaSeries[i]);
202
+ const ama = Number(amaArr[i]);
194
203
  const hasAma = Number.isFinite(ama) && ama > 0;
195
204
  // Feed the clip tracker every bar (non-finite values keep their slot,
196
205
  // exactly like the batch threshold). The chart's AMA is computed over
@@ -202,7 +211,7 @@ function simulateGridResetSeries(amaSeries, cfg) {
202
211
  const clipThreshold = clipTracker.push(hasAma ? ama : NaN);
203
212
  let slopePct = null;
204
213
  if (hasAma && i >= readyBars) {
205
- const s = estimateSlope(amaSeries, i, lookbackBars);
214
+ const s = estimateSlope(amaArr, i, lookbackBars);
206
215
  if (Number.isFinite(s))
207
216
  slopePct = s;
208
217
  }
@@ -245,10 +254,37 @@ function simulateGridResetSeries(amaSeries, cfg) {
245
254
  else if (priceTriggerArmed && driftPct[i] >= priceThreshold) {
246
255
  fired = GRID_RESET_PRICE;
247
256
  }
248
- else if (slopeTriggerArmed && slopeDeltaPct[i] != null && slopeDeltaPct[i] >= slopeThreshold) {
249
- fired = GRID_RESET_SLOPE;
257
+ else {
258
+ // Trigger B, now persistence-gated: require the threshold to be
259
+ // crossed for `slopePersistBars` consecutive bars in the same
260
+ // direction before firing. A single-bar excursion never charges the
261
+ // counter; a sustained move is confirmed K bars after onset (up to
262
+ // K-1 bars later than the ungated trigger).
263
+ const delta = slopeDeltaPct[i];
264
+ const candidate = slopeTriggerArmed && delta != null && delta >= slopeThreshold;
265
+ if (!candidate) {
266
+ slopePersistCount = 0;
267
+ slopePersistDir = 0;
268
+ }
269
+ else {
270
+ const dir = acceptedSlope != null && slopePct != null ? Math.sign(slopePct - acceptedSlope) : 0;
271
+ if (slopePersistBars <= 1) {
272
+ fired = GRID_RESET_SLOPE;
273
+ }
274
+ else if (dir !== 0 && dir === slopePersistDir) {
275
+ slopePersistCount++;
276
+ if (slopePersistCount >= slopePersistBars)
277
+ fired = GRID_RESET_SLOPE;
278
+ }
279
+ else {
280
+ slopePersistDir = dir;
281
+ slopePersistCount = 1;
282
+ }
283
+ }
250
284
  }
251
285
  if (fired !== GRID_RESET_NONE) {
286
+ slopePersistCount = 0;
287
+ slopePersistDir = 0;
252
288
  const previousCenter = acceptedCenter;
253
289
  acceptedCenter = currentCenter;
254
290
  // Re-seed the accepted slope on EVERY reset (price and slope alike),
@@ -312,6 +348,7 @@ function simulateGridResetSeries(amaSeries, cfg) {
312
348
  warmupBars,
313
349
  priceDeltaThresholdPercent: priceTriggerArmed ? priceThreshold : null,
314
350
  slopeDeltaThresholdPercent: slopeTriggerArmed ? slopeThreshold : null,
351
+ slopePersistBars,
315
352
  slopeTriggerArmed,
316
353
  },
317
354
  };
@@ -1,9 +1,74 @@
1
1
  import { normalizeCandle } from '../math_utils.js';
2
- declare function loadMarketProfiles(filePath?: any): any;
2
+ interface MarketMeta {
3
+ intervalSeconds?: unknown;
4
+ pool?: unknown;
5
+ poolId?: unknown;
6
+ feed?: unknown;
7
+ assetA?: {
8
+ symbol?: string;
9
+ id?: string;
10
+ };
11
+ assetB?: {
12
+ symbol?: string;
13
+ id?: string;
14
+ };
15
+ }
16
+ interface AmaDefaultsInput {
17
+ amaDefaults?: {
18
+ erPeriod?: unknown;
19
+ fastPeriod?: unknown;
20
+ slowPeriod?: unknown;
21
+ } | null;
22
+ amaErPeriod?: unknown;
23
+ amaFastPeriod?: unknown;
24
+ amaSlowPeriod?: unknown;
25
+ }
26
+ declare function loadMarketProfiles(filePath?: string | null | undefined): {
27
+ profiles?: Array<Record<string, unknown>>;
28
+ } | null;
3
29
  declare const TRADINGVIEW_PREFS_KEY_PREFIX = "dexbot2-tradingview-uplot-v3";
4
30
  declare const TRADINGVIEW_SYNC_KEY = "dexbot2-tradingview-sync";
5
- declare function sanitizeStorageComponent(value: any, fallback: string): string;
6
- declare function resolveChartStorageKey(meta?: any, baseIntervalSeconds?: any): string;
7
- declare function generateHTML(data: any, title?: any): string;
31
+ declare function sanitizeStorageComponent(value: unknown, fallback: string): string;
32
+ declare function resolveChartStorageKey(meta?: MarketMeta, baseIntervalSeconds?: number): string;
33
+ interface TvChartInput extends AmaDefaultsInput {
34
+ candles?: unknown[];
35
+ meta?: MarketMeta;
36
+ defaultTimeframe?: string;
37
+ marketProfiles?: unknown;
38
+ smaPeriod?: number;
39
+ smaEnabled?: boolean;
40
+ amaEnabled?: boolean;
41
+ vwapEnabled?: boolean;
42
+ vwapBars?: number;
43
+ priceScale?: string;
44
+ rangeWidthPct?: number;
45
+ rangeSpan?: number;
46
+ grid?: {
47
+ minPrice?: unknown;
48
+ maxPrice?: unknown;
49
+ incrementPercent?: number | null;
50
+ maxAsymmetryFactor?: number | null;
51
+ minScaleSlots?: number | null;
52
+ [key: string]: unknown;
53
+ } | null;
54
+ gridSim?: {
55
+ enabled?: boolean;
56
+ [key: string]: unknown;
57
+ } | null;
58
+ gridBounds?: {
59
+ low?: unknown;
60
+ high?: unknown;
61
+ };
62
+ orders?: {
63
+ buys?: unknown[];
64
+ sells?: unknown[];
65
+ };
66
+ storageKey?: string;
67
+ defaultPairMode?: string;
68
+ updateMarkerTsSec?: number | null;
69
+ updateMarkerNewBars?: number | null;
70
+ [key: string]: unknown;
71
+ }
72
+ declare function generateHTML(data: TvChartInput, title?: string): string;
8
73
  export { generateHTML, normalizeCandle, loadMarketProfiles, resolveChartStorageKey, sanitizeStorageComponent, TRADINGVIEW_PREFS_KEY_PREFIX, TRADINGVIEW_SYNC_KEY };
9
74
  //# sourceMappingURL=tradingview_uplot_chart_generator.d.ts.map