dexbot 1.6.12 → 1.6.13

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 (170) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/analysis/README.md +9 -11
  3. package/analysis/ama_fitting/README.md +5 -3
  4. package/claw/README.md +1 -0
  5. package/claw/docs/AI_BOT_LIBRARY_API.md +2 -0
  6. package/claw/modules/claw_bridge.ts +0 -3
  7. package/claw/modules/claw_skill_md.ts +1 -0
  8. package/claw/package.json +3 -3
  9. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  10. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  11. package/claw/tsconfig.json +2 -2
  12. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +1 -14
  13. package/dist/analysis/ama_fitting/fetch_lp_candles.js +51 -41
  14. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +1 -24
  15. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +36 -18
  16. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +18 -66
  17. package/dist/analysis/analyze_args.d.ts +12 -0
  18. package/dist/analysis/analyze_args.js +20 -0
  19. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +1 -16
  20. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +20 -101
  21. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +26 -92
  22. package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +19 -34
  23. package/dist/analysis/bot_fitting/shared_utils.d.ts +71 -3
  24. package/dist/analysis/bot_fitting/shared_utils.js +124 -8
  25. package/dist/analysis/chart_ui.d.ts +30 -1
  26. package/dist/analysis/chart_ui.js +37 -1
  27. package/dist/analysis/fills_cache.d.ts +3 -23
  28. package/dist/analysis/fills_cache.js +3 -84
  29. package/dist/analysis/fills_source.d.ts +31 -1
  30. package/dist/analysis/fills_source.js +69 -1
  31. package/dist/analysis/grid_correction_check.d.ts +1 -23
  32. package/dist/analysis/grid_correction_check.js +15 -58
  33. package/dist/analysis/math_utils.d.ts +85 -1
  34. package/dist/analysis/math_utils.js +116 -1
  35. package/dist/analysis/price_sources.d.ts +22 -1
  36. package/dist/analysis/price_sources.js +23 -0
  37. package/dist/analysis/resolve_source.js +31 -10
  38. package/dist/analysis/trade_profitability.d.ts +6 -0
  39. package/dist/analysis/trade_profitability.js +23 -97
  40. package/dist/analysis/tradingview/analyze_tradingview.d.ts +1 -17
  41. package/dist/analysis/tradingview/analyze_tradingview.js +1 -1
  42. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +2 -15
  43. package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -101
  44. package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +22 -80
  45. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +11 -37
  46. package/dist/analysis/trend_detection/volatility_chart_generator.js +9 -10
  47. package/dist/analysis/worker_pool.d.ts +38 -0
  48. package/dist/analysis/worker_pool.js +67 -0
  49. package/dist/dexbot.js +67 -48
  50. package/dist/market_adapter/ama_signal_runner.js +21 -54
  51. package/dist/market_adapter/candle_utils.d.ts +7 -1
  52. package/dist/market_adapter/candle_utils.js +11 -1
  53. package/dist/market_adapter/cli_args.d.ts +22 -0
  54. package/dist/market_adapter/cli_args.js +30 -0
  55. package/dist/market_adapter/core/config_normalizers.js +11 -6
  56. package/dist/market_adapter/core/kibana_candles.d.ts +3 -1
  57. package/dist/market_adapter/core/kibana_candles.js +3 -2
  58. package/dist/market_adapter/core/market_adapter_service.d.ts +85 -85
  59. package/dist/market_adapter/core/market_adapter_service.js +93 -158
  60. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +1 -6
  61. package/dist/market_adapter/core/signals/hurst_analyzer.js +1 -1
  62. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +1 -11
  63. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +1 -1
  64. package/dist/market_adapter/inputs/fetch_book_data.js +0 -1
  65. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +63 -107
  66. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +8 -1
  67. package/dist/market_adapter/inputs/fetch_lp_data.js +25 -7
  68. package/dist/market_adapter/inputs/kibana_feed_source.js +4 -26
  69. package/dist/market_adapter/inputs/window_cache.d.ts +4 -72
  70. package/dist/market_adapter/inputs/window_cache.js +52 -177
  71. package/dist/market_adapter/interval_utils.d.ts +11 -1
  72. package/dist/market_adapter/interval_utils.js +16 -1
  73. package/dist/market_adapter/lp_chart_runner.d.ts +3 -0
  74. package/dist/market_adapter/lp_chart_runner.js +37 -19
  75. package/dist/market_adapter/market_adapter.js +27 -72
  76. package/dist/market_adapter/utils/data_discovery.d.ts +45 -1
  77. package/dist/market_adapter/utils/data_discovery.js +220 -27
  78. package/dist/market_adapter/utils/month_shards.d.ts +84 -0
  79. package/dist/market_adapter/utils/month_shards.js +237 -0
  80. package/dist/modules/account_bots.d.ts +1 -0
  81. package/dist/modules/account_bots.js +102 -121
  82. package/dist/modules/account_orders.d.ts +13 -0
  83. package/dist/modules/account_orders.js +38 -44
  84. package/dist/modules/bitshares-native/chain_client.d.ts +1 -1
  85. package/dist/modules/bitshares-native/chain_client.js +14 -13
  86. package/dist/modules/bitshares-native/resolvers.js +22 -25
  87. package/dist/modules/bitshares-native/serial/types.js +22 -50
  88. package/dist/modules/bitshares-native/signing_client.d.ts +1 -1
  89. package/dist/modules/bot_defaults.d.ts +2 -1
  90. package/dist/modules/bot_settings.d.ts +1 -1
  91. package/dist/modules/broadcast_failure.d.ts +2 -1
  92. package/dist/modules/chain_orders.d.ts +1 -1
  93. package/dist/modules/chain_orders.js +51 -96
  94. package/dist/modules/cli_start_onboarding.d.ts +2 -1
  95. package/dist/modules/constants.d.ts +7 -1
  96. package/dist/modules/constants.js +20 -1
  97. package/dist/modules/cr_planner.d.ts +1 -1
  98. package/dist/modules/cr_planner.js +1 -5
  99. package/dist/modules/credit_pricing.d.ts +2 -1
  100. package/dist/modules/credit_pricing.js +36 -40
  101. package/dist/modules/credit_runtime.d.ts +7 -0
  102. package/dist/modules/credit_runtime.js +45 -73
  103. package/dist/modules/daemon_node_health.d.ts +4 -3
  104. package/dist/modules/dexbot_class.d.ts +28 -17
  105. package/dist/modules/dexbot_class.js +105 -58
  106. package/dist/modules/dexbot_cow_runtime.d.ts +0 -7
  107. package/dist/modules/dexbot_cow_runtime.js +54 -28
  108. package/dist/modules/dexbot_credential_client.d.ts +0 -7
  109. package/dist/modules/dexbot_credential_client.js +1 -2
  110. package/dist/modules/dexbot_fill_runtime.d.ts +1 -2
  111. package/dist/modules/dexbot_fill_runtime.js +5 -6
  112. package/dist/modules/dexbot_maintenance_runtime.d.ts +20 -3
  113. package/dist/modules/dexbot_maintenance_runtime.js +84 -69
  114. package/dist/modules/dexbot_startup_runtime.d.ts +0 -1
  115. package/dist/modules/dexbot_startup_runtime.js +13 -14
  116. package/dist/modules/general_settings.d.ts +1 -1
  117. package/dist/modules/graceful_shutdown.js +17 -11
  118. package/dist/modules/key_store.js +0 -1
  119. package/dist/modules/lazy_shim.d.ts +11 -0
  120. package/dist/modules/lazy_shim.js +16 -0
  121. package/dist/modules/node_connect_policy.d.ts +3 -2
  122. package/dist/modules/node_failure_ledger.d.ts +6 -5
  123. package/dist/modules/order/format.d.ts +12 -3
  124. package/dist/modules/order/format.js +15 -3
  125. package/dist/modules/order/genesis_policy.d.ts +3 -3
  126. package/dist/modules/order/genesis_policy.js +5 -2
  127. package/dist/modules/order/grid.d.ts +4 -2
  128. package/dist/modules/order/grid.js +91 -35
  129. package/dist/modules/order/index.d.ts +1 -0
  130. package/dist/modules/order/logger.d.ts +1 -8
  131. package/dist/modules/order/logger.js +0 -9
  132. package/dist/modules/order/manager.d.ts +9 -13
  133. package/dist/modules/order/manager.js +33 -50
  134. package/dist/modules/order/utils/order.js +39 -35
  135. package/dist/modules/order/utils/system.d.ts +9 -29
  136. package/dist/modules/order/utils/system.js +17 -2
  137. package/dist/modules/order/utils/validate.js +2 -2
  138. package/dist/modules/order/utils/withPoolRef.d.ts +2 -1
  139. package/dist/modules/paths.js +32 -34
  140. package/dist/modules/runtime_settings.d.ts +2 -4
  141. package/dist/modules/settings_merge.d.ts +2 -2
  142. package/dist/modules/socket_json_client.d.ts +2 -1
  143. package/dist/modules/types.d.ts +42 -27
  144. package/dist/modules/utils/errors.js +1 -3
  145. package/dist/modules/version_notice.d.ts +11 -10
  146. package/dist/pm2.d.ts +0 -1
  147. package/dist/pm2.js +56 -35
  148. package/dist/scripts/analyze-git.js +2 -15
  149. package/dist/scripts/chart_command.js +2 -2
  150. package/dist/scripts/check_any.d.ts +4 -0
  151. package/dist/scripts/check_any.js +53 -21
  152. package/dist/scripts/diagnose-pool-history.js +1 -6
  153. package/dist/scripts/run-tests.js +0 -1
  154. package/dist/scripts/sync-version.js +0 -10
  155. package/docs/BITSHARES_ONBOARDING.md +8 -12
  156. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
  157. package/docs/DEXBOT_COMPARISON.md +6 -6
  158. package/docs/EVOLUTION.md +9 -8
  159. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
  160. package/docs/README.md +1 -1
  161. package/docs/WORKFLOW.md +1 -0
  162. package/docs/architecture.md +19 -10
  163. package/market_adapter/README.md +6 -4
  164. package/package.json +6 -9
  165. package/scripts/README.md +43 -38
  166. package/tests/README.md +25 -10
  167. package/dist/scripts/diagnose-kibana-candles.d.ts +0 -3
  168. package/dist/scripts/diagnose-kibana-candles.js +0 -82
  169. package/scripts/git-viewer.sh +0 -489
  170. package/scripts/postinstall.js +0 -16
