dexbot 1.6.11 → 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.
- package/CHANGELOG.md +67 -4
- package/README.md +2 -1
- package/analysis/README.md +11 -11
- package/analysis/ama_fitting/README.md +5 -3
- package/analysis/tradingview/README.md +1 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +3 -3
- package/claw/README.md +1 -0
- package/claw/docs/AI_BOT_LIBRARY_API.md +2 -0
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
- package/claw/modules/chain_broadcast.ts +7 -1
- package/claw/modules/claw_bridge.ts +0 -3
- package/claw/modules/claw_launcher.ts +1 -1
- package/claw/modules/claw_skill_md.ts +1 -0
- package/claw/modules/launcher_mode_detector.ts +9 -2
- package/claw/package.json +3 -3
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/claw/tsconfig.json +2 -2
- package/dist/analysis/account_resolver.d.ts +1 -1
- package/dist/analysis/account_resolver.js +2 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +3 -4
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +3 -21
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +55 -45
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +1 -8
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +45 -24
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +34 -78
- package/dist/analysis/analyze_args.d.ts +43 -0
- package/dist/analysis/analyze_args.js +61 -0
- package/dist/analysis/analyze_dynamic_weight.js +7 -17
- package/dist/analysis/analyze_kalman.js +7 -17
- package/dist/analysis/analyze_regime.js +7 -17
- package/dist/analysis/analyze_regime_windows.js +8 -18
- package/dist/analysis/analyze_risk_profile.js +8 -18
- package/dist/analysis/analyze_trade_heatmap.js +7 -17
- package/dist/analysis/analyze_volatility.js +7 -17
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +221 -28
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +23 -103
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +32 -150
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +19 -34
- package/dist/analysis/bot_fitting/shared_utils.d.ts +77 -9
- package/dist/analysis/bot_fitting/shared_utils.js +125 -9
- package/dist/analysis/bot_key_utils.d.ts +18 -10
- package/dist/analysis/bot_key_utils.js +7 -4
- package/dist/analysis/bot_usage/discover_bot_accounts.js +44 -47
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -21
- package/dist/analysis/chain_pool.d.ts +3 -1
- package/dist/analysis/chart_ui.d.ts +35 -3
- package/dist/analysis/chart_ui.js +43 -4
- package/dist/analysis/chart_utils.d.ts +5 -5
- package/dist/analysis/chart_utils.js +9 -0
- package/dist/analysis/fills_cache.d.ts +4 -24
- package/dist/analysis/fills_cache.js +3 -84
- package/dist/analysis/fills_source.d.ts +33 -3
- package/dist/analysis/fills_source.js +83 -13
- package/dist/analysis/grid_correction_check.d.ts +2 -24
- package/dist/analysis/grid_correction_check.js +27 -69
- package/dist/analysis/math_utils.d.ts +91 -6
- package/dist/analysis/math_utils.js +119 -7
- package/dist/analysis/pnl_report.js +29 -29
- package/dist/analysis/price_sources.d.ts +30 -9
- package/dist/analysis/price_sources.js +28 -4
- package/dist/analysis/resolve_bot_accounts.js +2 -2
- package/dist/analysis/resolve_source.d.ts +1 -1
- package/dist/analysis/resolve_source.js +31 -10
- package/dist/analysis/trade_profitability.d.ts +29 -2
- package/dist/analysis/trade_profitability.js +73 -147
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +3 -8
- package/dist/analysis/tradingview/analyze_tradingview.js +7 -6
- package/dist/analysis/tradingview/grid_reset_config.d.ts +41 -32
- package/dist/analysis/tradingview/grid_reset_config.js +23 -11
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -9
- package/dist/analysis/tradingview/grid_reset_sim.js +4 -3
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +20 -34
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -101
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +26 -84
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +16 -41
- package/dist/analysis/trend_detection/huber_scale_variants.d.ts +9 -3
- package/dist/analysis/trend_detection/huber_scale_variants.js +4 -4
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +30 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js +3 -3
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts +31 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js +2 -2
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +33 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js +9 -10
- package/dist/analysis/worker_pool.d.ts +38 -0
- package/dist/analysis/worker_pool.js +67 -0
- package/dist/credential-daemon.js +34 -20
- package/dist/dexbot.js +78 -59
- package/dist/market_adapter/ama_signal_runner.js +21 -54
- package/dist/market_adapter/candle_utils.d.ts +29 -19
- package/dist/market_adapter/candle_utils.js +35 -21
- package/dist/market_adapter/cli_args.d.ts +22 -0
- package/dist/market_adapter/cli_args.js +30 -0
- package/dist/market_adapter/core/asymmetric_bounds.d.ts +13 -4
- package/dist/market_adapter/core/config_normalizers.d.ts +3 -3
- package/dist/market_adapter/core/config_normalizers.js +11 -6
- package/dist/market_adapter/core/kibana_candles.d.ts +56 -19
- package/dist/market_adapter/core/kibana_candles.js +12 -9
- package/dist/market_adapter/core/kibana_client.d.ts +9 -1
- package/dist/market_adapter/core/kibana_client.js +8 -7
- package/dist/market_adapter/core/kibana_market_candles.d.ts +3 -2
- package/dist/market_adapter/core/market_adapter_service.d.ts +320 -153
- package/dist/market_adapter/core/market_adapter_service.js +228 -269
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +1 -6
- package/dist/market_adapter/core/signals/hurst_analyzer.js +1 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +1 -11
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +1 -1
- package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
- package/dist/market_adapter/core/strategies/ama.js +2 -4
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +14 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js +12 -34
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts +7 -2
- package/dist/market_adapter/core/strategies/atr/calculator.js +2 -34
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts +7 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js +0 -22
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +34 -6
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +7 -7
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +24 -15
- package/dist/market_adapter/core/strategies/regime_gate.js +4 -31
- package/dist/market_adapter/core/strategies/regime_interp.d.ts +7 -1
- package/dist/market_adapter/core/strategies/regime_interp.js +14 -22
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts +11 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js +0 -13
- package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +29 -0
- package/dist/market_adapter/inputs/cex_candle_parsing.js +52 -0
- package/dist/market_adapter/inputs/fetch_book_data.d.ts +20 -4
- package/dist/market_adapter/inputs/fetch_book_data.js +3 -2
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +160 -332
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +50 -8
- package/dist/market_adapter/inputs/fetch_lp_data.js +47 -22
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
- package/dist/market_adapter/inputs/kibana_feed_source.js +26 -41
- package/dist/market_adapter/inputs/kibana_source.d.ts +25 -3
- package/dist/market_adapter/inputs/kibana_source.js +2 -2
- package/dist/market_adapter/inputs/window_cache.d.ts +93 -156
- package/dist/market_adapter/inputs/window_cache.js +59 -184
- package/dist/market_adapter/interval_utils.d.ts +15 -5
- package/dist/market_adapter/interval_utils.js +16 -1
- package/dist/market_adapter/log_format.d.ts +6 -6
- package/dist/market_adapter/log_format.js +28 -21
- package/dist/market_adapter/lp_chart_core.d.ts +22 -1
- package/dist/market_adapter/lp_chart_core.js +26 -192
- package/dist/market_adapter/lp_chart_runner.d.ts +10 -7
- package/dist/market_adapter/lp_chart_runner.js +37 -19
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts +41 -6
- package/dist/market_adapter/lp_chart_strategy_loader.js +8 -7
- package/dist/market_adapter/market_adapter.d.ts +94 -32
- package/dist/market_adapter/market_adapter.js +94 -120
- package/dist/market_adapter/utils/adapter_client.d.ts +3 -3
- package/dist/market_adapter/utils/adapter_client.js +2 -2
- package/dist/market_adapter/utils/atomic_write.d.ts +8 -1
- package/dist/market_adapter/utils/chain.d.ts +50 -41
- package/dist/market_adapter/utils/chain.js +40 -46
- package/dist/market_adapter/utils/data_discovery.d.ts +49 -2
- package/dist/market_adapter/utils/data_discovery.js +220 -27
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +12 -3
- package/dist/market_adapter/utils/file_json_cache.d.ts +2 -2
- package/dist/market_adapter/utils/file_lock.d.ts +28 -14
- package/dist/market_adapter/utils/file_lock.js +36 -32
- package/dist/market_adapter/utils/month_shards.d.ts +84 -0
- package/dist/market_adapter/utils/month_shards.js +237 -0
- package/dist/market_adapter/utils/native_history.d.ts +9 -2
- package/dist/market_adapter/utils/native_history.js +35 -28
- package/dist/modules/account_bots.d.ts +578 -21
- package/dist/modules/account_bots.js +272 -267
- package/dist/modules/account_orders.d.ts +79 -30
- package/dist/modules/account_orders.js +60 -64
- package/dist/modules/authority_resolver.d.ts +12 -2
- package/dist/modules/authority_resolver.js +15 -8
- package/dist/modules/bitshares-native/chain_client.d.ts +39 -4
- package/dist/modules/bitshares-native/chain_client.js +59 -59
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +11 -171
- package/dist/modules/bitshares-native/crypto/ecc.js +13 -176
- package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +33 -0
- package/dist/modules/bitshares-native/crypto/ecc_core.js +213 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -13
- package/dist/modules/bitshares-native/index.d.ts +1 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts +7 -7
- package/dist/modules/bitshares-native/resolvers.d.ts +18 -6
- package/dist/modules/bitshares-native/resolvers.js +22 -25
- package/dist/modules/bitshares-native/serial/lazy_buffer.d.ts +4 -0
- package/dist/modules/bitshares-native/serial/lazy_buffer.js +21 -0
- package/dist/modules/bitshares-native/serial/operations.d.ts +1 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts +16 -12
- package/dist/modules/bitshares-native/serial/serializer.js +7 -13
- package/dist/modules/bitshares-native/serial/types.d.ts +25 -16
- package/dist/modules/bitshares-native/serial/types.js +73 -108
- package/dist/modules/bitshares-native/signing_client.d.ts +32 -2
- package/dist/modules/bitshares-native/signing_client.js +19 -14
- package/dist/modules/bitshares-native/subscriptions.d.ts +81 -1
- package/dist/modules/bitshares-native/subscriptions.js +12 -12
- package/dist/modules/bitshares-native/transport.d.ts +5 -4
- package/dist/modules/bitshares-native/transport.js +5 -4
- package/dist/modules/bitshares-native/tx/builder.d.ts +40 -5
- package/dist/modules/bitshares-native/tx/builder.js +4 -3
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts +4 -4
- package/dist/modules/bitshares_client.d.ts +45 -13
- package/dist/modules/bitshares_client.js +28 -19
- package/dist/modules/bot_defaults.d.ts +8 -16
- package/dist/modules/bot_defaults.js +1 -5
- package/dist/modules/bot_settings.d.ts +44 -10
- package/dist/modules/bot_settings.js +11 -8
- package/dist/modules/bots_file_lock.d.ts +6 -6
- package/dist/modules/bots_file_lock.js +16 -12
- package/dist/modules/broadcast_failure.d.ts +4 -3
- package/dist/modules/broadcast_failure.js +5 -4
- package/dist/modules/chain_keys.d.ts +42 -40
- package/dist/modules/chain_keys.js +53 -45
- package/dist/modules/chain_orders.d.ts +94 -60
- package/dist/modules/chain_orders.js +81 -118
- package/dist/modules/cli_start_onboarding.d.ts +2 -1
- package/dist/modules/constants.d.ts +534 -32
- package/dist/modules/constants.js +35 -48
- package/dist/modules/cr_planner.d.ts +41 -3
- package/dist/modules/cr_planner.js +1 -5
- package/dist/modules/credential_policy.d.ts +68 -8
- package/dist/modules/credential_policy.js +37 -31
- package/dist/modules/credential_session_cache.d.ts +2 -2
- package/dist/modules/credit_pricing.d.ts +43 -6
- package/dist/modules/credit_pricing.js +70 -60
- package/dist/modules/credit_runtime.d.ts +283 -118
- package/dist/modules/credit_runtime.js +500 -231
- package/dist/modules/crypto/browser_provider.js +6 -4
- package/dist/modules/crypto/node_provider.js +1 -1
- package/dist/modules/crypto/pure_scrypt.js +35 -4
- package/dist/modules/crypto/pure_secp256k1.js +72 -26
- package/dist/modules/crypto/sync.d.ts +9 -9
- package/dist/modules/crypto/sync.js +16 -9
- package/dist/modules/daemon_node_health.d.ts +4 -3
- package/dist/modules/dexbot_class.d.ts +213 -146
- package/dist/modules/dexbot_class.js +183 -86
- package/dist/modules/dexbot_cow_runtime.d.ts +160 -87
- package/dist/modules/dexbot_cow_runtime.js +302 -234
- package/dist/modules/dexbot_credential_client.d.ts +19 -18
- package/dist/modules/dexbot_credential_client.js +1 -2
- package/dist/modules/dexbot_fill_runtime.d.ts +63 -49
- package/dist/modules/dexbot_fill_runtime.js +53 -47
- package/dist/modules/dexbot_maintenance_runtime.d.ts +127 -71
- package/dist/modules/dexbot_maintenance_runtime.js +187 -147
- package/dist/modules/dexbot_startup_runtime.d.ts +11 -11
- package/dist/modules/dexbot_startup_runtime.js +56 -57
- package/dist/modules/dexbot_state_recovery.d.ts +13 -12
- package/dist/modules/dexbot_state_recovery.js +18 -13
- package/dist/modules/fund_registry.d.ts +4 -2
- package/dist/modules/fund_registry.js +10 -10
- package/dist/modules/general_settings.d.ts +30 -4
- package/dist/modules/graceful_shutdown.d.ts +3 -3
- package/dist/modules/graceful_shutdown.js +19 -13
- package/dist/modules/grid_price_source.d.ts +1 -1
- package/dist/modules/key_store.d.ts +14 -8
- package/dist/modules/key_store.js +7 -7
- package/dist/modules/launcher/adapter_requirement.d.ts +11 -5
- package/dist/modules/launcher/adapter_requirement.js +5 -5
- package/dist/modules/launcher/bot_supervisor.d.ts +106 -24
- package/dist/modules/launcher/bot_supervisor.js +12 -11
- package/dist/modules/launcher/credential_bootstrap.d.ts +1 -1
- package/dist/modules/launcher/credential_bootstrap.js +1 -1
- package/dist/modules/launcher/credential_daemon.d.ts +4 -4
- package/dist/modules/launcher/credential_daemon.js +2 -2
- package/dist/modules/launcher/credential_secret.d.ts +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -2
- package/dist/modules/launcher/market_adapter_runtime.d.ts +61 -6
- package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -2
- package/dist/modules/launcher/market_adapter_watchdog.js +4 -0
- package/dist/modules/launcher/monolithic_runtime.d.ts +18 -16
- package/dist/modules/launcher/status_reporting.d.ts +22 -14
- package/dist/modules/launcher/supervisor_control.d.ts +8 -1
- package/dist/modules/launcher/supervisor_control.js +4 -2
- package/dist/modules/lazy_shim.d.ts +11 -0
- package/dist/modules/lazy_shim.js +16 -0
- package/dist/modules/market_adapter_whitelist.d.ts +9 -3
- package/dist/modules/market_adapter_whitelist.js +15 -3
- package/dist/modules/node_connect_policy.d.ts +3 -2
- package/dist/modules/node_failure_ledger.d.ts +6 -5
- package/dist/modules/node_manager.d.ts +41 -11
- package/dist/modules/node_manager.js +5 -4
- package/dist/modules/order/accounting.d.ts +53 -24
- package/dist/modules/order/accounting.js +16 -15
- package/dist/modules/order/async_lock.d.ts +5 -2
- package/dist/modules/order/async_lock.js +1 -1
- package/dist/modules/order/export.d.ts +7 -6
- package/dist/modules/order/export.js +1 -7
- package/dist/modules/order/format.d.ts +16 -7
- package/dist/modules/order/format.js +15 -3
- package/dist/modules/order/genesis_policy.d.ts +24 -21
- package/dist/modules/order/genesis_policy.js +17 -10
- package/dist/modules/order/grid.d.ts +144 -36
- package/dist/modules/order/grid.js +226 -145
- package/dist/modules/order/grid_reconcile.d.ts +21 -20
- package/dist/modules/order/grid_reconcile.js +13 -12
- package/dist/modules/order/grid_reconcile_internal.d.ts +85 -72
- package/dist/modules/order/grid_reconcile_internal.js +28 -19
- package/dist/modules/order/index.d.ts +264 -1
- package/dist/modules/order/logger.d.ts +46 -19
- package/dist/modules/order/logger.js +38 -49
- package/dist/modules/order/logger_state.d.ts +4 -4
- package/dist/modules/order/manager.d.ts +232 -191
- package/dist/modules/order/manager.js +110 -130
- package/dist/modules/order/processed_fill_store.d.ts +18 -3
- package/dist/modules/order/processed_fill_store.js +16 -27
- package/dist/modules/order/strategy.d.ts +21 -13
- package/dist/modules/order/strategy.js +5 -6
- package/dist/modules/order/sync_engine.d.ts +91 -33
- package/dist/modules/order/sync_engine.js +84 -53
- package/dist/modules/order/utils/math.d.ts +157 -102
- package/dist/modules/order/utils/math.js +77 -38
- package/dist/modules/order/utils/order.d.ts +310 -110
- package/dist/modules/order/utils/order.js +153 -126
- package/dist/modules/order/utils/slot.d.ts +1 -1
- package/dist/modules/order/utils/system.d.ts +156 -26
- package/dist/modules/order/utils/system.js +103 -71
- package/dist/modules/order/utils/validate.d.ts +89 -41
- package/dist/modules/order/utils/validate.js +26 -24
- package/dist/modules/order/utils/withPoolRef.d.ts +6 -4
- package/dist/modules/order/utils/withPoolRef.js +18 -12
- package/dist/modules/order/working_grid.d.ts +14 -13
- package/dist/modules/paths.d.ts +1 -4
- package/dist/modules/paths.js +33 -61
- package/dist/modules/process_discovery.d.ts +1 -1
- package/dist/modules/process_discovery.js +2 -1
- package/dist/modules/runtime.d.ts +7 -3
- package/dist/modules/runtime.js +4 -3
- package/dist/modules/runtime_settings.d.ts +14 -11
- package/dist/modules/runtime_settings.js +30 -24
- package/dist/modules/settings_merge.d.ts +29 -3
- package/dist/modules/settings_merge.js +56 -78
- package/dist/modules/socket_json_client.d.ts +9 -5
- package/dist/modules/storage/browser_adapter.d.ts +38 -53
- package/dist/modules/storage/browser_adapter.js +7 -30
- package/dist/modules/storage/index.d.ts +1 -1
- package/dist/modules/storage/node_adapter.d.ts +45 -27
- package/dist/modules/storage/node_adapter.js +9 -9
- package/dist/modules/storage/types.d.ts +5 -4
- package/dist/modules/types.d.ts +1090 -6
- package/dist/modules/types.js +4 -1
- package/dist/modules/utils/asset_symbols.d.ts +2 -1
- package/dist/modules/utils/asset_symbols.js +2 -1
- package/dist/modules/utils/errors.d.ts +9 -0
- package/dist/modules/utils/errors.js +24 -4
- package/dist/modules/utils/time_range.d.ts +1 -12
- package/dist/modules/utils/time_range.js +1 -1
- package/dist/modules/validate_profiles.js +53 -43
- package/dist/modules/version_notice.d.ts +23 -11
- package/dist/modules/version_notice.js +6 -4
- package/dist/pm2.d.ts +28 -27
- package/dist/pm2.js +61 -40
- package/dist/scripts/analyze-credit.d.ts +2 -1
- package/dist/scripts/analyze-credit.js +23 -24
- package/dist/scripts/analyze-git.js +2 -15
- package/dist/scripts/analyze-orders.d.ts +77 -9
- package/dist/scripts/analyze-orders.js +65 -40
- package/dist/scripts/chart_command.d.ts +27 -18
- package/dist/scripts/chart_command.js +15 -13
- package/dist/scripts/check_any.d.ts +22 -0
- package/dist/scripts/check_any.js +158 -0
- package/dist/scripts/diagnose-pool-history.js +13 -13
- package/dist/scripts/print_grid.js +0 -1
- package/dist/scripts/run-tests.js +39 -8
- package/dist/scripts/runner.js +1 -1
- package/dist/scripts/sync-version.js +0 -10
- package/dist/scripts/test-credit-renewal.js +30 -21
- package/dist/scripts/update.d.ts +10 -5
- package/dist/scripts/update.js +168 -103
- package/dist/scripts/update_dist_freshness.js +1 -0
- package/dist/scripts/update_layout.d.ts +61 -0
- package/dist/scripts/update_layout.js +180 -0
- package/dist/scripts/validate_bots.js +2 -1
- package/dist/scripts/verify-browser-bundle.js +8 -0
- package/dist/unlock.d.ts +28 -3
- package/dist/unlock.js +63 -35
- package/docs/BITSHARES_ONBOARDING.md +10 -12
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +2 -2
- package/docs/COW_INVARIANTS.md +13 -6
- package/docs/DEXBOT_COMPARISON.md +8 -8
- package/docs/EVOLUTION.md +10 -8
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
- package/docs/GRID_RECALCULATION.md +4 -2
- package/docs/GRID_RECONCILE.md +14 -3
- package/docs/LIFECYCLE.md +11 -11
- package/docs/MPA_CREDIT_USAGE.md +22 -3
- package/docs/README.md +14 -3
- package/docs/WORKFLOW.md +1 -0
- package/docs/architecture.md +31 -19
- package/docs/developer_guide.md +6 -6
- package/market_adapter/README.md +12 -5
- package/modules/README.md +4 -1
- package/package.json +9 -9
- package/scripts/README.md +43 -38
- package/tests/README.md +25 -10
- package/dist/scripts/diagnose-kibana-candles.d.ts +0 -3
- package/dist/scripts/diagnose-kibana-candles.js +0 -82
- package/scripts/git-viewer.sh +0 -489
- package/scripts/postinstall.js +0 -16
|
@@ -1,13 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
interface AssetRef {
|
|
2
|
+
id?: string;
|
|
3
|
+
precision?: number;
|
|
4
|
+
symbol?: string | null;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
interface LpPageInfo {
|
|
8
|
+
event?: string;
|
|
9
|
+
direction?: string;
|
|
10
|
+
page?: number;
|
|
11
|
+
attempt?: number;
|
|
12
|
+
error?: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
interface LpConfig {
|
|
16
|
+
intervalSeconds: number;
|
|
17
|
+
lookbackHours?: number;
|
|
18
|
+
apiKey?: string | null;
|
|
19
|
+
chunkMonths: number;
|
|
20
|
+
timeRange?: {
|
|
21
|
+
gte?: string;
|
|
22
|
+
lte?: string;
|
|
23
|
+
};
|
|
24
|
+
outPath?: string;
|
|
25
|
+
onPage?: (info: LpPageInfo) => void;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface BotConfig {
|
|
29
|
+
name?: string;
|
|
30
|
+
active?: boolean;
|
|
31
|
+
startPrice?: unknown;
|
|
32
|
+
assetA?: string;
|
|
33
|
+
assetB?: string;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
declare function outputPath(poolId: unknown, intervalSeconds: number, assetA: AssetRef, assetB: AssetRef): string;
|
|
37
|
+
declare function applyPrecisionOverrides(assetA: AssetRef, assetB: AssetRef, precA: number | null, precB: number | null): {
|
|
38
|
+
assetA: AssetRef;
|
|
39
|
+
assetB: AssetRef;
|
|
5
40
|
};
|
|
6
|
-
declare function
|
|
7
|
-
|
|
41
|
+
declare function loadCachedFetchContext(bot: BotConfig, intervalSeconds: number, dir?: string): {
|
|
42
|
+
poolId: string;
|
|
43
|
+
assetA: AssetRef;
|
|
44
|
+
assetB: AssetRef;
|
|
45
|
+
source: string;
|
|
46
|
+
path: string;
|
|
47
|
+
} | null;
|
|
48
|
+
declare function fetchCandlesSequentially(fullPoolId: string, assetA: AssetRef, assetB: AssetRef, config: LpConfig, outPath: string): Promise<number[][]>;
|
|
49
|
+
declare function parseBotsConfig(raw: string, sourceLabel?: string): BotConfig[];
|
|
8
50
|
/**
|
|
9
51
|
* Pick a bot: by name if given, otherwise first active bot with startPrice: "pool".
|
|
10
52
|
*/
|
|
11
|
-
declare function selectBot(bots:
|
|
12
|
-
export { applyPrecisionOverrides, parseBotsConfig, selectBot, fetchCandlesSequentially, outputPath };
|
|
53
|
+
declare function selectBot(bots: BotConfig[], botName: string | null | undefined): BotConfig;
|
|
54
|
+
export { applyPrecisionOverrides, parseBotsConfig, selectBot, fetchCandlesSequentially, outputPath, loadCachedFetchContext };
|
|
13
55
|
//# sourceMappingURL=fetch_lp_data.d.ts.map
|
|
@@ -35,8 +35,10 @@ import { normalizePoolId, resolveAsset, findPoolByAssets } from '../utils/chain.
|
|
|
35
35
|
import { writeJsonAtomic } from '../utils/atomic_write.js';
|
|
36
36
|
import { buildFetchWindowsFromRange, formatWindowLine, runCachedWindows, } from './window_cache.js';
|
|
37
37
|
import { PATHS } from '../../modules/paths.js';
|
|
38
|
+
import { loadLpSeriesFromBasePath } from '../utils/data_discovery.js';
|
|
39
|
+
import { shardStemFromName } from '../utils/month_shards.js';
|
|
38
40
|
import * as bitsharesClient from '../../modules/bitshares_client.js';
|
|
39
|
-
import { getErrorMessage } from '../../modules/utils/errors.js';
|
|
41
|
+
import { getErrorMessage, resolveSeamMs } from '../../modules/utils/errors.js';
|
|
40
42
|
import { isSameBotName } from '../../modules/utils/sanitize_key.js';
|
|
41
43
|
import { pathToFileURL } from 'node:url';
|
|
42
44
|
const storage = getStorage();
|
|
@@ -179,19 +181,30 @@ function buildRequestKey(config, fullPoolId, assetA, assetB, timeRange, outPath)
|
|
|
179
181
|
assetA: { id: assetA.id, precision: assetA.precision, symbol: assetA.symbol },
|
|
180
182
|
assetB: { id: assetB.id, precision: assetB.precision, symbol: assetB.symbol },
|
|
181
183
|
intervalSeconds: config.intervalSeconds,
|
|
182
|
-
lookbackHours: config.timeRange ? null : config.lookbackHours,
|
|
184
|
+
lookbackHours: config.timeRange ? null : (config.lookbackHours ?? null),
|
|
183
185
|
timeRange,
|
|
184
186
|
outPath: path.resolve(outPath),
|
|
185
187
|
chunkMonths,
|
|
186
188
|
};
|
|
187
189
|
}
|
|
188
|
-
function loadCachedFetchContext(bot, intervalSeconds) {
|
|
189
|
-
const dir = pairFolderPath(bot.assetA, bot.assetB);
|
|
190
|
+
function loadCachedFetchContext(bot, intervalSeconds, dir = pairFolderPath(bot.assetA, bot.assetB)) {
|
|
190
191
|
if (!storage.exists(dir))
|
|
191
192
|
return null;
|
|
192
193
|
const label = toIntervalLabel(intervalSeconds);
|
|
194
|
+
// Accept the whole-history export (`….json`) AND month shards
|
|
195
|
+
// (`….shard_YYYY-MM.json`). After the shard refactor `dexbot tv`/`dw` only
|
|
196
|
+
// write shards, so a shard-only pair had no cached context and fell back to
|
|
197
|
+
// a full blockchain connect. A shard's meta carries the same
|
|
198
|
+
// pool/asset/precision identity, and reading one shard is cheaper than
|
|
199
|
+
// parsing a multi-MB whole-history export.
|
|
200
|
+
const matchesInterval = (name) => {
|
|
201
|
+
if (name.endsWith(`${label}.json`))
|
|
202
|
+
return true;
|
|
203
|
+
const stem = shardStemFromName(name);
|
|
204
|
+
return stem ? stem.endsWith(`_${label}`) : false;
|
|
205
|
+
};
|
|
193
206
|
const dataFiles = storage.readdir(dir)
|
|
194
|
-
.filter(
|
|
207
|
+
.filter(matchesInterval)
|
|
195
208
|
.sort();
|
|
196
209
|
for (const file of dataFiles) {
|
|
197
210
|
try {
|
|
@@ -226,7 +239,9 @@ function loadCachedFetchContext(bot, intervalSeconds) {
|
|
|
226
239
|
// candle fetchers (pool, book, feed) through the single runCachedWindows
|
|
227
240
|
// entry point. Storage is fixed calendar-month shards, so there is no
|
|
228
241
|
// orphan cleanup and no per-run rewrite.
|
|
229
|
-
function isLpShardMatch(
|
|
242
|
+
function isLpShardMatch(metaInput, requestKeyInput) {
|
|
243
|
+
const meta = metaInput;
|
|
244
|
+
const requestKey = requestKeyInput;
|
|
230
245
|
if (meta.pool !== requestKey.pool)
|
|
231
246
|
return false;
|
|
232
247
|
if (meta.intervalSeconds !== requestKey.intervalSeconds)
|
|
@@ -259,14 +274,15 @@ async function fetchCandlesSequentially(fullPoolId, assetA, assetB, config, outP
|
|
|
259
274
|
console.log(` Auto-splitting fetch into ${total} sequential ${chunkMonths}-month fetch windows`);
|
|
260
275
|
}
|
|
261
276
|
const fetchRange = async (gte, lte, window, signal) => {
|
|
262
|
-
const
|
|
277
|
+
const w = window;
|
|
278
|
+
const tag = formatWindowLine('Window', w.index, total, w.gte, w.lte);
|
|
263
279
|
const attemptStartMs = Date.now();
|
|
264
280
|
// A partial window (one swap direction failed) is still returned for
|
|
265
281
|
// this run's output, but flagged so the shared runner withholds it
|
|
266
282
|
// from disk — persisting it would bake the missing side in as
|
|
267
283
|
// gap-filled zeros that are never re-queried.
|
|
268
284
|
let sawPartial = false;
|
|
269
|
-
const userOnPage = config
|
|
285
|
+
const userOnPage = config.onPage;
|
|
270
286
|
const onPage = (info) => {
|
|
271
287
|
if (info?.event === 'partial')
|
|
272
288
|
sawPartial = true;
|
|
@@ -304,7 +320,6 @@ async function fetchCandlesSequentially(fullPoolId, assetA, assetB, config, outP
|
|
|
304
320
|
assetA: requestKey.assetA,
|
|
305
321
|
assetB: requestKey.assetB,
|
|
306
322
|
intervalSeconds: requestKey.intervalSeconds,
|
|
307
|
-
chunkIndex: window.index,
|
|
308
323
|
timeRange: { gte: window.gte, lte: window.lte },
|
|
309
324
|
format: '[timestamp_ms, open, high, low, close, volume_A]',
|
|
310
325
|
}),
|
|
@@ -312,7 +327,9 @@ async function fetchCandlesSequentially(fullPoolId, assetA, assetB, config, outP
|
|
|
312
327
|
bucketMs,
|
|
313
328
|
allowSubFetch: true,
|
|
314
329
|
fetchAttempts: FETCH_MAX_ATTEMPTS,
|
|
315
|
-
|
|
330
|
+
// Backoff base is overridable via the same `kibanaRetryDelayMs` seam the
|
|
331
|
+
// page/range retry loops use; tests set it to 0 to skip wall-clock sleeps.
|
|
332
|
+
fetchBackoffBaseMs: resolveSeamMs(config?.kibanaRetryDelayMs, FETCH_RETRY_BACKOFF_BASE_MS),
|
|
316
333
|
onFetchRetry: (info) => {
|
|
317
334
|
console.warn(` Window fetch retry ${info.attempt}/${info.attempts} for ${String(info.gte).slice(0, 10)} → ${String(info.lte).slice(0, 10)} in ${info.backoffMs}ms after failure: ${getErrorMessage(info.error)}`);
|
|
318
335
|
},
|
|
@@ -357,15 +374,17 @@ async function run() {
|
|
|
357
374
|
console.log('══════════════════════════════════════════════');
|
|
358
375
|
console.log(' Kibana LP Fetcher — Pool-centric');
|
|
359
376
|
console.log('══════════════════════════════════════════════');
|
|
360
|
-
let fullPoolId
|
|
377
|
+
let fullPoolId = '';
|
|
378
|
+
let assetA = {};
|
|
379
|
+
let assetB = {};
|
|
361
380
|
// ── Mode A: manual --pool override (no blockchain connection needed) ──────
|
|
362
381
|
if (cliPoolId) {
|
|
363
382
|
console.log(` Mode: Manual (--pool ${cliPoolId})`);
|
|
364
|
-
fullPoolId = normalizePoolId(cliPoolId);
|
|
383
|
+
fullPoolId = normalizePoolId(cliPoolId) ?? '';
|
|
365
384
|
// Still need to discover asset IDs from Kibana; precisions from CLI or default
|
|
366
385
|
console.log(` Pool: ${fullPoolId}`);
|
|
367
386
|
console.log(` Interval: ${bucketLabel} candles`);
|
|
368
|
-
console.log(` Range: ${config.timeRange ? `${config.timeRange.gte} → ${config.timeRange.lte}` : `last ${config.lookbackHours}h (${(config.lookbackHours / 24 / 365).toFixed(2)} years)`}`);
|
|
387
|
+
console.log(` Range: ${config.timeRange ? `${config.timeRange.gte} → ${config.timeRange.lte}` : `last ${config.lookbackHours ?? 0}h (${((config.lookbackHours ?? 0) / 24 / 365).toFixed(2)} years)`}`);
|
|
369
388
|
console.log('══════════════════════════════════════════════');
|
|
370
389
|
console.log(`\n[1/4] Discovering assets in pool ${fullPoolId}...`);
|
|
371
390
|
let assetIds;
|
|
@@ -407,7 +426,7 @@ async function run() {
|
|
|
407
426
|
console.log(` Mode: Auto (bots.json → blockchain → Kibana)`);
|
|
408
427
|
console.log(` Bot: ${bot.name} (${bot.assetA} / ${bot.assetB})`);
|
|
409
428
|
console.log(` Interval: ${bucketLabel} candles`);
|
|
410
|
-
console.log(` Range: ${config.timeRange ? `${config.timeRange.gte} → ${config.timeRange.lte}` : `last ${config.lookbackHours}h (${(config.lookbackHours / 24 / 365).toFixed(2)} years)`}`);
|
|
429
|
+
console.log(` Range: ${config.timeRange ? `${config.timeRange.gte} → ${config.timeRange.lte}` : `last ${config.lookbackHours ?? 0}h (${((config.lookbackHours ?? 0) / 24 / 365).toFixed(2)} years)`}`);
|
|
411
430
|
console.log(` Auth: ${config.apiKey ? 'API key set' : 'open (no auth)'}`);
|
|
412
431
|
console.log('══════════════════════════════════════════════');
|
|
413
432
|
if (cachedContext) {
|
|
@@ -447,13 +466,13 @@ async function run() {
|
|
|
447
466
|
console.log(`\n[2/4] Finding liquidity pool for ${bot.assetA} / ${bot.assetB}...`);
|
|
448
467
|
let pool;
|
|
449
468
|
try {
|
|
450
|
-
pool = await findPoolByAssets(assetA.id, assetB.id, { bitsharesClient, sortBy: 'assetABalance' });
|
|
469
|
+
pool = await findPoolByAssets(String(assetA.id), String(assetB.id), { bitsharesClient, sortBy: 'assetABalance' });
|
|
451
470
|
}
|
|
452
471
|
catch (err) {
|
|
453
472
|
console.error(` Pool lookup failed: ${getErrorMessage(err)}`);
|
|
454
473
|
process.exit(1);
|
|
455
474
|
}
|
|
456
|
-
fullPoolId = pool.id;
|
|
475
|
+
fullPoolId = String(pool.id);
|
|
457
476
|
console.log(` Pool: ${fullPoolId}`);
|
|
458
477
|
}
|
|
459
478
|
}
|
|
@@ -464,7 +483,7 @@ async function run() {
|
|
|
464
483
|
// it checks the range actually being fetched; otherwise a cheap recent
|
|
465
484
|
// window capped at 48h. The resolved window below feeds BOTH the query and
|
|
466
485
|
// the labels, so they can never diverge.
|
|
467
|
-
const probeCapHours = Math.min(config.lookbackHours, 48);
|
|
486
|
+
const probeCapHours = Math.min(config.lookbackHours ?? 0, 48);
|
|
468
487
|
const probeTimeRange = config.timeRange
|
|
469
488
|
? {
|
|
470
489
|
gte: config.timeRange.gte ?? new Date(Date.now() - probeCapHours * 3600 * 1000).toISOString(),
|
|
@@ -506,7 +525,7 @@ async function run() {
|
|
|
506
525
|
// ── Fetch full history ────────────────────────────────────────────────────
|
|
507
526
|
const fetchModeLabel = config.timeRange
|
|
508
527
|
? `${config.timeRange.gte ?? '…'} → ${config.timeRange.lte ?? '…'}`
|
|
509
|
-
: `${config.lookbackHours}h`;
|
|
528
|
+
: `${config.lookbackHours ?? 0}h`;
|
|
510
529
|
console.log(`\n[${stepFetch}/4] Fetching full history (${fetchModeLabel}, ${bucketLabel} buckets)...`);
|
|
511
530
|
let candles;
|
|
512
531
|
try {
|
|
@@ -538,6 +557,12 @@ async function run() {
|
|
|
538
557
|
keyBySymbols: `${assetA.symbol}|${assetB.symbol}`,
|
|
539
558
|
keyByIds: `${assetA.id}|${assetB.id}`,
|
|
540
559
|
};
|
|
560
|
+
// Derive the whole-history export from the assembled shard cache rather
|
|
561
|
+
// than from this run's fetched range: a later narrow run must not overwrite
|
|
562
|
+
// a full-history file with a subset. Falls back to the fetched candles when
|
|
563
|
+
// the shards were withheld (e.g. a partial fetch).
|
|
564
|
+
const assembled = loadLpSeriesFromBasePath(outPath);
|
|
565
|
+
const exportCandles = assembled && assembled.candles.length > 0 ? assembled.candles : candles;
|
|
541
566
|
const output = {
|
|
542
567
|
meta: {
|
|
543
568
|
fetchedAt: new Date().toISOString(),
|
|
@@ -547,8 +572,8 @@ async function run() {
|
|
|
547
572
|
assetB,
|
|
548
573
|
pair,
|
|
549
574
|
intervalSeconds: config.intervalSeconds,
|
|
550
|
-
lookbackHours: config.lookbackHours,
|
|
551
|
-
candleCount:
|
|
575
|
+
lookbackHours: config.lookbackHours ?? 0,
|
|
576
|
+
candleCount: exportCandles.length,
|
|
552
577
|
priceUnit: `${assetB.symbol} per ${assetA.symbol}`,
|
|
553
578
|
// Candle format: [timestamp_ms, open, high, low, close, volume_in_assetA]
|
|
554
579
|
// Raw Kibana LP exchange documents are ordered and converted to true OHLC.
|
|
@@ -557,7 +582,7 @@ async function run() {
|
|
|
557
582
|
// Actual received used (operation_result_object), not min_to_receive.
|
|
558
583
|
format: '[timestamp_ms, open, high, low, close, volume_A]',
|
|
559
584
|
},
|
|
560
|
-
candles,
|
|
585
|
+
candles: exportCandles,
|
|
561
586
|
};
|
|
562
587
|
writeJsonAtomic(outPath, output);
|
|
563
588
|
const kb = (storage.stat(outPath).size / 1024).toFixed(1);
|
|
@@ -571,5 +596,5 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
|
|
571
596
|
process.exit(1);
|
|
572
597
|
});
|
|
573
598
|
}
|
|
574
|
-
export { applyPrecisionOverrides, parseBotsConfig, selectBot, fetchCandlesSequentially, outputPath };
|
|
599
|
+
export { applyPrecisionOverrides, parseBotsConfig, selectBot, fetchCandlesSequentially, outputPath, loadCachedFetchContext };
|
|
575
600
|
//# sourceMappingURL=fetch_lp_data.js.map
|
|
@@ -1,21 +1,72 @@
|
|
|
1
1
|
declare const OP_TYPE_FEED = 19;
|
|
2
|
+
interface AssetRef {
|
|
3
|
+
id?: string;
|
|
4
|
+
precision?: number;
|
|
5
|
+
symbol?: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
interface FeedPoint {
|
|
9
|
+
tsMs: number;
|
|
10
|
+
price: number;
|
|
11
|
+
sequence?: number;
|
|
12
|
+
kibanaSortKey?: string;
|
|
13
|
+
feedPublishCount?: number;
|
|
14
|
+
}
|
|
15
|
+
interface RatioPoint {
|
|
16
|
+
tsMs: number;
|
|
17
|
+
price: number;
|
|
18
|
+
feedPublishCount?: number;
|
|
19
|
+
}
|
|
20
|
+
interface FeedLeg {
|
|
21
|
+
mpa?: AssetRef;
|
|
22
|
+
backing?: AssetRef;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
interface FeedContext {
|
|
26
|
+
kind?: string;
|
|
27
|
+
legs: FeedLeg[];
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
interface FeedConfig {
|
|
31
|
+
intervalSeconds?: number;
|
|
32
|
+
lookbackHours?: number;
|
|
33
|
+
timeRange?: {
|
|
34
|
+
gte?: string;
|
|
35
|
+
lte?: string;
|
|
36
|
+
} | null;
|
|
37
|
+
kibanaPageSize?: number;
|
|
38
|
+
kibanaPageRetries?: number;
|
|
39
|
+
kibanaRetryDelayMs?: number;
|
|
40
|
+
kibanaMaxPages?: number;
|
|
41
|
+
kibanaSearch?: (...args: unknown[]) => Promise<unknown>;
|
|
42
|
+
fillGaps?: boolean;
|
|
43
|
+
fillGapsToRequestedRange?: boolean;
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
}
|
|
2
46
|
/**
|
|
3
47
|
* Backing-per-MPA from a settlement_price { base, quote } object, handling
|
|
4
48
|
* either base/quote orientation. Returns null when the price does not span
|
|
5
49
|
* exactly the mpa/backing pair.
|
|
6
50
|
*/
|
|
7
|
-
declare function backingPerMpa(settlement:
|
|
51
|
+
declare function backingPerMpa(settlement: unknown, mpaAsset: AssetRef | null | undefined, backingAsset: AssetRef | null | undefined): number | null;
|
|
8
52
|
/**
|
|
9
53
|
* Kibana hit → { tsMs, price, sequence, kibanaSortKey } in backing-per-MPA,
|
|
10
54
|
* or null when the hit carries no usable settlement price for the pair.
|
|
11
55
|
*/
|
|
12
|
-
declare function hitToFeedPrice(hit:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
56
|
+
declare function hitToFeedPrice(hit: unknown, { mpaAsset, backingAsset }: {
|
|
57
|
+
mpaAsset: AssetRef | null | undefined;
|
|
58
|
+
backingAsset: AssetRef | null | undefined;
|
|
59
|
+
}): FeedPoint | null;
|
|
60
|
+
declare function buildFeedDocumentQuery({ mpaAssetId, lookbackHours, timeRange, size, searchAfter }: {
|
|
61
|
+
mpaAssetId: string;
|
|
62
|
+
lookbackHours?: number;
|
|
63
|
+
timeRange?: {
|
|
64
|
+
gte?: string;
|
|
65
|
+
lte?: string;
|
|
66
|
+
} | null;
|
|
67
|
+
size: number;
|
|
68
|
+
searchAfter: unknown[] | null;
|
|
69
|
+
}): Record<string, unknown>;
|
|
19
70
|
/**
|
|
20
71
|
* Price points → OHLC candles per interval bucket.
|
|
21
72
|
* Pure function (no I/O) for unit testing.
|
|
@@ -24,12 +75,12 @@ declare function buildFeedDocumentQuery({ mpaAssetId, lookbackHours, timeRange,
|
|
|
24
75
|
* @param {number} intervalSeconds – bucket size (1h default)
|
|
25
76
|
* @returns {Array} [[timestamp_ms, open, high, low, close, publishCount], ...]
|
|
26
77
|
*/
|
|
27
|
-
declare function bucketPricesToCandles(points:
|
|
78
|
+
declare function bucketPricesToCandles(points: unknown, intervalSeconds?: number): number[][];
|
|
28
79
|
/**
|
|
29
80
|
* Invert candles (1/price, high/low swapped). Pure function for pair
|
|
30
81
|
* orientation when the MPA is the B leg (B-per-A = MPA-per-backing).
|
|
31
82
|
*/
|
|
32
|
-
declare function invertCandles(candles:
|
|
83
|
+
declare function invertCandles(candles: unknown): number[][];
|
|
33
84
|
/**
|
|
34
85
|
* OHLC feed candles for an MPA in backing-per-MPA units
|
|
35
86
|
* (e.g. BTS per HONEST.USD).
|
|
@@ -38,7 +89,7 @@ declare function invertCandles(candles: any): any;
|
|
|
38
89
|
* @param {Object} backingAsset – { id, precision, symbol }
|
|
39
90
|
* @param {Object} [config] – { intervalSeconds, timeRange | lookbackHours, fillGaps, fillGapsToRequestedRange, kibanaSearch, ... }
|
|
40
91
|
*/
|
|
41
|
-
declare function getFeedCandlesForMpa(mpaAsset:
|
|
92
|
+
declare function getFeedCandlesForMpa(mpaAsset: AssetRef, backingAsset: AssetRef, config?: FeedConfig): Promise<number[][]>;
|
|
42
93
|
/**
|
|
43
94
|
* Cross-rate price points for two MPAs sharing one backing asset.
|
|
44
95
|
*
|
|
@@ -50,7 +101,7 @@ declare function getFeedCandlesForMpa(mpaAsset: any, backingAsset: any, config?:
|
|
|
50
101
|
* Numerator publishes predating the first denominator publish are dropped
|
|
51
102
|
* (no reference price yet). Pure function of two point lists otherwise.
|
|
52
103
|
*/
|
|
53
|
-
declare function crossPointsToRatios(numeratorPoints:
|
|
104
|
+
declare function crossPointsToRatios(numeratorPoints: unknown, denominatorPoints: unknown, intervalSeconds?: number): RatioPoint[];
|
|
54
105
|
/**
|
|
55
106
|
* Feed candles oriented for a tv pair (B-per-A units).
|
|
56
107
|
*
|
|
@@ -60,7 +111,7 @@ declare function crossPointsToRatios(numeratorPoints: any, denominatorPoints: an
|
|
|
60
111
|
* cannot price that pair; use pool/orderbook candles instead, or
|
|
61
112
|
* getFeedCandlesForMpaCross() when both legs are MPAs.
|
|
62
113
|
*/
|
|
63
|
-
declare function getFeedCandlesForPair(assetA:
|
|
114
|
+
declare function getFeedCandlesForPair(assetA: AssetRef, assetB: AssetRef, mpaAsset: AssetRef, backingAsset: AssetRef, config?: FeedConfig): Promise<number[][]>;
|
|
64
115
|
/**
|
|
65
116
|
* Cross-rate feed candles for an MPA/MPA pair sharing one backing asset
|
|
66
117
|
* (e.g. HONEST.USD/HONEST.EUR, both BTS-backed), in B-per-A units.
|
|
@@ -74,7 +125,15 @@ declare function getFeedCandlesForPair(assetA: any, assetB: any, mpaAsset: any,
|
|
|
74
125
|
* @param {Object} legA – { mpa, backing } for one MPA leg
|
|
75
126
|
* @param {Object} legB – { mpa, backing } for the other MPA leg
|
|
76
127
|
*/
|
|
77
|
-
declare function getFeedCandlesForMpaCross(assetA:
|
|
78
|
-
declare function fetchFeedCandlesSequentially(feedCtx:
|
|
128
|
+
declare function getFeedCandlesForMpaCross(assetA: AssetRef, assetB: AssetRef, legA: FeedLeg, legB: FeedLeg, config?: FeedConfig): Promise<number[][]>;
|
|
129
|
+
declare function fetchFeedCandlesSequentially(feedCtx: FeedContext, assetA: AssetRef, assetB: AssetRef, opts?: {
|
|
130
|
+
intervalSeconds?: number;
|
|
131
|
+
chunkMonths?: number;
|
|
132
|
+
timeRange?: {
|
|
133
|
+
gte?: string;
|
|
134
|
+
lte?: string;
|
|
135
|
+
};
|
|
136
|
+
outPath?: string;
|
|
137
|
+
}): Promise<number[][]>;
|
|
79
138
|
export { OP_TYPE_FEED, backingPerMpa, hitToFeedPrice, buildFeedDocumentQuery, crossPointsToRatios, bucketPricesToCandles, invertCandles, getFeedCandlesForMpa, getFeedCandlesForPair, getFeedCandlesForMpaCross, fetchFeedCandlesSequentially, };
|
|
80
139
|
//# sourceMappingURL=kibana_feed_source.d.ts.map
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
* - Volume is the feed publish count per bucket, NOT traded asset volume.
|
|
31
31
|
*/
|
|
32
32
|
import { fillCandleGaps } from '../candle_utils.js';
|
|
33
|
-
import { resolveRequestedFillRange } from '../core/kibana_candles.js';
|
|
33
|
+
import { resolveRequestedFillRange, hitSortKey, hitSequence } from '../core/kibana_candles.js';
|
|
34
|
+
import { parseChainTimeToMs } from '../interval_utils.js';
|
|
34
35
|
import { kibanaSearch, DEFAULT_CONFIG as BASE_CONFIG } from '../core/kibana_client.js';
|
|
35
36
|
import { path } from '../../modules/path_api.js';
|
|
36
37
|
import { PATHS } from '../../modules/paths.js';
|
|
@@ -51,7 +52,6 @@ const FEED_SOURCE_FIELDS = [
|
|
|
51
52
|
'operation_history.op_object.asset_id',
|
|
52
53
|
'operation_history.op_object.feed.settlement_price',
|
|
53
54
|
];
|
|
54
|
-
// ─── Default Config ───────────────────────────────────────────────────────────
|
|
55
55
|
const DEFAULT_CONFIG = {
|
|
56
56
|
...BASE_CONFIG,
|
|
57
57
|
intervalSeconds: 3600,
|
|
@@ -82,8 +82,9 @@ function floatAmount(raw, precision) {
|
|
|
82
82
|
* exactly the mpa/backing pair.
|
|
83
83
|
*/
|
|
84
84
|
function backingPerMpa(settlement, mpaAsset, backingAsset) {
|
|
85
|
-
const
|
|
86
|
-
const
|
|
85
|
+
const s = settlement;
|
|
86
|
+
const base = s?.base;
|
|
87
|
+
const quote = s?.quote;
|
|
87
88
|
if (!base || !quote)
|
|
88
89
|
return null;
|
|
89
90
|
const baseId = String(base.asset_id || '');
|
|
@@ -95,8 +96,8 @@ function backingPerMpa(settlement, mpaAsset, backingAsset) {
|
|
|
95
96
|
const ids = new Set([baseId, quoteId]);
|
|
96
97
|
if (!ids.has(mpaId) || !ids.has(backingId))
|
|
97
98
|
return null;
|
|
98
|
-
const baseFloat = floatAmount(base.amount, baseId === mpaId ? mpaAsset
|
|
99
|
-
const quoteFloat = floatAmount(quote.amount, quoteId === mpaId ? mpaAsset
|
|
99
|
+
const baseFloat = floatAmount(base.amount, baseId === mpaId ? mpaAsset?.precision : backingAsset?.precision);
|
|
100
|
+
const quoteFloat = floatAmount(quote.amount, quoteId === mpaId ? mpaAsset?.precision : backingAsset?.precision);
|
|
100
101
|
if (!Number.isFinite(baseFloat) || !Number.isFinite(quoteFloat) || baseFloat <= 0 || quoteFloat <= 0)
|
|
101
102
|
return null;
|
|
102
103
|
// backing-per-MPA: divide the backing side by the MPA side.
|
|
@@ -110,35 +111,15 @@ function parseFeedTimestamp(source) {
|
|
|
110
111
|
const raw = source?.block_data?.block_time;
|
|
111
112
|
if (raw == null)
|
|
112
113
|
return null;
|
|
113
|
-
const
|
|
114
|
-
const tsMs = Date.parse(text.endsWith('Z') ? text : `${text}Z`);
|
|
114
|
+
const tsMs = parseChainTimeToMs(String(raw));
|
|
115
115
|
return Number.isFinite(tsMs) ? tsMs : null;
|
|
116
116
|
}
|
|
117
|
-
function hitSortKey(hit) {
|
|
118
|
-
const sort = Array.isArray(hit?.sort) ? hit.sort : [];
|
|
119
|
-
return sort.map((v) => String(v)).join('|') || String(hit?._id || '');
|
|
120
|
-
}
|
|
121
|
-
function hitSequence(source) {
|
|
122
|
-
const candidates = [
|
|
123
|
-
source?.operation_id_num,
|
|
124
|
-
source?.account_history?.operation_id,
|
|
125
|
-
source?.account_history?.sequence,
|
|
126
|
-
];
|
|
127
|
-
for (const value of candidates) {
|
|
128
|
-
if (typeof value === 'number' && Number.isFinite(value))
|
|
129
|
-
return value;
|
|
130
|
-
const m = String(value || '').match(/(\d+)$/);
|
|
131
|
-
if (m)
|
|
132
|
-
return Number(m[1]);
|
|
133
|
-
}
|
|
134
|
-
return Number.NaN;
|
|
135
|
-
}
|
|
136
117
|
/**
|
|
137
118
|
* Kibana hit → { tsMs, price, sequence, kibanaSortKey } in backing-per-MPA,
|
|
138
119
|
* or null when the hit carries no usable settlement price for the pair.
|
|
139
120
|
*/
|
|
140
121
|
function hitToFeedPrice(hit, { mpaAsset, backingAsset }) {
|
|
141
|
-
const source = hit?._source || {};
|
|
122
|
+
const source = (hit?._source || {});
|
|
142
123
|
const tsMs = parseFeedTimestamp(source);
|
|
143
124
|
if (tsMs == null)
|
|
144
125
|
return null;
|
|
@@ -149,7 +130,7 @@ function hitToFeedPrice(hit, { mpaAsset, backingAsset }) {
|
|
|
149
130
|
return {
|
|
150
131
|
tsMs,
|
|
151
132
|
price: price,
|
|
152
|
-
sequence: hitSequence(source),
|
|
133
|
+
sequence: hitSequence(source, 'account_history.operation_id'),
|
|
153
134
|
kibanaSortKey: hitSortKey(hit),
|
|
154
135
|
};
|
|
155
136
|
}
|
|
@@ -207,7 +188,7 @@ async function fetchFeedPricePoints({ mpaAsset, backingAsset, config = {} }) {
|
|
|
207
188
|
`Narrow the timeRange or raise kibanaMaxPages.`);
|
|
208
189
|
}
|
|
209
190
|
const query = buildFeedDocumentQuery({
|
|
210
|
-
mpaAssetId: mpaAsset.id,
|
|
191
|
+
mpaAssetId: String(mpaAsset.id),
|
|
211
192
|
lookbackHours: cfg.lookbackHours,
|
|
212
193
|
timeRange: cfg.timeRange ?? null,
|
|
213
194
|
size,
|
|
@@ -323,7 +304,8 @@ function bucketPricesToCandles(points, intervalSeconds = 3600) {
|
|
|
323
304
|
* orientation when the MPA is the B leg (B-per-A = MPA-per-backing).
|
|
324
305
|
*/
|
|
325
306
|
function invertCandles(candles) {
|
|
326
|
-
|
|
307
|
+
const list = Array.isArray(candles) ? candles : [];
|
|
308
|
+
return list
|
|
327
309
|
.filter((c) => Array.isArray(c) && c.slice(1, 5).every((v) => Number.isFinite(Number(v)) && Number(v) > 0))
|
|
328
310
|
.map((c) => [c[0], 1 / c[4], 1 / c[3], 1 / c[2], 1 / c[1], c[5]]);
|
|
329
311
|
}
|
|
@@ -346,10 +328,10 @@ function applyGapFill(consolidated, cfg) {
|
|
|
346
328
|
return consolidated;
|
|
347
329
|
}
|
|
348
330
|
if (cfg.fillGapsToRequestedRange === false) {
|
|
349
|
-
return fillCandleGaps(consolidated, cfg.intervalSeconds);
|
|
331
|
+
return fillCandleGaps(consolidated, Number(cfg.intervalSeconds));
|
|
350
332
|
}
|
|
351
333
|
const { startTs, endTs } = resolveRequestedFillRange(cfg);
|
|
352
|
-
return fillCandleGaps(consolidated, cfg.intervalSeconds, startTs, endTs);
|
|
334
|
+
return fillCandleGaps(consolidated, Number(cfg.intervalSeconds), startTs, endTs);
|
|
353
335
|
}
|
|
354
336
|
/**
|
|
355
337
|
* Cross-rate price points for two MPAs sharing one backing asset.
|
|
@@ -363,6 +345,8 @@ function applyGapFill(consolidated, cfg) {
|
|
|
363
345
|
* (no reference price yet). Pure function of two point lists otherwise.
|
|
364
346
|
*/
|
|
365
347
|
function crossPointsToRatios(numeratorPoints, denominatorPoints, intervalSeconds = 0) {
|
|
348
|
+
const numer = Array.isArray(numeratorPoints) ? numeratorPoints : [];
|
|
349
|
+
const denom = Array.isArray(denominatorPoints) ? denominatorPoints : [];
|
|
366
350
|
const ratios = [];
|
|
367
351
|
let j = 0;
|
|
368
352
|
let lastDenominator = null;
|
|
@@ -371,14 +355,14 @@ function crossPointsToRatios(numeratorPoints, denominatorPoints, intervalSeconds
|
|
|
371
355
|
const denominatorCounts = new Map();
|
|
372
356
|
const countedBuckets = new Set();
|
|
373
357
|
if (Number.isFinite(bucketMs) && bucketMs > 0) {
|
|
374
|
-
for (const point of
|
|
358
|
+
for (const point of numer) {
|
|
375
359
|
const tsMs = Number(point?.tsMs);
|
|
376
360
|
if (Number.isFinite(tsMs)) {
|
|
377
361
|
const bucket = Math.floor(tsMs / bucketMs) * bucketMs;
|
|
378
362
|
numeratorCounts.set(bucket, (numeratorCounts.get(bucket) || 0) + 1);
|
|
379
363
|
}
|
|
380
364
|
}
|
|
381
|
-
for (const point of
|
|
365
|
+
for (const point of denom) {
|
|
382
366
|
const tsMs = Number(point?.tsMs);
|
|
383
367
|
if (Number.isFinite(tsMs)) {
|
|
384
368
|
const bucket = Math.floor(tsMs / bucketMs) * bucketMs;
|
|
@@ -386,13 +370,13 @@ function crossPointsToRatios(numeratorPoints, denominatorPoints, intervalSeconds
|
|
|
386
370
|
}
|
|
387
371
|
}
|
|
388
372
|
}
|
|
389
|
-
for (const point of
|
|
373
|
+
for (const point of numer) {
|
|
390
374
|
const tsMs = Number(point?.tsMs);
|
|
391
375
|
const price = Number(point?.price);
|
|
392
376
|
if (!Number.isFinite(tsMs) || !Number.isFinite(price) || price <= 0)
|
|
393
377
|
continue;
|
|
394
|
-
while (j <
|
|
395
|
-
lastDenominator =
|
|
378
|
+
while (j < denom.length && Number(denom[j]?.tsMs) <= tsMs) {
|
|
379
|
+
lastDenominator = denom[j];
|
|
396
380
|
j++;
|
|
397
381
|
}
|
|
398
382
|
const refPrice = Number(lastDenominator?.price);
|
|
@@ -421,7 +405,7 @@ async function fetchFeedCrossPoints({ mpaA, mpaB, backing, config = {} }) {
|
|
|
421
405
|
fetchFeedPricePoints({ mpaAsset: mpaA, backingAsset: backing, config }),
|
|
422
406
|
fetchFeedPricePoints({ mpaAsset: mpaB, backingAsset: backing, config }),
|
|
423
407
|
]);
|
|
424
|
-
return crossPointsToRatios(pointsA, pointsB, config.intervalSeconds || 3600);
|
|
408
|
+
return crossPointsToRatios(pointsA, pointsB, Number(config.intervalSeconds) || 3600);
|
|
425
409
|
}
|
|
426
410
|
/**
|
|
427
411
|
* Feed candles oriented for a tv pair (B-per-A units).
|
|
@@ -507,7 +491,9 @@ function feedOutputPath(feedKey, intervalSeconds, assetA, assetB) {
|
|
|
507
491
|
const folder = `${slugPart(assetA?.symbol)}_${slugPart(assetB?.symbol)}`;
|
|
508
492
|
return path.join(PATHS.MARKET_ADAPTER.FEED_DATA_DIR, folder, `feed_${slugPart(feedKey)}_${label}.json`);
|
|
509
493
|
}
|
|
510
|
-
function isFeedChunkMatch(
|
|
494
|
+
function isFeedChunkMatch(metaInput, requestKeyInput) {
|
|
495
|
+
const meta = metaInput;
|
|
496
|
+
const requestKey = requestKeyInput;
|
|
511
497
|
if (meta.feed !== requestKey.feed)
|
|
512
498
|
return false;
|
|
513
499
|
if (meta.intervalSeconds !== requestKey.intervalSeconds)
|
|
@@ -555,7 +541,6 @@ async function fetchFeedCandlesSequentially(feedCtx, assetA, assetB, opts = {})
|
|
|
555
541
|
assetA: requestKey.assetA,
|
|
556
542
|
assetB: requestKey.assetB,
|
|
557
543
|
intervalSeconds,
|
|
558
|
-
chunkIndex: window.index,
|
|
559
544
|
timeRange: { gte: window.gte, lte: window.lte },
|
|
560
545
|
format: '[timestamp_ms, open, high, low, close, feed_publish_count]',
|
|
561
546
|
}),
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
interface KibanaSourceConfig {
|
|
2
|
+
intervalSeconds?: number;
|
|
3
|
+
lookbackHours?: number;
|
|
4
|
+
timeRange?: {
|
|
5
|
+
gte?: string;
|
|
6
|
+
lte?: string;
|
|
7
|
+
} | null;
|
|
8
|
+
kibanaSearch?: (cfg: unknown, query: unknown) => Promise<unknown>;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
1
11
|
/**
|
|
2
12
|
* Auto-discover the two asset IDs for a pool by looking at what has been sold
|
|
3
13
|
* into it. Returns an array of asset ID strings, e.g. ['1.3.0', '1.3.3926'].
|
|
@@ -9,7 +19,7 @@
|
|
|
9
19
|
* but may exceed 2 (e.g. fee asset) or be
|
|
10
20
|
* fewer on thin data.
|
|
11
21
|
*/
|
|
12
|
-
declare function discoverPoolAssets(poolId:
|
|
22
|
+
declare function discoverPoolAssets(poolId: unknown, config?: KibanaSourceConfig): Promise<string[]>;
|
|
13
23
|
/**
|
|
14
24
|
* Fetch bidirectional LP price candles for a specific pool.
|
|
15
25
|
*
|
|
@@ -23,7 +33,13 @@ declare function discoverPoolAssets(poolId: any, config?: any): Promise<any>;
|
|
|
23
33
|
* @param {Object} [config]
|
|
24
34
|
* @returns {Promise<Array>} OHLCV candles
|
|
25
35
|
*/
|
|
26
|
-
declare function getLpCandlesForPool(poolId:
|
|
36
|
+
declare function getLpCandlesForPool(poolId: unknown, assetA: {
|
|
37
|
+
id?: string | null;
|
|
38
|
+
symbol?: string | null;
|
|
39
|
+
}, assetB: {
|
|
40
|
+
id?: string | null;
|
|
41
|
+
symbol?: string | null;
|
|
42
|
+
}, config?: KibanaSourceConfig): Promise<number[][]>;
|
|
27
43
|
/**
|
|
28
44
|
* Close prices only — convenience wrapper for AMA input.
|
|
29
45
|
*
|
|
@@ -33,6 +49,12 @@ declare function getLpCandlesForPool(poolId: any, assetA: any, assetB: any, conf
|
|
|
33
49
|
* @param {Object} [config]
|
|
34
50
|
* @returns {Promise<number[]>}
|
|
35
51
|
*/
|
|
36
|
-
declare function getLpClosePricesForPool(poolId:
|
|
52
|
+
declare function getLpClosePricesForPool(poolId: unknown, assetA: {
|
|
53
|
+
id?: string | null;
|
|
54
|
+
symbol?: string | null;
|
|
55
|
+
}, assetB: {
|
|
56
|
+
id?: string | null;
|
|
57
|
+
symbol?: string | null;
|
|
58
|
+
}, config?: KibanaSourceConfig): Promise<number[]>;
|
|
37
59
|
export { discoverPoolAssets, getLpCandlesForPool, getLpClosePricesForPool };
|
|
38
60
|
//# sourceMappingURL=kibana_source.d.ts.map
|
|
@@ -45,7 +45,7 @@ const DEFAULT_CONFIG = {
|
|
|
45
45
|
*/
|
|
46
46
|
function buildDiscoveryQuery(poolId, lookbackHours, timeRange = null) {
|
|
47
47
|
const rangeValue = timeRange?.gte && timeRange?.lte
|
|
48
|
-
? { gte: timeRange.gte, lte: timeRange.lte }
|
|
48
|
+
? { gte: String(timeRange.gte), lte: String(timeRange.lte) }
|
|
49
49
|
: { gte: `now-${lookbackHours}h`, lte: 'now' };
|
|
50
50
|
return {
|
|
51
51
|
size: 0,
|
|
@@ -87,7 +87,7 @@ async function discoverPoolAssets(poolId, config = {}) {
|
|
|
87
87
|
const search = typeof cfg.kibanaSearch === 'function' ? cfg.kibanaSearch : kibanaSearch;
|
|
88
88
|
const result = await search(cfg, query);
|
|
89
89
|
const buckets = result.aggregations?.sold_assets?.buckets ?? [];
|
|
90
|
-
return buckets.map((b) => b.key);
|
|
90
|
+
return buckets.map((b) => String(b.key));
|
|
91
91
|
}
|
|
92
92
|
const LP_FIELD_MAP = {
|
|
93
93
|
soldAssetField: 'operation_history.op_object.amount_to_sell.asset_id.keyword',
|