dexbot 1.6.11 → 1.6.12
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 +35 -4
- package/README.md +2 -1
- package/analysis/README.md +2 -0
- package/analysis/tradingview/README.md +1 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +3 -3
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
- package/claw/modules/chain_broadcast.ts +7 -1
- package/claw/modules/claw_launcher.ts +1 -1
- package/claw/modules/launcher_mode_detector.ts +9 -2
- 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/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 +2 -7
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +4 -4
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +20 -4
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +9 -6
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +16 -12
- package/dist/analysis/analyze_args.d.ts +31 -0
- package/dist/analysis/analyze_args.js +41 -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 +220 -12
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +6 -5
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +11 -63
- package/dist/analysis/bot_fitting/shared_utils.d.ts +7 -7
- package/dist/analysis/bot_fitting/shared_utils.js +2 -2
- 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 +5 -2
- package/dist/analysis/chart_ui.js +6 -3
- package/dist/analysis/chart_utils.d.ts +5 -5
- package/dist/analysis/chart_utils.js +9 -0
- package/dist/analysis/fills_cache.d.ts +1 -1
- package/dist/analysis/fills_source.d.ts +2 -2
- package/dist/analysis/fills_source.js +14 -12
- package/dist/analysis/grid_correction_check.d.ts +1 -1
- package/dist/analysis/grid_correction_check.js +12 -11
- package/dist/analysis/math_utils.d.ts +7 -6
- package/dist/analysis/math_utils.js +5 -8
- package/dist/analysis/pnl_report.js +29 -29
- package/dist/analysis/price_sources.d.ts +8 -8
- package/dist/analysis/price_sources.js +5 -4
- package/dist/analysis/resolve_bot_accounts.js +2 -2
- package/dist/analysis/resolve_source.d.ts +1 -1
- package/dist/analysis/trade_profitability.d.ts +23 -2
- package/dist/analysis/trade_profitability.js +50 -50
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +17 -6
- package/dist/analysis/tradingview/analyze_tradingview.js +6 -5
- 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 +18 -19
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -1
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +5 -5
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +5 -4
- 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/credential-daemon.js +34 -20
- package/dist/dexbot.js +11 -11
- package/dist/market_adapter/candle_utils.d.ts +22 -18
- package/dist/market_adapter/candle_utils.js +24 -20
- 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/kibana_candles.d.ts +53 -18
- package/dist/market_adapter/core/kibana_candles.js +9 -7
- 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 +284 -117
- package/dist/market_adapter/core/market_adapter_service.js +137 -113
- 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 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +96 -224
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +42 -7
- package/dist/market_adapter/inputs/fetch_lp_data.js +22 -15
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
- package/dist/market_adapter/inputs/kibana_feed_source.js +29 -22
- 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 +99 -94
- package/dist/market_adapter/inputs/window_cache.js +8 -8
- package/dist/market_adapter/interval_utils.d.ts +4 -4
- 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 +7 -7
- 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 +67 -48
- 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 +4 -1
- 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/native_history.d.ts +9 -2
- package/dist/market_adapter/utils/native_history.js +35 -28
- package/dist/modules/account_bots.d.ts +577 -21
- package/dist/modules/account_bots.js +182 -158
- package/dist/modules/account_orders.d.ts +66 -30
- package/dist/modules/account_orders.js +22 -20
- 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 +38 -3
- package/dist/modules/bitshares-native/chain_client.js +45 -46
- 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/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 +55 -62
- 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 +6 -15
- 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 +2 -2
- 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 +93 -59
- package/dist/modules/chain_orders.js +31 -23
- package/dist/modules/constants.d.ts +527 -31
- package/dist/modules/constants.js +15 -47
- package/dist/modules/cr_planner.d.ts +40 -2
- 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 +42 -6
- package/dist/modules/credit_pricing.js +44 -30
- package/dist/modules/credit_runtime.d.ts +276 -118
- package/dist/modules/credit_runtime.js +462 -165
- 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/dexbot_class.d.ts +195 -139
- package/dist/modules/dexbot_class.js +78 -28
- package/dist/modules/dexbot_cow_runtime.d.ts +167 -87
- package/dist/modules/dexbot_cow_runtime.js +248 -206
- package/dist/modules/dexbot_credential_client.d.ts +19 -11
- package/dist/modules/dexbot_fill_runtime.d.ts +63 -48
- package/dist/modules/dexbot_fill_runtime.js +48 -41
- package/dist/modules/dexbot_maintenance_runtime.d.ts +109 -70
- package/dist/modules/dexbot_maintenance_runtime.js +108 -83
- package/dist/modules/dexbot_startup_runtime.d.ts +11 -10
- package/dist/modules/dexbot_startup_runtime.js +43 -43
- 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 +2 -2
- 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 -6
- 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/market_adapter_whitelist.d.ts +9 -3
- package/dist/modules/market_adapter_whitelist.js +15 -3
- 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 +4 -4
- package/dist/modules/order/genesis_policy.d.ts +21 -18
- package/dist/modules/order/genesis_policy.js +12 -8
- package/dist/modules/order/grid.d.ts +142 -36
- package/dist/modules/order/grid.js +148 -123
- 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 +263 -1
- package/dist/modules/order/logger.d.ts +45 -11
- package/dist/modules/order/logger.js +38 -40
- package/dist/modules/order/logger_state.d.ts +4 -4
- package/dist/modules/order/manager.d.ts +225 -180
- package/dist/modules/order/manager.js +80 -83
- 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 +122 -99
- package/dist/modules/order/utils/slot.d.ts +1 -1
- package/dist/modules/order/utils/system.d.ts +176 -26
- package/dist/modules/order/utils/system.js +86 -69
- package/dist/modules/order/utils/validate.d.ts +89 -41
- package/dist/modules/order/utils/validate.js +24 -22
- package/dist/modules/order/utils/withPoolRef.d.ts +4 -3
- 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 +1 -27
- 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 +15 -10
- 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 +7 -4
- 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 +1071 -2
- 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 +23 -1
- 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 +14 -3
- package/dist/modules/version_notice.js +6 -4
- package/dist/pm2.d.ts +29 -27
- package/dist/pm2.js +5 -5
- package/dist/scripts/analyze-credit.d.ts +2 -1
- package/dist/scripts/analyze-credit.js +23 -24
- 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 +13 -11
- package/dist/scripts/check_any.d.ts +18 -0
- package/dist/scripts/check_any.js +126 -0
- package/dist/scripts/diagnose-pool-history.js +12 -7
- package/dist/scripts/print_grid.js +0 -1
- package/dist/scripts/run-tests.js +39 -7
- package/dist/scripts/runner.js +1 -1
- 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 +2 -0
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
- package/docs/COW_INVARIANTS.md +13 -6
- package/docs/DEXBOT_COMPARISON.md +8 -8
- package/docs/EVOLUTION.md +10 -9
- 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/architecture.md +12 -9
- package/docs/developer_guide.md +6 -6
- package/market_adapter/README.md +6 -1
- package/modules/README.md +4 -1
- package/package.json +4 -1
|
@@ -36,7 +36,7 @@ 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
38
|
import * as bitsharesClient from '../../modules/bitshares_client.js';
|
|
39
|
-
import { getErrorMessage } from '../../modules/utils/errors.js';
|
|
39
|
+
import { getErrorMessage, resolveSeamMs } from '../../modules/utils/errors.js';
|
|
40
40
|
import { isSameBotName } from '../../modules/utils/sanitize_key.js';
|
|
41
41
|
import { pathToFileURL } from 'node:url';
|
|
42
42
|
const storage = getStorage();
|
|
@@ -179,7 +179,7 @@ function buildRequestKey(config, fullPoolId, assetA, assetB, timeRange, outPath)
|
|
|
179
179
|
assetA: { id: assetA.id, precision: assetA.precision, symbol: assetA.symbol },
|
|
180
180
|
assetB: { id: assetB.id, precision: assetB.precision, symbol: assetB.symbol },
|
|
181
181
|
intervalSeconds: config.intervalSeconds,
|
|
182
|
-
lookbackHours: config.timeRange ? null : config.lookbackHours,
|
|
182
|
+
lookbackHours: config.timeRange ? null : (config.lookbackHours ?? null),
|
|
183
183
|
timeRange,
|
|
184
184
|
outPath: path.resolve(outPath),
|
|
185
185
|
chunkMonths,
|
|
@@ -226,7 +226,9 @@ function loadCachedFetchContext(bot, intervalSeconds) {
|
|
|
226
226
|
// candle fetchers (pool, book, feed) through the single runCachedWindows
|
|
227
227
|
// entry point. Storage is fixed calendar-month shards, so there is no
|
|
228
228
|
// orphan cleanup and no per-run rewrite.
|
|
229
|
-
function isLpShardMatch(
|
|
229
|
+
function isLpShardMatch(metaInput, requestKeyInput) {
|
|
230
|
+
const meta = metaInput;
|
|
231
|
+
const requestKey = requestKeyInput;
|
|
230
232
|
if (meta.pool !== requestKey.pool)
|
|
231
233
|
return false;
|
|
232
234
|
if (meta.intervalSeconds !== requestKey.intervalSeconds)
|
|
@@ -259,14 +261,15 @@ async function fetchCandlesSequentially(fullPoolId, assetA, assetB, config, outP
|
|
|
259
261
|
console.log(` Auto-splitting fetch into ${total} sequential ${chunkMonths}-month fetch windows`);
|
|
260
262
|
}
|
|
261
263
|
const fetchRange = async (gte, lte, window, signal) => {
|
|
262
|
-
const
|
|
264
|
+
const w = window;
|
|
265
|
+
const tag = formatWindowLine('Window', w.index, total, w.gte, w.lte);
|
|
263
266
|
const attemptStartMs = Date.now();
|
|
264
267
|
// A partial window (one swap direction failed) is still returned for
|
|
265
268
|
// this run's output, but flagged so the shared runner withholds it
|
|
266
269
|
// from disk — persisting it would bake the missing side in as
|
|
267
270
|
// gap-filled zeros that are never re-queried.
|
|
268
271
|
let sawPartial = false;
|
|
269
|
-
const userOnPage = config
|
|
272
|
+
const userOnPage = config.onPage;
|
|
270
273
|
const onPage = (info) => {
|
|
271
274
|
if (info?.event === 'partial')
|
|
272
275
|
sawPartial = true;
|
|
@@ -312,7 +315,9 @@ async function fetchCandlesSequentially(fullPoolId, assetA, assetB, config, outP
|
|
|
312
315
|
bucketMs,
|
|
313
316
|
allowSubFetch: true,
|
|
314
317
|
fetchAttempts: FETCH_MAX_ATTEMPTS,
|
|
315
|
-
|
|
318
|
+
// Backoff base is overridable via the same `kibanaRetryDelayMs` seam the
|
|
319
|
+
// page/range retry loops use; tests set it to 0 to skip wall-clock sleeps.
|
|
320
|
+
fetchBackoffBaseMs: resolveSeamMs(config?.kibanaRetryDelayMs, FETCH_RETRY_BACKOFF_BASE_MS),
|
|
316
321
|
onFetchRetry: (info) => {
|
|
317
322
|
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
323
|
},
|
|
@@ -357,15 +362,17 @@ async function run() {
|
|
|
357
362
|
console.log('══════════════════════════════════════════════');
|
|
358
363
|
console.log(' Kibana LP Fetcher — Pool-centric');
|
|
359
364
|
console.log('══════════════════════════════════════════════');
|
|
360
|
-
let fullPoolId
|
|
365
|
+
let fullPoolId = '';
|
|
366
|
+
let assetA = {};
|
|
367
|
+
let assetB = {};
|
|
361
368
|
// ── Mode A: manual --pool override (no blockchain connection needed) ──────
|
|
362
369
|
if (cliPoolId) {
|
|
363
370
|
console.log(` Mode: Manual (--pool ${cliPoolId})`);
|
|
364
|
-
fullPoolId = normalizePoolId(cliPoolId);
|
|
371
|
+
fullPoolId = normalizePoolId(cliPoolId) ?? '';
|
|
365
372
|
// Still need to discover asset IDs from Kibana; precisions from CLI or default
|
|
366
373
|
console.log(` Pool: ${fullPoolId}`);
|
|
367
374
|
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)`}`);
|
|
375
|
+
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
376
|
console.log('══════════════════════════════════════════════');
|
|
370
377
|
console.log(`\n[1/4] Discovering assets in pool ${fullPoolId}...`);
|
|
371
378
|
let assetIds;
|
|
@@ -407,7 +414,7 @@ async function run() {
|
|
|
407
414
|
console.log(` Mode: Auto (bots.json → blockchain → Kibana)`);
|
|
408
415
|
console.log(` Bot: ${bot.name} (${bot.assetA} / ${bot.assetB})`);
|
|
409
416
|
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)`}`);
|
|
417
|
+
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
418
|
console.log(` Auth: ${config.apiKey ? 'API key set' : 'open (no auth)'}`);
|
|
412
419
|
console.log('══════════════════════════════════════════════');
|
|
413
420
|
if (cachedContext) {
|
|
@@ -447,13 +454,13 @@ async function run() {
|
|
|
447
454
|
console.log(`\n[2/4] Finding liquidity pool for ${bot.assetA} / ${bot.assetB}...`);
|
|
448
455
|
let pool;
|
|
449
456
|
try {
|
|
450
|
-
pool = await findPoolByAssets(assetA.id, assetB.id, { bitsharesClient, sortBy: 'assetABalance' });
|
|
457
|
+
pool = await findPoolByAssets(String(assetA.id), String(assetB.id), { bitsharesClient, sortBy: 'assetABalance' });
|
|
451
458
|
}
|
|
452
459
|
catch (err) {
|
|
453
460
|
console.error(` Pool lookup failed: ${getErrorMessage(err)}`);
|
|
454
461
|
process.exit(1);
|
|
455
462
|
}
|
|
456
|
-
fullPoolId = pool.id;
|
|
463
|
+
fullPoolId = String(pool.id);
|
|
457
464
|
console.log(` Pool: ${fullPoolId}`);
|
|
458
465
|
}
|
|
459
466
|
}
|
|
@@ -464,7 +471,7 @@ async function run() {
|
|
|
464
471
|
// it checks the range actually being fetched; otherwise a cheap recent
|
|
465
472
|
// window capped at 48h. The resolved window below feeds BOTH the query and
|
|
466
473
|
// the labels, so they can never diverge.
|
|
467
|
-
const probeCapHours = Math.min(config.lookbackHours, 48);
|
|
474
|
+
const probeCapHours = Math.min(config.lookbackHours ?? 0, 48);
|
|
468
475
|
const probeTimeRange = config.timeRange
|
|
469
476
|
? {
|
|
470
477
|
gte: config.timeRange.gte ?? new Date(Date.now() - probeCapHours * 3600 * 1000).toISOString(),
|
|
@@ -506,7 +513,7 @@ async function run() {
|
|
|
506
513
|
// ── Fetch full history ────────────────────────────────────────────────────
|
|
507
514
|
const fetchModeLabel = config.timeRange
|
|
508
515
|
? `${config.timeRange.gte ?? '…'} → ${config.timeRange.lte ?? '…'}`
|
|
509
|
-
: `${config.lookbackHours}h`;
|
|
516
|
+
: `${config.lookbackHours ?? 0}h`;
|
|
510
517
|
console.log(`\n[${stepFetch}/4] Fetching full history (${fetchModeLabel}, ${bucketLabel} buckets)...`);
|
|
511
518
|
let candles;
|
|
512
519
|
try {
|
|
@@ -547,7 +554,7 @@ async function run() {
|
|
|
547
554
|
assetB,
|
|
548
555
|
pair,
|
|
549
556
|
intervalSeconds: config.intervalSeconds,
|
|
550
|
-
lookbackHours: config.lookbackHours,
|
|
557
|
+
lookbackHours: config.lookbackHours ?? 0,
|
|
551
558
|
candleCount: candles.length,
|
|
552
559
|
priceUnit: `${assetB.symbol} per ${assetA.symbol}`,
|
|
553
560
|
// Candle format: [timestamp_ms, open, high, low, close, volume_in_assetA]
|
|
@@ -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
|
|
@@ -51,7 +51,6 @@ const FEED_SOURCE_FIELDS = [
|
|
|
51
51
|
'operation_history.op_object.asset_id',
|
|
52
52
|
'operation_history.op_object.feed.settlement_price',
|
|
53
53
|
];
|
|
54
|
-
// ─── Default Config ───────────────────────────────────────────────────────────
|
|
55
54
|
const DEFAULT_CONFIG = {
|
|
56
55
|
...BASE_CONFIG,
|
|
57
56
|
intervalSeconds: 3600,
|
|
@@ -82,8 +81,9 @@ function floatAmount(raw, precision) {
|
|
|
82
81
|
* exactly the mpa/backing pair.
|
|
83
82
|
*/
|
|
84
83
|
function backingPerMpa(settlement, mpaAsset, backingAsset) {
|
|
85
|
-
const
|
|
86
|
-
const
|
|
84
|
+
const s = settlement;
|
|
85
|
+
const base = s?.base;
|
|
86
|
+
const quote = s?.quote;
|
|
87
87
|
if (!base || !quote)
|
|
88
88
|
return null;
|
|
89
89
|
const baseId = String(base.asset_id || '');
|
|
@@ -95,8 +95,8 @@ function backingPerMpa(settlement, mpaAsset, backingAsset) {
|
|
|
95
95
|
const ids = new Set([baseId, quoteId]);
|
|
96
96
|
if (!ids.has(mpaId) || !ids.has(backingId))
|
|
97
97
|
return null;
|
|
98
|
-
const baseFloat = floatAmount(base.amount, baseId === mpaId ? mpaAsset
|
|
99
|
-
const quoteFloat = floatAmount(quote.amount, quoteId === mpaId ? mpaAsset
|
|
98
|
+
const baseFloat = floatAmount(base.amount, baseId === mpaId ? mpaAsset?.precision : backingAsset?.precision);
|
|
99
|
+
const quoteFloat = floatAmount(quote.amount, quoteId === mpaId ? mpaAsset?.precision : backingAsset?.precision);
|
|
100
100
|
if (!Number.isFinite(baseFloat) || !Number.isFinite(quoteFloat) || baseFloat <= 0 || quoteFloat <= 0)
|
|
101
101
|
return null;
|
|
102
102
|
// backing-per-MPA: divide the backing side by the MPA side.
|
|
@@ -115,14 +115,16 @@ function parseFeedTimestamp(source) {
|
|
|
115
115
|
return Number.isFinite(tsMs) ? tsMs : null;
|
|
116
116
|
}
|
|
117
117
|
function hitSortKey(hit) {
|
|
118
|
-
const
|
|
119
|
-
|
|
118
|
+
const h = hit;
|
|
119
|
+
const sort = Array.isArray(h?.sort) ? h.sort : [];
|
|
120
|
+
return sort.map((v) => String(v)).join('|') || String(h?._id || '');
|
|
120
121
|
}
|
|
121
122
|
function hitSequence(source) {
|
|
123
|
+
const src = source;
|
|
122
124
|
const candidates = [
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
src?.operation_id_num,
|
|
126
|
+
src?.account_history?.operation_id,
|
|
127
|
+
src?.account_history?.sequence,
|
|
126
128
|
];
|
|
127
129
|
for (const value of candidates) {
|
|
128
130
|
if (typeof value === 'number' && Number.isFinite(value))
|
|
@@ -138,7 +140,7 @@ function hitSequence(source) {
|
|
|
138
140
|
* or null when the hit carries no usable settlement price for the pair.
|
|
139
141
|
*/
|
|
140
142
|
function hitToFeedPrice(hit, { mpaAsset, backingAsset }) {
|
|
141
|
-
const source = hit?._source || {};
|
|
143
|
+
const source = (hit?._source || {});
|
|
142
144
|
const tsMs = parseFeedTimestamp(source);
|
|
143
145
|
if (tsMs == null)
|
|
144
146
|
return null;
|
|
@@ -207,7 +209,7 @@ async function fetchFeedPricePoints({ mpaAsset, backingAsset, config = {} }) {
|
|
|
207
209
|
`Narrow the timeRange or raise kibanaMaxPages.`);
|
|
208
210
|
}
|
|
209
211
|
const query = buildFeedDocumentQuery({
|
|
210
|
-
mpaAssetId: mpaAsset.id,
|
|
212
|
+
mpaAssetId: String(mpaAsset.id),
|
|
211
213
|
lookbackHours: cfg.lookbackHours,
|
|
212
214
|
timeRange: cfg.timeRange ?? null,
|
|
213
215
|
size,
|
|
@@ -323,7 +325,8 @@ function bucketPricesToCandles(points, intervalSeconds = 3600) {
|
|
|
323
325
|
* orientation when the MPA is the B leg (B-per-A = MPA-per-backing).
|
|
324
326
|
*/
|
|
325
327
|
function invertCandles(candles) {
|
|
326
|
-
|
|
328
|
+
const list = Array.isArray(candles) ? candles : [];
|
|
329
|
+
return list
|
|
327
330
|
.filter((c) => Array.isArray(c) && c.slice(1, 5).every((v) => Number.isFinite(Number(v)) && Number(v) > 0))
|
|
328
331
|
.map((c) => [c[0], 1 / c[4], 1 / c[3], 1 / c[2], 1 / c[1], c[5]]);
|
|
329
332
|
}
|
|
@@ -346,10 +349,10 @@ function applyGapFill(consolidated, cfg) {
|
|
|
346
349
|
return consolidated;
|
|
347
350
|
}
|
|
348
351
|
if (cfg.fillGapsToRequestedRange === false) {
|
|
349
|
-
return fillCandleGaps(consolidated, cfg.intervalSeconds);
|
|
352
|
+
return fillCandleGaps(consolidated, Number(cfg.intervalSeconds));
|
|
350
353
|
}
|
|
351
354
|
const { startTs, endTs } = resolveRequestedFillRange(cfg);
|
|
352
|
-
return fillCandleGaps(consolidated, cfg.intervalSeconds, startTs, endTs);
|
|
355
|
+
return fillCandleGaps(consolidated, Number(cfg.intervalSeconds), startTs, endTs);
|
|
353
356
|
}
|
|
354
357
|
/**
|
|
355
358
|
* Cross-rate price points for two MPAs sharing one backing asset.
|
|
@@ -363,6 +366,8 @@ function applyGapFill(consolidated, cfg) {
|
|
|
363
366
|
* (no reference price yet). Pure function of two point lists otherwise.
|
|
364
367
|
*/
|
|
365
368
|
function crossPointsToRatios(numeratorPoints, denominatorPoints, intervalSeconds = 0) {
|
|
369
|
+
const numer = Array.isArray(numeratorPoints) ? numeratorPoints : [];
|
|
370
|
+
const denom = Array.isArray(denominatorPoints) ? denominatorPoints : [];
|
|
366
371
|
const ratios = [];
|
|
367
372
|
let j = 0;
|
|
368
373
|
let lastDenominator = null;
|
|
@@ -371,14 +376,14 @@ function crossPointsToRatios(numeratorPoints, denominatorPoints, intervalSeconds
|
|
|
371
376
|
const denominatorCounts = new Map();
|
|
372
377
|
const countedBuckets = new Set();
|
|
373
378
|
if (Number.isFinite(bucketMs) && bucketMs > 0) {
|
|
374
|
-
for (const point of
|
|
379
|
+
for (const point of numer) {
|
|
375
380
|
const tsMs = Number(point?.tsMs);
|
|
376
381
|
if (Number.isFinite(tsMs)) {
|
|
377
382
|
const bucket = Math.floor(tsMs / bucketMs) * bucketMs;
|
|
378
383
|
numeratorCounts.set(bucket, (numeratorCounts.get(bucket) || 0) + 1);
|
|
379
384
|
}
|
|
380
385
|
}
|
|
381
|
-
for (const point of
|
|
386
|
+
for (const point of denom) {
|
|
382
387
|
const tsMs = Number(point?.tsMs);
|
|
383
388
|
if (Number.isFinite(tsMs)) {
|
|
384
389
|
const bucket = Math.floor(tsMs / bucketMs) * bucketMs;
|
|
@@ -386,13 +391,13 @@ function crossPointsToRatios(numeratorPoints, denominatorPoints, intervalSeconds
|
|
|
386
391
|
}
|
|
387
392
|
}
|
|
388
393
|
}
|
|
389
|
-
for (const point of
|
|
394
|
+
for (const point of numer) {
|
|
390
395
|
const tsMs = Number(point?.tsMs);
|
|
391
396
|
const price = Number(point?.price);
|
|
392
397
|
if (!Number.isFinite(tsMs) || !Number.isFinite(price) || price <= 0)
|
|
393
398
|
continue;
|
|
394
|
-
while (j <
|
|
395
|
-
lastDenominator =
|
|
399
|
+
while (j < denom.length && Number(denom[j]?.tsMs) <= tsMs) {
|
|
400
|
+
lastDenominator = denom[j];
|
|
396
401
|
j++;
|
|
397
402
|
}
|
|
398
403
|
const refPrice = Number(lastDenominator?.price);
|
|
@@ -421,7 +426,7 @@ async function fetchFeedCrossPoints({ mpaA, mpaB, backing, config = {} }) {
|
|
|
421
426
|
fetchFeedPricePoints({ mpaAsset: mpaA, backingAsset: backing, config }),
|
|
422
427
|
fetchFeedPricePoints({ mpaAsset: mpaB, backingAsset: backing, config }),
|
|
423
428
|
]);
|
|
424
|
-
return crossPointsToRatios(pointsA, pointsB, config.intervalSeconds || 3600);
|
|
429
|
+
return crossPointsToRatios(pointsA, pointsB, Number(config.intervalSeconds) || 3600);
|
|
425
430
|
}
|
|
426
431
|
/**
|
|
427
432
|
* Feed candles oriented for a tv pair (B-per-A units).
|
|
@@ -507,7 +512,9 @@ function feedOutputPath(feedKey, intervalSeconds, assetA, assetB) {
|
|
|
507
512
|
const folder = `${slugPart(assetA?.symbol)}_${slugPart(assetB?.symbol)}`;
|
|
508
513
|
return path.join(PATHS.MARKET_ADAPTER.FEED_DATA_DIR, folder, `feed_${slugPart(feedKey)}_${label}.json`);
|
|
509
514
|
}
|
|
510
|
-
function isFeedChunkMatch(
|
|
515
|
+
function isFeedChunkMatch(metaInput, requestKeyInput) {
|
|
516
|
+
const meta = metaInput;
|
|
517
|
+
const requestKey = requestKeyInput;
|
|
511
518
|
if (meta.feed !== requestKey.feed)
|
|
512
519
|
return false;
|
|
513
520
|
if (meta.intervalSeconds !== requestKey.intervalSeconds)
|
|
@@ -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',
|