dexbot 1.6.6 → 1.6.8
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 +89 -1
- package/README.md +8 -5
- package/analysis/README.md +2 -3
- package/analysis/tradingview/README.md +78 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +4 -0
- package/dist/analysis/tradingview/analyze_tradingview.js +55 -0
- package/dist/analysis/tradingview/grid_reset_config.d.ts +61 -0
- package/dist/analysis/tradingview/grid_reset_config.js +235 -0
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +67 -0
- package/dist/analysis/tradingview/grid_reset_sim.js +307 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +419 -3
- package/dist/dexbot.js +44 -15
- package/dist/market_adapter/core/market_adapter_service.js +14 -2
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
- package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
- package/dist/market_adapter/inputs/window_cache.js +302 -48
- package/dist/market_adapter/market_adapter.d.ts +8 -1
- package/dist/market_adapter/market_adapter.js +22 -4
- package/dist/modules/account_bots.js +20 -9
- package/dist/modules/account_orders.d.ts +44 -4
- package/dist/modules/account_orders.js +104 -7
- package/dist/modules/bitshares-native/chain_client.d.ts +10 -0
- package/dist/modules/bitshares-native/chain_client.js +197 -28
- package/dist/modules/bitshares-native/subscriptions.js +312 -10
- package/dist/modules/bitshares-native/transport.d.ts +1 -0
- package/dist/modules/bitshares-native/transport.js +97 -3
- package/dist/modules/bitshares_client.d.ts +20 -0
- package/dist/modules/bitshares_client.js +29 -0
- package/dist/modules/bot_settings.js +10 -1
- package/dist/modules/chain_keys.d.ts +37 -22
- package/dist/modules/chain_keys.js +145 -44
- package/dist/modules/cli_start_onboarding.d.ts +10 -0
- package/dist/modules/cli_start_onboarding.js +15 -0
- package/dist/modules/cli_start_output.d.ts +6 -0
- package/dist/modules/cli_start_output.js +8 -0
- package/dist/modules/config.d.ts +1 -0
- package/dist/modules/config.js +1 -0
- package/dist/modules/constants.d.ts +23 -2
- package/dist/modules/constants.js +196 -15
- package/dist/modules/dexbot_class.d.ts +6 -76
- package/dist/modules/dexbot_class.js +0 -32
- package/dist/modules/dexbot_cow_runtime.d.ts +3 -58
- package/dist/modules/dexbot_cow_runtime.js +53 -96
- package/dist/modules/dexbot_fill_runtime.d.ts +6 -1
- package/dist/modules/dexbot_fill_runtime.js +22 -3
- package/dist/modules/dexbot_maintenance_runtime.d.ts +38 -1
- package/dist/modules/dexbot_maintenance_runtime.js +103 -11
- package/dist/modules/dexbot_startup_runtime.js +73 -20
- package/dist/modules/dexbot_state_recovery.d.ts +6 -0
- package/dist/modules/dexbot_state_recovery.js +34 -1
- package/dist/modules/order/async_lock.d.ts +8 -0
- package/dist/modules/order/async_lock.js +15 -0
- package/dist/modules/order/genesis_policy.d.ts +162 -0
- package/dist/modules/order/genesis_policy.js +267 -0
- package/dist/modules/order/grid.js +109 -135
- package/dist/modules/order/grid_reconcile.d.ts +9 -0
- package/dist/modules/order/grid_reconcile.js +13 -4
- package/dist/modules/order/grid_reconcile_internal.js +13 -2
- package/dist/modules/order/logger.d.ts +12 -2
- package/dist/modules/order/logger.js +29 -7
- package/dist/modules/order/manager.d.ts +53 -0
- package/dist/modules/order/manager.js +86 -25
- package/dist/modules/order/sync_engine.d.ts +19 -0
- package/dist/modules/order/sync_engine.js +284 -344
- package/dist/modules/order/utils/math.d.ts +22 -1
- package/dist/modules/order/utils/math.js +64 -1
- package/dist/modules/order/utils/order.d.ts +43 -58
- package/dist/modules/order/utils/order.js +302 -194
- package/dist/modules/order/utils/system.d.ts +97 -0
- package/dist/modules/order/utils/system.js +282 -3
- package/dist/modules/paths.d.ts +8 -1
- package/dist/modules/paths.js +11 -3
- package/dist/modules/utils/text_width.d.ts +19 -0
- package/dist/modules/utils/text_width.js +97 -0
- package/dist/modules/version_notice.d.ts +165 -0
- package/dist/modules/version_notice.js +364 -0
- package/dist/pm2.js +104 -18
- package/dist/scripts/update.js +62 -13
- package/dist/unlock.d.ts +14 -2
- package/dist/unlock.js +101 -4
- package/docs/BITSHARES_ONBOARDING.md +8 -1
- package/docs/COW_INVARIANTS.md +11 -2
- package/docs/CREDENTIAL_SECURITY.md +26 -0
- package/docs/DEXBOT_COMPARISON.md +4 -4
- package/docs/EVOLUTION.md +20 -18
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +204 -31
- package/docs/GRID_RECALCULATION.md +12 -0
- package/docs/LOGGING.md +17 -2
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +6 -7
- package/docs/README.md +3 -1
- package/docs/WORKFLOW.md +16 -5
- package/market_adapter/README.md +1 -1
- package/modules/README.md +18 -1
- package/package.json +14 -6
- package/scripts/README.md +28 -2
- package/scripts/clear-all.sh +13 -4
- package/scripts/clear-logs.sh +13 -4
- package/scripts/clear-market-adapter.sh +6 -0
- package/scripts/clear-orders.sh +5 -0
- package/scripts/lib/dexbot-paths.sh +108 -0
- package/tests/README.md +11 -3
- package/analysis/account_resolver.ts +0 -161
- package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
- package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
- package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
- package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
- package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
- package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
- package/analysis/analyze_dynamic_weight.ts +0 -243
- package/analysis/analyze_kalman.ts +0 -157
- package/analysis/analyze_regime.ts +0 -158
- package/analysis/analyze_regime_windows.ts +0 -470
- package/analysis/analyze_risk_profile.ts +0 -199
- package/analysis/analyze_trade_heatmap.ts +0 -362
- package/analysis/analyze_volatility.ts +0 -182
- package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
- package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
- package/analysis/bot_fitting/shared_utils.ts +0 -52
- package/analysis/bot_key_utils.ts +0 -426
- package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
- package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
- package/analysis/chain_pool.ts +0 -47
- package/analysis/chart_css.ts +0 -62
- package/analysis/chart_ui.ts +0 -105
- package/analysis/chart_utils.ts +0 -210
- package/analysis/fills_source.ts +0 -228
- package/analysis/grid_correction_check.ts +0 -786
- package/analysis/math_utils.ts +0 -53
- package/analysis/price_sources.ts +0 -136
- package/analysis/resolve_bot_accounts.ts +0 -199
- package/analysis/resolve_source.ts +0 -99
- package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
- package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
- package/analysis/trade_profitability.ts +0 -1335
- package/analysis/tradingview/analyze_tradingview.ts +0 -280
- package/analysis/tradingview/h-bts_tradingview.html +0 -1570
- package/analysis/tradingview/t-bts_tradingview.html +0 -1570
- package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
- package/analysis/trend_detection/hurst_analyzer.ts +0 -7
- package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
- package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
- package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
- package/analysis/trend_detection/package.json +0 -23
- package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
- package/analysis/trend_detection/regime_chart_generator.ts +0 -338
- package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
- package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
- package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
- package/analysis/tsconfig.json +0 -29
- package/claw/tests/package.json +0 -3
- package/claw/tests/test_claw_bridge.ts +0 -570
- package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
- package/claw/tests/test_claw_chain_layer.ts +0 -739
- package/claw/tests/test_claw_data_flow.ts +0 -525
- package/claw/tests/test_claw_domain_logic.ts +0 -471
- package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
- package/claw/tests/test_claw_mcp_transport.ts +0 -243
- package/claw/tests/test_claw_regressions.ts +0 -711
- package/claw/tests/test_claw_skill_generation.ts +0 -103
- package/claw/tests/test_claw_state_store.ts +0 -44
- package/claw/tests/test_dexbot_profiles.ts +0 -654
- package/claw/tests/test_memu_bridge.ts +0 -189
- package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
- package/claw/tests/test_position_health.ts +0 -343
- package/claw/tests/test_position_manager.ts +0 -429
- package/claw/tests/test_position_manager_watch_health.ts +0 -100
- package/claw/tests/test_short_mpa_strategy.ts +0 -232
- package/dist/analysis/account_resolver.d.ts.map +0 -1
- package/dist/analysis/account_resolver.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
- package/dist/analysis/analyze_kalman.d.ts.map +0 -1
- package/dist/analysis/analyze_kalman.js.map +0 -1
- package/dist/analysis/analyze_regime.d.ts.map +0 -1
- package/dist/analysis/analyze_regime.js.map +0 -1
- package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
- package/dist/analysis/analyze_regime_windows.js.map +0 -1
- package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
- package/dist/analysis/analyze_risk_profile.js.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
- package/dist/analysis/analyze_volatility.d.ts.map +0 -1
- package/dist/analysis/analyze_volatility.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
- package/dist/analysis/bot_key_utils.d.ts.map +0 -1
- package/dist/analysis/bot_key_utils.js.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
- package/dist/analysis/chain_pool.d.ts.map +0 -1
- package/dist/analysis/chain_pool.js.map +0 -1
- package/dist/analysis/chart_css.d.ts.map +0 -1
- package/dist/analysis/chart_css.js.map +0 -1
- package/dist/analysis/chart_ui.d.ts.map +0 -1
- package/dist/analysis/chart_ui.js.map +0 -1
- package/dist/analysis/chart_utils.d.ts.map +0 -1
- package/dist/analysis/chart_utils.js.map +0 -1
- package/dist/analysis/fills_source.d.ts.map +0 -1
- package/dist/analysis/fills_source.js.map +0 -1
- package/dist/analysis/grid_correction_check.d.ts.map +0 -1
- package/dist/analysis/grid_correction_check.js.map +0 -1
- package/dist/analysis/math_utils.d.ts.map +0 -1
- package/dist/analysis/math_utils.js.map +0 -1
- package/dist/analysis/price_sources.d.ts.map +0 -1
- package/dist/analysis/price_sources.js.map +0 -1
- package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/resolve_bot_accounts.js.map +0 -1
- package/dist/analysis/resolve_source.d.ts.map +0 -1
- package/dist/analysis/resolve_source.js.map +0 -1
- package/dist/analysis/trade_profitability.d.ts.map +0 -1
- package/dist/analysis/trade_profitability.js.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -128
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -37
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
- package/dist/bot.d.ts.map +0 -1
- package/dist/bot.js.map +0 -1
- package/dist/credential-daemon.d.ts.map +0 -1
- package/dist/credential-daemon.js.map +0 -1
- package/dist/dexbot.d.ts.map +0 -1
- package/dist/dexbot.js.map +0 -1
- package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
- package/dist/market_adapter/ama_signal_runner.js.map +0 -1
- package/dist/market_adapter/candle_utils.d.ts.map +0 -1
- package/dist/market_adapter/candle_utils.js.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
- package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
- package/dist/market_adapter/core/config_normalizers.js.map +0 -1
- package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_candles.js.map +0 -1
- package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_client.js.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
- package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
- package/dist/market_adapter/inputs/window_cache.js.map +0 -1
- package/dist/market_adapter/interval_utils.d.ts.map +0 -1
- package/dist/market_adapter/interval_utils.js.map +0 -1
- package/dist/market_adapter/log_format.d.ts.map +0 -1
- package/dist/market_adapter/log_format.js.map +0 -1
- package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_core.js.map +0 -1
- package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_runner.js.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
- package/dist/market_adapter/market_adapter.d.ts.map +0 -1
- package/dist/market_adapter/market_adapter.js.map +0 -1
- package/dist/market_adapter/test_helpers.d.ts.map +0 -1
- package/dist/market_adapter/test_helpers.js.map +0 -1
- package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
- package/dist/market_adapter/utils/adapter_client.js.map +0 -1
- package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
- package/dist/market_adapter/utils/atomic_write.js.map +0 -1
- package/dist/market_adapter/utils/chain.d.ts.map +0 -1
- package/dist/market_adapter/utils/chain.js.map +0 -1
- package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
- package/dist/market_adapter/utils/data_discovery.js.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
- package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
- package/dist/market_adapter/utils/file_lock.js.map +0 -1
- package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
- package/dist/market_adapter/utils/native_history.js.map +0 -1
- package/dist/modules/account_bots.d.ts.map +0 -1
- package/dist/modules/account_bots.js.map +0 -1
- package/dist/modules/account_orders.d.ts.map +0 -1
- package/dist/modules/account_orders.js.map +0 -1
- package/dist/modules/authority_resolver.d.ts.map +0 -1
- package/dist/modules/authority_resolver.js.map +0 -1
- package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/chain_client.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
- package/dist/modules/bitshares-native/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/index.js.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
- package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
- package/dist/modules/bitshares-native/resolvers.js.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
- package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/index.js.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
- package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/types.js.map +0 -1
- package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/signing_client.js.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
- package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
- package/dist/modules/bitshares-native/transport.js.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
- package/dist/modules/bitshares_client.d.ts.map +0 -1
- package/dist/modules/bitshares_client.js.map +0 -1
- package/dist/modules/bot_defaults.d.ts.map +0 -1
- package/dist/modules/bot_defaults.js.map +0 -1
- package/dist/modules/bot_settings.d.ts.map +0 -1
- package/dist/modules/bot_settings.js.map +0 -1
- package/dist/modules/bots_file_lock.d.ts.map +0 -1
- package/dist/modules/bots_file_lock.js.map +0 -1
- package/dist/modules/broadcast_failure.d.ts.map +0 -1
- package/dist/modules/broadcast_failure.js.map +0 -1
- package/dist/modules/chain_keys.d.ts.map +0 -1
- package/dist/modules/chain_keys.js.map +0 -1
- package/dist/modules/chain_orders.d.ts.map +0 -1
- package/dist/modules/chain_orders.js.map +0 -1
- package/dist/modules/cli_colors.d.ts.map +0 -1
- package/dist/modules/cli_colors.js.map +0 -1
- package/dist/modules/config.d.ts.map +0 -1
- package/dist/modules/config.js.map +0 -1
- package/dist/modules/constants.d.ts.map +0 -1
- package/dist/modules/constants.js.map +0 -1
- package/dist/modules/cr_planner.d.ts.map +0 -1
- package/dist/modules/cr_planner.js.map +0 -1
- package/dist/modules/credential_policy.d.ts.map +0 -1
- package/dist/modules/credential_policy.js.map +0 -1
- package/dist/modules/credential_runtime.d.ts.map +0 -1
- package/dist/modules/credential_runtime.js.map +0 -1
- package/dist/modules/credential_session_cache.d.ts.map +0 -1
- package/dist/modules/credential_session_cache.js.map +0 -1
- package/dist/modules/credit_pricing.d.ts.map +0 -1
- package/dist/modules/credit_pricing.js.map +0 -1
- package/dist/modules/credit_runtime.d.ts.map +0 -1
- package/dist/modules/credit_runtime.js.map +0 -1
- package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
- package/dist/modules/crypto/browser_provider.js.map +0 -1
- package/dist/modules/crypto/index.d.ts.map +0 -1
- package/dist/modules/crypto/index.js.map +0 -1
- package/dist/modules/crypto/node_provider.d.ts.map +0 -1
- package/dist/modules/crypto/node_provider.js.map +0 -1
- package/dist/modules/crypto/provider.d.ts.map +0 -1
- package/dist/modules/crypto/provider.js.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
- package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
- package/dist/modules/crypto/pure_scrypt.js.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
- package/dist/modules/crypto/sync.d.ts.map +0 -1
- package/dist/modules/crypto/sync.js.map +0 -1
- package/dist/modules/daemon_node_health.d.ts.map +0 -1
- package/dist/modules/daemon_node_health.js.map +0 -1
- package/dist/modules/dexbot_class.d.ts.map +0 -1
- package/dist/modules/dexbot_class.js.map +0 -1
- package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_cow_runtime.js.map +0 -1
- package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
- package/dist/modules/dexbot_credential_client.js.map +0 -1
- package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_fill_runtime.js.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
- package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_startup_runtime.js.map +0 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
- package/dist/modules/dexbot_state_recovery.js.map +0 -1
- package/dist/modules/env.d.ts.map +0 -1
- package/dist/modules/env.js.map +0 -1
- package/dist/modules/fund_registry.d.ts.map +0 -1
- package/dist/modules/fund_registry.js.map +0 -1
- package/dist/modules/general_settings.d.ts.map +0 -1
- package/dist/modules/general_settings.js.map +0 -1
- package/dist/modules/graceful_shutdown.d.ts.map +0 -1
- package/dist/modules/graceful_shutdown.js.map +0 -1
- package/dist/modules/grid_price_source.d.ts.map +0 -1
- package/dist/modules/grid_price_source.js.map +0 -1
- package/dist/modules/key_store.d.ts.map +0 -1
- package/dist/modules/key_store.js.map +0 -1
- package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
- package/dist/modules/launcher/adapter_requirement.js.map +0 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
- package/dist/modules/launcher/bot_supervisor.js.map +0 -1
- package/dist/modules/launcher/child_env.d.ts.map +0 -1
- package/dist/modules/launcher/child_env.js.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
- package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/credential_daemon.js.map +0 -1
- package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
- package/dist/modules/launcher/credential_secret.js.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
- package/dist/modules/launcher/headless_password.d.ts.map +0 -1
- package/dist/modules/launcher/headless_password.js.map +0 -1
- package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
- package/dist/modules/launcher/launch_modes.js.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
- package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
- package/dist/modules/launcher/runtime_entry.js.map +0 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
- package/dist/modules/launcher/status_reporting.js.map +0 -1
- package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
- package/dist/modules/launcher/supervisor_control.js.map +0 -1
- package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
- package/dist/modules/market_adapter_whitelist.js.map +0 -1
- package/dist/modules/node_connect_policy.d.ts.map +0 -1
- package/dist/modules/node_connect_policy.js.map +0 -1
- package/dist/modules/node_failure_ledger.d.ts.map +0 -1
- package/dist/modules/node_failure_ledger.js.map +0 -1
- package/dist/modules/node_health_cache.d.ts.map +0 -1
- package/dist/modules/node_health_cache.js.map +0 -1
- package/dist/modules/node_manager.d.ts.map +0 -1
- package/dist/modules/node_manager.js.map +0 -1
- package/dist/modules/order/accounting.d.ts.map +0 -1
- package/dist/modules/order/accounting.js.map +0 -1
- package/dist/modules/order/async_lock.d.ts.map +0 -1
- package/dist/modules/order/async_lock.js.map +0 -1
- package/dist/modules/order/export.d.ts.map +0 -1
- package/dist/modules/order/export.js.map +0 -1
- package/dist/modules/order/format.d.ts.map +0 -1
- package/dist/modules/order/format.js.map +0 -1
- package/dist/modules/order/grid.d.ts.map +0 -1
- package/dist/modules/order/grid.js.map +0 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile.js.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
- package/dist/modules/order/index.d.ts.map +0 -1
- package/dist/modules/order/index.js.map +0 -1
- package/dist/modules/order/logger.d.ts.map +0 -1
- package/dist/modules/order/logger.js.map +0 -1
- package/dist/modules/order/logger_state.d.ts.map +0 -1
- package/dist/modules/order/logger_state.js.map +0 -1
- package/dist/modules/order/manager.d.ts.map +0 -1
- package/dist/modules/order/manager.js.map +0 -1
- package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
- package/dist/modules/order/processed_fill_store.js.map +0 -1
- package/dist/modules/order/strategy.d.ts.map +0 -1
- package/dist/modules/order/strategy.js.map +0 -1
- package/dist/modules/order/sync_engine.d.ts.map +0 -1
- package/dist/modules/order/sync_engine.js.map +0 -1
- package/dist/modules/order/utils/math.d.ts.map +0 -1
- package/dist/modules/order/utils/math.js.map +0 -1
- package/dist/modules/order/utils/order.d.ts.map +0 -1
- package/dist/modules/order/utils/order.js.map +0 -1
- package/dist/modules/order/utils/slot.d.ts.map +0 -1
- package/dist/modules/order/utils/slot.js.map +0 -1
- package/dist/modules/order/utils/system.d.ts.map +0 -1
- package/dist/modules/order/utils/system.js.map +0 -1
- package/dist/modules/order/utils/timeout.d.ts.map +0 -1
- package/dist/modules/order/utils/timeout.js.map +0 -1
- package/dist/modules/order/utils/validate.d.ts.map +0 -1
- package/dist/modules/order/utils/validate.js.map +0 -1
- package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
- package/dist/modules/order/utils/withPoolRef.js.map +0 -1
- package/dist/modules/order/working_grid.d.ts.map +0 -1
- package/dist/modules/order/working_grid.js.map +0 -1
- package/dist/modules/path_api.d.ts.map +0 -1
- package/dist/modules/path_api.js.map +0 -1
- package/dist/modules/paths.d.ts.map +0 -1
- package/dist/modules/paths.js.map +0 -1
- package/dist/modules/process_discovery.d.ts.map +0 -1
- package/dist/modules/process_discovery.js.map +0 -1
- package/dist/modules/runtime.d.ts.map +0 -1
- package/dist/modules/runtime.js.map +0 -1
- package/dist/modules/runtime_settings.d.ts.map +0 -1
- package/dist/modules/runtime_settings.js.map +0 -1
- package/dist/modules/settings_merge.d.ts.map +0 -1
- package/dist/modules/settings_merge.js.map +0 -1
- package/dist/modules/socket_json_client.d.ts.map +0 -1
- package/dist/modules/socket_json_client.js.map +0 -1
- package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
- package/dist/modules/storage/browser_adapter.js.map +0 -1
- package/dist/modules/storage/index.d.ts.map +0 -1
- package/dist/modules/storage/index.js.map +0 -1
- package/dist/modules/storage/node_adapter.d.ts.map +0 -1
- package/dist/modules/storage/node_adapter.js.map +0 -1
- package/dist/modules/storage/types.d.ts.map +0 -1
- package/dist/modules/storage/types.js.map +0 -1
- package/dist/modules/types.d.ts.map +0 -1
- package/dist/modules/types.js.map +0 -1
- package/dist/modules/utils/base58check.d.ts.map +0 -1
- package/dist/modules/utils/base58check.js.map +0 -1
- package/dist/modules/utils/build_dir.d.ts.map +0 -1
- package/dist/modules/utils/build_dir.js.map +0 -1
- package/dist/modules/utils/chain_logs.d.ts.map +0 -1
- package/dist/modules/utils/chain_logs.js.map +0 -1
- package/dist/modules/utils/errors.d.ts.map +0 -1
- package/dist/modules/utils/errors.js.map +0 -1
- package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
- package/dist/modules/utils/sanitize_key.js.map +0 -1
- package/dist/modules/validate_profiles.d.ts.map +0 -1
- package/dist/modules/validate_profiles.js.map +0 -1
- package/dist/pm2.d.ts.map +0 -1
- package/dist/pm2.js.map +0 -1
- package/dist/scripts/analyze-credit.d.ts.map +0 -1
- package/dist/scripts/analyze-credit.js.map +0 -1
- package/dist/scripts/analyze-git.d.ts.map +0 -1
- package/dist/scripts/analyze-git.js.map +0 -1
- package/dist/scripts/analyze-orders.d.ts.map +0 -1
- package/dist/scripts/analyze-orders.js.map +0 -1
- package/dist/scripts/chart_command.d.ts.map +0 -1
- package/dist/scripts/chart_command.js.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
- package/dist/scripts/diagnose-pool-history.js.map +0 -1
- package/dist/scripts/divergence-calc.d.ts.map +0 -1
- package/dist/scripts/divergence-calc.js.map +0 -1
- package/dist/scripts/dw.d.ts.map +0 -1
- package/dist/scripts/dw.js.map +0 -1
- package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
- package/dist/scripts/generate_lp_chart.js.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
- package/dist/scripts/native_release_gates.d.ts.map +0 -1
- package/dist/scripts/native_release_gates.js.map +0 -1
- package/dist/scripts/print_grid.d.ts.map +0 -1
- package/dist/scripts/print_grid.js.map +0 -1
- package/dist/scripts/run-tests.d.ts.map +0 -1
- package/dist/scripts/run-tests.js.map +0 -1
- package/dist/scripts/runner.d.ts.map +0 -1
- package/dist/scripts/runner.js.map +0 -1
- package/dist/scripts/sync-version.d.ts.map +0 -1
- package/dist/scripts/sync-version.js.map +0 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
- package/dist/scripts/test-credit-renewal.js.map +0 -1
- package/dist/scripts/tv.d.ts.map +0 -1
- package/dist/scripts/tv.js.map +0 -1
- package/dist/scripts/update.d.ts.map +0 -1
- package/dist/scripts/update.js.map +0 -1
- package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
- package/dist/scripts/update_dist_freshness.js.map +0 -1
- package/dist/scripts/validate_bots.d.ts.map +0 -1
- package/dist/scripts/validate_bots.js.map +0 -1
- package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
- package/dist/scripts/verify-browser-bundle.js.map +0 -1
- package/dist/unlock.d.ts.map +0 -1
- package/dist/unlock.js.map +0 -1
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/**
|
|
3
|
-
* KIBANA BOT QUERIES
|
|
4
|
-
*
|
|
5
|
-
* Elasticsearch query builders for analyzing DEXBot / DEXBot2 order activity
|
|
6
|
-
* on the BitShares blockchain via the public Kibana instance.
|
|
7
|
-
*
|
|
8
|
-
* Data source:
|
|
9
|
-
* https://kibana.bitshares.dev / bitshares-* index
|
|
10
|
-
* Time field: block_data.block_time
|
|
11
|
-
*
|
|
12
|
-
* BitShares operation types used here:
|
|
13
|
-
* 1 = limit_order_create (field: op_object.seller)
|
|
14
|
-
* 2 = limit_order_cancel (field: op_object.fee_paying_account)
|
|
15
|
-
* 4 = fill_order (field: op_object.account_id)
|
|
16
|
-
*
|
|
17
|
-
* Relevant ES field paths:
|
|
18
|
-
* limit_order_create:
|
|
19
|
-
* op_object.seller — account that placed the order
|
|
20
|
-
* op_object.amount_to_sell.amount — integer sell amount
|
|
21
|
-
* op_object.amount_to_sell.asset_id — sell asset ID (e.g. '1.3.0' = BTS)
|
|
22
|
-
* op_object.min_to_receive.amount — integer min-receive (= limit price numerator)
|
|
23
|
-
* op_object.min_to_receive.asset_id — receive asset ID
|
|
24
|
-
* op_object.expiration — ISO datetime
|
|
25
|
-
*
|
|
26
|
-
* fill_order:
|
|
27
|
-
* op_object.account_id — whose order was filled
|
|
28
|
-
* op_object.pays.amount / .asset_id — what was paid
|
|
29
|
-
* op_object.receives.amount / .asset_id — what was received
|
|
30
|
-
* op_object.order_id — the limit order that filled
|
|
31
|
-
*
|
|
32
|
-
* limit_order_cancel:
|
|
33
|
-
* op_object.fee_paying_account — account that cancelled
|
|
34
|
-
* op_object.order — the order ID cancelled
|
|
35
|
-
*
|
|
36
|
-
* limit_order_update (op 77, DEXBot2-only — native in-place re-price):
|
|
37
|
-
* op_object.seller — account that updated the order
|
|
38
|
-
* op_object.order — the limit order ID updated
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
import { kibanaSearch, DEFAULT_CONFIG as BASE_CONFIG } from '../../market_adapter/core/kibana_client.js';
|
|
43
|
-
|
|
44
|
-
// ─── Constants ────────────────────────────────────────────────────────────────
|
|
45
|
-
|
|
46
|
-
const OP_LIMIT_ORDER_CREATE = 1;
|
|
47
|
-
const OP_LIMIT_ORDER_CANCEL = 2;
|
|
48
|
-
const OP_FILL_ORDER = 4;
|
|
49
|
-
// Native in-place order re-price. Only DEXBot2 broadcasts this (COW UPDATE
|
|
50
|
-
// actions via buildUpdateOrderOp); DEXBot1 (Python staggered_orders) predates
|
|
51
|
-
// it and can only cancel + recreate. Presence of op 77 on an account is the
|
|
52
|
-
// DEXBot2 fingerprint; absence means cancel-only (DEXBot1-style).
|
|
53
|
-
const OP_LIMIT_ORDER_UPDATE = 77;
|
|
54
|
-
|
|
55
|
-
const DEFAULT_CONFIG = {
|
|
56
|
-
...BASE_CONFIG,
|
|
57
|
-
timeout: 25000,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// ─── Raw document query builders (size>0, for price/grid analysis) ────────────
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Fetch raw limit_order_create documents for grid spacing analysis.
|
|
64
|
-
* Returns the price-relevant fields plus timestamps.
|
|
65
|
-
*
|
|
66
|
-
* @param {string} accountId
|
|
67
|
-
* @param {number} lookbackHours
|
|
68
|
-
* @param {string} [sellAssetId] - optional: filter to one sell-side asset
|
|
69
|
-
* @param {number} [maxResults]
|
|
70
|
-
* @returns {Object} Elasticsearch query object
|
|
71
|
-
*/
|
|
72
|
-
function buildOrderPriceQuery(accountId: string, lookbackHours: number, sellAssetId: string | null = null, maxResults: number = 1000) {
|
|
73
|
-
const filters = [
|
|
74
|
-
{ term: { operation_type: OP_LIMIT_ORDER_CREATE } },
|
|
75
|
-
{ term: { 'operation_history.op_object.seller.keyword': accountId } },
|
|
76
|
-
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
77
|
-
];
|
|
78
|
-
if (sellAssetId) {
|
|
79
|
-
filters.push({ term: { 'operation_history.op_object.amount_to_sell.asset_id.keyword': sellAssetId } } as any);
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
size: maxResults,
|
|
83
|
-
_source: [
|
|
84
|
-
'block_data.block_time',
|
|
85
|
-
'operation_history.op_object.amount_to_sell',
|
|
86
|
-
'operation_history.op_object.min_to_receive',
|
|
87
|
-
'operation_history.op_object.expiration',
|
|
88
|
-
],
|
|
89
|
-
query: { bool: { filter: filters } },
|
|
90
|
-
sort: [{ 'block_data.block_time': { order: 'desc' } }],
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// ─── Discovery query builders ─────────────────────────────────────────────────
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Top N accounts by limit_order_create count (seller field).
|
|
98
|
-
* Use this to discover the most active order-placing accounts.
|
|
99
|
-
*/
|
|
100
|
-
function buildTopSellerAccountsQuery(lookbackHours: number, topN: number = 100, minCreates: number = 10) {
|
|
101
|
-
return {
|
|
102
|
-
size: 0,
|
|
103
|
-
query: {
|
|
104
|
-
bool: {
|
|
105
|
-
filter: [
|
|
106
|
-
{ term: { operation_type: OP_LIMIT_ORDER_CREATE } },
|
|
107
|
-
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
108
|
-
],
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
aggs: {
|
|
112
|
-
by_account: {
|
|
113
|
-
terms: {
|
|
114
|
-
field: 'operation_history.op_object.seller.keyword',
|
|
115
|
-
size: topN,
|
|
116
|
-
min_doc_count: minCreates,
|
|
117
|
-
order: { _count: 'desc' },
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Top N accounts by limit_order_cancel count (fee_paying_account field).
|
|
126
|
-
*/
|
|
127
|
-
function buildTopCancellerAccountsQuery(lookbackHours: number, topN: number = 100, minCancels: number = 5) {
|
|
128
|
-
return {
|
|
129
|
-
size: 0,
|
|
130
|
-
query: {
|
|
131
|
-
bool: {
|
|
132
|
-
filter: [
|
|
133
|
-
{ term: { operation_type: OP_LIMIT_ORDER_CANCEL } },
|
|
134
|
-
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
135
|
-
],
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
aggs: {
|
|
139
|
-
by_account: {
|
|
140
|
-
terms: {
|
|
141
|
-
field: 'operation_history.op_object.fee_paying_account.keyword',
|
|
142
|
-
size: topN,
|
|
143
|
-
min_doc_count: minCancels,
|
|
144
|
-
order: { _count: 'desc' },
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Top N accounts by fill_order count (account_id field).
|
|
153
|
-
*/
|
|
154
|
-
function buildTopFilledAccountsQuery(lookbackHours: number, topN: number = 100, minFills: number = 3) {
|
|
155
|
-
return {
|
|
156
|
-
size: 0,
|
|
157
|
-
query: {
|
|
158
|
-
bool: {
|
|
159
|
-
filter: [
|
|
160
|
-
{ term: { operation_type: OP_FILL_ORDER } },
|
|
161
|
-
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
162
|
-
],
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
aggs: {
|
|
166
|
-
by_account: {
|
|
167
|
-
terms: {
|
|
168
|
-
field: 'operation_history.op_object.account_id.keyword',
|
|
169
|
-
size: topN,
|
|
170
|
-
min_doc_count: minFills,
|
|
171
|
-
order: { _count: 'desc' },
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Top N accounts by limit_order_update count (seller field, op 77).
|
|
180
|
-
* DEXBot2 fingerprint: only DEXBot2 broadcasts native in-place re-prices
|
|
181
|
-
* (COW UPDATE actions). DEXBot1-style bots never emit op 77 — they cancel
|
|
182
|
-
* (op 2) and recreate (op 1) instead.
|
|
183
|
-
*/
|
|
184
|
-
function buildTopUpdaterAccountsQuery(lookbackHours: number, topN: number = 200, minUpdates: number = 1) {
|
|
185
|
-
return {
|
|
186
|
-
size: 0,
|
|
187
|
-
query: {
|
|
188
|
-
bool: {
|
|
189
|
-
filter: [
|
|
190
|
-
{ term: { operation_type: OP_LIMIT_ORDER_UPDATE } },
|
|
191
|
-
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
192
|
-
],
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
aggs: {
|
|
196
|
-
by_account: {
|
|
197
|
-
terms: {
|
|
198
|
-
field: 'operation_history.op_object.seller.keyword',
|
|
199
|
-
size: topN,
|
|
200
|
-
min_doc_count: minUpdates,
|
|
201
|
-
order: { _count: 'desc' },
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// ─── Exports ──────────────────────────────────────────────────────────────────
|
|
209
|
-
|
|
210
|
-
export { DEFAULT_CONFIG, kibanaSearch, buildOrderPriceQuery, buildTopSellerAccountsQuery, buildTopCancellerAccountsQuery, buildTopFilledAccountsQuery, buildTopUpdaterAccountsQuery }
|
|
211
|
-
|
package/analysis/chain_pool.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* SHARED CHAIN POOL (analysis)
|
|
5
|
-
*
|
|
6
|
-
* Single source of truth for the node list and the ephemeral read-only
|
|
7
|
-
* connection used by analysis tools for small on-chain lookups (account name
|
|
8
|
-
* resolution, asset precision resolution).
|
|
9
|
-
*
|
|
10
|
-
* Analysis tools deliberately do NOT use the production singleton client
|
|
11
|
-
* (modules/bitshares_client.ts): they are short-lived processes and must never
|
|
12
|
-
* disturb a running bot's connection state. Instead each lookup opens a fresh
|
|
13
|
-
* read-only client over the built-in node pool, which the native transport
|
|
14
|
-
* races in parallel and then retries sequentially — so one dead node is not
|
|
15
|
-
* fatal.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import * as C from '../modules/constants.js';
|
|
19
|
-
|
|
20
|
-
/** Nodes for ephemeral read-only analysis connections (node management pool). */
|
|
21
|
-
function defaultNodePool(): string[] {
|
|
22
|
-
return [...C.NODE_MANAGEMENT.DEFAULT_NODES];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Run `fn` against a fresh read-only client connected over the built-in pool.
|
|
27
|
-
* Transport INFO logging is silenced for the duration of the short-lived
|
|
28
|
-
* connection and the client is always disconnected afterwards.
|
|
29
|
-
*/
|
|
30
|
-
async function withReadOnlyClient<T>(fn: (client: any) => Promise<T>): Promise<T> {
|
|
31
|
-
const { createReadOnlyClient } = await import('../modules/bitshares-native/index.js');
|
|
32
|
-
const client = createReadOnlyClient({ nodes: defaultNodePool() });
|
|
33
|
-
// Suppress transport INFO logs during ephemeral connection:
|
|
34
|
-
// bitshares-native transport logger (new Logger('Transport')) writes
|
|
35
|
-
// "[timestamp] [INFO] [Transport] ..." — silence by raising log level.
|
|
36
|
-
const prevLevel = process.env.LOG_LEVEL;
|
|
37
|
-
process.env.LOG_LEVEL = 'warn';
|
|
38
|
-
try {
|
|
39
|
-
await client.connect();
|
|
40
|
-
return await fn(client);
|
|
41
|
-
} finally {
|
|
42
|
-
try { client.disconnect(); } catch (_) { /* best-effort cleanup */ }
|
|
43
|
-
process.env.LOG_LEVEL = prevLevel;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export { withReadOnlyClient };
|
package/analysis/chart_css.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Shared CSS fragments for uPlot chart generators.
|
|
5
|
-
*
|
|
6
|
-
* All functions return raw CSS strings for interpolation into HTML template
|
|
7
|
-
* literals. Consumers compose these fragments inside their `<style>` blocks.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
function baseResetCSS(): string {
|
|
11
|
-
return `* { box-sizing: border-box; }
|
|
12
|
-
body { background: #0b0e14; color: #d1d5db; font-family: 'Segoe UI', sans-serif; margin: 0; padding: 0; overflow: hidden; }`;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function headerCSS(height = 45): string {
|
|
16
|
-
return `#header { padding: 10px 20px; background: #161b22; border-bottom: 1px solid #30363d; display: flex; align-items: center; justify-content: space-between; height: ${height}px; z-index: 100; }`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function panelsCSS(headerHeight = 45): string {
|
|
20
|
-
return `#panels { display: flex; flex-direction: column; height: calc(100vh - ${headerHeight}px); width: 100vw; }`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function uplotBgCSS(bgColor = '#0b0e14'): string {
|
|
24
|
-
return `.uplot { background: ${bgColor}; }`;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function dotCSS(): string {
|
|
28
|
-
return `.dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function cursorCSS(): string {
|
|
32
|
-
return `.u-cursor-x { border-left: 1px dashed rgba(255,255,255,0.3) !important; }
|
|
33
|
-
.u-cursor-y { border-top: 1px dashed rgba(255,255,255,0.3) !important; display: none; }
|
|
34
|
-
.is-hovered .u-cursor-y { display: block; }`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function sectionLabelCSS(): string {
|
|
38
|
-
return `.section-label { position: absolute; top: 8px; right: 12px; font-size: 9px; color: #30363d; text-transform: uppercase; letter-spacing: 1px; z-index: 10; pointer-events: none; }`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function legendCSS(): string {
|
|
42
|
-
return `.legend { position: absolute; top: 8px; left: 12px; font-size: 11px; pointer-events: none; z-index: 10; display: flex; gap: 14px; color: #adbac7; white-space: nowrap; align-items: center; }
|
|
43
|
-
.legend-item { display: flex; align-items: center; gap: 5px; }`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function sharedChartCSS(): string {
|
|
47
|
-
return [
|
|
48
|
-
baseResetCSS(),
|
|
49
|
-
headerCSS(),
|
|
50
|
-
panelsCSS(),
|
|
51
|
-
uplotBgCSS(),
|
|
52
|
-
dotCSS(),
|
|
53
|
-
cursorCSS(),
|
|
54
|
-
sectionLabelCSS(),
|
|
55
|
-
legendCSS(),
|
|
56
|
-
].join('\n ');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Only the composed sheet and the single fragments with external consumers are
|
|
60
|
-
// exported; page-specific generators interpolate these inside their own
|
|
61
|
-
// <style> blocks while keeping their layout rules inline.
|
|
62
|
-
export { sharedChartCSS, uplotBgCSS, cursorCSS }
|
package/analysis/chart_ui.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Shared browser-side JavaScript helpers for uPlot chart generators.
|
|
5
|
-
*
|
|
6
|
-
* All functions return raw JS code strings for interpolation into inline
|
|
7
|
-
* `<script>` template literals. Consumers embed these alongside their own
|
|
8
|
-
* chart-specific logic.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const Y_AXIS_SIZE = 58;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Return the uPlot cursor config object literal.
|
|
15
|
-
* Consumers must define `SYNC_KEY` before calling this.
|
|
16
|
-
*/
|
|
17
|
-
function makeCursorConfig(): string {
|
|
18
|
-
return `{
|
|
19
|
-
show: true,
|
|
20
|
-
x: true,
|
|
21
|
-
y: true,
|
|
22
|
-
points: { show: false },
|
|
23
|
-
drag: { x: false, y: false, setScale: false },
|
|
24
|
-
sync: { key: SYNC_KEY, setSeries: false, scales: ['x', null] },
|
|
25
|
-
focus: { prox: -1 },
|
|
26
|
-
}`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Return the `bindHoverState(chart)` function definition.
|
|
31
|
-
*/
|
|
32
|
-
function bindHoverStateFn(): string {
|
|
33
|
-
return `function bindHoverState(chart) {
|
|
34
|
-
const root = chart.root;
|
|
35
|
-
root.addEventListener('mouseenter', () => root.classList.add('is-hovered'));
|
|
36
|
-
root.addEventListener('mouseleave', () => root.classList.remove('is-hovered'));
|
|
37
|
-
}`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Return the `fmtDate(ts)` browser-side function definition.
|
|
42
|
-
*/
|
|
43
|
-
function fmtDateFn(): string {
|
|
44
|
-
return `function fmtDate(ts) {
|
|
45
|
-
if (ts == null) return '-';
|
|
46
|
-
const d = new Date(ts * 1000);
|
|
47
|
-
return d.toLocaleDateString('en-GB', { day: '2-digit', month: 'short', year: '2-digit' })
|
|
48
|
-
+ ' ' + d.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' });
|
|
49
|
-
}`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Return the chart event wiring loop that binds mousemove, mouseleave,
|
|
54
|
-
* hover-state, wheelZoom, and pan on each chart.
|
|
55
|
-
*
|
|
56
|
-
* @param chartsVar JS variable name holding the charts array (e.g. `'charts'`)
|
|
57
|
-
* @param updateFn name of the legend update function (e.g. `'updateLegend'`)
|
|
58
|
-
* @param fallback expression for the mouseleave fallback index
|
|
59
|
-
* (e.g. `'lastLiveIdx'`, `'null'`, or `'shiftChart.cursor.idx ?? data.realBarCount - 1'`)
|
|
60
|
-
*/
|
|
61
|
-
function wireChartEvents(chartsVar: string, updateFn: string, fallback: string): string {
|
|
62
|
-
return `let leavePending = null;
|
|
63
|
-
${chartsVar}.forEach(chart => {
|
|
64
|
-
chart.over.addEventListener('mousemove', () => {
|
|
65
|
-
if (leavePending !== null) { clearTimeout(leavePending); leavePending = null; }
|
|
66
|
-
${updateFn}(chart.cursor.idx);
|
|
67
|
-
});
|
|
68
|
-
chart.over.addEventListener('mouseleave', () => {
|
|
69
|
-
leavePending = setTimeout(() => { leavePending = null; ${updateFn}(${fallback}); }, 60);
|
|
70
|
-
});
|
|
71
|
-
bindHoverState(chart);
|
|
72
|
-
bindWheelZoom(chart);
|
|
73
|
-
bindPan(chart);
|
|
74
|
-
});`;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Return the Ctrl+0 zoom-reset keyboard shortcut handler.
|
|
79
|
-
* Consumers must define `xMin`, `xMax`, and `syncXRange` before calling this.
|
|
80
|
-
*/
|
|
81
|
-
function zoomResetScript(): string {
|
|
82
|
-
return `window.addEventListener('keydown', (e) => {
|
|
83
|
-
if ((e.ctrlKey || e.metaKey) && e.key === '0') syncXRange(xMin, xMax);
|
|
84
|
-
});`;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Return the `sizeCharts()` function definition.
|
|
89
|
-
*
|
|
90
|
-
* @param pairs array of [chartVariableName, panelDomId] pairs
|
|
91
|
-
* e.g. `[['priceChart', 'price-panel'], ['kalmanChart', 'kalman-panel']]`
|
|
92
|
-
*/
|
|
93
|
-
function sizeChartsFn(pairs: Array<[string, string]>): string {
|
|
94
|
-
const entries = pairs.map(([chartVar, panelId]) => `[${chartVar}, '${panelId}']`).join(', ');
|
|
95
|
-
const nullCheck = pairs.map(([chartVar]) => `!${chartVar}`).join(' || ');
|
|
96
|
-
return `function sizeCharts() {
|
|
97
|
-
if (${nullCheck}) return;
|
|
98
|
-
[${entries}].forEach(([chart, id]) => {
|
|
99
|
-
const el = document.getElementById(id);
|
|
100
|
-
chart.setSize({ width: el.offsetWidth, height: el.offsetHeight });
|
|
101
|
-
});
|
|
102
|
-
}`;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export { Y_AXIS_SIZE, makeCursorConfig, bindHoverStateFn, fmtDateFn, wireChartEvents, zoomResetScript, sizeChartsFn }
|
package/analysis/chart_utils.ts
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { getStorage } from '../modules/storage/index.js';
|
|
6
|
-
import { PATHS } from '../modules/paths.js';
|
|
7
|
-
const { ensureDir } = getStorage();
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Chart utilities for analysis HTML generators.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
// Vendored uPlot runtime assets are inlined directly into every generated chart
|
|
14
|
-
// (see uplotInlineTags below), so each chart is a single self-contained file
|
|
15
|
-
// that renders anywhere: no DEXBot2 install, no sibling uplot/ dir, no CDN, no
|
|
16
|
-
// network. The vendored originals always live with the code under the analysis
|
|
17
|
-
// assets dir.
|
|
18
|
-
let _uplotRuntime: { css: string; js: string } | null = null;
|
|
19
|
-
|
|
20
|
-
function getUplotRuntime() {
|
|
21
|
-
if (!_uplotRuntime) {
|
|
22
|
-
const dir = PATHS.ANALYSIS.ASSETS_DIR;
|
|
23
|
-
_uplotRuntime = {
|
|
24
|
-
css: fs.readFileSync(path.join(dir, 'uPlot.min.css'), 'utf8'),
|
|
25
|
-
js: fs.readFileSync(path.join(dir, 'uPlot.iife.min.js'), 'utf8'),
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
return _uplotRuntime;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Inline <style>/<script> tags carrying the vendored uPlot runtime. Embedding
|
|
33
|
-
* the source (not a relative <script src>) makes a chart portable: it keeps
|
|
34
|
-
* rendering after being copied, mailed, or reopened on a machine without a
|
|
35
|
-
* DEXBot2 installation. The inline script must be the first script that runs,
|
|
36
|
-
* placed before any chart-initialization code, since uPlot must exist first.
|
|
37
|
-
* Both the minified JS (no `</script>`) and CSS (no `</style>`) are safe to
|
|
38
|
-
* embed verbatim.
|
|
39
|
-
*/
|
|
40
|
-
function uplotInlineTags({ css = true, js = true } = {}) {
|
|
41
|
-
const { css: cssCode, js: jsCode } = getUplotRuntime();
|
|
42
|
-
const parts: string[] = [];
|
|
43
|
-
if (css && cssCode) parts.push(`<style>\n${cssCode}\n</style>`);
|
|
44
|
-
if (js && jsCode) parts.push(`<script>\n${jsCode}\n</script>`);
|
|
45
|
-
return parts.join('\n ');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function escapeHtml(str: string) {
|
|
50
|
-
const map: Record<string, string> = {
|
|
51
|
-
'&': '&',
|
|
52
|
-
'<': '<',
|
|
53
|
-
'>': '>',
|
|
54
|
-
'"': '"',
|
|
55
|
-
"'": ''',
|
|
56
|
-
};
|
|
57
|
-
return String(str).replace(/[&<>"']/g, (m: any) => map[m]);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function serializeJsonForScript(value: any) {
|
|
61
|
-
return JSON.stringify(value).replace(/</g, '\\u003c');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function toEpochSeconds(ts: any, fallbackIdx: any) {
|
|
65
|
-
const ms = new Date(ts).getTime();
|
|
66
|
-
if (Number.isFinite(ms)) return Math.floor(ms / 1000);
|
|
67
|
-
return fallbackIdx * 3600;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function toFileUrl(filePath: any): string {
|
|
71
|
-
return `file://${path.resolve(String(filePath))}`;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function writeChartFile(filePath: any, html: any) {
|
|
75
|
-
const chartDir = path.dirname(filePath);
|
|
76
|
-
if (!fs.existsSync(chartDir)) ensureDir(chartDir);
|
|
77
|
-
// Atomic write (tmp + rename, matching the production storage adapter
|
|
78
|
-
// pattern) so a crash mid-write can never leave a truncated chart file.
|
|
79
|
-
const tmpPath = `${filePath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2, 10)}.tmp`;
|
|
80
|
-
try {
|
|
81
|
-
fs.writeFileSync(tmpPath, html, 'utf8');
|
|
82
|
-
fs.renameSync(tmpPath, filePath);
|
|
83
|
-
} catch (err) {
|
|
84
|
-
try { fs.unlinkSync(tmpPath); } catch (_) { /* best-effort cleanup */ }
|
|
85
|
-
throw err;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Serialize the exact source of the given pure functions for injection into a
|
|
91
|
-
* generated HTML <script> block. Each function is emitted as a top-level
|
|
92
|
-
* function declaration (Function.prototype.toString()), so browser-embedded
|
|
93
|
-
* charts run the same logic as the Node-side modules instead of a hand-copied
|
|
94
|
-
* copy. Functions must be self-contained (no imports or module-level constants
|
|
95
|
-
* referenced from their bodies); callers pass all config values explicitly.
|
|
96
|
-
*
|
|
97
|
-
* The emitted block is wrapped in marker comments so test harnesses can extract
|
|
98
|
-
* the embedded sources reliably regardless of the function list or ordering.
|
|
99
|
-
*/
|
|
100
|
-
function embedFunctionSources(fns: Array<Function>): string {
|
|
101
|
-
const sources = fns.map((fn) => fn.toString()).join('\n\n');
|
|
102
|
-
return `/* EMBEDDED_FUNCS_START */\n${sources}\n/* EMBEDDED_FUNCS_END */`;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Shared uPlot interaction boilerplate for embedded browser scripts.
|
|
107
|
-
* Consumers must define `xMin`, `xMax`, `charts`, `pendingRange`, and `pendingRangeRaf`
|
|
108
|
-
* before embedding this script block.
|
|
109
|
-
*/
|
|
110
|
-
const UPLOT_SHARED_SCRIPT = `
|
|
111
|
-
function clampXRange(min, max) {
|
|
112
|
-
let nextMin = min, nextMax = max;
|
|
113
|
-
if (!Number.isFinite(nextMin) || !Number.isFinite(nextMax) || nextMax <= nextMin) {
|
|
114
|
-
return { min: xMin, max: xMax };
|
|
115
|
-
}
|
|
116
|
-
if (nextMin < xMin) { nextMax += xMin - nextMin; nextMin = xMin; }
|
|
117
|
-
if (nextMax > xMax) { nextMin -= nextMax - xMax; nextMax = xMax; }
|
|
118
|
-
if (nextMin < xMin) nextMin = xMin;
|
|
119
|
-
if (nextMax > xMax) nextMax = xMax;
|
|
120
|
-
if (nextMax <= nextMin) return { min: xMin, max: xMax };
|
|
121
|
-
return { min: nextMin, max: nextMax };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function syncXRange(min, max) {
|
|
125
|
-
pendingRange = clampXRange(min, max);
|
|
126
|
-
if (pendingRangeRaf) return;
|
|
127
|
-
const raf = typeof requestAnimationFrame !== 'undefined' ? requestAnimationFrame.bind(window) : (fn) => setTimeout(fn, 0);
|
|
128
|
-
pendingRangeRaf = raf(() => {
|
|
129
|
-
const next = pendingRange;
|
|
130
|
-
pendingRange = null;
|
|
131
|
-
pendingRangeRaf = 0;
|
|
132
|
-
if (!next) return;
|
|
133
|
-
charts.forEach(c => c && c.batch(() => c.setScale('x', next)));
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function bindWheelZoom(chart) {
|
|
138
|
-
chart.root.addEventListener('wheel', (e) => {
|
|
139
|
-
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
140
|
-
e.preventDefault();
|
|
141
|
-
e.stopPropagation();
|
|
142
|
-
const rect = chart.root.getBoundingClientRect();
|
|
143
|
-
|
|
144
|
-
// Correctly calculate plot-relative 'left' for accurate centering
|
|
145
|
-
const left = e.clientX - rect.left - (chart.bbox.left / (chart.pxRatio || 1));
|
|
146
|
-
const center = chart.posToVal(left, 'x');
|
|
147
|
-
|
|
148
|
-
const s = chart.scales.x || {};
|
|
149
|
-
const currMin = Number.isFinite(s.min) ? s.min : xMin;
|
|
150
|
-
const currMax = Number.isFinite(s.max) ? s.max : xMax;
|
|
151
|
-
const span = currMax - currMin;
|
|
152
|
-
if (!Number.isFinite(span) || span <= 0) return;
|
|
153
|
-
const factor = e.deltaY < 0 ? 0.85 : 1.15;
|
|
154
|
-
const nextSpan = Math.max(1, Math.min(xMax - xMin, span * factor));
|
|
155
|
-
const ratio = (center - currMin) / span;
|
|
156
|
-
syncXRange(center - nextSpan * ratio, center - nextSpan * ratio + nextSpan);
|
|
157
|
-
}, { passive: false });
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function bindPan(chart) {
|
|
161
|
-
let dragging = false, startClientX = 0, startClientY = 0, startMin = xMin, startMax = xMax, xUnitsPerPx = 0;
|
|
162
|
-
const getScale = () => {
|
|
163
|
-
const s = chart.scales.x || {};
|
|
164
|
-
return { currMin: Number.isFinite(s.min) ? s.min : xMin, currMax: Number.isFinite(s.max) ? s.max : xMax };
|
|
165
|
-
};
|
|
166
|
-
const onMouseMove = (e) => {
|
|
167
|
-
if (!dragging) return;
|
|
168
|
-
|
|
169
|
-
// Ignore if vertical movement is dominant (likely scrolling)
|
|
170
|
-
if (Math.abs(e.clientY - startClientY) > 20) return;
|
|
171
|
-
|
|
172
|
-
e.preventDefault();
|
|
173
|
-
const deltaPx = e.clientX - startClientX;
|
|
174
|
-
const deltaVal = deltaPx * xUnitsPerPx;
|
|
175
|
-
syncXRange(startMin - deltaVal, startMax - deltaVal);
|
|
176
|
-
};
|
|
177
|
-
const endDrag = () => {
|
|
178
|
-
if (!dragging) return;
|
|
179
|
-
dragging = false;
|
|
180
|
-
document.body.style.cursor = '';
|
|
181
|
-
window.removeEventListener('mousemove', onMouseMove);
|
|
182
|
-
window.removeEventListener('mouseup', endDrag);
|
|
183
|
-
};
|
|
184
|
-
chart.root.addEventListener('mousedown', (e) => {
|
|
185
|
-
if (!e || e.button !== 0 || e.ctrlKey || e.metaKey || e.altKey) return;
|
|
186
|
-
const rect = chart.root.getBoundingClientRect();
|
|
187
|
-
if (e.clientX < rect.left || e.clientX > rect.right || e.clientY < rect.top || e.clientY > rect.bottom) return;
|
|
188
|
-
|
|
189
|
-
e.preventDefault();
|
|
190
|
-
e.stopPropagation();
|
|
191
|
-
|
|
192
|
-
dragging = true;
|
|
193
|
-
startClientX = e.clientX;
|
|
194
|
-
startClientY = e.clientY;
|
|
195
|
-
const cur = getScale();
|
|
196
|
-
startMin = cur.currMin; startMax = cur.currMax;
|
|
197
|
-
|
|
198
|
-
// Calculate units per pixel once at start of drag to avoid sliding bug
|
|
199
|
-
// chart.bbox.width is in device pixels; divide by pxRatio for CSS pixels
|
|
200
|
-
xUnitsPerPx = (cur.currMax - cur.currMin) / (chart.bbox.width / (chart.pxRatio || 1));
|
|
201
|
-
|
|
202
|
-
document.body.style.cursor = 'grabbing';
|
|
203
|
-
window.addEventListener('mousemove', onMouseMove);
|
|
204
|
-
window.addEventListener('mouseup', endDrag, { once: true });
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
`;
|
|
208
|
-
|
|
209
|
-
export { escapeHtml, serializeJsonForScript, toEpochSeconds, writeChartFile, toFileUrl, embedFunctionSources, UPLOT_SHARED_SCRIPT, uplotInlineTags }
|
|
210
|
-
|