dexbot 1.1.10

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 (807) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +287 -0
  3. package/claw/README.md +513 -0
  4. package/claw/scripts/memu_runner.py +385 -0
  5. package/claw/skills/bitshares-guide/SKILL.md +14 -0
  6. package/claw/skills/bitshares-guide/references/example-skill-shells.md +18 -0
  7. package/claw/skills/bitshares-guide/references/presentation-patterns.md +19 -0
  8. package/claw/skills/bitshares-guide/references/scope-guardrails.md +9 -0
  9. package/claw/skills/launcher-ops/SKILL.md +18 -0
  10. package/claw/skills/launcher-ops/references/launcher-workflow.md +23 -0
  11. package/claw/skills/margin-trading/SKILL.md +23 -0
  12. package/claw/skills/margin-trading/references/honest-asset-list.md +74 -0
  13. package/claw/skills/margin-trading/references/honest-assets.md +44 -0
  14. package/claw/skills/margin-trading/references/position-management.md +203 -0
  15. package/claw/skills/margin-trading/references/trading-concepts.md +80 -0
  16. package/claw/skills/memu-memory/SKILL.md +218 -0
  17. package/claw/skills/shared/references/js-automation-overview.md +24 -0
  18. package/claw/skills/shared/references/safety-and-staleness.md +11 -0
  19. package/claw/skills/shared/references/skill-boundaries.md +17 -0
  20. package/claw/skills/trend-detection/SKILL.md +33 -0
  21. package/claw/skills/trend-detection/agents/openai.yaml +3 -0
  22. package/claw/skills/trend-detection/references/service.md +45 -0
  23. package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts +3 -0
  24. package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +1 -0
  25. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +149 -0
  26. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +1 -0
  27. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts +3 -0
  28. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +1 -0
  29. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +387 -0
  30. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +1 -0
  31. package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts +3 -0
  32. package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +1 -0
  33. package/dist/analysis/ama_fitting/calibrate_convergence_er.js +200 -0
  34. package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +1 -0
  35. package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts +3 -0
  36. package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +1 -0
  37. package/dist/analysis/ama_fitting/fetch_lp_candles.js +212 -0
  38. package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +1 -0
  39. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +31 -0
  40. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +1 -0
  41. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +249 -0
  42. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +1 -0
  43. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts +2 -0
  44. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +1 -0
  45. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +782 -0
  46. package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +1 -0
  47. package/dist/analysis/analyze_derivatives.d.ts +95 -0
  48. package/dist/analysis/analyze_derivatives.d.ts.map +1 -0
  49. package/dist/analysis/analyze_derivatives.js +295 -0
  50. package/dist/analysis/analyze_derivatives.js.map +1 -0
  51. package/dist/analysis/analyze_dynamic_weight.d.ts +14 -0
  52. package/dist/analysis/analyze_dynamic_weight.d.ts.map +1 -0
  53. package/dist/analysis/analyze_dynamic_weight.js +208 -0
  54. package/dist/analysis/analyze_dynamic_weight.js.map +1 -0
  55. package/dist/analysis/analyze_kalman.d.ts +13 -0
  56. package/dist/analysis/analyze_kalman.d.ts.map +1 -0
  57. package/dist/analysis/analyze_kalman.js +123 -0
  58. package/dist/analysis/analyze_kalman.js.map +1 -0
  59. package/dist/analysis/analyze_regime.d.ts +20 -0
  60. package/dist/analysis/analyze_regime.d.ts.map +1 -0
  61. package/dist/analysis/analyze_regime.js +139 -0
  62. package/dist/analysis/analyze_regime.js.map +1 -0
  63. package/dist/analysis/analyze_regime_windows.d.ts +19 -0
  64. package/dist/analysis/analyze_regime_windows.d.ts.map +1 -0
  65. package/dist/analysis/analyze_regime_windows.js +413 -0
  66. package/dist/analysis/analyze_regime_windows.js.map +1 -0
  67. package/dist/analysis/analyze_risk_profile.d.ts +3 -0
  68. package/dist/analysis/analyze_risk_profile.d.ts.map +1 -0
  69. package/dist/analysis/analyze_risk_profile.js +159 -0
  70. package/dist/analysis/analyze_risk_profile.js.map +1 -0
  71. package/dist/analysis/analyze_trade_heatmap.d.ts +3 -0
  72. package/dist/analysis/analyze_trade_heatmap.d.ts.map +1 -0
  73. package/dist/analysis/analyze_trade_heatmap.js +367 -0
  74. package/dist/analysis/analyze_trade_heatmap.js.map +1 -0
  75. package/dist/analysis/analyze_volatility.d.ts +22 -0
  76. package/dist/analysis/analyze_volatility.d.ts.map +1 -0
  77. package/dist/analysis/analyze_volatility.js +172 -0
  78. package/dist/analysis/analyze_volatility.js.map +1 -0
  79. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +99 -0
  80. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +1 -0
  81. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +804 -0
  82. package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +1 -0
  83. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +2 -0
  84. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +1 -0
  85. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +347 -0
  86. package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +1 -0
  87. package/dist/analysis/bot_fitting/shared_utils.d.ts +15 -0
  88. package/dist/analysis/bot_fitting/shared_utils.d.ts.map +1 -0
  89. package/dist/analysis/bot_fitting/shared_utils.js +48 -0
  90. package/dist/analysis/bot_fitting/shared_utils.js.map +1 -0
  91. package/dist/analysis/bot_key_utils.d.ts +16 -0
  92. package/dist/analysis/bot_key_utils.d.ts.map +1 -0
  93. package/dist/analysis/bot_key_utils.js +61 -0
  94. package/dist/analysis/bot_key_utils.js.map +1 -0
  95. package/dist/analysis/bot_usage/discover_bot_accounts.d.ts +3 -0
  96. package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +1 -0
  97. package/dist/analysis/bot_usage/discover_bot_accounts.js +498 -0
  98. package/dist/analysis/bot_usage/discover_bot_accounts.js.map +1 -0
  99. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +546 -0
  100. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -0
  101. package/dist/analysis/bot_usage/kibana_bot_queries.js +427 -0
  102. package/dist/analysis/bot_usage/kibana_bot_queries.js.map +1 -0
  103. package/dist/analysis/chart_utils.d.ts +13 -0
  104. package/dist/analysis/chart_utils.d.ts.map +1 -0
  105. package/dist/analysis/chart_utils.js +142 -0
  106. package/dist/analysis/chart_utils.js.map +1 -0
  107. package/dist/analysis/derivative_chart_generator.d.ts +18 -0
  108. package/dist/analysis/derivative_chart_generator.d.ts.map +1 -0
  109. package/dist/analysis/derivative_chart_generator.js +896 -0
  110. package/dist/analysis/derivative_chart_generator.js.map +1 -0
  111. package/dist/analysis/math_utils.d.ts +35 -0
  112. package/dist/analysis/math_utils.d.ts.map +1 -0
  113. package/dist/analysis/math_utils.js +121 -0
  114. package/dist/analysis/math_utils.js.map +1 -0
  115. package/dist/analysis/price_sources.d.ts +34 -0
  116. package/dist/analysis/price_sources.d.ts.map +1 -0
  117. package/dist/analysis/price_sources.js +103 -0
  118. package/dist/analysis/price_sources.js.map +1 -0
  119. package/dist/analysis/trade_profitability.d.ts +115 -0
  120. package/dist/analysis/trade_profitability.d.ts.map +1 -0
  121. package/dist/analysis/trade_profitability.js +1247 -0
  122. package/dist/analysis/trade_profitability.js.map +1 -0
  123. package/dist/analysis/tradingview/analyze_tradingview.d.ts +38 -0
  124. package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +1 -0
  125. package/dist/analysis/tradingview/analyze_tradingview.js +212 -0
  126. package/dist/analysis/tradingview/analyze_tradingview.js.map +1 -0
  127. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +9 -0
  128. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -0
  129. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +1717 -0
  130. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -0
  131. package/dist/analysis/trend_detection/derivative_analyzer.d.ts +250 -0
  132. package/dist/analysis/trend_detection/derivative_analyzer.d.ts.map +1 -0
  133. package/dist/analysis/trend_detection/derivative_analyzer.js +903 -0
  134. package/dist/analysis/trend_detection/derivative_analyzer.js.map +1 -0
  135. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +6 -0
  136. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +1 -0
  137. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +1449 -0
  138. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +1 -0
  139. package/dist/analysis/trend_detection/hurst_analyzer.d.ts +42 -0
  140. package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +1 -0
  141. package/dist/analysis/trend_detection/hurst_analyzer.js +159 -0
  142. package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -0
  143. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +6 -0
  144. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +1 -0
  145. package/dist/analysis/trend_detection/kalman_chart_generator.js +408 -0
  146. package/dist/analysis/trend_detection/kalman_chart_generator.js.map +1 -0
  147. package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts +103 -0
  148. package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +1 -0
  149. package/dist/analysis/trend_detection/kalman_trend_analyzer.js +229 -0
  150. package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -0
  151. package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts +34 -0
  152. package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +1 -0
  153. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +89 -0
  154. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -0
  155. package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts +39 -0
  156. package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +1 -0
  157. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +132 -0
  158. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -0
  159. package/dist/analysis/trend_detection/regime_chart_generator.d.ts +6 -0
  160. package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +1 -0
  161. package/dist/analysis/trend_detection/regime_chart_generator.js +345 -0
  162. package/dist/analysis/trend_detection/regime_chart_generator.js.map +1 -0
  163. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +2 -0
  164. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +1 -0
  165. package/dist/analysis/trend_detection/tests/test_kalman_trend.js +130 -0
  166. package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +1 -0
  167. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +2 -0
  168. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +1 -0
  169. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +38 -0
  170. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +1 -0
  171. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +6 -0
  172. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +1 -0
  173. package/dist/analysis/trend_detection/volatility_chart_generator.js +732 -0
  174. package/dist/analysis/trend_detection/volatility_chart_generator.js.map +1 -0
  175. package/dist/bot.d.ts +49 -0
  176. package/dist/bot.d.ts.map +1 -0
  177. package/dist/bot.js +221 -0
  178. package/dist/bot.js.map +1 -0
  179. package/dist/credential-daemon.d.ts +64 -0
  180. package/dist/credential-daemon.d.ts.map +1 -0
  181. package/dist/credential-daemon.js +987 -0
  182. package/dist/credential-daemon.js.map +1 -0
  183. package/dist/dexbot.d.ts +87 -0
  184. package/dist/dexbot.d.ts.map +1 -0
  185. package/dist/dexbot.js +1222 -0
  186. package/dist/dexbot.js.map +1 -0
  187. package/dist/market_adapter/ama_signal_runner.d.ts +3 -0
  188. package/dist/market_adapter/ama_signal_runner.d.ts.map +1 -0
  189. package/dist/market_adapter/ama_signal_runner.js +175 -0
  190. package/dist/market_adapter/ama_signal_runner.js.map +1 -0
  191. package/dist/market_adapter/candle_utils.d.ts +57 -0
  192. package/dist/market_adapter/candle_utils.d.ts.map +1 -0
  193. package/dist/market_adapter/candle_utils.js +252 -0
  194. package/dist/market_adapter/candle_utils.js.map +1 -0
  195. package/dist/market_adapter/core/asymmetric_bounds.d.ts +20 -0
  196. package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +1 -0
  197. package/dist/market_adapter/core/asymmetric_bounds.js +88 -0
  198. package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -0
  199. package/dist/market_adapter/core/config_normalizers.d.ts +10 -0
  200. package/dist/market_adapter/core/config_normalizers.d.ts.map +1 -0
  201. package/dist/market_adapter/core/config_normalizers.js +24 -0
  202. package/dist/market_adapter/core/config_normalizers.js.map +1 -0
  203. package/dist/market_adapter/core/kibana_candles.d.ts +74 -0
  204. package/dist/market_adapter/core/kibana_candles.d.ts.map +1 -0
  205. package/dist/market_adapter/core/kibana_candles.js +249 -0
  206. package/dist/market_adapter/core/kibana_candles.js.map +1 -0
  207. package/dist/market_adapter/core/kibana_client.d.ts +27 -0
  208. package/dist/market_adapter/core/kibana_client.d.ts.map +1 -0
  209. package/dist/market_adapter/core/kibana_client.js +120 -0
  210. package/dist/market_adapter/core/kibana_client.js.map +1 -0
  211. package/dist/market_adapter/core/kibana_market_candles.d.ts +143 -0
  212. package/dist/market_adapter/core/kibana_market_candles.d.ts.map +1 -0
  213. package/dist/market_adapter/core/kibana_market_candles.js +170 -0
  214. package/dist/market_adapter/core/kibana_market_candles.js.map +1 -0
  215. package/dist/market_adapter/core/market_adapter_service.d.ts +210 -0
  216. package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -0
  217. package/dist/market_adapter/core/market_adapter_service.js +2328 -0
  218. package/dist/market_adapter/core/market_adapter_service.js.map +1 -0
  219. package/dist/market_adapter/core/strategies/ama.d.ts +2 -0
  220. package/dist/market_adapter/core/strategies/ama.d.ts.map +1 -0
  221. package/dist/market_adapter/core/strategies/ama.js +138 -0
  222. package/dist/market_adapter/core/strategies/ama.js.map +1 -0
  223. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +50 -0
  224. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +1 -0
  225. package/dist/market_adapter/core/strategies/ama_slope_model.js +143 -0
  226. package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -0
  227. package/dist/market_adapter/core/strategies/atr/calculator.d.ts +12 -0
  228. package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +1 -0
  229. package/dist/market_adapter/core/strategies/atr/calculator.js +47 -0
  230. package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -0
  231. package/dist/market_adapter/core/strategies/collateral_manager.d.ts +32 -0
  232. package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +1 -0
  233. package/dist/market_adapter/core/strategies/collateral_manager.js +68 -0
  234. package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -0
  235. package/dist/market_adapter/core/strategies/regime_gate.d.ts +66 -0
  236. package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -0
  237. package/dist/market_adapter/core/strategies/regime_gate.js +189 -0
  238. package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -0
  239. package/dist/market_adapter/index.d.ts +10 -0
  240. package/dist/market_adapter/index.d.ts.map +1 -0
  241. package/dist/market_adapter/index.js +71 -0
  242. package/dist/market_adapter/index.js.map +1 -0
  243. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts +3 -0
  244. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +1 -0
  245. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +1165 -0
  246. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -0
  247. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +54 -0
  248. package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -0
  249. package/dist/market_adapter/inputs/fetch_lp_data.js +743 -0
  250. package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -0
  251. package/dist/market_adapter/inputs/kibana_source.d.ts +68 -0
  252. package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -0
  253. package/dist/market_adapter/inputs/kibana_source.js +143 -0
  254. package/dist/market_adapter/inputs/kibana_source.js.map +1 -0
  255. package/dist/market_adapter/interval_utils.d.ts +6 -0
  256. package/dist/market_adapter/interval_utils.d.ts.map +1 -0
  257. package/dist/market_adapter/interval_utils.js +14 -0
  258. package/dist/market_adapter/interval_utils.js.map +1 -0
  259. package/dist/market_adapter/log_format.d.ts +16 -0
  260. package/dist/market_adapter/log_format.d.ts.map +1 -0
  261. package/dist/market_adapter/log_format.js +72 -0
  262. package/dist/market_adapter/log_format.js.map +1 -0
  263. package/dist/market_adapter/lp_chart_core.d.ts +6 -0
  264. package/dist/market_adapter/lp_chart_core.d.ts.map +1 -0
  265. package/dist/market_adapter/lp_chart_core.js +874 -0
  266. package/dist/market_adapter/lp_chart_core.js.map +1 -0
  267. package/dist/market_adapter/lp_chart_runner.d.ts +135 -0
  268. package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -0
  269. package/dist/market_adapter/lp_chart_runner.js +337 -0
  270. package/dist/market_adapter/lp_chart_runner.js.map +1 -0
  271. package/dist/market_adapter/lp_chart_strategy_loader.d.ts +23 -0
  272. package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +1 -0
  273. package/dist/market_adapter/lp_chart_strategy_loader.js +169 -0
  274. package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -0
  275. package/dist/market_adapter/market_adapter.d.ts +133 -0
  276. package/dist/market_adapter/market_adapter.d.ts.map +1 -0
  277. package/dist/market_adapter/market_adapter.js +1331 -0
  278. package/dist/market_adapter/market_adapter.js.map +1 -0
  279. package/dist/market_adapter/merge_lp_data.d.ts +3 -0
  280. package/dist/market_adapter/merge_lp_data.d.ts.map +1 -0
  281. package/dist/market_adapter/merge_lp_data.js +125 -0
  282. package/dist/market_adapter/merge_lp_data.js.map +1 -0
  283. package/dist/market_adapter/test_helpers.d.ts +14 -0
  284. package/dist/market_adapter/test_helpers.d.ts.map +1 -0
  285. package/dist/market_adapter/test_helpers.js +22 -0
  286. package/dist/market_adapter/test_helpers.js.map +1 -0
  287. package/dist/market_adapter/utils/adapter_client.d.ts +20 -0
  288. package/dist/market_adapter/utils/adapter_client.d.ts.map +1 -0
  289. package/dist/market_adapter/utils/adapter_client.js +88 -0
  290. package/dist/market_adapter/utils/adapter_client.js.map +1 -0
  291. package/dist/market_adapter/utils/atomic_write.d.ts +9 -0
  292. package/dist/market_adapter/utils/atomic_write.d.ts.map +1 -0
  293. package/dist/market_adapter/utils/atomic_write.js +13 -0
  294. package/dist/market_adapter/utils/atomic_write.js.map +1 -0
  295. package/dist/market_adapter/utils/chain.d.ts +50 -0
  296. package/dist/market_adapter/utils/chain.d.ts.map +1 -0
  297. package/dist/market_adapter/utils/chain.js +196 -0
  298. package/dist/market_adapter/utils/chain.js.map +1 -0
  299. package/dist/market_adapter/utils/data_discovery.d.ts +6 -0
  300. package/dist/market_adapter/utils/data_discovery.d.ts.map +1 -0
  301. package/dist/market_adapter/utils/data_discovery.js +35 -0
  302. package/dist/market_adapter/utils/data_discovery.js.map +1 -0
  303. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +15 -0
  304. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -0
  305. package/dist/market_adapter/utils/dynamic_grid_snapshot.js +60 -0
  306. package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -0
  307. package/dist/market_adapter/utils/file_lock.d.ts +19 -0
  308. package/dist/market_adapter/utils/file_lock.d.ts.map +1 -0
  309. package/dist/market_adapter/utils/file_lock.js +191 -0
  310. package/dist/market_adapter/utils/file_lock.js.map +1 -0
  311. package/dist/market_adapter/utils/native_history.d.ts +19 -0
  312. package/dist/market_adapter/utils/native_history.d.ts.map +1 -0
  313. package/dist/market_adapter/utils/native_history.js +172 -0
  314. package/dist/market_adapter/utils/native_history.js.map +1 -0
  315. package/dist/market_adapter/utils/paths.d.ts +5 -0
  316. package/dist/market_adapter/utils/paths.d.ts.map +1 -0
  317. package/dist/market_adapter/utils/paths.js +7 -0
  318. package/dist/market_adapter/utils/paths.js.map +1 -0
  319. package/dist/modules/account_bots.d.ts +112 -0
  320. package/dist/modules/account_bots.d.ts.map +1 -0
  321. package/dist/modules/account_bots.js +1259 -0
  322. package/dist/modules/account_bots.js.map +1 -0
  323. package/dist/modules/account_orders.d.ts +273 -0
  324. package/dist/modules/account_orders.d.ts.map +1 -0
  325. package/dist/modules/account_orders.js +662 -0
  326. package/dist/modules/account_orders.js.map +1 -0
  327. package/dist/modules/authority_resolver.d.ts +2 -0
  328. package/dist/modules/authority_resolver.d.ts.map +1 -0
  329. package/dist/modules/authority_resolver.js +231 -0
  330. package/dist/modules/authority_resolver.js.map +1 -0
  331. package/dist/modules/bitshares-native/chain_client.d.ts +38 -0
  332. package/dist/modules/bitshares-native/chain_client.d.ts.map +1 -0
  333. package/dist/modules/bitshares-native/chain_client.js +322 -0
  334. package/dist/modules/bitshares-native/chain_client.js.map +1 -0
  335. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts +59 -0
  336. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +1 -0
  337. package/dist/modules/bitshares-native/crypto/ecc.browser.js +456 -0
  338. package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -0
  339. package/dist/modules/bitshares-native/crypto/ecc.d.ts +66 -0
  340. package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +1 -0
  341. package/dist/modules/bitshares-native/crypto/ecc.js +557 -0
  342. package/dist/modules/bitshares-native/crypto/ecc.js.map +1 -0
  343. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -0
  344. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +1 -0
  345. package/dist/modules/bitshares-native/crypto/ecc_selector.js +20 -0
  346. package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -0
  347. package/dist/modules/bitshares-native/index.d.ts +3 -0
  348. package/dist/modules/bitshares-native/index.d.ts.map +1 -0
  349. package/dist/modules/bitshares-native/index.js +32 -0
  350. package/dist/modules/bitshares-native/index.js.map +1 -0
  351. package/dist/modules/bitshares-native/resolvers.d.ts +40 -0
  352. package/dist/modules/bitshares-native/resolvers.d.ts.map +1 -0
  353. package/dist/modules/bitshares-native/resolvers.js +161 -0
  354. package/dist/modules/bitshares-native/resolvers.js.map +1 -0
  355. package/dist/modules/bitshares-native/serial/chain_constants.d.ts +56 -0
  356. package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +1 -0
  357. package/dist/modules/bitshares-native/serial/chain_constants.js +92 -0
  358. package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -0
  359. package/dist/modules/bitshares-native/serial/index.d.ts +10 -0
  360. package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -0
  361. package/dist/modules/bitshares-native/serial/index.js +14 -0
  362. package/dist/modules/bitshares-native/serial/index.js.map +1 -0
  363. package/dist/modules/bitshares-native/serial/operations.d.ts +102 -0
  364. package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -0
  365. package/dist/modules/bitshares-native/serial/operations.js +615 -0
  366. package/dist/modules/bitshares-native/serial/operations.js.map +1 -0
  367. package/dist/modules/bitshares-native/serial/serializer.d.ts +64 -0
  368. package/dist/modules/bitshares-native/serial/serializer.d.ts.map +1 -0
  369. package/dist/modules/bitshares-native/serial/serializer.js +252 -0
  370. package/dist/modules/bitshares-native/serial/serializer.js.map +1 -0
  371. package/dist/modules/bitshares-native/serial/types.d.ts +120 -0
  372. package/dist/modules/bitshares-native/serial/types.d.ts.map +1 -0
  373. package/dist/modules/bitshares-native/serial/types.js +837 -0
  374. package/dist/modules/bitshares-native/serial/types.js.map +1 -0
  375. package/dist/modules/bitshares-native/signing_client.d.ts +6 -0
  376. package/dist/modules/bitshares-native/signing_client.d.ts.map +1 -0
  377. package/dist/modules/bitshares-native/signing_client.js +141 -0
  378. package/dist/modules/bitshares-native/signing_client.js.map +1 -0
  379. package/dist/modules/bitshares-native/subscriptions.d.ts +6 -0
  380. package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -0
  381. package/dist/modules/bitshares-native/subscriptions.js +865 -0
  382. package/dist/modules/bitshares-native/subscriptions.js.map +1 -0
  383. package/dist/modules/bitshares-native/transport.d.ts +51 -0
  384. package/dist/modules/bitshares-native/transport.d.ts.map +1 -0
  385. package/dist/modules/bitshares-native/transport.js +447 -0
  386. package/dist/modules/bitshares-native/transport.js.map +1 -0
  387. package/dist/modules/bitshares-native/tx/builder.d.ts +30 -0
  388. package/dist/modules/bitshares-native/tx/builder.d.ts.map +1 -0
  389. package/dist/modules/bitshares-native/tx/builder.js +262 -0
  390. package/dist/modules/bitshares-native/tx/builder.js.map +1 -0
  391. package/dist/modules/bitshares_client.d.ts +129 -0
  392. package/dist/modules/bitshares_client.d.ts.map +1 -0
  393. package/dist/modules/bitshares_client.js +627 -0
  394. package/dist/modules/bitshares_client.js.map +1 -0
  395. package/dist/modules/bot_settings.d.ts +33 -0
  396. package/dist/modules/bot_settings.d.ts.map +1 -0
  397. package/dist/modules/bot_settings.js +328 -0
  398. package/dist/modules/bot_settings.js.map +1 -0
  399. package/dist/modules/bots_file_lock.d.ts +88 -0
  400. package/dist/modules/bots_file_lock.d.ts.map +1 -0
  401. package/dist/modules/bots_file_lock.js +161 -0
  402. package/dist/modules/bots_file_lock.js.map +1 -0
  403. package/dist/modules/chain_keys.d.ts +302 -0
  404. package/dist/modules/chain_keys.d.ts.map +1 -0
  405. package/dist/modules/chain_keys.js +1095 -0
  406. package/dist/modules/chain_keys.js.map +1 -0
  407. package/dist/modules/chain_orders.d.ts +423 -0
  408. package/dist/modules/chain_orders.d.ts.map +1 -0
  409. package/dist/modules/chain_orders.js +1201 -0
  410. package/dist/modules/chain_orders.js.map +1 -0
  411. package/dist/modules/cli_whitelist_args.d.ts +6 -0
  412. package/dist/modules/cli_whitelist_args.d.ts.map +1 -0
  413. package/dist/modules/cli_whitelist_args.js +13 -0
  414. package/dist/modules/cli_whitelist_args.js.map +1 -0
  415. package/dist/modules/config.d.ts +57 -0
  416. package/dist/modules/config.d.ts.map +1 -0
  417. package/dist/modules/config.js +107 -0
  418. package/dist/modules/config.js.map +1 -0
  419. package/dist/modules/constants.d.ts +635 -0
  420. package/dist/modules/constants.d.ts.map +1 -0
  421. package/dist/modules/constants.js +1464 -0
  422. package/dist/modules/constants.js.map +1 -0
  423. package/dist/modules/cr_planner.d.ts +51 -0
  424. package/dist/modules/cr_planner.d.ts.map +1 -0
  425. package/dist/modules/cr_planner.js +299 -0
  426. package/dist/modules/cr_planner.js.map +1 -0
  427. package/dist/modules/credential_policy.d.ts +188 -0
  428. package/dist/modules/credential_policy.d.ts.map +1 -0
  429. package/dist/modules/credential_policy.js +1452 -0
  430. package/dist/modules/credential_policy.js.map +1 -0
  431. package/dist/modules/credential_runtime.d.ts +42 -0
  432. package/dist/modules/credential_runtime.d.ts.map +1 -0
  433. package/dist/modules/credential_runtime.js +148 -0
  434. package/dist/modules/credential_runtime.js.map +1 -0
  435. package/dist/modules/credential_session_cache.d.ts +36 -0
  436. package/dist/modules/credential_session_cache.d.ts.map +1 -0
  437. package/dist/modules/credential_session_cache.js +106 -0
  438. package/dist/modules/credential_session_cache.js.map +1 -0
  439. package/dist/modules/credit_runtime.d.ts +412 -0
  440. package/dist/modules/credit_runtime.d.ts.map +1 -0
  441. package/dist/modules/credit_runtime.js +2866 -0
  442. package/dist/modules/credit_runtime.js.map +1 -0
  443. package/dist/modules/crypto/browser_provider.d.ts +15 -0
  444. package/dist/modules/crypto/browser_provider.d.ts.map +1 -0
  445. package/dist/modules/crypto/browser_provider.js +113 -0
  446. package/dist/modules/crypto/browser_provider.js.map +1 -0
  447. package/dist/modules/crypto/index.d.ts +9 -0
  448. package/dist/modules/crypto/index.d.ts.map +1 -0
  449. package/dist/modules/crypto/index.js +44 -0
  450. package/dist/modules/crypto/index.js.map +1 -0
  451. package/dist/modules/crypto/node_provider.d.ts +15 -0
  452. package/dist/modules/crypto/node_provider.d.ts.map +1 -0
  453. package/dist/modules/crypto/node_provider.js +74 -0
  454. package/dist/modules/crypto/node_provider.js.map +1 -0
  455. package/dist/modules/crypto/provider.d.ts +34 -0
  456. package/dist/modules/crypto/provider.d.ts.map +1 -0
  457. package/dist/modules/crypto/provider.js +3 -0
  458. package/dist/modules/crypto/provider.js.map +1 -0
  459. package/dist/modules/crypto/pure_ripemd160.d.ts +8 -0
  460. package/dist/modules/crypto/pure_ripemd160.d.ts.map +1 -0
  461. package/dist/modules/crypto/pure_ripemd160.js +142 -0
  462. package/dist/modules/crypto/pure_ripemd160.js.map +1 -0
  463. package/dist/modules/crypto/pure_scrypt.d.ts +23 -0
  464. package/dist/modules/crypto/pure_scrypt.d.ts.map +1 -0
  465. package/dist/modules/crypto/pure_scrypt.js +161 -0
  466. package/dist/modules/crypto/pure_scrypt.js.map +1 -0
  467. package/dist/modules/crypto/pure_secp256k1.d.ts +29 -0
  468. package/dist/modules/crypto/pure_secp256k1.d.ts.map +1 -0
  469. package/dist/modules/crypto/pure_secp256k1.js +195 -0
  470. package/dist/modules/crypto/pure_secp256k1.js.map +1 -0
  471. package/dist/modules/crypto/sync.d.ts +13 -0
  472. package/dist/modules/crypto/sync.d.ts.map +1 -0
  473. package/dist/modules/crypto/sync.js +37 -0
  474. package/dist/modules/crypto/sync.js.map +1 -0
  475. package/dist/modules/dexbot_class.d.ts +1074 -0
  476. package/dist/modules/dexbot_class.d.ts.map +1 -0
  477. package/dist/modules/dexbot_class.js +4613 -0
  478. package/dist/modules/dexbot_class.js.map +1 -0
  479. package/dist/modules/dexbot_credential_client.d.ts +71 -0
  480. package/dist/modules/dexbot_credential_client.d.ts.map +1 -0
  481. package/dist/modules/dexbot_credential_client.js +224 -0
  482. package/dist/modules/dexbot_credential_client.js.map +1 -0
  483. package/dist/modules/dexbot_fill_runtime.d.ts +173 -0
  484. package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -0
  485. package/dist/modules/dexbot_fill_runtime.js +217 -0
  486. package/dist/modules/dexbot_fill_runtime.js.map +1 -0
  487. package/dist/modules/dexbot_maintenance_runtime.d.ts +279 -0
  488. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -0
  489. package/dist/modules/dexbot_maintenance_runtime.js +1613 -0
  490. package/dist/modules/dexbot_maintenance_runtime.js.map +1 -0
  491. package/dist/modules/env.d.ts +12 -0
  492. package/dist/modules/env.d.ts.map +1 -0
  493. package/dist/modules/env.js +57 -0
  494. package/dist/modules/env.js.map +1 -0
  495. package/dist/modules/fund_registry.d.ts +96 -0
  496. package/dist/modules/fund_registry.d.ts.map +1 -0
  497. package/dist/modules/fund_registry.js +261 -0
  498. package/dist/modules/fund_registry.js.map +1 -0
  499. package/dist/modules/general_settings.d.ts +36 -0
  500. package/dist/modules/general_settings.d.ts.map +1 -0
  501. package/dist/modules/general_settings.js +63 -0
  502. package/dist/modules/general_settings.js.map +1 -0
  503. package/dist/modules/graceful_shutdown.d.ts +86 -0
  504. package/dist/modules/graceful_shutdown.d.ts.map +1 -0
  505. package/dist/modules/graceful_shutdown.js +164 -0
  506. package/dist/modules/graceful_shutdown.js.map +1 -0
  507. package/dist/modules/key_store.d.ts +60 -0
  508. package/dist/modules/key_store.d.ts.map +1 -0
  509. package/dist/modules/key_store.js +215 -0
  510. package/dist/modules/key_store.js.map +1 -0
  511. package/dist/modules/launcher/bot_supervisor.d.ts +84 -0
  512. package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -0
  513. package/dist/modules/launcher/bot_supervisor.js +1067 -0
  514. package/dist/modules/launcher/bot_supervisor.js.map +1 -0
  515. package/dist/modules/launcher/child_env.d.ts +9 -0
  516. package/dist/modules/launcher/child_env.d.ts.map +1 -0
  517. package/dist/modules/launcher/child_env.js +78 -0
  518. package/dist/modules/launcher/child_env.js.map +1 -0
  519. package/dist/modules/launcher/credential_bootstrap.d.ts +22 -0
  520. package/dist/modules/launcher/credential_bootstrap.d.ts.map +1 -0
  521. package/dist/modules/launcher/credential_bootstrap.js +303 -0
  522. package/dist/modules/launcher/credential_bootstrap.js.map +1 -0
  523. package/dist/modules/launcher/credential_daemon.d.ts +32 -0
  524. package/dist/modules/launcher/credential_daemon.d.ts.map +1 -0
  525. package/dist/modules/launcher/credential_daemon.js +173 -0
  526. package/dist/modules/launcher/credential_daemon.js.map +1 -0
  527. package/dist/modules/launcher/credential_secret.d.ts +6 -0
  528. package/dist/modules/launcher/credential_secret.d.ts.map +1 -0
  529. package/dist/modules/launcher/credential_secret.js +15 -0
  530. package/dist/modules/launcher/credential_secret.js.map +1 -0
  531. package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -0
  532. package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -0
  533. package/dist/modules/launcher/foreign_cred_daemon.js +166 -0
  534. package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -0
  535. package/dist/modules/launcher/headless_password.d.ts +8 -0
  536. package/dist/modules/launcher/headless_password.d.ts.map +1 -0
  537. package/dist/modules/launcher/headless_password.js +33 -0
  538. package/dist/modules/launcher/headless_password.js.map +1 -0
  539. package/dist/modules/launcher/launch_modes.d.ts +36 -0
  540. package/dist/modules/launcher/launch_modes.d.ts.map +1 -0
  541. package/dist/modules/launcher/launch_modes.js +129 -0
  542. package/dist/modules/launcher/launch_modes.js.map +1 -0
  543. package/dist/modules/launcher/market_adapter_runtime.d.ts +43 -0
  544. package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -0
  545. package/dist/modules/launcher/market_adapter_runtime.js +217 -0
  546. package/dist/modules/launcher/market_adapter_runtime.js.map +1 -0
  547. package/dist/modules/launcher/market_adapter_watchdog.d.ts +26 -0
  548. package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -0
  549. package/dist/modules/launcher/market_adapter_watchdog.js +214 -0
  550. package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -0
  551. package/dist/modules/launcher/monolithic_runtime.d.ts +89 -0
  552. package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -0
  553. package/dist/modules/launcher/monolithic_runtime.js +425 -0
  554. package/dist/modules/launcher/monolithic_runtime.js.map +1 -0
  555. package/dist/modules/launcher/runtime_entry.d.ts +26 -0
  556. package/dist/modules/launcher/runtime_entry.d.ts.map +1 -0
  557. package/dist/modules/launcher/runtime_entry.js +49 -0
  558. package/dist/modules/launcher/runtime_entry.js.map +1 -0
  559. package/dist/modules/launcher/status_reporting.d.ts +48 -0
  560. package/dist/modules/launcher/status_reporting.d.ts.map +1 -0
  561. package/dist/modules/launcher/status_reporting.js +113 -0
  562. package/dist/modules/launcher/status_reporting.js.map +1 -0
  563. package/dist/modules/launcher/supervisor_control.d.ts +6 -0
  564. package/dist/modules/launcher/supervisor_control.d.ts.map +1 -0
  565. package/dist/modules/launcher/supervisor_control.js +59 -0
  566. package/dist/modules/launcher/supervisor_control.js.map +1 -0
  567. package/dist/modules/logger.d.ts +2 -0
  568. package/dist/modules/logger.d.ts.map +1 -0
  569. package/dist/modules/logger.js +71 -0
  570. package/dist/modules/logger.js.map +1 -0
  571. package/dist/modules/market_adapter_whitelist.d.ts +22 -0
  572. package/dist/modules/market_adapter_whitelist.d.ts.map +1 -0
  573. package/dist/modules/market_adapter_whitelist.js +82 -0
  574. package/dist/modules/market_adapter_whitelist.js.map +1 -0
  575. package/dist/modules/node_health_cache.d.ts +55 -0
  576. package/dist/modules/node_health_cache.d.ts.map +1 -0
  577. package/dist/modules/node_health_cache.js +134 -0
  578. package/dist/modules/node_health_cache.js.map +1 -0
  579. package/dist/modules/node_manager.d.ts +215 -0
  580. package/dist/modules/node_manager.d.ts.map +1 -0
  581. package/dist/modules/node_manager.js +628 -0
  582. package/dist/modules/node_manager.js.map +1 -0
  583. package/dist/modules/order/accounting.d.ts +349 -0
  584. package/dist/modules/order/accounting.d.ts.map +1 -0
  585. package/dist/modules/order/accounting.js +1191 -0
  586. package/dist/modules/order/accounting.js.map +1 -0
  587. package/dist/modules/order/async_lock.d.ts +126 -0
  588. package/dist/modules/order/async_lock.d.ts.map +1 -0
  589. package/dist/modules/order/async_lock.js +195 -0
  590. package/dist/modules/order/async_lock.js.map +1 -0
  591. package/dist/modules/order/export.d.ts +129 -0
  592. package/dist/modules/order/export.d.ts.map +1 -0
  593. package/dist/modules/order/export.js +316 -0
  594. package/dist/modules/order/export.js.map +1 -0
  595. package/dist/modules/order/format.d.ts +158 -0
  596. package/dist/modules/order/format.d.ts.map +1 -0
  597. package/dist/modules/order/format.js +232 -0
  598. package/dist/modules/order/format.js.map +1 -0
  599. package/dist/modules/order/grid.d.ts +549 -0
  600. package/dist/modules/order/grid.d.ts.map +1 -0
  601. package/dist/modules/order/grid.js +1746 -0
  602. package/dist/modules/order/grid.js.map +1 -0
  603. package/dist/modules/order/grid_reconcile.d.ts +154 -0
  604. package/dist/modules/order/grid_reconcile.d.ts.map +1 -0
  605. package/dist/modules/order/grid_reconcile.js +1192 -0
  606. package/dist/modules/order/grid_reconcile.js.map +1 -0
  607. package/dist/modules/order/index.d.ts +55 -0
  608. package/dist/modules/order/index.d.ts.map +1 -0
  609. package/dist/modules/order/index.js +79 -0
  610. package/dist/modules/order/index.js.map +1 -0
  611. package/dist/modules/order/logger.d.ts +136 -0
  612. package/dist/modules/order/logger.d.ts.map +1 -0
  613. package/dist/modules/order/logger.js +614 -0
  614. package/dist/modules/order/logger.js.map +1 -0
  615. package/dist/modules/order/logger_state.d.ts +133 -0
  616. package/dist/modules/order/logger_state.d.ts.map +1 -0
  617. package/dist/modules/order/logger_state.js +170 -0
  618. package/dist/modules/order/logger_state.js.map +1 -0
  619. package/dist/modules/order/manager.d.ts +413 -0
  620. package/dist/modules/order/manager.d.ts.map +1 -0
  621. package/dist/modules/order/manager.js +1605 -0
  622. package/dist/modules/order/manager.js.map +1 -0
  623. package/dist/modules/order/processed_fill_store.d.ts +135 -0
  624. package/dist/modules/order/processed_fill_store.d.ts.map +1 -0
  625. package/dist/modules/order/processed_fill_store.js +288 -0
  626. package/dist/modules/order/processed_fill_store.js.map +1 -0
  627. package/dist/modules/order/runner.d.ts +70 -0
  628. package/dist/modules/order/runner.d.ts.map +1 -0
  629. package/dist/modules/order/runner.js +140 -0
  630. package/dist/modules/order/runner.js.map +1 -0
  631. package/dist/modules/order/strategy.d.ts +196 -0
  632. package/dist/modules/order/strategy.d.ts.map +1 -0
  633. package/dist/modules/order/strategy.js +398 -0
  634. package/dist/modules/order/strategy.js.map +1 -0
  635. package/dist/modules/order/sync_engine.d.ts +386 -0
  636. package/dist/modules/order/sync_engine.d.ts.map +1 -0
  637. package/dist/modules/order/sync_engine.js +1459 -0
  638. package/dist/modules/order/sync_engine.js.map +1 -0
  639. package/dist/modules/order/utils/math.d.ts +677 -0
  640. package/dist/modules/order/utils/math.d.ts.map +1 -0
  641. package/dist/modules/order/utils/math.js +1172 -0
  642. package/dist/modules/order/utils/math.js.map +1 -0
  643. package/dist/modules/order/utils/order.d.ts +572 -0
  644. package/dist/modules/order/utils/order.d.ts.map +1 -0
  645. package/dist/modules/order/utils/order.js +1145 -0
  646. package/dist/modules/order/utils/order.js.map +1 -0
  647. package/dist/modules/order/utils/system.d.ts +268 -0
  648. package/dist/modules/order/utils/system.d.ts.map +1 -0
  649. package/dist/modules/order/utils/system.js +1261 -0
  650. package/dist/modules/order/utils/system.js.map +1 -0
  651. package/dist/modules/order/utils/validate.d.ts +280 -0
  652. package/dist/modules/order/utils/validate.d.ts.map +1 -0
  653. package/dist/modules/order/utils/validate.js +918 -0
  654. package/dist/modules/order/utils/validate.js.map +1 -0
  655. package/dist/modules/order/working_grid.d.ts +212 -0
  656. package/dist/modules/order/working_grid.d.ts.map +1 -0
  657. package/dist/modules/order/working_grid.js +279 -0
  658. package/dist/modules/order/working_grid.js.map +1 -0
  659. package/dist/modules/path_api.d.ts +32 -0
  660. package/dist/modules/path_api.d.ts.map +1 -0
  661. package/dist/modules/path_api.js +148 -0
  662. package/dist/modules/path_api.js.map +1 -0
  663. package/dist/modules/paths.d.ts +58 -0
  664. package/dist/modules/paths.d.ts.map +1 -0
  665. package/dist/modules/paths.js +82 -0
  666. package/dist/modules/paths.js.map +1 -0
  667. package/dist/modules/process_discovery.d.ts +58 -0
  668. package/dist/modules/process_discovery.d.ts.map +1 -0
  669. package/dist/modules/process_discovery.js +265 -0
  670. package/dist/modules/process_discovery.js.map +1 -0
  671. package/dist/modules/runtime.d.ts +34 -0
  672. package/dist/modules/runtime.d.ts.map +1 -0
  673. package/dist/modules/runtime.js +98 -0
  674. package/dist/modules/runtime.js.map +1 -0
  675. package/dist/modules/runtime_settings.d.ts +12 -0
  676. package/dist/modules/runtime_settings.d.ts.map +1 -0
  677. package/dist/modules/runtime_settings.js +122 -0
  678. package/dist/modules/runtime_settings.js.map +1 -0
  679. package/dist/modules/settings_merge.d.ts +38 -0
  680. package/dist/modules/settings_merge.d.ts.map +1 -0
  681. package/dist/modules/settings_merge.js +246 -0
  682. package/dist/modules/settings_merge.js.map +1 -0
  683. package/dist/modules/storage/browser_adapter.d.ts +56 -0
  684. package/dist/modules/storage/browser_adapter.d.ts.map +1 -0
  685. package/dist/modules/storage/browser_adapter.js +231 -0
  686. package/dist/modules/storage/browser_adapter.js.map +1 -0
  687. package/dist/modules/storage/index.d.ts +28 -0
  688. package/dist/modules/storage/index.d.ts.map +1 -0
  689. package/dist/modules/storage/index.js +52 -0
  690. package/dist/modules/storage/index.js.map +1 -0
  691. package/dist/modules/storage/node_adapter.d.ts +49 -0
  692. package/dist/modules/storage/node_adapter.d.ts.map +1 -0
  693. package/dist/modules/storage/node_adapter.js +167 -0
  694. package/dist/modules/storage/node_adapter.js.map +1 -0
  695. package/dist/modules/storage/types.d.ts +92 -0
  696. package/dist/modules/storage/types.d.ts.map +1 -0
  697. package/dist/modules/storage/types.js +3 -0
  698. package/dist/modules/storage/types.js.map +1 -0
  699. package/dist/modules/types.d.ts +1382 -0
  700. package/dist/modules/types.d.ts.map +1 -0
  701. package/dist/modules/types.js +11 -0
  702. package/dist/modules/types.js.map +1 -0
  703. package/dist/modules/utils/base58check.d.ts +12 -0
  704. package/dist/modules/utils/base58check.d.ts.map +1 -0
  705. package/dist/modules/utils/base58check.js +112 -0
  706. package/dist/modules/utils/base58check.js.map +1 -0
  707. package/dist/modules/utils/build_dir.d.ts +7 -0
  708. package/dist/modules/utils/build_dir.d.ts.map +1 -0
  709. package/dist/modules/utils/build_dir.js +8 -0
  710. package/dist/modules/utils/build_dir.js.map +1 -0
  711. package/dist/modules/utils/fs_utils.d.ts +25 -0
  712. package/dist/modules/utils/fs_utils.d.ts.map +1 -0
  713. package/dist/modules/utils/fs_utils.js +27 -0
  714. package/dist/modules/utils/fs_utils.js.map +1 -0
  715. package/dist/modules/utils/math_utils.d.ts +10 -0
  716. package/dist/modules/utils/math_utils.d.ts.map +1 -0
  717. package/dist/modules/utils/math_utils.js +17 -0
  718. package/dist/modules/utils/math_utils.js.map +1 -0
  719. package/dist/modules/validate_profiles.d.ts +37 -0
  720. package/dist/modules/validate_profiles.d.ts.map +1 -0
  721. package/dist/modules/validate_profiles.js +369 -0
  722. package/dist/modules/validate_profiles.js.map +1 -0
  723. package/dist/pm2.d.ts +167 -0
  724. package/dist/pm2.d.ts.map +1 -0
  725. package/dist/pm2.js +998 -0
  726. package/dist/pm2.js.map +1 -0
  727. package/dist/scripts/analyze-git.d.ts +11 -0
  728. package/dist/scripts/analyze-git.d.ts.map +1 -0
  729. package/dist/scripts/analyze-git.js +851 -0
  730. package/dist/scripts/analyze-git.js.map +1 -0
  731. package/dist/scripts/analyze-orders.d.ts +17 -0
  732. package/dist/scripts/analyze-orders.d.ts.map +1 -0
  733. package/dist/scripts/analyze-orders.js +1568 -0
  734. package/dist/scripts/analyze-orders.js.map +1 -0
  735. package/dist/scripts/diagnose-kibana-candles.d.ts +3 -0
  736. package/dist/scripts/diagnose-kibana-candles.d.ts.map +1 -0
  737. package/dist/scripts/diagnose-kibana-candles.js +82 -0
  738. package/dist/scripts/diagnose-kibana-candles.js.map +1 -0
  739. package/dist/scripts/diagnose-pool-history.d.ts +3 -0
  740. package/dist/scripts/diagnose-pool-history.d.ts.map +1 -0
  741. package/dist/scripts/diagnose-pool-history.js +296 -0
  742. package/dist/scripts/diagnose-pool-history.js.map +1 -0
  743. package/dist/scripts/divergence-calc.d.ts +26 -0
  744. package/dist/scripts/divergence-calc.d.ts.map +1 -0
  745. package/dist/scripts/divergence-calc.js +119 -0
  746. package/dist/scripts/divergence-calc.js.map +1 -0
  747. package/dist/scripts/generate_lp_chart.d.ts +31 -0
  748. package/dist/scripts/generate_lp_chart.d.ts.map +1 -0
  749. package/dist/scripts/generate_lp_chart.js +92 -0
  750. package/dist/scripts/generate_lp_chart.js.map +1 -0
  751. package/dist/scripts/generate_mainnet_corpus_report.d.ts +24 -0
  752. package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +1 -0
  753. package/dist/scripts/generate_mainnet_corpus_report.js +237 -0
  754. package/dist/scripts/generate_mainnet_corpus_report.js.map +1 -0
  755. package/dist/scripts/generate_market_adapter_whitelist.d.ts +2 -0
  756. package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +1 -0
  757. package/dist/scripts/generate_market_adapter_whitelist.js +111 -0
  758. package/dist/scripts/generate_market_adapter_whitelist.js.map +1 -0
  759. package/dist/scripts/migrate_bot_keys.d.ts +6 -0
  760. package/dist/scripts/migrate_bot_keys.d.ts.map +1 -0
  761. package/dist/scripts/migrate_bot_keys.js +301 -0
  762. package/dist/scripts/migrate_bot_keys.js.map +1 -0
  763. package/dist/scripts/native_release_gates.d.ts +3 -0
  764. package/dist/scripts/native_release_gates.d.ts.map +1 -0
  765. package/dist/scripts/native_release_gates.js +52 -0
  766. package/dist/scripts/native_release_gates.js.map +1 -0
  767. package/dist/scripts/print_grid.d.ts +16 -0
  768. package/dist/scripts/print_grid.d.ts.map +1 -0
  769. package/dist/scripts/print_grid.js +80 -0
  770. package/dist/scripts/print_grid.js.map +1 -0
  771. package/dist/scripts/run-tests.d.ts +2 -0
  772. package/dist/scripts/run-tests.d.ts.map +1 -0
  773. package/dist/scripts/run-tests.js +49 -0
  774. package/dist/scripts/run-tests.js.map +1 -0
  775. package/dist/scripts/sync-version.d.ts +14 -0
  776. package/dist/scripts/sync-version.d.ts.map +1 -0
  777. package/dist/scripts/sync-version.js +158 -0
  778. package/dist/scripts/sync-version.js.map +1 -0
  779. package/dist/scripts/test-credit-renewal.d.ts +2 -0
  780. package/dist/scripts/test-credit-renewal.d.ts.map +1 -0
  781. package/dist/scripts/test-credit-renewal.js +329 -0
  782. package/dist/scripts/test-credit-renewal.js.map +1 -0
  783. package/dist/scripts/update.d.ts +24 -0
  784. package/dist/scripts/update.d.ts.map +1 -0
  785. package/dist/scripts/update.js +650 -0
  786. package/dist/scripts/update.js.map +1 -0
  787. package/dist/scripts/validate_bots.d.ts +16 -0
  788. package/dist/scripts/validate_bots.d.ts.map +1 -0
  789. package/dist/scripts/validate_bots.js +106 -0
  790. package/dist/scripts/validate_bots.js.map +1 -0
  791. package/dist/scripts/verify-browser-bundle.d.ts +22 -0
  792. package/dist/scripts/verify-browser-bundle.d.ts.map +1 -0
  793. package/dist/scripts/verify-browser-bundle.js +339 -0
  794. package/dist/scripts/verify-browser-bundle.js.map +1 -0
  795. package/dist/unlock.d.ts +48 -0
  796. package/dist/unlock.d.ts.map +1 -0
  797. package/dist/unlock.js +925 -0
  798. package/dist/unlock.js.map +1 -0
  799. package/package.json +112 -0
  800. package/scripts/README.md +356 -0
  801. package/scripts/clear-all.sh +195 -0
  802. package/scripts/clear-logs.sh +95 -0
  803. package/scripts/clear-market-adapter.sh +196 -0
  804. package/scripts/clear-orders.sh +113 -0
  805. package/scripts/create-bot-symlinks.sh +51 -0
  806. package/scripts/postinstall.js +9 -0
  807. package/scripts/reset-settings.sh +118 -0
