dexbot 1.4.19 → 1.4.21

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 (302) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +22 -12
  3. package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +2 -2
  4. package/analysis/ama_fitting/calibrate_convergence_er.ts +1 -1
  5. package/analysis/ama_fitting/optimizer_high_resolution.ts +2 -1
  6. package/analysis/ama_fitting/package.json +1 -1
  7. package/analysis/analyze_derivatives.ts +4 -2
  8. package/analysis/analyze_dynamic_weight.ts +3 -1
  9. package/analysis/analyze_kalman.ts +3 -1
  10. package/analysis/analyze_regime.ts +3 -1
  11. package/analysis/analyze_regime_windows.ts +3 -1
  12. package/analysis/analyze_volatility.ts +2 -2
  13. package/analysis/bot_fitting/backtest_ama_sweep.ts +2 -1
  14. package/analysis/bot_fitting/backtest_bot_fitting.ts +17 -12
  15. package/analysis/bot_fitting/shared_utils.ts +1 -1
  16. package/analysis/bot_key_utils.ts +1 -5
  17. package/analysis/bot_usage/kibana_bot_queries.ts +1 -256
  18. package/analysis/chart_css.ts +1 -1
  19. package/analysis/chart_utils.ts +24 -0
  20. package/analysis/derivative_chart_generator.ts +3 -2
  21. package/analysis/math_utils.ts +1 -8
  22. package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
  23. package/analysis/trend_detection/dynamic_weight_chart_generator.ts +91 -55
  24. package/analysis/trend_detection/package.json +1 -1
  25. package/claw/ecosystem.config.cjs +2 -3
  26. package/claw/examples/claw_profiles_example.ts +4 -1
  27. package/claw/examples/memu_integration_example.ts +17 -17
  28. package/claw/modules/chain_actions.ts +51 -54
  29. package/claw/modules/chain_broadcast.ts +66 -104
  30. package/claw/modules/claw_bridge.ts +60 -80
  31. package/claw/modules/claw_catalog.ts +48 -17
  32. package/claw/modules/claw_infra.ts +1 -5
  33. package/claw/modules/claw_launcher.ts +47 -49
  34. package/claw/modules/claw_skill_md.ts +14 -16
  35. package/claw/modules/credit_runtime_adapter.ts +2 -18
  36. package/claw/modules/decision_loop.ts +4 -0
  37. package/claw/modules/dexbot_bridge.ts +1 -1
  38. package/claw/modules/dexbot_profiles.ts +8 -22
  39. package/claw/modules/honest_ecosystem.ts +24 -8
  40. package/claw/modules/launcher_paths.ts +4 -2
  41. package/claw/modules/liquidity_pools.ts +10 -3
  42. package/claw/modules/mcp_utils.ts +109 -0
  43. package/claw/modules/memu_bridge.ts +76 -54
  44. package/claw/modules/mpa_utils.ts +26 -3
  45. package/claw/modules/position_discovery.ts +16 -27
  46. package/claw/modules/position_manager.ts +32 -41
  47. package/claw/modules/position_manager_watch.ts +3 -2
  48. package/claw/modules/short_mpa_strategy.ts +1 -9
  49. package/claw/modules/skill_utils.ts +5 -3
  50. package/claw/modules/utils.ts +9 -1
  51. package/claw/package.json +1 -1
  52. package/claw/runtimes/openclaw-plugin/index.ts +27 -10
  53. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  54. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  55. package/claw/scripts/claw_bridge.ts +1 -1
  56. package/claw/scripts/claw_mcp_server.ts +19 -78
  57. package/claw/scripts/honest_assets_report.ts +19 -84
  58. package/claw/scripts/memu_mcp_server.ts +57 -155
  59. package/claw/tests/test_claw_bridge.ts +6 -2
  60. package/claw/tests/test_claw_mcp_transport.ts +2 -2
  61. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +2 -2
  62. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +1 -1
  63. package/dist/analysis/ama_fitting/calibrate_convergence_er.js +1 -1
  64. package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +1 -1
  65. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +1 -1
  66. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +2 -1
  67. package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +1 -1
  68. package/dist/analysis/analyze_derivatives.d.ts.map +1 -1
  69. package/dist/analysis/analyze_derivatives.js +4 -2
  70. package/dist/analysis/analyze_derivatives.js.map +1 -1
  71. package/dist/analysis/analyze_dynamic_weight.js +3 -1
  72. package/dist/analysis/analyze_dynamic_weight.js.map +1 -1
  73. package/dist/analysis/analyze_kalman.js +3 -1
  74. package/dist/analysis/analyze_kalman.js.map +1 -1
  75. package/dist/analysis/analyze_regime.js +3 -1
  76. package/dist/analysis/analyze_regime.js.map +1 -1
  77. package/dist/analysis/analyze_regime_windows.js +3 -1
  78. package/dist/analysis/analyze_regime_windows.js.map +1 -1
  79. package/dist/analysis/analyze_volatility.js +2 -2
  80. package/dist/analysis/analyze_volatility.js.map +1 -1
  81. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +1 -1
  82. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +2 -1
  83. package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +1 -1
  84. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +18 -13
  85. package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +1 -1
  86. package/dist/analysis/bot_fitting/shared_utils.d.ts +1 -12
  87. package/dist/analysis/bot_fitting/shared_utils.d.ts.map +1 -1
  88. package/dist/analysis/bot_fitting/shared_utils.js +1 -1
  89. package/dist/analysis/bot_fitting/shared_utils.js.map +1 -1
  90. package/dist/analysis/bot_key_utils.d.ts +1 -1
  91. package/dist/analysis/bot_key_utils.d.ts.map +1 -1
  92. package/dist/analysis/bot_key_utils.js +1 -5
  93. package/dist/analysis/bot_key_utils.js.map +1 -1
  94. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -337
  95. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -1
  96. package/dist/analysis/bot_usage/kibana_bot_queries.js +1 -241
  97. package/dist/analysis/bot_usage/kibana_bot_queries.js.map +1 -1
  98. package/dist/analysis/chart_css.d.ts +1 -15
  99. package/dist/analysis/chart_css.d.ts.map +1 -1
  100. package/dist/analysis/chart_css.js +1 -1
  101. package/dist/analysis/chart_css.js.map +1 -1
  102. package/dist/analysis/chart_utils.d.ts +0 -3
  103. package/dist/analysis/chart_utils.d.ts.map +1 -1
  104. package/dist/analysis/chart_utils.js +25 -0
  105. package/dist/analysis/chart_utils.js.map +1 -1
  106. package/dist/analysis/derivative_chart_generator.d.ts.map +1 -1
  107. package/dist/analysis/derivative_chart_generator.js +3 -2
  108. package/dist/analysis/derivative_chart_generator.js.map +1 -1
  109. package/dist/analysis/math_utils.d.ts +3 -5
  110. package/dist/analysis/math_utils.d.ts.map +1 -1
  111. package/dist/analysis/math_utils.js +3 -5
  112. package/dist/analysis/math_utils.js.map +1 -1
  113. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +1 -1
  114. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +82 -50
  115. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +1 -1
  116. package/dist/bot.js +2 -2
  117. package/dist/bot.js.map +1 -1
  118. package/dist/credential-daemon.js +1 -1
  119. package/dist/credential-daemon.js.map +1 -1
  120. package/dist/dexbot.d.ts.map +1 -1
  121. package/dist/dexbot.js +20 -17
  122. package/dist/dexbot.js.map +1 -1
  123. package/dist/market_adapter/ama_signal_runner.js +3 -3
  124. package/dist/market_adapter/core/kibana_client.d.ts +1 -3
  125. package/dist/market_adapter/core/kibana_client.d.ts.map +1 -1
  126. package/dist/market_adapter/core/kibana_client.js +1 -1
  127. package/dist/market_adapter/core/kibana_client.js.map +1 -1
  128. package/dist/market_adapter/core/market_adapter_service.d.ts +1 -2
  129. package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -1
  130. package/dist/market_adapter/core/market_adapter_service.js +9 -4
  131. package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
  132. package/dist/market_adapter/core/strategies/regime_gate.d.ts +1 -2
  133. package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -1
  134. package/dist/market_adapter/core/strategies/regime_gate.js +1 -1
  135. package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
  136. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +2 -2
  137. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
  138. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +5 -5
  139. package/dist/market_adapter/inputs/fetch_lp_data.js +5 -5
  140. package/dist/market_adapter/inputs/kibana_source.d.ts +1 -2
  141. package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -1
  142. package/dist/market_adapter/inputs/kibana_source.js +1 -1
  143. package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
  144. package/dist/market_adapter/lp_chart_strategy_loader.d.ts +1 -2
  145. package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +1 -1
  146. package/dist/market_adapter/lp_chart_strategy_loader.js +4 -4
  147. package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -1
  148. package/dist/market_adapter/market_adapter.d.ts.map +1 -1
  149. package/dist/market_adapter/market_adapter.js +2 -1
  150. package/dist/market_adapter/market_adapter.js.map +1 -1
  151. package/dist/modules/account_bots.d.ts +3 -0
  152. package/dist/modules/account_bots.d.ts.map +1 -1
  153. package/dist/modules/account_bots.js +156 -46
  154. package/dist/modules/account_bots.js.map +1 -1
  155. package/dist/modules/account_orders.d.ts +1 -7
  156. package/dist/modules/account_orders.d.ts.map +1 -1
  157. package/dist/modules/account_orders.js +9 -17
  158. package/dist/modules/account_orders.js.map +1 -1
  159. package/dist/modules/bitshares_client.d.ts +2 -14
  160. package/dist/modules/bitshares_client.d.ts.map +1 -1
  161. package/dist/modules/bitshares_client.js +22 -31
  162. package/dist/modules/bitshares_client.js.map +1 -1
  163. package/dist/modules/bot_settings.js +1 -1
  164. package/dist/modules/bot_settings.js.map +1 -1
  165. package/dist/modules/chain_keys.js +2 -2
  166. package/dist/modules/chain_keys.js.map +1 -1
  167. package/dist/modules/chain_orders.d.ts +2 -3
  168. package/dist/modules/chain_orders.d.ts.map +1 -1
  169. package/dist/modules/chain_orders.js +8 -25
  170. package/dist/modules/chain_orders.js.map +1 -1
  171. package/dist/modules/config.d.ts +2 -0
  172. package/dist/modules/config.d.ts.map +1 -1
  173. package/dist/modules/config.js +6 -1
  174. package/dist/modules/config.js.map +1 -1
  175. package/dist/modules/constants.d.ts +0 -1
  176. package/dist/modules/constants.d.ts.map +1 -1
  177. package/dist/modules/constants.js +1 -5
  178. package/dist/modules/constants.js.map +1 -1
  179. package/dist/modules/credential_policy.js +1 -1
  180. package/dist/modules/credential_policy.js.map +1 -1
  181. package/dist/modules/dexbot_class.d.ts.map +1 -1
  182. package/dist/modules/dexbot_class.js +3 -2
  183. package/dist/modules/dexbot_class.js.map +1 -1
  184. package/dist/modules/dexbot_cow_runtime.d.ts +0 -7
  185. package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
  186. package/dist/modules/dexbot_cow_runtime.js +95 -0
  187. package/dist/modules/dexbot_cow_runtime.js.map +1 -1
  188. package/dist/modules/dexbot_state_recovery.d.ts.map +1 -1
  189. package/dist/modules/dexbot_state_recovery.js +22 -2
  190. package/dist/modules/dexbot_state_recovery.js.map +1 -1
  191. package/dist/modules/fund_registry.d.ts.map +1 -1
  192. package/dist/modules/fund_registry.js +5 -2
  193. package/dist/modules/fund_registry.js.map +1 -1
  194. package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
  195. package/dist/modules/launcher/bot_supervisor.js +6 -7
  196. package/dist/modules/launcher/bot_supervisor.js.map +1 -1
  197. package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -1
  198. package/dist/modules/launcher/foreign_cred_daemon.js +6 -0
  199. package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
  200. package/dist/modules/launcher/market_adapter_runtime.d.ts +2 -3
  201. package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
  202. package/dist/modules/launcher/market_adapter_runtime.js +7 -15
  203. package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
  204. package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
  205. package/dist/modules/launcher/monolithic_runtime.js +1 -0
  206. package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
  207. package/dist/modules/launcher/status_reporting.d.ts +1 -2
  208. package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
  209. package/dist/modules/launcher/status_reporting.js +1 -4
  210. package/dist/modules/launcher/status_reporting.js.map +1 -1
  211. package/dist/modules/order/accounting.js +2 -2
  212. package/dist/modules/order/accounting.js.map +1 -1
  213. package/dist/modules/order/format.d.ts +0 -8
  214. package/dist/modules/order/format.d.ts.map +1 -1
  215. package/dist/modules/order/format.js +0 -8
  216. package/dist/modules/order/format.js.map +1 -1
  217. package/dist/modules/order/grid.d.ts.map +1 -1
  218. package/dist/modules/order/grid.js +146 -32
  219. package/dist/modules/order/grid.js.map +1 -1
  220. package/dist/modules/order/logger.js +1 -1
  221. package/dist/modules/order/logger.js.map +1 -1
  222. package/dist/modules/order/logger_state.d.ts +1 -13
  223. package/dist/modules/order/logger_state.d.ts.map +1 -1
  224. package/dist/modules/order/logger_state.js +1 -11
  225. package/dist/modules/order/logger_state.js.map +1 -1
  226. package/dist/modules/order/manager.d.ts +13 -0
  227. package/dist/modules/order/manager.d.ts.map +1 -1
  228. package/dist/modules/order/manager.js +75 -2
  229. package/dist/modules/order/manager.js.map +1 -1
  230. package/dist/modules/order/processed_fill_store.d.ts +0 -5
  231. package/dist/modules/order/processed_fill_store.d.ts.map +1 -1
  232. package/dist/modules/order/processed_fill_store.js +1 -12
  233. package/dist/modules/order/processed_fill_store.js.map +1 -1
  234. package/dist/modules/order/sync_engine.d.ts.map +1 -1
  235. package/dist/modules/order/sync_engine.js +10 -3
  236. package/dist/modules/order/sync_engine.js.map +1 -1
  237. package/dist/modules/order/utils/math.d.ts +80 -1
  238. package/dist/modules/order/utils/math.d.ts.map +1 -1
  239. package/dist/modules/order/utils/math.js +138 -2
  240. package/dist/modules/order/utils/math.js.map +1 -1
  241. package/dist/modules/order/utils/order.d.ts.map +1 -1
  242. package/dist/modules/order/utils/order.js +10 -2
  243. package/dist/modules/order/utils/order.js.map +1 -1
  244. package/dist/modules/paths.d.ts +26 -1
  245. package/dist/modules/paths.d.ts.map +1 -1
  246. package/dist/modules/paths.js +39 -6
  247. package/dist/modules/paths.js.map +1 -1
  248. package/dist/modules/runtime_settings.js +3 -1
  249. package/dist/modules/runtime_settings.js.map +1 -1
  250. package/dist/modules/settings_merge.d.ts.map +1 -1
  251. package/dist/modules/settings_merge.js +3 -1
  252. package/dist/modules/settings_merge.js.map +1 -1
  253. package/dist/modules/storage/browser_adapter.d.ts +8 -3
  254. package/dist/modules/storage/browser_adapter.d.ts.map +1 -1
  255. package/dist/modules/storage/browser_adapter.js +53 -4
  256. package/dist/modules/storage/browser_adapter.js.map +1 -1
  257. package/dist/modules/utils/sanitize_key.d.ts +7 -0
  258. package/dist/modules/utils/sanitize_key.d.ts.map +1 -0
  259. package/dist/modules/utils/sanitize_key.js +15 -0
  260. package/dist/modules/utils/sanitize_key.js.map +1 -0
  261. package/dist/pm2.js +6 -6
  262. package/dist/pm2.js.map +1 -1
  263. package/dist/scripts/analyze-git.js +2 -1
  264. package/dist/scripts/analyze-git.js.map +1 -1
  265. package/dist/scripts/analyze-orders.d.ts +2 -2
  266. package/dist/scripts/analyze-orders.d.ts.map +1 -1
  267. package/dist/scripts/analyze-orders.js +6 -14
  268. package/dist/scripts/analyze-orders.js.map +1 -1
  269. package/dist/scripts/runner.js +1 -1
  270. package/dist/scripts/runner.js.map +1 -1
  271. package/dist/scripts/update.js +1 -1
  272. package/dist/scripts/update.js.map +1 -1
  273. package/docs/BITSHARES_ONBOARDING.md +63 -18
  274. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +5 -14
  275. package/docs/COW_INVARIANTS.md +4 -4
  276. package/docs/CREDENTIAL_SECURITY.md +0 -11
  277. package/docs/DEXBOT_COMPARISON.md +11 -11
  278. package/docs/EVOLUTION.md +12 -10
  279. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +27 -83
  280. package/docs/GRID_RECALCULATION.md +1 -13
  281. package/docs/GRID_RECONCILE.md +24 -24
  282. package/docs/LIFECYCLE.md +4 -4
  283. package/docs/LOGGING.md +1 -1
  284. package/docs/MPA_CREDIT_USAGE.md +3 -3
  285. package/docs/README.md +2 -2
  286. package/docs/WORKFLOW.md +2 -2
  287. package/docs/architecture.md +43 -38
  288. package/docs/developer_guide.md +16 -18
  289. package/market_adapter/README.md +0 -2
  290. package/modules/README.md +2 -1
  291. package/package.json +2 -3
  292. package/scripts/README.md +1 -1
  293. package/scripts/lib/dexbot-paths.sh +20 -11
  294. package/claw/openclaw.plugin.json +0 -13
  295. package/dist/market_adapter/merge_lp_data.d.ts +0 -3
  296. package/dist/market_adapter/merge_lp_data.d.ts.map +0 -1
  297. package/dist/market_adapter/merge_lp_data.js +0 -125
  298. package/dist/market_adapter/merge_lp_data.js.map +0 -1
  299. package/dist/market_adapter/utils/paths.d.ts +0 -3
  300. package/dist/market_adapter/utils/paths.d.ts.map +0 -1
  301. package/dist/market_adapter/utils/paths.js +0 -5
  302. package/dist/market_adapter/utils/paths.js.map +0 -1