@@ -342,6 +342,39 @@ declare class MarketAdapterService {
342
342
  buy: number;
343
343
  profile: string;
344
344
  meta: {
345
+ amaChannelContribution: any;
346
+ rawFinalOffset: any;
347
+ trendOffset: any;
348
+ finalOffset: any;
349
+ minOutputThreshold: number;
350
+ outputThreshold: number;
351
+ belowMinOutputThreshold: boolean;
352
+ kalmanReady: boolean;
353
+ isReady: boolean;
354
+ maxVolatilityOffset: number;
355
+ kalmanSmoothPct: number;
356
+ kalmanDispScaleMult: number;
357
+ kalmanDispThresholdMult: number;
358
+ kalmanSmoothSpanPct: number;
359
+ signalConfirmBars: number;
360
+ amaSlope: {
361
+ maxSlopePct: number;
362
+ };
363
+ kalmanSlope: {
364
+ maxSlopePct: number;
365
+ };
366
+ clipPercentile: number;
367
+ neutralZonePct: number;
368
+ volatilityThreshold: number;
369
+ volatilityExponent: number;
370
+ volatilityScaleX: number;
371
+ maxAsymmetryFactor: {} | null;
372
+ minScaleSlots: {} | null;
373
+ alpha: number;
374
+ dw: number;
375
+ gain: number;
376
+ atrPeriod: number;
377
+ maxSlopeOffset: number;
345
378
  source: string;
346
379
  staticSell: number;
347
380
  staticBuy: number;
@@ -355,39 +388,6 @@ declare class MarketAdapterService {
355
388
  regimeSensitivity: number;
356
389
  absoluteThreshold: number;
357
390
  volatilityPenalty: number;
358
- alpha: number;
359
- dw: number;
360
- gain: number;
361
- atrPeriod: number;
362
- maxSlopeOffset: number;
363
- maxAsymmetryFactor: {} | null;
364
- minScaleSlots: {} | null;
365
- clipPercentile: number;
366
- neutralZonePct: number;
367
- volatilityThreshold: number;
368
- volatilityExponent: number;
369
- volatilityScaleX: number;
370
- amaSlope: {
371
- maxSlopePct: number;
372
- };
373
- kalmanSlope: {
374
- maxSlopePct: number;
375
- };
376
- maxVolatilityOffset: number;
377
- kalmanSmoothPct: number;
378
- kalmanDispScaleMult: number;
379
- kalmanDispThresholdMult: number;
380
- kalmanSmoothSpanPct: number;
381
- signalConfirmBars: number;
382
- amaChannelContribution: any;
383
- rawFinalOffset: any;
384
- trendOffset: any;
385
- finalOffset: any;
386
- minOutputThreshold: number;
387
- outputThreshold: number;
388
- belowMinOutputThreshold: boolean;
389
- kalmanReady: boolean;
390
- isReady: boolean;
391
391
  };
392
392
  };
393
393
  dynamicWeightsPayload: {
@@ -398,41 +398,6 @@ declare class MarketAdapterService {
398
398
  hurstRegime?: string | null | undefined;
399
399
  peRegime?: string | null | undefined;
400
400
  regimeReady?: boolean | undefined;
401
- effectiveWeights: {
402
- sell: number;
403
- buy: number;
404
- };
405
- baseWeights: {
406
- sell: number;
407
- buy: number;
408
- };
409
- slopeOffset: number;
410
- rawSlopeOffset: number;
411
- amaSlopeGated: any;
412
- volatilityPenalty: number;
413
- finalOffset: any;
414
- alpha: number;
415
- dw: number;
416
- gain: number;
417
- atrPeriod: number;
418
- maxSlopeOffset: number;
419
- amaSlope: {
420
- maxSlopePct: number;
421
- };
422
- kalmanSlope: {
423
- maxSlopePct: number;
424
- };
425
- clipPercentile: number;
426
- neutralZonePct: number;
427
- volatilityThreshold: number;
428
- volatilityExponent: number;
429
- volatilityScaleX: number;
430
- maxVolatilityOffset: number;
431
- kalmanSmoothPct: number;
432
- kalmanDispScaleMult: number;
433
- kalmanDispThresholdMult: number;
434
- kalmanSmoothSpanPct: number;
435
- signalConfirmBars: number;
436
401
  rawFinalOffset: any;
437
402
  maxAsymmetryFactor: {} | null;
438
403
  minScaleSlots: {} | null;
@@ -447,6 +412,41 @@ declare class MarketAdapterService {
447
412
  outputThreshold: number;
448
413
  belowMinOutputThreshold: boolean;
449
414
  kalmanReady: boolean;
415
+ maxVolatilityOffset: number;
416
+ kalmanSmoothPct: number;
417
+ kalmanDispScaleMult: number;
418
+ kalmanDispThresholdMult: number;
419
+ kalmanSmoothSpanPct: number;
420
+ signalConfirmBars: number;
421
+ clipPercentile: number;
422
+ neutralZonePct: number;
423
+ volatilityThreshold: number;
424
+ volatilityExponent: number;
425
+ volatilityScaleX: number;
426
+ amaSlope: {
427
+ maxSlopePct: number;
428
+ };
429
+ kalmanSlope: {
430
+ maxSlopePct: number;
431
+ };
432
+ alpha: number;
433
+ dw: number;
434
+ gain: number;
435
+ atrPeriod: number;
436
+ maxSlopeOffset: number;
437
+ effectiveWeights: {
438
+ sell: number;
439
+ buy: number;
440
+ };
441
+ baseWeights: {
442
+ sell: number;
443
+ buy: number;
444
+ };
445
+ slopeOffset: number;
446
+ rawSlopeOffset: number;
447
+ amaSlopeGated: any;
448
+ volatilityPenalty: number;
449
+ finalOffset: any;
450
450
  };
451
451
  slopeResult: {
452
452
  slopeOffset: number;
@@ -461,6 +461,23 @@ declare class MarketAdapterService {
461
461
  regimeResult: RegimeMultiplierResult | null;
462
462
  kalmanResult: import("./signals/kalman_trend_analyzer.js").TrendAnalysis;
463
463
  amaSlope: {
464
+ maxVolatilityOffset: number;
465
+ kalmanSmoothPct: number;
466
+ kalmanDispScaleMult: number;
467
+ kalmanDispThresholdMult: number;
468
+ kalmanSmoothSpanPct: number;
469
+ signalConfirmBars: number;
470
+ amaSlope: {
471
+ maxSlopePct: number;
472
+ };
473
+ kalmanSlope: {
474
+ maxSlopePct: number;
475
+ };
476
+ alpha: number;
477
+ dw: number;
478
+ gain: number;
479
+ atrPeriod: number;
480
+ maxSlopeOffset: number;
464
481
  trend: string;
465
482
  confidence: number;
466
483
  slopePct: number | null;
@@ -472,23 +489,6 @@ declare class MarketAdapterService {
472
489
  weightVariance: number;
473
490
  isReady: boolean;
474
491
  kalmanReady: boolean;
475
- alpha: number;
476
- dw: number;
477
- gain: number;
478
- atrPeriod: number;
479
- maxSlopeOffset: number;
480
- amaSlope: {
481
- maxSlopePct: number;
482
- };
483
- kalmanSlope: {
484
- maxSlopePct: number;
485
- };
486
- maxVolatilityOffset: number;
487
- kalmanSmoothPct: number;
488
- kalmanDispScaleMult: number;
489
- kalmanDispThresholdMult: number;
490
- kalmanSmoothSpanPct: number;
491
- signalConfirmBars: number;
492
492
  };
493
493
  };
494
494
  processBot(bot: JsonObj, state: AdapterState, cfg: JsonObj, contextCache: Map<string, ContextCacheEntry>, hooks?: JsonObj): Promise<BotCycleResult>;
@@ -886,16 +886,14 @@ class MarketAdapterService {
886
886
  const outputThreshold = minOutputThreshold;
887
887
  // Per-bar directional offset series — canonical implementation shared
888
888
  // with the research chart and test harness (see dynamic_weight_series.ts).
889
- const seriesResult = computeDynamicWeightSeries({
889
+ // The base inputs are identical for the real series and the AMA-only
890
+ // diagnostic; only the Kalman inputs and clip threshold differ.
891
+ const seriesBaseInputs = {
890
892
  amaValues,
891
- kalmanVelocityPct: kalmanSmoothedVelocityPct,
892
- kalmanDisplacementPct: kalmanHistory.map((kr) => kr.displacementRawPct),
893
- kalmanIsReady: kalmanHistory.map((kr) => kr.isReady),
894
893
  regimeMultipliers,
895
894
  lookbackBars,
896
895
  amaErPeriod: botAma.erPeriod,
897
896
  amaClipThreshold,
898
- kalClipThreshold,
899
897
  neutralZonePct: nz,
900
898
  amaMaxSlopePct: amaMaxS,
901
899
  kalmanMaxSlopePct: kalMaxS,
@@ -907,6 +905,13 @@ class MarketAdapterService {
907
905
  minOutputThreshold,
908
906
  signalConfirmBars,
909
907
  clampFinalOutput: true,
908
+ };
909
+ const seriesResult = computeDynamicWeightSeries({
910
+ ...seriesBaseInputs,
911
+ kalmanVelocityPct: kalmanSmoothedVelocityPct,
912
+ kalmanDisplacementPct: kalmanHistory.map((kr) => kr.displacementRawPct),
913
+ kalmanIsReady: kalmanHistory.map((kr) => kr.isReady),
914
+ kalClipThreshold,
910
915
  });
911
916
  const { combinedOffSeries, gatedOffSeries, echoedOffSeries, echoedGatedOffSeries, } = seriesResult;
912
917
  const rawFinalOff = combinedOffSeries[combinedOffSeries.length - 1] ?? 0;
@@ -920,55 +925,44 @@ class MarketAdapterService {
920
925
  // alpha*(offset/norm)*gain*regime recomputation diverged from
921
926
  // finalOffset whenever gating or signal confirmation was active.)
922
927
  const amaOnlySeriesResult = computeDynamicWeightSeries({
923
- amaValues,
928
+ ...seriesBaseInputs,
924
929
  kalmanVelocityPct: kalmanSmoothedVelocityPct.map(() => null),
925
930
  kalmanDisplacementPct: kalmanHistory.map(() => null),
926
931
  kalmanIsReady: kalmanHistory.map(() => false),
927
- regimeMultipliers,
928
- lookbackBars,
929
- amaErPeriod: botAma.erPeriod,
930
- amaClipThreshold,
931
932
  kalClipThreshold: Infinity,
932
- neutralZonePct: nz,
933
- amaMaxSlopePct: amaMaxS,
934
- kalmanMaxSlopePct: kalMaxS,
935
- offsetClamp,
936
- dispScaleMinPct,
937
- alpha,
938
- dw,
939
- gain,
940
- minOutputThreshold,
941
- signalConfirmBars,
942
- clampFinalOutput: true,
943
933
  });
944
934
  const amaSlopeGated = slopeResult.isReady
945
935
  ? (useAmaBlend
946
936
  ? (amaOnlySeriesResult.echoedOffSeries[amaOnlySeriesResult.echoedOffSeries.length - 1] ?? 0)
947
937
  : 0)
948
938
  : 0;
949
- const amaSlope = {
950
- trend: slopeResult.trend,
951
- confidence: slopeResult.confidence,
952
- slopePct: slopeResult.slopePct,
953
- slopeOffset: slopeResult.slopeOffset,
954
- rawSlopeOffset: slopeResult.rawSlopeOffset,
955
- amaSlopeGated,
956
- regimeMultiplier,
957
- symmetricDelta: slopeResult.symmetricDelta,
958
- weightVariance,
959
- isReady: slopeResult.isReady,
960
- kalmanReady: kalmanResult?.isReady ?? false,
939
+ // Shared report fragments so the diagnostic `amaSlope` snapshot, the
940
+ // persisted `weights.meta` and `dynamicWeightsPayload` cannot drift
941
+ // apart. Kept as separate pieces so each object keeps its original
942
+ // key order.
943
+ const blendReport = {
961
944
  alpha,
962
945
  dw,
963
946
  gain,
964
- atrPeriod: atrPeriod,
947
+ atrPeriod,
965
948
  maxSlopeOffset: mo,
949
+ };
950
+ const slopeConfigReport = {
966
951
  amaSlope: {
967
952
  maxSlopePct: amaMaxS,
968
953
  },
969
954
  kalmanSlope: {
970
955
  maxSlopePct: kalMaxS,
971
956
  },
957
+ };
958
+ const volatilityReport = {
959
+ clipPercentile,
960
+ neutralZonePct: nz,
961
+ volatilityThreshold,
962
+ volatilityExponent,
963
+ volatilityScaleX,
964
+ };
965
+ const kalmanReport = {
972
966
  maxVolatilityOffset: volatilityClamp,
973
967
  kalmanSmoothPct,
974
968
  kalmanDispScaleMult,
@@ -976,6 +970,22 @@ class MarketAdapterService {
976
970
  kalmanSmoothSpanPct,
977
971
  signalConfirmBars,
978
972
  };
973
+ const amaSlope = {
974
+ trend: slopeResult.trend,
975
+ confidence: slopeResult.confidence,
976
+ slopePct: slopeResult.slopePct,
977
+ slopeOffset: slopeResult.slopeOffset,
978
+ rawSlopeOffset: slopeResult.rawSlopeOffset,
979
+ amaSlopeGated,
980
+ regimeMultiplier,
981
+ symmetricDelta: slopeResult.symmetricDelta,
982
+ weightVariance,
983
+ isReady: slopeResult.isReady,
984
+ kalmanReady: kalmanResult?.isReady ?? false,
985
+ ...blendReport,
986
+ ...slopeConfigReport,
987
+ ...kalmanReport,
988
+ };
979
989
  const staticSell = bot.weightDistribution?.sell ?? 0;
980
990
  const staticBuy = bot.weightDistribution?.buy ?? 0;
981
991
  const MIN_W = MARKET_ADAPTER.DYNAMIC_WEIGHT_MIN_WEIGHT;
@@ -1007,34 +1017,16 @@ class MarketAdapterService {
1007
1017
  regimeSensitivity,
1008
1018
  absoluteThreshold,
1009
1019
  volatilityPenalty: volPenalty,
1010
- alpha,
1011
- dw,
1012
- gain,
1013
- atrPeriod: atrPeriod,
1014
- maxSlopeOffset: mo,
1020
+ ...blendReport,
1015
1021
  maxAsymmetryFactor: (cfg.asymmetricBounds?.maxAsymmetryFactor != null)
1016
1022
  ? cfg.asymmetricBounds.maxAsymmetryFactor
1017
1023
  : null,
1018
1024
  minScaleSlots: (cfg.asymmetricBounds?.minScaleSlots != null)
1019
1025
  ? cfg.asymmetricBounds.minScaleSlots
1020
1026
  : null,
1021
- clipPercentile,
1022
- neutralZonePct: nz,
1023
- volatilityThreshold,
1024
- volatilityExponent,
1025
- volatilityScaleX,
1026
- amaSlope: {
1027
- maxSlopePct: amaMaxS,
1028
- },
1029
- kalmanSlope: {
1030
- maxSlopePct: kalMaxS,
1031
- },
1032
- maxVolatilityOffset: volatilityClamp,
1033
- kalmanSmoothPct,
1034
- kalmanDispScaleMult,
1035
- kalmanDispThresholdMult,
1036
- kalmanSmoothSpanPct,
1037
- signalConfirmBars,
1027
+ ...volatilityReport,
1028
+ ...slopeConfigReport,
1029
+ ...kalmanReport,
1038
1030
  amaChannelContribution: amaSlopeGated,
1039
1031
  rawFinalOffset: rawFinalOff,
1040
1032
  trendOffset: trendOff,
@@ -1054,28 +1046,10 @@ class MarketAdapterService {
1054
1046
  amaSlopeGated,
1055
1047
  volatilityPenalty: volPenalty,
1056
1048
  finalOffset: finalOff,
1057
- alpha,
1058
- dw,
1059
- gain,
1060
- atrPeriod: atrPeriod,
1061
- maxSlopeOffset: mo,
1062
- amaSlope: {
1063
- maxSlopePct: amaMaxS,
1064
- },
1065
- kalmanSlope: {
1066
- maxSlopePct: kalMaxS,
1067
- },
1068
- clipPercentile,
1069
- neutralZonePct: nz,
1070
- volatilityThreshold,
1071
- volatilityExponent,
1072
- volatilityScaleX,
1073
- maxVolatilityOffset: volatilityClamp,
1074
- kalmanSmoothPct,
1075
- kalmanDispScaleMult,
1076
- kalmanDispThresholdMult,
1077
- kalmanSmoothSpanPct,
1078
- signalConfirmBars,
1049
+ ...blendReport,
1050
+ ...slopeConfigReport,
1051
+ ...volatilityReport,
1052
+ ...kalmanReport,
1079
1053
  rawFinalOffset: rawFinalOff,
1080
1054
  maxAsymmetryFactor: (cfg.asymmetricBounds?.maxAsymmetryFactor != null)
1081
1055
  ? cfg.asymmetricBounds.maxAsymmetryFactor
@@ -1471,6 +1445,21 @@ class MarketAdapterService {
1471
1445
  nativePagesFetched = null;
1472
1446
  const bucketMs = Number(Number(cfg.intervalSeconds)) * 1000;
1473
1447
  const nowMs = this.getNowMs();
1448
+ // Native order-book history fetch shared by the bootstrap
1449
+ // fallback and the incremental path. Returns [] on failure
1450
+ // (after the same warn the inline blocks used to emit).
1451
+ const fetchNativeHistory = async (startMs, failureLabel) => {
1452
+ try {
1453
+ if (typeof deps.fetchNativeMarketHistorySince === 'function') {
1454
+ return await deps.withRetries(() => deps.fetchNativeMarketHistorySince(ctx.assetA, ctx.assetB, startMs, nowMs, Number(cfg.intervalSeconds), { fillCandleGaps: deps.fillCandleGaps }), cfg.sourceRetries, cfg.retryDelayMs, failureLabel);
1455
+ }
1456
+ }
1457
+ catch (_) {
1458
+ if (typeof deps.logger?.warn === 'function')
1459
+ deps.logger.warn(`[market_adapter] ${ctx.botKey}: ${failureLabel}`);
1460
+ }
1461
+ return [];
1462
+ };
1474
1463
  if (needBootstrap) {
1475
1464
  // Bootstrap: Kibana first (deep history), native as fallback
1476
1465
  const kibanaLookbackHours = this.bootstrapKibanaLookbackHours(cfg, rawKeepCount);
@@ -1495,16 +1484,7 @@ class MarketAdapterService {
1495
1484
  // Fall back to native
1496
1485
  const nativeLookbackHours = Math.max(Number(cfg.bootstrapLookbackHours) || 0, Number(Number(cfg.nativeBackfillHours)) || 0, (analysisKeepCount * Math.max(Number(Number(cfg.intervalSeconds)) || 3600, 3600)) / 3600);
1497
1486
  const nativeStartMs = Math.max(0, nowMs - (nativeLookbackHours * 3600 * 1000));
1498
- let nativeCandles = [];
1499
- try {
1500
- if (typeof deps.fetchNativeMarketHistorySince === 'function') {
1501
- nativeCandles = await deps.withRetries(() => deps.fetchNativeMarketHistorySince(ctx.assetA, ctx.assetB, nativeStartMs, nowMs, Number(cfg.intervalSeconds), { fillCandleGaps: deps.fillCandleGaps }), cfg.sourceRetries, cfg.retryDelayMs, 'native market history bootstrap failed');
1502
- }
1503
- }
1504
- catch (_) {
1505
- if (typeof deps.logger?.warn === 'function')
1506
- deps.logger.warn(`[market_adapter] ${ctx.botKey}: native market history bootstrap failed`);
1507
- }
1487
+ const nativeCandles = await fetchNativeHistory(nativeStartMs, 'native market history bootstrap failed');
1508
1488
  if (Array.isArray(nativeCandles) && nativeCandles.length > 0) {
1509
1489
  nextCandles = nativeCandles;
1510
1490
  sourceLabel = 'native-book-bootstrap';
@@ -1518,16 +1498,7 @@ class MarketAdapterService {
1518
1498
  // Incremental: native fetch
1519
1499
  const lastTs = nextCandles[nextCandles.length - 1]?.[0] || 0;
1520
1500
  const nativeStartMs = Math.max(0, lastTs - bucketMs);
1521
- let nativeCandles = [];
1522
- try {
1523
- if (typeof deps.fetchNativeMarketHistorySince === 'function') {
1524
- nativeCandles = await deps.withRetries(() => deps.fetchNativeMarketHistorySince(ctx.assetA, ctx.assetB, nativeStartMs, nowMs, Number(cfg.intervalSeconds), { fillCandleGaps: deps.fillCandleGaps }), cfg.sourceRetries, cfg.retryDelayMs, 'native market history fetch failed');
1525
- }
1526
- }
1527
- catch (_) {
1528
- if (typeof deps.logger?.warn === 'function')
1529
- deps.logger.warn(`[market_adapter] ${ctx.botKey}: native market history fetch failed`);
1530
- }
1501
+ const nativeCandles = await fetchNativeHistory(nativeStartMs, 'native market history fetch failed');
1531
1502
  if (Array.isArray(nativeCandles) && nativeCandles.length > 0) {
1532
1503
  nextCandles = deps.mergeCandles(nextCandles, nativeCandles);
1533
1504
  sourceLabel = 'native-book-history';
@@ -1960,6 +1931,26 @@ class MarketAdapterService {
1960
1931
  ? previousClosedCandleTs
1961
1932
  : null;
1962
1933
  hasNewClosedCandle = lastClosedCandleTs !== null && lastClosedCandleTs > previousClosedCandleTs;
1934
+ // Fields shared by the persisted bot state and the cycle result.
1935
+ // Built on demand so `consumedClosedCandleTs` is read after the
1936
+ // retry-baseline adjustment below, rather than frozen early.
1937
+ const buildCandleCycleFields = () => ({
1938
+ candleCount: nextCandles.length,
1939
+ analysisCandleCount: closedCandles.length,
1940
+ rawKeepCount,
1941
+ analysisKeepCount,
1942
+ amaWarmupBars,
1943
+ kibanaGapRepairCount,
1944
+ kibanaBackfillCount,
1945
+ unresolvedGapCount,
1946
+ nativeRecentTradeSequences,
1947
+ nativeLastTradeTs,
1948
+ nativeOverlapCount,
1949
+ nativePagesFetched,
1950
+ lastCandleTs: rawLastCandleTs,
1951
+ rawLastCandleTs,
1952
+ lastClosedCandleTs: consumedClosedCandleTs,
1953
+ });
1963
1954
  const candlePayload = {
1964
1955
  meta: {
1965
1956
  updatedAt: nowIso,
@@ -2009,21 +2000,7 @@ class MarketAdapterService {
2009
2000
  poolId: ctx.poolId,
2010
2001
  marketSource,
2011
2002
  candleFile: deps.path.relative(deps.root, filePath),
2012
- candleCount: nextCandles.length,
2013
- analysisCandleCount: closedCandles.length,
2014
- rawKeepCount,
2015
- analysisKeepCount,
2016
- amaWarmupBars,
2017
- kibanaGapRepairCount,
2018
- kibanaBackfillCount,
2019
- unresolvedGapCount,
2020
- nativeRecentTradeSequences,
2021
- nativeLastTradeTs,
2022
- nativeOverlapCount,
2023
- nativePagesFetched,
2024
- lastCandleTs: rawLastCandleTs,
2025
- rawLastCandleTs,
2026
- lastClosedCandleTs: consumedClosedCandleTs,
2003
+ ...buildCandleCycleFields(),
2027
2004
  lastCycleSource: sourceLabel,
2028
2005
  lastCycleAt: nowIso,
2029
2006
  staleData,
@@ -2035,27 +2012,13 @@ class MarketAdapterService {
2035
2012
  dryRunMessages,
2036
2013
  source: sourceLabel,
2037
2014
  marketSource,
2038
- candleCount: nextCandles.length,
2039
- analysisCandleCount: closedCandles.length,
2040
- rawKeepCount,
2041
- analysisKeepCount,
2042
- amaWarmupBars,
2043
- kibanaGapRepairCount,
2044
- kibanaBackfillCount,
2045
- unresolvedGapCount,
2046
- nativeRecentTradeSequences,
2047
- nativeLastTradeTs,
2048
- nativeOverlapCount,
2049
- nativePagesFetched,
2015
+ ...buildCandleCycleFields(),
2050
2016
  thresholdPercent: botThreshold,
2051
2017
  staleData,
2052
2018
  staleAgeHours,
2053
2019
  triggerSuppressedReason,
2054
2020
  poolId: ctx.poolId,
2055
2021
  candleFile: deps.path.relative(deps.root, filePath),
2056
- lastCandleTs: rawLastCandleTs,
2057
- rawLastCandleTs,
2058
- lastClosedCandleTs: consumedClosedCandleTs,
2059
2022
  amaConfig: {
2060
2023
  erPeriod: botAma.erPeriod,
2061
2024
  fastPeriod: botAma.fastPeriod,
@@ -2484,21 +2447,7 @@ class MarketAdapterService {
2484
2447
  poolId: ctx.poolId,
2485
2448
  marketSource,
2486
2449
  candleFile: deps.path.relative(deps.root, filePath),
2487
- candleCount: nextCandles.length,
2488
- analysisCandleCount: analysisCandles.length,
2489
- rawKeepCount,
2490
- analysisKeepCount,
2491
- amaWarmupBars,
2492
- kibanaGapRepairCount,
2493
- kibanaBackfillCount,
2494
- unresolvedGapCount,
2495
- nativeRecentTradeSequences,
2496
- nativeLastTradeTs,
2497
- nativeOverlapCount,
2498
- nativePagesFetched,
2499
- lastCandleTs: rawLastCandleTs,
2500
- rawLastCandleTs,
2501
- lastClosedCandleTs: consumedClosedCandleTs,
2450
+ ...buildCandleCycleFields(),
2502
2451
  lastAmaPrice: amaPrice,
2503
2452
  amaCenterPrice: Number(botState.amaCenterPrice || 0) > 0
2504
2453
  ? Number(botState.amaCenterPrice)
@@ -2553,18 +2502,7 @@ class MarketAdapterService {
2553
2502
  source: sourceLabel,
2554
2503
  marketSource,
2555
2504
  intervalSeconds: Number(cfg.intervalSeconds),
2556
- candleCount: nextCandles.length,
2557
- analysisCandleCount: analysisCandles.length,
2558
- rawKeepCount,
2559
- analysisKeepCount,
2560
- amaWarmupBars,
2561
- kibanaGapRepairCount,
2562
- kibanaBackfillCount,
2563
- unresolvedGapCount,
2564
- nativeRecentTradeSequences,
2565
- nativeLastTradeTs,
2566
- nativeOverlapCount,
2567
- nativePagesFetched,
2505
+ ...buildCandleCycleFields(),
2568
2506
  amaPrice,
2569
2507
  previousCenterPrice,
2570
2508
  deltaPercent,
@@ -2592,9 +2530,6 @@ class MarketAdapterService {
2592
2530
  hasExplicitBaseWeights,
2593
2531
  poolId: ctx.poolId,
2594
2532
  candleFile: deps.path.relative(deps.root, filePath),
2595
- lastCandleTs: rawLastCandleTs,
2596
- rawLastCandleTs,
2597
- lastClosedCandleTs: consumedClosedCandleTs,
2598
2533
  lastClosedCandleClose: Number(latestClosedCandle?.[4]),
2599
2534
  centerPrice,
2600
2535
  amaConfig: {
@@ -1,8 +1,3 @@
1
- /**
2
- * Compute R/S (rescaled range) over `returns[from..to)` (to exclusive).
3
- * Taking a range instead of a slice keeps the caller's buffer reusable.
4
- */
5
- declare function computeRS(returns: ArrayLike<number>, from: number, to: number): number;
6
1
  /**
7
2
  * Shared Hurst zone classification used by both HurstAnalyzer.getAnalysis()
8
3
  * and the regime gate, so the zone boundaries live in exactly one place.
@@ -53,5 +48,5 @@ declare class HurstAnalyzer {
53
48
  updateCount: number;
54
49
  };
55
50
  }
56
- export { HurstAnalyzer, classifyHurst, computeRS };
51
+ export { HurstAnalyzer, classifyHurst };
57
52
  //# sourceMappingURL=hurst_analyzer.d.ts.map
@@ -188,5 +188,5 @@ class HurstAnalyzer {
188
188
  };
189
189
  }
190
190
  }
191
- export { HurstAnalyzer, classifyHurst, computeRS };
191
+ export { HurstAnalyzer, classifyHurst };
192
192
  //# sourceMappingURL=hurst_analyzer.js.map
@@ -1,13 +1,3 @@
1
- /**
2
- * Ordinal pattern key for the m values starting at `prices[start]`, stepping by
3
- * `delay`. Returns the permutation of source indices (sorted by value, ties
4
- * broken by source index) encoded as a factorial-number-system integer, so the
5
- * key is a small int (m! - 1 <= 5039 for m = 7) instead of a string.
6
- *
7
- * Sorting uses a preallocated scratch pair and insertion sort (m <= 7), so the
8
- * hot path allocates nothing.
9
- */
10
- declare function ordinalPatternKey(prices: Float64Array, start: number, m: number, delay: number): number;
11
1
  interface PermutationEntropyAnalysis {
12
2
  isReady: boolean;
13
3
  entropy: number;
@@ -56,5 +46,5 @@ declare class PermutationEntropyAnalyzer {
56
46
  update(price: number): PermutationEntropyAnalysis;
57
47
  getAnalysis(): PermutationEntropyAnalysis;
58
48
  }
59
- export { PermutationEntropyAnalyzer, ordinalPatternKey };
49
+ export { PermutationEntropyAnalyzer };
60
50
  //# sourceMappingURL=permutation_entropy_analyzer.d.ts.map
@@ -248,5 +248,5 @@ class PermutationEntropyAnalyzer {
248
248
  };
249
249
  }
250
250
  }
251
- export { PermutationEntropyAnalyzer, ordinalPatternKey };
251
+ export { PermutationEntropyAnalyzer };
252
252
  //# sourceMappingURL=permutation_entropy_analyzer.js.map
@@ -127,7 +127,6 @@ async function fetchMarketCandlesSequentially(assetA, assetB, opts = {}) {
127
127
  assetA: requestKey.assetA,
128
128
  assetB: requestKey.assetB,
129
129
  intervalSeconds,
130
- chunkIndex: window.index,
131
130
  timeRange: { gte: window.gte, lte: window.lte },
132
131
  format: '[timestamp_ms, open, high, low, close, volume_A]',
133
132
  }),