@@ -0,0 +1,804 @@
1
+ 'use strict';
2
+ /**
3
+ * AMA SWEEP BACKTEST — persistent grid simulation
4
+ *
5
+ * Models the real bot mechanics:
6
+ * - Orders sit at FIXED chain prices until canceled or filled
7
+ * - When AMA drifts past reposition threshold, grid re-centers
8
+ * - Grid compression: AMA shift pushes one side's orders closer to market
9
+ * - Order sizing depends on capital, ratio (range width), and weight profile
10
+ * - Three weight profiles: valley, neutral, mountain (symmetric buy/sell)
11
+ *
12
+ * Usage:
13
+ * tsx analysis/bot_fitting/backtest_ama_sweep.ts --data <path-to-lp-candles.json>
14
+ * tsx analysis/bot_fitting/backtest_ama_sweep.ts --data <path-to-lp-candles.json> --spread 4:16:1 --increment 0.5:4:0.25
15
+ */
16
+ const fs = require('fs');
17
+ const path = require('path');
18
+ const os = require('os');
19
+ const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
20
+ const { calculateAMA } = require('../../market_adapter/core/strategies/ama');
21
+ const { range } = require('../math_utils');
22
+ const { parseListOrRange, loadLpData, fmt } = require('./shared_utils');
23
+ const { readJSON, writeJSON } = require('../../modules/utils/fs_utils');
24
+ const DEFAULT_MAX_ORDERS = 20; // matches bot default activeOrders per side
25
+ const DEFAULT_FEE_ROUNDTRIP_PCT = 0.20;
26
+ const DEFAULT_MIN_SPREAD_FACTOR = 2.1;
27
+ const DEFAULT_CAPITAL = 10000; // notional units per side
28
+ const DEFAULT_BTS_CREATE_FEE = 0.48260;
29
+ const DEFAULT_BTS_CANCEL_FEE = 0.00482;
30
+ const DEFAULT_BTS_MAKER_CREATE_FACTOR = 0.10;
31
+ const DEFAULT_TX_FEE_PRICE = 1.0;
32
+ // Weight profiles (symmetric for both sides)
33
+ // valley: heavier at edges (outer levels), lighter near center
34
+ // neutral: equal across all levels
35
+ // mountain: heavier near center, lighter at edges
36
+ const WEIGHT_PROFILES = {
37
+ valley: -0.8, // negative = invert decay → outer levels get more
38
+ neutral: 0, // flat = equal distribution
39
+ mountain: 1.5, // strong decay → inner levels get more
40
+ };
41
+ // Search grid defaults — centered around bot defaults (spread=2%, increment=0.5%)
42
+ // Spread = distance from center to first order on each side (half the bid-ask gap)
43
+ // Increment = distance between successive orders on the same side
44
+ const DEFAULT_SPREAD_VALUES = [...range(0.5, 4, 0.25), ...range(5, 12, 1)];
45
+ const DEFAULT_INCREMENT_VALUES = [...range(0.2, 2, 0.1), ...range(2.5, 8, 0.5)];
46
+ const DEFAULT_RATIO_VALUES = [1.05, 1.1, 1.15, 1.2, 1.3, 1.5, 2, 3, 5, 10];
47
+ // Reposition threshold: AMA must move this fraction from last grid center to trigger re-center
48
+ const DEFAULT_REPOSITION_PCT = 2.5;
49
+ function jsonSafe(key, val) {
50
+ if (val === -Infinity || val === Infinity)
51
+ return null;
52
+ return val;
53
+ }
54
+ function parseArgs() {
55
+ const args = process.argv.slice(2);
56
+ const out = {
57
+ dataPath: null,
58
+ resultsPath: null,
59
+ spreadValues: DEFAULT_SPREAD_VALUES,
60
+ incrementValues: DEFAULT_INCREMENT_VALUES,
61
+ ratioValues: DEFAULT_RATIO_VALUES,
62
+ maxOrders: DEFAULT_MAX_ORDERS,
63
+ feeRoundtripPct: DEFAULT_FEE_ROUNDTRIP_PCT,
64
+ minSpreadFactor: DEFAULT_MIN_SPREAD_FACTOR,
65
+ capital: DEFAULT_CAPITAL,
66
+ repositionPct: DEFAULT_REPOSITION_PCT,
67
+ btsCreateFee: DEFAULT_BTS_CREATE_FEE,
68
+ btsCancelFee: DEFAULT_BTS_CANCEL_FEE,
69
+ makerCreateFactor: DEFAULT_BTS_MAKER_CREATE_FACTOR,
70
+ txFeePrice: DEFAULT_TX_FEE_PRICE,
71
+ topN: 15,
72
+ };
73
+ for (let i = 0; i < args.length; i++) {
74
+ const arg = args[i];
75
+ const val = args[i + 1];
76
+ if (arg === '--help' || arg === '-h') {
77
+ printHelp();
78
+ process.exit(0);
79
+ }
80
+ if (!val)
81
+ continue;
82
+ switch (arg) {
83
+ case '--data':
84
+ out.dataPath = path.resolve(val);
85
+ i++;
86
+ break;
87
+ case '--results':
88
+ out.resultsPath = path.resolve(val);
89
+ i++;
90
+ break;
91
+ case '--spread':
92
+ out.spreadValues = parseListOrRange(val, DEFAULT_SPREAD_VALUES);
93
+ i++;
94
+ break;
95
+ case '--increment':
96
+ out.incrementValues = parseListOrRange(val, DEFAULT_INCREMENT_VALUES);
97
+ i++;
98
+ break;
99
+ case '--ratio':
100
+ out.ratioValues = parseListOrRange(val, DEFAULT_RATIO_VALUES);
101
+ i++;
102
+ break;
103
+ case '--max-orders':
104
+ out.maxOrders = Number(val);
105
+ i++;
106
+ break;
107
+ case '--fee':
108
+ out.feeRoundtripPct = Number(val);
109
+ i++;
110
+ break;
111
+ case '--min-spread-factor':
112
+ out.minSpreadFactor = Number(val);
113
+ i++;
114
+ break;
115
+ case '--capital':
116
+ out.capital = Number(val);
117
+ i++;
118
+ break;
119
+ case '--reposition':
120
+ out.repositionPct = Number(val);
121
+ i++;
122
+ break;
123
+ case '--bts-create-fee':
124
+ out.btsCreateFee = Number(val);
125
+ i++;
126
+ break;
127
+ case '--bts-cancel-fee':
128
+ out.btsCancelFee = Number(val);
129
+ i++;
130
+ break;
131
+ case '--maker-create-factor':
132
+ out.makerCreateFactor = Number(val);
133
+ i++;
134
+ break;
135
+ case '--tx-fee-price':
136
+ out.txFeePrice = Number(val);
137
+ i++;
138
+ break;
139
+ case '--top':
140
+ out.topN = Number(val);
141
+ i++;
142
+ break;
143
+ }
144
+ }
145
+ if (!out.dataPath) {
146
+ throw new Error('--data <path-to-lp-candles.json> is required');
147
+ }
148
+ if (!out.resultsPath) {
149
+ throw new Error('--results <path-to-optimization-results.json> is required');
150
+ }
151
+ return out;
152
+ }
153
+ function printHelp() {
154
+ console.log('AMA Sweep Backtest — persistent grid simulation with weight profiles');
155
+ console.log('');
156
+ console.log('Usage:');
157
+ console.log(' tsx analysis/bot_fitting/backtest_ama_sweep.ts [options]');
158
+ console.log('');
159
+ console.log('Options:');
160
+ console.log(' --data <path> LP candle JSON');
161
+ console.log(' --results <path> AMA optimizer results JSON');
162
+ console.log(' --spread <spec> Spread values (% ): 1:10:0.5 or 2,4,8');
163
+ console.log(' --increment <spec> Increment values (%): 0.5:5:0.5 or 1,2,3');
164
+ console.log(' --ratio <spec> Max/min ratio: 1.5,2,3,5');
165
+ console.log(' --max-orders <n> Max orders per side (default: 20, actual limited by ratio+increment)');
166
+ console.log(' --fee <pct> Round-trip fee % (default: 0.20)');
167
+ console.log(' --min-spread-factor <n> Spread >= factor * increment (default: 2.1)');
168
+ console.log(' --capital <n> Notional capital per side (default: 10000)');
169
+ console.log(' --reposition <pct> AMA drift % to trigger re-center (default: 2.5)');
170
+ console.log(' --bts-create-fee <n> BTS create fee (default: 0.48260)');
171
+ console.log(' --bts-cancel-fee <n> BTS cancel fee (default: 0.00482)');
172
+ console.log(' --maker-create-factor Maker share of create fee (default: 0.10)');
173
+ console.log(' --tx-fee-price <n> Convert BTS fees into backtest units (default: 1.0)');
174
+ console.log(' --top <n> Show top N results (default: 15)');
175
+ }
176
+ function loadAmaStrategies(resultsPath) {
177
+ const json = readJSON(resultsPath);
178
+ const amas = json.meta?.amas;
179
+ if (!amas)
180
+ throw new Error('No meta.amas found in results file.');
181
+ const out = [];
182
+ for (const [key, val] of Object.entries(amas)) {
183
+ const v = val;
184
+ if (!v || !Number.isFinite(v.er))
185
+ continue;
186
+ out.push({ id: key, name: v.label || key, er: v.er, fast: v.fast, slow: v.slow });
187
+ }
188
+ out.sort((a, b) => a.id.localeCompare(b.id));
189
+ if (out.length === 0)
190
+ throw new Error('No valid AMA strategies found');
191
+ return out;
192
+ }
193
+ // ── Order sizing with weight profiles ────────────────────────────────────────
194
+ /**
195
+ * Allocate capital across N levels using weight profile.
196
+ * weight > 0: mountain (more near center, exponential decay outward)
197
+ * weight = 0: neutral (equal)
198
+ * weight < 0: valley (more at edges, inverted decay)
199
+ *
200
+ * @param {number} totalFunds Capital for this side
201
+ * @param {number} n Number of levels
202
+ * @param {number} weight Profile weight factor
203
+ * @param {number} incrementFactor Increment as fraction (e.g. 0.02 for 2%)
204
+ * @returns {number[]} Size per level, index 0 = closest to center
205
+ */
206
+ function allocateFundsByWeights(totalFunds, n, weight, incrementFactor) {
207
+ if (n <= 0)
208
+ return [];
209
+ if (weight === 0) {
210
+ const sz = totalFunds / n;
211
+ return new Array(n).fill(sz);
212
+ }
213
+ const base = 1 - incrementFactor;
214
+ const absWeight = Math.abs(weight);
215
+ const raw = new Array(n);
216
+ for (let i = 0; i < n; i++) {
217
+ // i=0 is closest to center
218
+ raw[i] = Math.pow(base, i * absWeight);
219
+ }
220
+ if (weight < 0) {
221
+ // Valley: reverse so outer levels (high i) get the large weights
222
+ raw.reverse();
223
+ }
224
+ const total = raw.reduce((s, w) => s + w, 0) || 1;
225
+ return raw.map((w) => (w / total) * totalFunds);
226
+ }
227
+ // ── Persistent grid simulation ───────────────────────────────────────────────
228
+ /**
229
+ * Build a fresh grid centered at `center`.
230
+ *
231
+ * Grid placement (matches real bot):
232
+ * Level k (1-based):
233
+ * offset_k = spreadPct/2/100 + (k-1) * incrementPct
234
+ * buyPrice = center * (1 - offset_k)
235
+ * sellPrice = center * (1 + offset_k)
236
+ *
237
+ * So spread controls the dead zone around center (no orders within spread/2),
238
+ * and increment is the gap between successive orders on the same side.
239
+ *
240
+ * Returns arrays of buy and sell order objects with fixed chain prices and sizes.
241
+ */
242
+ function buildGrid(center, params, capitalPerSide, weightFactor) {
243
+ const { incrementPct, maxMinRatio, maxOrders, spreadPct } = params;
244
+ const minBound = center / maxMinRatio;
245
+ const maxBound = center * maxMinRatio;
246
+ const halfSpread = spreadPct / 200; // as fraction
247
+ const buys = [];
248
+ const sells = [];
249
+ // Fill as many levels as fit within ratio bounds (up to maxOrders cap)
250
+ for (let k = 1; k <= maxOrders; k++) {
251
+ const offset = halfSpread + (k - 1) * incrementPct;
252
+ if (offset >= 0.95)
253
+ continue;
254
+ const buyPrice = center * (1 - offset);
255
+ const sellPrice = center * (1 + offset);
256
+ // Bounds check — skip levels outside ratio range
257
+ if (buyPrice < minBound || sellPrice > maxBound)
258
+ continue;
259
+ buys.push({ level: k, price: buyPrice, filledBar: -1 });
260
+ sells.push({ level: k, price: sellPrice, filledBar: -1 });
261
+ }
262
+ // Size allocation — index 0 = closest to center
263
+ const buySizes = allocateFundsByWeights(capitalPerSide, buys.length, weightFactor, incrementPct);
264
+ const sellSizes = allocateFundsByWeights(capitalPerSide, sells.length, weightFactor, incrementPct);
265
+ buys.forEach((o, i) => { o.size = buySizes[i] || 0; });
266
+ sells.forEach((o, i) => { o.size = sellSizes[i] || 0; });
267
+ return { buys, sells };
268
+ }
269
+ function closeFilledInventoryAtPrice(openBuys, openSells, exitPrice, feeRoundtripPct) {
270
+ if (!Number.isFinite(exitPrice) || exitPrice <= 0) {
271
+ return { grossUnits: 0, profitUnits: 0, closedOrders: 0 };
272
+ }
273
+ let grossUnits = 0;
274
+ let profitUnits = 0;
275
+ let closedOrders = 0;
276
+ for (const order of openBuys.values()) {
277
+ if (!order?.filled || !Number.isFinite(order.price) || order.price <= 0)
278
+ continue;
279
+ if (!Number.isFinite(order.size) || order.size <= 0)
280
+ continue;
281
+ const grossPct = (exitPrice / order.price - 1) * 100;
282
+ const netPct = grossPct - feeRoundtripPct;
283
+ grossUnits += order.size * (grossPct / 100);
284
+ profitUnits += order.size * (netPct / 100);
285
+ closedOrders++;
286
+ }
287
+ for (const order of openSells.values()) {
288
+ if (!order?.filled || !Number.isFinite(order.price) || order.price <= 0)
289
+ continue;
290
+ if (!Number.isFinite(order.size) || order.size <= 0)
291
+ continue;
292
+ const grossPct = (order.price / exitPrice - 1) * 100;
293
+ const netPct = grossPct - feeRoundtripPct;
294
+ grossUnits += order.size * (grossPct / 100);
295
+ profitUnits += order.size * (netPct / 100);
296
+ closedOrders++;
297
+ }
298
+ return { grossUnits, profitUnits, closedOrders };
299
+ }
300
+ function countCancelableOrders(openBuys, openSells) {
301
+ let count = 0;
302
+ for (const order of openBuys.values()) {
303
+ if (!order?.filled)
304
+ count++;
305
+ }
306
+ for (const order of openSells.values()) {
307
+ if (!order?.filled)
308
+ count++;
309
+ }
310
+ return count;
311
+ }
312
+ function simulatePersistentGrid(candles, amaValues, params, weightName, weightFactor) {
313
+ const { spreadPct, incrementPct, maxMinRatio, maxOrders, feeRoundtripPct, capital, repositionThreshold, btsCreateFee, btsCancelFee, makerCreateFactor, txFeePrice } = params;
314
+ const skip = Math.max(20, Math.floor(candles.length * 0.1));
315
+ const capitalPerSide = capital;
316
+ // State
317
+ let gridCenter = amaValues[skip];
318
+ let grid = buildGrid(gridCenter, params, capitalPerSide, weightFactor);
319
+ let lastRepositionBar = skip;
320
+ // Open orders: maps level -> { price, size, bar, side }
321
+ const openBuys = new Map();
322
+ const openSells = new Map();
323
+ // Place initial orders
324
+ for (const o of grid.buys)
325
+ openBuys.set(o.level, { price: o.price, size: o.size, bar: skip });
326
+ for (const o of grid.sells)
327
+ openSells.set(o.level, { price: o.price, size: o.size, bar: skip });
328
+ let matchedPairs = 0;
329
+ let totalProfitUnits = 0; // profit in capital units (size * netPct)
330
+ let totalGrossUnits = 0;
331
+ let touchedOrders = 0;
332
+ let canceledOnReposition = 0;
333
+ let repositionCount = 0;
334
+ let peakOpenOrders = 0;
335
+ let imbalanceSum = 0;
336
+ let imbalanceSamples = 0;
337
+ let matchedOpenDurationBars = 0;
338
+ let gridAgeSumBars = 0;
339
+ let maxGridAgeBars = 0;
340
+ let centerDriftSumPct = 0;
341
+ let maxCenterDriftPct = 0;
342
+ let nearThresholdBars = 0;
343
+ let triggerDriftSumPct = 0;
344
+ let runningProfit = 0;
345
+ let peakEquityProfit = 0;
346
+ let maxDrawdown = 0;
347
+ // Track inventory risk: net exposure from filled-but-unmatched orders
348
+ let inventoryExposure = 0; // positive = long (bought), negative = short (sold)
349
+ let maxInventoryExposure = 0;
350
+ const liveBars = candles.length - skip - 1;
351
+ const ordersPerSide = grid.buys.length; // actual orders placed per side (clipped by ratio)
352
+ const makerCreateFeeBts = btsCreateFee * makerCreateFactor;
353
+ const newOrdersPerReposition = ordersPerSide * 2;
354
+ for (let i = skip + 1; i < candles.length; i++) {
355
+ const ama = amaValues[i];
356
+ const hi = candles[i].high;
357
+ const lo = candles[i].low;
358
+ const gridAgeBars = i - lastRepositionBar;
359
+ // ── Reposition check: AMA drifted too far from grid center ──────
360
+ const drift = Math.abs(ama - gridCenter) / gridCenter;
361
+ const driftPct = drift * 100;
362
+ centerDriftSumPct += driftPct;
363
+ if (driftPct > maxCenterDriftPct)
364
+ maxCenterDriftPct = driftPct;
365
+ gridAgeSumBars += gridAgeBars;
366
+ if (gridAgeBars > maxGridAgeBars)
367
+ maxGridAgeBars = gridAgeBars;
368
+ if (drift >= repositionThreshold * 0.5)
369
+ nearThresholdBars++;
370
+ if (drift >= repositionThreshold) {
371
+ triggerDriftSumPct += driftPct;
372
+ canceledOnReposition += countCancelableOrders(openBuys, openSells);
373
+ repositionCount++;
374
+ const exitPrice = Number.isFinite(ama) && ama > 0 ? ama : candles[i].close;
375
+ const forcedClose = closeFilledInventoryAtPrice(openBuys, openSells, exitPrice, feeRoundtripPct);
376
+ totalGrossUnits += forcedClose.grossUnits;
377
+ totalProfitUnits += forcedClose.profitUnits;
378
+ runningProfit += forcedClose.profitUnits;
379
+ // Unmatched inventory is realized on reposition (position closed at market)
380
+ inventoryExposure = 0;
381
+ openBuys.clear();
382
+ openSells.clear();
383
+ // Re-center grid
384
+ gridCenter = ama;
385
+ grid = buildGrid(gridCenter, params, capitalPerSide, weightFactor);
386
+ lastRepositionBar = i;
387
+ for (const o of grid.buys)
388
+ openBuys.set(o.level, { price: o.price, size: o.size, bar: i });
389
+ for (const o of grid.sells)
390
+ openSells.set(o.level, { price: o.price, size: o.size, bar: i });
391
+ }
392
+ // ── Track imbalance & peak ──────────────────────────────────────
393
+ const currentOpen = openBuys.size + openSells.size;
394
+ if (currentOpen > peakOpenOrders)
395
+ peakOpenOrders = currentOpen;
396
+ imbalanceSum += Math.abs(openBuys.size - openSells.size);
397
+ imbalanceSamples++;
398
+ // ── Check fills on PERSISTENT orders (fixed chain prices) ───────
399
+ // Only check UNFILLED orders (skip already-filled pending match)
400
+ const filledBuysThisBar = [];
401
+ const filledSellsThisBar = [];
402
+ for (const [lvl, order] of openBuys) {
403
+ if (!order.filled && lo <= order.price) {
404
+ filledBuysThisBar.push({ lvl, order });
405
+ }
406
+ }
407
+ for (const [lvl, order] of openSells) {
408
+ if (!order.filled && hi >= order.price) {
409
+ filledSellsThisBar.push({ lvl, order });
410
+ }
411
+ }
412
+ // Process buy fills
413
+ for (const fb of filledBuysThisBar) {
414
+ touchedOrders++;
415
+ inventoryExposure += fb.order.size; // bought → long exposure
416
+ // Mark as filled, waiting for paired sell at same level
417
+ openBuys.set(fb.lvl, { ...fb.order, filled: true, filledBar: i, side: 'buy' });
418
+ }
419
+ // Process sell fills
420
+ for (const fs of filledSellsThisBar) {
421
+ touchedOrders++;
422
+ inventoryExposure -= fs.order.size; // sold → short exposure
423
+ // Mark as filled, waiting for paired buy at same level
424
+ openSells.set(fs.lvl, { ...fs.order, filled: true, filledBar: i, side: 'sell' });
425
+ }
426
+ // Match completed pairs: both buy AND sell at same level are filled
427
+ for (let k = 1; k <= maxOrders; k++) {
428
+ const buyEntry = openBuys.get(k);
429
+ const sellEntry = openSells.get(k);
430
+ if (!buyEntry?.filled || !sellEntry?.filled)
431
+ continue;
432
+ // Matched pair!
433
+ openBuys.delete(k);
434
+ openSells.delete(k);
435
+ matchedPairs++;
436
+ const duration = Math.abs(sellEntry.filledBar - buyEntry.filledBar);
437
+ matchedOpenDurationBars += duration;
438
+ const avgSize = (buyEntry.size + sellEntry.size) / 2;
439
+ const pairGrossPct = (sellEntry.price / buyEntry.price - 1) * 100;
440
+ const pairNetPct = pairGrossPct - feeRoundtripPct;
441
+ const profitUnits = avgSize * (pairNetPct / 100);
442
+ totalGrossUnits += avgSize * (pairGrossPct / 100);
443
+ totalProfitUnits += profitUnits;
444
+ runningProfit += profitUnits;
445
+ }
446
+ // Track max inventory exposure
447
+ const absExposure = Math.abs(inventoryExposure);
448
+ if (absExposure > maxInventoryExposure)
449
+ maxInventoryExposure = absExposure;
450
+ // ── Drawdown tracking ───────────────────────────────────────────
451
+ const markPrice = Number.isFinite(candles[i].close) && candles[i].close > 0
452
+ ? candles[i].close
453
+ : ((Number.isFinite(ama) && ama > 0) ? ama : gridCenter);
454
+ const unrealized = closeFilledInventoryAtPrice(openBuys, openSells, markPrice, feeRoundtripPct).profitUnits;
455
+ const equityProfit = runningProfit + unrealized;
456
+ if (equityProfit > peakEquityProfit)
457
+ peakEquityProfit = equityProfit;
458
+ const dd = peakEquityProfit - equityProfit;
459
+ if (dd > maxDrawdown)
460
+ maxDrawdown = dd;
461
+ }
462
+ const fillEfficiency = touchedOrders > 0 ? (matchedPairs / touchedOrders) * 100 : 0;
463
+ const pairsPerDay = liveBars > 0 ? matchedPairs / (liveBars / 24) : 0;
464
+ const avgOpenDurationBars = matchedPairs > 0 ? matchedOpenDurationBars / matchedPairs : 0;
465
+ const avgImbalance = imbalanceSamples > 0 ? imbalanceSum / imbalanceSamples : 0;
466
+ const avgProfitPerPair = matchedPairs > 0 ? totalProfitUnits / matchedPairs : 0;
467
+ const profitPerCapital = capital > 0 ? totalProfitUnits / (capital * 2) : 0; // total capital = 2 sides
468
+ const maxDrawdownPct = capital > 0 ? (maxDrawdown / (capital * 2)) * 100 : 0;
469
+ const avgGridAgeBars = liveBars > 0 ? gridAgeSumBars / liveBars : 0;
470
+ const avgCenterDriftPct = liveBars > 0 ? centerDriftSumPct / liveBars : 0;
471
+ const nearThresholdBarsPct = liveBars > 0 ? (nearThresholdBars / liveBars) * 100 : 0;
472
+ const avgTriggerDriftPct = repositionCount > 0 ? triggerDriftSumPct / repositionCount : 0;
473
+ const avgCancelOrdersPerReposition = repositionCount > 0 ? canceledOnReposition / repositionCount : 0;
474
+ const estimatedFeePerRepositionBts = newOrdersPerReposition * makerCreateFeeBts + avgCancelOrdersPerReposition * btsCancelFee;
475
+ const totalRepositionFeesBts = repositionCount * estimatedFeePerRepositionBts;
476
+ const feePerDayBts = liveBars > 0 ? totalRepositionFeesBts / (liveBars / 24) : 0;
477
+ const totalRepositionFeeUnits = totalRepositionFeesBts * txFeePrice;
478
+ const netProfitUnits = totalProfitUnits - totalRepositionFeeUnits;
479
+ const netProfitPerCapital = capital > 0 ? netProfitUnits / (capital * 2) : 0;
480
+ // Score: profit per capital scaled by activity (log pairs to avoid pure frequency chasing)
481
+ const activityBonus = matchedPairs > 0 ? Math.log10(matchedPairs) : null;
482
+ const grossScore = activityBonus == null ? -Infinity : (profitPerCapital * 100 * activityBonus - maxDrawdownPct * 0.5);
483
+ const netScore = activityBonus == null ? -Infinity : (netProfitPerCapital * 100 * activityBonus - maxDrawdownPct * 0.5);
484
+ const score = netScore;
485
+ return {
486
+ weightName,
487
+ spreadPct,
488
+ incrementPct: incrementPct * 100, // store as %
489
+ maxMinRatio,
490
+ matchedPairs,
491
+ touchedOrders,
492
+ fillEfficiency,
493
+ totalProfitUnits,
494
+ totalGrossUnits,
495
+ profitPerCapital,
496
+ pairsPerDay,
497
+ avgOpenDurationBars,
498
+ avgProfitPerPair,
499
+ peakOpenOrders,
500
+ avgImbalance,
501
+ canceledOnReposition,
502
+ repositionCount,
503
+ maxDrawdown,
504
+ maxDrawdownPct,
505
+ maxInventoryExposure,
506
+ avgGridAgeBars,
507
+ maxGridAgeBars,
508
+ avgCenterDriftPct,
509
+ maxCenterDriftPct,
510
+ nearThresholdBarsPct,
511
+ avgTriggerDriftPct,
512
+ makerCreateFeeBts,
513
+ btsCancelFee,
514
+ avgCancelOrdersPerReposition,
515
+ estimatedFeePerRepositionBts,
516
+ totalRepositionFeesBts,
517
+ feePerDayBts,
518
+ netProfitUnits,
519
+ netProfitPerCapital,
520
+ ordersPerSide,
521
+ grossScore,
522
+ netScore,
523
+ score,
524
+ };
525
+ }
526
+ // ── Per-AMA sweep logic (runs in main thread or worker) ─────────────────────
527
+ function sweepOneAma(strategy, candles, closes, weightEntries, cfg) {
528
+ const amaValues = calculateAMA(closes, { erPeriod: strategy.er, fastPeriod: strategy.fast, slowPeriod: strategy.slow });
529
+ let best = null;
530
+ const top5 = [];
531
+ const allSims = [];
532
+ let evaluated = 0;
533
+ const minSpreadFactor = Number.isFinite(cfg.minSpreadFactor) && cfg.minSpreadFactor > 0 ? cfg.minSpreadFactor : null;
534
+ for (const spreadPct of cfg.spreadValues) {
535
+ for (const incrementPctRaw of cfg.incrementValues) {
536
+ if (spreadPct < cfg.feeRoundtripPct + 0.01)
537
+ continue;
538
+ if (minSpreadFactor != null && spreadPct < (incrementPctRaw * minSpreadFactor))
539
+ continue;
540
+ for (const maxMinRatio of cfg.ratioValues) {
541
+ for (const [weightName, weightFactor] of weightEntries) {
542
+ evaluated++;
543
+ const sim = simulatePersistentGrid(candles, amaValues, {
544
+ spreadPct,
545
+ incrementPct: incrementPctRaw / 100,
546
+ maxMinRatio,
547
+ maxOrders: cfg.maxOrders,
548
+ feeRoundtripPct: cfg.feeRoundtripPct,
549
+ capital: cfg.capital,
550
+ repositionThreshold: cfg.repositionPct / 100,
551
+ btsCreateFee: cfg.btsCreateFee,
552
+ btsCancelFee: cfg.btsCancelFee,
553
+ makerCreateFactor: cfg.makerCreateFactor,
554
+ txFeePrice: cfg.txFeePrice,
555
+ }, weightName, weightFactor);
556
+ if (!best || sim.score > best.score)
557
+ best = sim;
558
+ if (sim.matchedPairs > 0) {
559
+ const t5key = `${sim.spreadPct}|${sim.incrementPct}|${sim.maxMinRatio}|${sim.weightName}`;
560
+ const existing = top5.findIndex((t) => `${t.spreadPct}|${t.incrementPct}|${t.maxMinRatio}|${t.weightName}` === t5key);
561
+ if (existing < 0) {
562
+ top5.push(sim);
563
+ top5.sort((a, b) => b.score - a.score);
564
+ if (top5.length > 5)
565
+ top5.length = 5;
566
+ }
567
+ allSims.push(sim);
568
+ }
569
+ }
570
+ }
571
+ }
572
+ }
573
+ return { strategy, best, top5, allSims, evaluated };
574
+ }
575
+ // ── Worker thread handler ───────────────────────────────────────────────────
576
+ if (!isMainThread) {
577
+ const { strategy, candles, closes, weightEntries, cfg } = workerData;
578
+ const result = sweepOneAma(strategy, candles, closes, weightEntries, cfg);
579
+ parentPort.postMessage(result);
580
+ process.exit(0);
581
+ }
582
+ // ── Parallel dispatch (main thread) ─────────────────────────────────────────
583
+ function runParallel(strategies, candles, closes, weightEntries, cfg) {
584
+ const numCpus = Math.min(os.cpus().length, strategies.length);
585
+ console.log(` Workers: ${numCpus} threads (${os.cpus().length} CPUs available)\n`);
586
+ return Promise.all(strategies.map((strategy) => {
587
+ return new Promise((resolve, reject) => {
588
+ const worker = new Worker(__filename, {
589
+ workerData: { strategy, candles, closes, weightEntries, cfg },
590
+ });
591
+ worker.on('message', resolve);
592
+ worker.on('error', reject);
593
+ worker.on('exit', (code) => {
594
+ if (code !== 0)
595
+ reject(new Error(`Worker exited with code ${code}`));
596
+ });
597
+ });
598
+ }));
599
+ }
600
+ // ── Main ────────────────────────────────────────────────────────────────────
601
+ async function run() {
602
+ const cfg = parseArgs();
603
+ const loaded = loadLpData(cfg.dataPath);
604
+ const candles = loaded.candles;
605
+ const closes = candles.map((c) => c.close);
606
+ const strategies = loadAmaStrategies(cfg.resultsPath);
607
+ const weightEntries = Object.entries(WEIGHT_PROFILES);
608
+ const totalCombos = cfg.spreadValues.length * cfg.incrementValues.length *
609
+ cfg.ratioValues.length * weightEntries.length;
610
+ console.log('================================================================================');
611
+ console.log(' AMA SWEEP BACKTEST — persistent grid + weight profiles');
612
+ console.log('================================================================================');
613
+ console.log(` Data: ${path.basename(cfg.dataPath)} (${candles.length} candles, ~${(candles.length / 24).toFixed(0)} days)`);
614
+ console.log(` AMAs: ${strategies.map((s) => s.id).join(', ')}`);
615
+ console.log(` Weights: ${weightEntries.map(([n, w]) => `${n}(${w})`).join(', ')}`);
616
+ console.log(` Spread: ${cfg.spreadValues[0]}..${cfg.spreadValues[cfg.spreadValues.length - 1]}% (${cfg.spreadValues.length})`);
617
+ console.log(` Increment: ${cfg.incrementValues[0]}..${cfg.incrementValues[cfg.incrementValues.length - 1]}% (${cfg.incrementValues.length})`);
618
+ console.log(` Ratio: ${cfg.ratioValues[0]}..${cfg.ratioValues[cfg.ratioValues.length - 1]} (${cfg.ratioValues.length})`);
619
+ console.log(` Max orders: ${cfg.maxOrders}/side (actual count from ratio+increment) | Capital: ${cfg.capital}/side | Fee: ${cfg.feeRoundtripPct}%`);
620
+ console.log(` Spread floor: > fee (${cfg.feeRoundtripPct}%)`);
621
+ console.log(` Reposition: ${cfg.repositionPct}% AMA drift from grid center`);
622
+ console.log(` Tx model: create=${fmt(cfg.btsCreateFee, 5)} BTS, cancel=${fmt(cfg.btsCancelFee, 5)} BTS, maker=${fmt(cfg.makerCreateFactor * 100, 1)}%, 1 BTS=${fmt(cfg.txFeePrice, 2)} units`);
623
+ console.log(` Combos/AMA: ${totalCombos} | Total: ${totalCombos * strategies.length}\n`);
624
+ // ── Run AMA sweeps in parallel (one worker per AMA strategy) ──────
625
+ const byAma = [];
626
+ const allResults = [];
627
+ const workerResults = await runParallel(strategies, candles, closes, weightEntries, cfg);
628
+ for (const wr of workerResults) {
629
+ byAma.push(wr);
630
+ for (const sim of wr.allSims) {
631
+ allResults.push({ strategy: wr.strategy, sim });
632
+ }
633
+ const b = wr.best;
634
+ const bestLabel = b && b.matchedPairs > 0
635
+ ? `score=${fmt(b.score, 1)} pairs=${b.matchedPairs} net/cap=${fmt(b.netProfitPerCapital * 100, 1)}% gross=${fmt(b.profitPerCapital * 100, 1)}%`
636
+ : 'no fills';
637
+ process.stdout.write(` ${wr.strategy.id} (ER=${wr.strategy.er}, F=${wr.strategy.fast}, S=${wr.strategy.slow}): ${wr.evaluated} combos, ${bestLabel}\n`);
638
+ }
639
+ // ── Per-AMA best ────────────────────────────────────────────────────────
640
+ console.log('\n================================================================================');
641
+ console.log(' BEST PARAMS PER AMA');
642
+ console.log('================================================================================');
643
+ console.log('AMA | wt | spr% | inc% | ratio | nOrd | pairs | net/cap | gross/cap | drift | fee/d | score');
644
+ console.log('------+-------+-------+-------+-------+------+--------+---------+-----------+-------+-------+------');
645
+ for (const row of byAma) {
646
+ const b = row.best;
647
+ if (!b || b.matchedPairs === 0) {
648
+ console.log(`${row.strategy.id.padEnd(5)} | (no fills)`);
649
+ continue;
650
+ }
651
+ console.log(`${row.strategy.id.padEnd(5)} | ` +
652
+ `${b.weightName.padEnd(5)} | ` +
653
+ `${fmt(b.spreadPct, 1).padStart(5)} | ` +
654
+ `${fmt(b.incrementPct, 1).padStart(5)} | ` +
655
+ `${fmt(b.maxMinRatio, 2).padStart(5)} | ` +
656
+ `${String(b.ordersPerSide).padStart(4)} | ` +
657
+ `${String(b.matchedPairs).padStart(6)} | ` +
658
+ `${fmt(b.netProfitPerCapital * 100, 2).padStart(7)}% | ` +
659
+ `${fmt(b.profitPerCapital * 100, 2).padStart(10)}% | ` +
660
+ `${fmt(b.avgCenterDriftPct, 2).padStart(5)}% | ` +
661
+ `${fmt(b.feePerDayBts, 2).padStart(5)} | ` +
662
+ `${fmt(b.score, 1).padStart(6)}`);
663
+ }
664
+ // ── Top 5 per AMA ───────────────────────────────────────────────────────
665
+ for (const row of byAma) {
666
+ if (row.top5.length === 0)
667
+ continue;
668
+ console.log(`\n ${row.strategy.id} — Top 5:`);
669
+ console.log(' # | wt | spr% | inc% | ratio | nOrd | pairs | net/cap | drift | gAge | fee/d | score');
670
+ console.log(' --+-------+-------+-------+-------+------+--------+---------+-------+------+-------+------');
671
+ row.top5.forEach((b, idx) => {
672
+ console.log(` ${idx + 1} | ` +
673
+ `${b.weightName.padEnd(5)} | ` +
674
+ `${fmt(b.spreadPct, 1).padStart(5)} | ` +
675
+ `${fmt(b.incrementPct, 1).padStart(5)} | ` +
676
+ `${fmt(b.maxMinRatio, 2).padStart(5)} | ` +
677
+ `${String(b.ordersPerSide).padStart(4)} | ` +
678
+ `${String(b.matchedPairs).padStart(6)} | ` +
679
+ `${fmt(b.netProfitPerCapital * 100, 2).padStart(7)}% | ` +
680
+ `${fmt(b.avgCenterDriftPct, 2).padStart(5)}% | ` +
681
+ `${fmt(b.avgGridAgeBars, 0).padStart(4)} | ` +
682
+ `${fmt(b.feePerDayBts, 2).padStart(5)} | ` +
683
+ `${fmt(b.score, 1).padStart(6)}`);
684
+ });
685
+ }
686
+ // ── Global ranking (deduplicated) ───────────────────────────────────────
687
+ allResults.sort((a, b) => b.sim.score - a.sim.score);
688
+ const seen = new Set();
689
+ const deduped = [];
690
+ for (const r of allResults) {
691
+ const key = `${r.strategy.id}|${r.sim.spreadPct}|${r.sim.incrementPct}|${r.sim.maxMinRatio}|${r.sim.weightName}`;
692
+ if (seen.has(key))
693
+ continue;
694
+ seen.add(key);
695
+ deduped.push(r);
696
+ }
697
+ if (deduped.length === 0) {
698
+ console.log('\n NO CONFIGURATIONS PRODUCED ANY MATCHED PAIRS.');
699
+ return;
700
+ }
701
+ const topN = Math.min(cfg.topN, deduped.length);
702
+ console.log(`\n================================================================================`);
703
+ console.log(` GLOBAL TOP ${topN}`);
704
+ console.log('================================================================================');
705
+ console.log('# | AMA | wt | spr% | inc% | ratio | nOrd | pairs | net/cap | drift | fee/d | score');
706
+ console.log('---+-------+-------+-------+-------+-------+------+--------+---------+-------+-------+------');
707
+ for (let i = 0; i < topN; i++) {
708
+ const { strategy, sim } = deduped[i];
709
+ console.log(`${String(i + 1).padStart(2)} | ` +
710
+ `${strategy.id.padEnd(5)} | ` +
711
+ `${sim.weightName.padEnd(5)} | ` +
712
+ `${fmt(sim.spreadPct, 1).padStart(5)} | ` +
713
+ `${fmt(sim.incrementPct, 1).padStart(5)} | ` +
714
+ `${fmt(sim.maxMinRatio, 2).padStart(5)} | ` +
715
+ `${String(sim.ordersPerSide).padStart(4)} | ` +
716
+ `${String(sim.matchedPairs).padStart(6)} | ` +
717
+ `${fmt(sim.netProfitPerCapital * 100, 2).padStart(7)}% | ` +
718
+ `${fmt(sim.avgCenterDriftPct, 2).padStart(5)}% | ` +
719
+ `${fmt(sim.feePerDayBts, 2).padStart(5)} | ` +
720
+ `${fmt(sim.score, 1).padStart(6)}`);
721
+ }
722
+ // ── Winner ──────────────────────────────────────────────────────────────
723
+ const winner = deduped[0];
724
+ console.log(`\n================================================================================`);
725
+ console.log(` WINNER`);
726
+ console.log('================================================================================');
727
+ console.log(` AMA: ${winner.strategy.id} (ER=${winner.strategy.er}, Fast=${winner.strategy.fast}, Slow=${winner.strategy.slow})`);
728
+ console.log(` Weight: ${winner.sim.weightName} (${WEIGHT_PROFILES[winner.sim.weightName]})`);
729
+ console.log(` Spread: ${fmt(winner.sim.spreadPct, 1)}%`);
730
+ console.log(` Increment: ${fmt(winner.sim.incrementPct, 1)}%`);
731
+ console.log(` Ratio: ${fmt(winner.sim.maxMinRatio, 1)}x`);
732
+ console.log(` Pairs: ${winner.sim.matchedPairs} (${fmt(winner.sim.pairsPerDay, 2)}/day)`);
733
+ console.log(` Fill eff: ${fmt(winner.sim.fillEfficiency, 1)}%`);
734
+ console.log(` Profit/cap: gross ${fmt(winner.sim.profitPerCapital * 100, 2)}% | net ${fmt(winner.sim.netProfitPerCapital * 100, 2)}%`);
735
+ console.log(` Net profit: ${fmt(winner.sim.netProfitUnits, 0)} units after ${fmt(winner.sim.totalRepositionFeesBts, 1)} BTS reposition fees`);
736
+ console.log(` Avg/pair: ${fmt(winner.sim.avgProfitPerPair, 2)} units`);
737
+ console.log(` Max DD: ${fmt(winner.sim.maxDrawdownPct, 2)}%`);
738
+ console.log(` Repositions: ${winner.sim.repositionCount}`);
739
+ console.log(` Grid age: avg ${fmt(winner.sim.avgGridAgeBars, 1)} bars | max ${fmt(winner.sim.maxGridAgeBars, 0)} bars`);
740
+ console.log(` Drift: avg ${fmt(winner.sim.avgCenterDriftPct, 2)}% | max ${fmt(winner.sim.maxCenterDriftPct, 2)}% | near-threshold ${fmt(winner.sim.nearThresholdBarsPct, 1)}%`);
741
+ console.log(` Tx burn: ${fmt(winner.sim.estimatedFeePerRepositionBts, 4)} BTS/reposition | ${fmt(winner.sim.feePerDayBts, 2)} BTS/day`);
742
+ console.log(` Score: ${fmt(winner.sim.score, 2)}`);
743
+ // ── Save JSON ───────────────────────────────────────────────────────────
744
+ const outName = `ama_sweep_results_${path.basename(cfg.dataPath, '.json')}.json`;
745
+ const outPath = path.join(__dirname, outName);
746
+ writeJSON(outPath, {
747
+ meta: {
748
+ generatedAt: new Date().toISOString(),
749
+ dataPath: path.relative(process.cwd(), cfg.dataPath),
750
+ resultsPath: path.relative(process.cwd(), cfg.resultsPath),
751
+ candles: candles.length,
752
+ days: candles.length / 24,
753
+ maxOrders: cfg.maxOrders,
754
+ capitalPerSide: cfg.capital,
755
+ feeRoundtripPct: cfg.feeRoundtripPct,
756
+ repositionPct: cfg.repositionPct,
757
+ btsCreateFee: cfg.btsCreateFee,
758
+ btsCancelFee: cfg.btsCancelFee,
759
+ makerCreateFactor: cfg.makerCreateFactor,
760
+ txFeePrice: cfg.txFeePrice,
761
+ weightProfiles: WEIGHT_PROFILES,
762
+ search: {
763
+ spreadValues: cfg.spreadValues,
764
+ incrementValues: cfg.incrementValues,
765
+ ratioValues: cfg.ratioValues,
766
+ minSpreadFactor: cfg.minSpreadFactor,
767
+ combosPerAma: totalCombos,
768
+ totalCombos: totalCombos * strategies.length,
769
+ },
770
+ scoring: 'netProfitPerCapital * 100 * log10(max(1, matchedPairs)) - maxDrawdownPct * 0.5',
771
+ },
772
+ strategies,
773
+ perAma: byAma.map((row) => ({
774
+ strategy: row.strategy,
775
+ evaluated: row.evaluated,
776
+ best: row.best,
777
+ top5: row.top5,
778
+ })),
779
+ globalTop: deduped.slice(0, Math.max(cfg.topN, 20)).map(({ strategy, sim }) => ({
780
+ ama: strategy.id,
781
+ amaParams: { er: strategy.er, fast: strategy.fast, slow: strategy.slow },
782
+ ...sim,
783
+ })),
784
+ winner: {
785
+ ama: winner.strategy.id,
786
+ amaParams: { er: winner.strategy.er, fast: winner.strategy.fast, slow: winner.strategy.slow },
787
+ ...winner.sim,
788
+ },
789
+ });
790
+ console.log(`\nSaved: ${path.relative(process.cwd(), outPath)}`);
791
+ }
792
+ if (require.main === module) {
793
+ run().catch((err) => { console.error(err); process.exit(1); });
794
+ }
795
+ module.exports = {
796
+ WEIGHT_PROFILES,
797
+ allocateFundsByWeights,
798
+ buildGrid,
799
+ closeFilledInventoryAtPrice,
800
+ countCancelableOrders,
801
+ simulatePersistentGrid,
802
+ sweepOneAma,
803
+ };
804
+ //# sourceMappingURL=backtest_ama_sweep.js.map