@@ -34,7 +34,6 @@
34
34
  */
35
35
 
36
36
 
37
- import { toIntervalLabel } from '../../market_adapter/interval_utils.js';
38
37
  import { kibanaSearch, DEFAULT_CONFIG as BASE_CONFIG } from '../../market_adapter/core/kibana_client.js';
39
38
  'use strict';
40
39
 
@@ -49,159 +48,6 @@ const DEFAULT_CONFIG = {
49
48
  timeout: 25000,
50
49
  };
51
50
 
52
- // ─── Aggregation query builders (size:0, for counts & timelines) ───────────────
53
-
54
- /**
55
- * Time-bucketed count of limit_order_create ops for an account.
56
- * Optionally filtered to orders selling a specific asset.
57
- */
58
- function buildOrderCreateQuery(accountId: string, lookbackHours: number, intervalSeconds: number = 3600, sellAssetId: string | null = null) {
59
- const filters = [
60
- { term: { operation_type: OP_LIMIT_ORDER_CREATE } },
61
- { term: { 'operation_history.op_object.seller.keyword': accountId } },
62
- { range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
63
- ];
64
- if (sellAssetId) {
65
- filters.push({ term: { 'operation_history.op_object.amount_to_sell.asset_id.keyword': sellAssetId } } as any);
66
- }
67
- return {
68
- size: 0,
69
- query: { bool: { filter: filters } },
70
- aggs: {
71
- by_time: {
72
- date_histogram: {
73
- field: 'block_data.block_time',
74
- fixed_interval: toIntervalLabel(intervalSeconds),
75
- min_doc_count: 1,
76
- },
77
- },
78
- total: { value_count: { field: 'operation_type' } },
79
- },
80
- };
81
- }
82
-
83
- /**
84
- * Time-bucketed count of fill_order ops for an account.
85
- * Optionally filtered to fills where account pays a specific asset.
86
- */
87
- function buildFillOrderQuery(accountId: string, lookbackHours: number, intervalSeconds: number = 3600, paysAssetId: string | null = null) {
88
- const filters = [
89
- { term: { operation_type: OP_FILL_ORDER } },
90
- { term: { 'operation_history.op_object.account_id.keyword': accountId } },
91
- { range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
92
- ];
93
- if (paysAssetId) {
94
- filters.push({ term: { 'operation_history.op_object.pays.asset_id.keyword': paysAssetId } } as any);
95
- }
96
- return {
97
- size: 0,
98
- query: { bool: { filter: filters } },
99
- aggs: {
100
- by_time: {
101
- date_histogram: {
102
- field: 'block_data.block_time',
103
- fixed_interval: toIntervalLabel(intervalSeconds),
104
- min_doc_count: 1,
105
- },
106
- },
107
- total: { value_count: { field: 'operation_type' } },
108
- },
109
- };
110
- }
111
-
112
- /**
113
- * Time-bucketed count of limit_order_cancel ops for an account.
114
- */
115
- function buildOrderCancelQuery(accountId: string, lookbackHours: number, intervalSeconds: number = 3600) {
116
- return {
117
- size: 0,
118
- query: {
119
- bool: {
120
- filter: [
121
- { term: { operation_type: OP_LIMIT_ORDER_CANCEL } },
122
- { term: { 'operation_history.op_object.fee_paying_account.keyword': accountId } },
123
- { range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
124
- ],
125
- },
126
- },
127
- aggs: {
128
- by_time: {
129
- date_histogram: {
130
- field: 'block_data.block_time',
131
- fixed_interval: toIntervalLabel(intervalSeconds),
132
- min_doc_count: 1,
133
- },
134
- },
135
- total: { value_count: { field: 'operation_type' } },
136
- },
137
- };
138
- }
139
-
140
- /**
141
- * Daily activity breakdown by operation type for an account.
142
- * Merges creates (by seller), fills (by account_id), cancels (by fee_paying_account)
143
- * into one aggregation using a filter per op type.
144
- */
145
- function buildDailyActivityQuery(accountId: string, lookbackHours: number) {
146
- return {
147
- size: 0,
148
- query: {
149
- bool: {
150
- filter: [
151
- { range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
152
- ],
153
- },
154
- },
155
- aggs: {
156
- creates: {
157
- filter: {
158
- bool: {
159
- filter: [
160
- { term: { operation_type: OP_LIMIT_ORDER_CREATE } },
161
- { term: { 'operation_history.op_object.seller.keyword': accountId } },
162
- ],
163
- },
164
- },
165
- aggs: {
166
- by_day: {
167
- date_histogram: { field: 'block_data.block_time', fixed_interval: '1d', min_doc_count: 1 },
168
- },
169
- },
170
- },
171
- fills: {
172
- filter: {
173
- bool: {
174
- filter: [
175
- { term: { operation_type: OP_FILL_ORDER } },
176
- { term: { 'operation_history.op_object.account_id.keyword': accountId } },
177
- ],
178
- },
179
- },
180
- aggs: {
181
- by_day: {
182
- date_histogram: { field: 'block_data.block_time', fixed_interval: '1d', min_doc_count: 1 },
183
- },
184
- },
185
- },
186
- cancels: {
187
- filter: {
188
- bool: {
189
- filter: [
190
- { term: { operation_type: OP_LIMIT_ORDER_CANCEL } },
191
- { term: { 'operation_history.op_object.fee_paying_account.keyword': accountId } },
192
- ],
193
- },
194
- },
195
- aggs: {
196
- by_day: {
197
- date_histogram: { field: 'block_data.block_time', fixed_interval: '1d', min_doc_count: 1 },
198
- },
199
- },
200
- },
201
- },
202
- };
203
- }
204
-
205
51
  // ─── Raw document query builders (size>0, for price/grid analysis) ────────────
206
52
 
207
53
  /**
@@ -236,107 +82,6 @@ function buildOrderPriceQuery(accountId: string, lookbackHours: number, sellAsse
236
82
  };
237
83
  }
238
84
 
239
- /**
240
- * Fetch raw fill_order documents for fill-price analysis.
241
- *
242
- * @param {string} accountId
243
- * @param {number} lookbackHours
244
- * @param {string} [paysAssetId]
245
- * @param {number} [maxResults]
246
- * @returns {Object} Elasticsearch query object
247
- */
248
- function buildFillPriceQuery(accountId: string, lookbackHours: number, paysAssetId: string | null = null, maxResults: number = 500) {
249
- const filters = [
250
- { term: { operation_type: OP_FILL_ORDER } },
251
- { term: { 'operation_history.op_object.account_id.keyword': accountId } },
252
- { range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
253
- ];
254
- if (paysAssetId) {
255
- filters.push({ term: { 'operation_history.op_object.pays.asset_id.keyword': paysAssetId } } as any);
256
- }
257
- return {
258
- size: maxResults,
259
- _source: [
260
- 'block_data.block_time',
261
- 'operation_history.op_object.pays',
262
- 'operation_history.op_object.receives',
263
- 'operation_history.op_object.order_id',
264
- ],
265
- query: { bool: { filter: filters } },
266
- sort: [{ 'block_data.block_time': { order: 'desc' } }],
267
- };
268
- }
269
-
270
- /**
271
- * Discover which asset pairs an account trades by aggregating the sell asset IDs.
272
- * Returns top asset IDs by order count.
273
- */
274
- function buildAssetDiscoveryQuery(accountId: string, lookbackHours: number) {
275
- return {
276
- size: 0,
277
- query: {
278
- bool: {
279
- filter: [
280
- { term: { operation_type: OP_LIMIT_ORDER_CREATE } },
281
- { term: { 'operation_history.op_object.seller.keyword': accountId } },
282
- { range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
283
- ],
284
- },
285
- },
286
- aggs: {
287
- sell_assets: {
288
- terms: {
289
- field: 'operation_history.op_object.amount_to_sell.asset_id.keyword',
290
- size: 10,
291
- },
292
- },
293
- recv_assets: {
294
- terms: {
295
- field: 'operation_history.op_object.min_to_receive.asset_id.keyword',
296
- size: 10,
297
- },
298
- },
299
- },
300
- };
301
- }
302
-
303
- // ─── Fetch helpers ────────────────────────────────────────────────────────────
304
-
305
- async function fetchOrderCreate(accountId: string, lookbackHours: number, config: any = {}, sellAssetId: string | null = null, intervalSeconds: number = 3600) {
306
- const cfg = { ...DEFAULT_CONFIG, ...config };
307
- return kibanaSearch(cfg, buildOrderCreateQuery(accountId, lookbackHours, intervalSeconds, sellAssetId));
308
- }
309
-
310
- async function fetchFillOrder(accountId: string, lookbackHours: number, config: any = {}, paysAssetId: string | null = null, intervalSeconds: number = 3600) {
311
- const cfg = { ...DEFAULT_CONFIG, ...config };
312
- return kibanaSearch(cfg, buildFillOrderQuery(accountId, lookbackHours, intervalSeconds, paysAssetId));
313
- }
314
-
315
- async function fetchOrderCancel(accountId: string, lookbackHours: number, config: any = {}, intervalSeconds: number = 3600) {
316
- const cfg = { ...DEFAULT_CONFIG, ...config };
317
- return kibanaSearch(cfg, buildOrderCancelQuery(accountId, lookbackHours, intervalSeconds));
318
- }
319
-
320
- async function fetchOrderPrices(accountId: string, lookbackHours: number, config: any = {}, sellAssetId: string | null = null, maxResults: number = 1000) {
321
- const cfg = { ...DEFAULT_CONFIG, ...config };
322
- return kibanaSearch(cfg, buildOrderPriceQuery(accountId, lookbackHours, sellAssetId, maxResults));
323
- }
324
-
325
- async function fetchFillPrices(accountId: string, lookbackHours: number, config: any = {}, paysAssetId: string | null = null, maxResults: number = 500) {
326
- const cfg = { ...DEFAULT_CONFIG, ...config };
327
- return kibanaSearch(cfg, buildFillPriceQuery(accountId, lookbackHours, paysAssetId, maxResults));
328
- }
329
-
330
- async function fetchDailyActivity(accountId: string, lookbackHours: number, config: any = {}) {
331
- const cfg = { ...DEFAULT_CONFIG, ...config };
332
- return kibanaSearch(cfg, buildDailyActivityQuery(accountId, lookbackHours));
333
- }
334
-
335
- async function fetchAssetDiscovery(accountId: string, lookbackHours: number, config: any = {}) {
336
- const cfg = { ...DEFAULT_CONFIG, ...config };
337
- return kibanaSearch(cfg, buildAssetDiscoveryQuery(accountId, lookbackHours));
338
- }
339
-
340
85
  // ─── Discovery query builders ─────────────────────────────────────────────────
341
86
 
342
87
  /**
@@ -423,5 +168,5 @@ function buildTopFilledAccountsQuery(lookbackHours: number, topN: number = 100,
423
168
 
424
169
  // ─── Exports ──────────────────────────────────────────────────────────────────
425
170
 
426
- export { OP_LIMIT_ORDER_CREATE, OP_LIMIT_ORDER_CANCEL, OP_FILL_ORDER, DEFAULT_CONFIG, kibanaSearch, buildOrderCreateQuery, buildFillOrderQuery, buildOrderCancelQuery, buildDailyActivityQuery, buildAssetDiscoveryQuery, buildOrderPriceQuery, buildFillPriceQuery, fetchOrderCreate, fetchFillOrder, fetchOrderCancel, fetchOrderPrices, fetchFillPrices, fetchDailyActivity, fetchAssetDiscovery, buildTopSellerAccountsQuery, buildTopCancellerAccountsQuery, buildTopFilledAccountsQuery }
171
+ export { DEFAULT_CONFIG, kibanaSearch, buildOrderPriceQuery, buildTopSellerAccountsQuery, buildTopCancellerAccountsQuery, buildTopFilledAccountsQuery }
427
172
 
@@ -57,4 +57,4 @@ function sharedChartCSS(): string {
57
57
  ].join('\n ');
58
58
  }
59
59
 
60
- export { baseResetCSS, headerCSS, panelsCSS, uplotBgCSS, dotCSS, cursorCSS, sectionLabelCSS, legendCSS, sharedChartCSS }
60
+ export { sharedChartCSS }
@@ -2,6 +2,7 @@
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { getStorage } from '../modules/storage/index.js';
5
+ import { PATHS } from '../modules/paths.js';
5
6
  const { ensureDir } = getStorage();
6
7
  'use strict';
7
8
 
@@ -9,6 +10,28 @@ const { ensureDir } = getStorage();
9
10
  * Chart utilities for analysis HTML generators.
10
11
  */
11
12
 
13
+ // Runtime assets every generated chart references as ../uplot/* relative to
14
+ // its own directory (charts live in <root>/charts, assets in <root>/uplot).
15
+ const UPLOT_RUNTIME_FILES = ['uPlot.iife.min.js', 'uPlot.min.css'];
16
+
17
+ /**
18
+ * Generated HTML loads uPlot from a sibling `uplot/` dir next to the charts
19
+ * dir. In a source checkout that dir is the vendored original; anywhere else
20
+ * (relocated analysis root under npm/home profiles, or a custom --chart path)
21
+ * materialize a copy so the relative refs keep resolving.
22
+ */
23
+ function ensureSiblingUplotAssets(chartDir: any) {
24
+ const targetDir = path.join(path.dirname(path.resolve(chartDir)), 'uplot');
25
+ const sourceDir = PATHS.ANALYSIS.ASSETS_DIR;
26
+ if (targetDir === path.resolve(sourceDir)) return;
27
+ if (UPLOT_RUNTIME_FILES.every((f) => fs.existsSync(path.join(targetDir, f)))) return;
28
+ if (!fs.existsSync(sourceDir)) return;
29
+ fs.mkdirSync(targetDir, { recursive: true });
30
+ for (const f of UPLOT_RUNTIME_FILES) {
31
+ fs.copyFileSync(path.join(sourceDir, f), path.join(targetDir, f));
32
+ }
33
+ }
34
+
12
35
 
13
36
  function escapeHtml(str: string) {
14
37
  const map: Record<string, string> = {
@@ -34,6 +57,7 @@ function toEpochSeconds(ts: any, fallbackIdx: any) {
34
57
  function writeChartFile(filePath: any, html: any) {
35
58
  const chartDir = path.dirname(filePath);
36
59
  if (!fs.existsSync(chartDir)) ensureDir(chartDir);
60
+ ensureSiblingUplotAssets(chartDir);
37
61
  fs.writeFileSync(filePath, html, 'utf8');
38
62
  }
39
63
 
@@ -8,11 +8,12 @@ import { getStorage } from '../modules/storage/index.js';
8
8
  const { ensureDir, readJSON } = getStorage();
9
9
  import { fixedTo } from '../modules/order/utils/math.js';
10
10
  import { bindHoverStateFn, zoomResetScript } from './chart_ui.js';
11
+ import { PATHS } from '../modules/paths.js';
11
12
  'use strict';
12
13
  function parseArgs(argv = process.argv.slice(2)) {
13
14
  const cfg: { inputFile: string | null; outputFile: string; title: string; quiet: boolean } = {
14
15
  inputFile: null,
15
- outputFile: 'analysis/charts/derivative_chart.html',
16
+ outputFile: path.join(PATHS.ANALYSIS.CHARTS_DIR, 'derivative_chart.html'),
16
17
  title: 'Derivative Trend Analysis',
17
18
  quiet: false,
18
19
  };
@@ -40,7 +41,7 @@ Derivative Chart Generator (uPlot)
40
41
  Usage:
41
42
  tsx analysis/derivative_chart_generator.ts --input <file.json> [options]
42
43
  Options:
43
- --output FILE Output HTML (default: analysis/charts/derivative_chart.html)
44
+ --output FILE Output HTML (default: <analysis charts dir>/derivative_chart.html)
44
45
  --title TEXT Chart title
45
46
  --quiet Suppress output
46
47
  `);
@@ -5,19 +5,15 @@ import { getStorage } from '../modules/storage/index.js';
5
5
  const { readJSON } = getStorage();
6
6
  import {
7
7
  getCandleClose,
8
- getCandleHigh,
9
- getCandleLow,
10
8
  getCandleTimestamp,
11
9
  normalizeCandle,
12
10
  } from '../market_adapter/candle_utils.js';
13
- import { computeATRSeries } from '../market_adapter/core/strategies/atr/calculator.js';
14
11
 
15
12
 
16
13
  /**
17
14
  * Math utilities for analysis scripts.
18
15
  *
19
- * Candle accessors and ATR series computation are centralized in
20
- * market_adapter (candle_utils.ts / strategies/atr/calculator.ts) and
16
+ * Candle accessors are centralized in market_adapter (candle_utils.ts) and
21
17
  * re-exported here so analysis tooling shares one logic path with the
22
18
  * live adapter and the browser-embedded chart scripts.
23
19
  */
@@ -50,10 +46,7 @@ function loadCandleFile(filePath: any) {
50
46
  export {
51
47
  range,
52
48
  calcStdDev,
53
- computeATRSeries,
54
49
  getCandleClose,
55
- getCandleHigh,
56
- getCandleLow,
57
50
  getCandleTimestamp,
58
51
  normalizeCandle,
59
52
  loadCandleFile,
@@ -160,7 +160,7 @@ All panels share aligned vertical time grid lines, and the bottom output panel s
160
160
  | **nz%** | 0–1 | 0.00 | Neutral zone: dead-band below which offset is forced to 0 |
161
161
  | **lb** | 1–32 | 9 | Logarithmic. Lookback bars for AMA slope calculation |
162
162
  | **amaS%** | 0.04–0.12 | 0.085 | Logarithmic. Gear ratio for average per-bar AMA slope saturation |
163
- | **kalS%** | 0.15–1.5 | 0.8 | Logarithmic. Gear ratio for Kalman composite saturation |
163
+ | **kalS%** | 0.5–1.5 | 1.0 | Logarithmic. Gear ratio for Kalman composite saturation |
164
164
  | **clip%** | 0–55 | 10 | Percentile clip: filters extreme inputs (0 = off) |
165
165
 
166
166
  ### Output Controls