dexbot 1.6.12 → 1.6.14
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 +65 -1
- package/README.md +2 -2
- package/analysis/README.md +9 -11
- package/analysis/ama_fitting/README.md +5 -3
- package/claw/README.md +1 -0
- package/claw/docs/AI_BOT_LIBRARY_API.md +3 -1
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -4
- package/claw/modules/claw_bridge.ts +0 -3
- package/claw/modules/claw_catalog.ts +8 -4
- package/claw/modules/claw_skill_md.ts +1 -0
- package/claw/modules/dexbot_profiles.ts +59 -15
- package/claw/modules/types.ts +2 -1
- package/claw/package.json +3 -3
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/claw/skills/margin-trading/SKILL.md +1 -1
- package/claw/skills/margin-trading/references/position-management.md +1 -1
- package/claw/tsconfig.json +2 -2
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +1 -14
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +51 -41
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +1 -24
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +36 -18
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +18 -66
- package/dist/analysis/analyze_args.d.ts +12 -0
- package/dist/analysis/analyze_args.js +20 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +1 -16
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +20 -101
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +26 -92
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +19 -34
- package/dist/analysis/bot_fitting/shared_utils.d.ts +71 -3
- package/dist/analysis/bot_fitting/shared_utils.js +124 -8
- package/dist/analysis/chart_ui.d.ts +30 -1
- package/dist/analysis/chart_ui.js +37 -1
- package/dist/analysis/fills_cache.d.ts +3 -23
- package/dist/analysis/fills_cache.js +3 -84
- package/dist/analysis/fills_source.d.ts +31 -1
- package/dist/analysis/fills_source.js +69 -1
- package/dist/analysis/grid_correction_check.d.ts +1 -23
- package/dist/analysis/grid_correction_check.js +15 -58
- package/dist/analysis/math_utils.d.ts +85 -1
- package/dist/analysis/math_utils.js +116 -1
- package/dist/analysis/price_sources.d.ts +22 -1
- package/dist/analysis/price_sources.js +23 -0
- package/dist/analysis/resolve_source.js +31 -10
- package/dist/analysis/trade_profitability.d.ts +6 -0
- package/dist/analysis/trade_profitability.js +23 -97
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +1 -17
- package/dist/analysis/tradingview/analyze_tradingview.js +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +27 -40
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -101
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +22 -80
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +11 -37
- package/dist/analysis/trend_detection/volatility_chart_generator.js +9 -10
- package/dist/analysis/worker_pool.d.ts +38 -0
- package/dist/analysis/worker_pool.js +67 -0
- package/dist/dexbot.js +67 -48
- package/dist/market_adapter/ama_signal_runner.js +21 -54
- package/dist/market_adapter/candle_utils.d.ts +7 -1
- package/dist/market_adapter/candle_utils.js +11 -1
- package/dist/market_adapter/cli_args.d.ts +22 -0
- package/dist/market_adapter/cli_args.js +30 -0
- package/dist/market_adapter/core/config_normalizers.js +11 -6
- package/dist/market_adapter/core/kibana_candles.d.ts +3 -1
- package/dist/market_adapter/core/kibana_candles.js +3 -2
- package/dist/market_adapter/core/market_adapter_service.d.ts +85 -85
- package/dist/market_adapter/core/market_adapter_service.js +93 -158
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +1 -6
- package/dist/market_adapter/core/signals/hurst_analyzer.js +1 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +1 -11
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +1 -1
- package/dist/market_adapter/inputs/fetch_book_data.js +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +63 -107
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +8 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js +25 -7
- package/dist/market_adapter/inputs/kibana_feed_source.js +4 -26
- package/dist/market_adapter/inputs/window_cache.d.ts +4 -72
- package/dist/market_adapter/inputs/window_cache.js +52 -177
- package/dist/market_adapter/interval_utils.d.ts +11 -1
- package/dist/market_adapter/interval_utils.js +16 -1
- package/dist/market_adapter/lp_chart_runner.d.ts +3 -0
- package/dist/market_adapter/lp_chart_runner.js +37 -19
- package/dist/market_adapter/market_adapter.js +27 -72
- package/dist/market_adapter/utils/data_discovery.d.ts +45 -1
- package/dist/market_adapter/utils/data_discovery.js +220 -27
- package/dist/market_adapter/utils/month_shards.d.ts +84 -0
- package/dist/market_adapter/utils/month_shards.js +237 -0
- package/dist/modules/account_bots.d.ts +8 -6
- package/dist/modules/account_bots.js +112 -131
- package/dist/modules/account_orders.d.ts +49 -4
- package/dist/modules/account_orders.js +114 -49
- package/dist/modules/bitshares-native/chain_client.d.ts +1 -1
- package/dist/modules/bitshares-native/chain_client.js +14 -13
- package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +1 -2
- package/dist/modules/bitshares-native/crypto/ecc_core.js +1 -1
- package/dist/modules/bitshares-native/resolvers.js +22 -25
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts +1 -2
- package/dist/modules/bitshares-native/serial/chain_constants.js +1 -2
- package/dist/modules/bitshares-native/serial/types.js +22 -50
- package/dist/modules/bitshares-native/signing_client.d.ts +1 -1
- package/dist/modules/bot_defaults.d.ts +18 -3
- package/dist/modules/bot_defaults.js +34 -8
- package/dist/modules/bot_settings.d.ts +5 -1
- package/dist/modules/bot_settings.js +55 -21
- package/dist/modules/broadcast_failure.d.ts +2 -1
- package/dist/modules/chain_orders.d.ts +1 -1
- package/dist/modules/chain_orders.js +51 -96
- package/dist/modules/cli_start_onboarding.d.ts +2 -1
- package/dist/modules/config.js +6 -1
- package/dist/modules/constants.d.ts +14 -6
- package/dist/modules/constants.js +32 -6
- package/dist/modules/cr_planner.d.ts +1 -1
- package/dist/modules/cr_planner.js +1 -5
- package/dist/modules/credit_pricing.d.ts +2 -1
- package/dist/modules/credit_pricing.js +36 -40
- package/dist/modules/credit_runtime.d.ts +7 -0
- package/dist/modules/credit_runtime.js +45 -73
- package/dist/modules/daemon_node_health.d.ts +4 -3
- package/dist/modules/dexbot_class.d.ts +33 -17
- package/dist/modules/dexbot_class.js +113 -61
- package/dist/modules/dexbot_cow_runtime.d.ts +62 -181
- package/dist/modules/dexbot_cow_runtime.js +380 -69
- package/dist/modules/dexbot_credential_client.d.ts +1 -23
- package/dist/modules/dexbot_credential_client.js +2 -3
- package/dist/modules/dexbot_fill_runtime.d.ts +2 -3
- package/dist/modules/dexbot_fill_runtime.js +17 -7
- package/dist/modules/dexbot_maintenance_runtime.d.ts +36 -81
- package/dist/modules/dexbot_maintenance_runtime.js +137 -133
- package/dist/modules/dexbot_startup_runtime.d.ts +0 -1
- package/dist/modules/dexbot_startup_runtime.js +25 -14
- package/dist/modules/dexbot_state_recovery.js +16 -0
- package/dist/modules/general_settings.d.ts +1 -1
- package/dist/modules/graceful_shutdown.js +17 -11
- package/dist/modules/key_store.d.ts +0 -5
- package/dist/modules/key_store.js +1 -2
- package/dist/modules/lazy_shim.d.ts +11 -0
- package/dist/modules/lazy_shim.js +16 -0
- package/dist/modules/node_connect_policy.d.ts +3 -2
- package/dist/modules/node_failure_ledger.d.ts +6 -5
- package/dist/modules/order/accounting.js +11 -11
- package/dist/modules/order/export.js +2 -2
- package/dist/modules/order/format.d.ts +26 -3
- package/dist/modules/order/format.js +33 -3
- package/dist/modules/order/genesis_policy.d.ts +4 -4
- package/dist/modules/order/genesis_policy.js +6 -3
- package/dist/modules/order/grid.d.ts +26 -12
- package/dist/modules/order/grid.js +468 -80
- package/dist/modules/order/grid_reconcile.d.ts +1 -1
- package/dist/modules/order/grid_reconcile.js +5 -5
- package/dist/modules/order/grid_reconcile_internal.js +48 -40
- package/dist/modules/order/index.d.ts +35 -8
- package/dist/modules/order/logger.d.ts +1 -8
- package/dist/modules/order/logger.js +2 -11
- package/dist/modules/order/manager.d.ts +18 -15
- package/dist/modules/order/manager.js +91 -74
- package/dist/modules/order/strategy.d.ts +2 -2
- package/dist/modules/order/strategy.js +51 -21
- package/dist/modules/order/sync_engine.js +4 -0
- package/dist/modules/order/utils/math.d.ts +3 -3
- package/dist/modules/order/utils/math.js +38 -27
- package/dist/modules/order/utils/order.d.ts +58 -58
- package/dist/modules/order/utils/order.js +158 -137
- package/dist/modules/order/utils/system.d.ts +202 -35
- package/dist/modules/order/utils/system.js +409 -31
- package/dist/modules/order/utils/validate.js +28 -6
- package/dist/modules/order/utils/withPoolRef.d.ts +2 -1
- package/dist/modules/paths.js +32 -34
- package/dist/modules/runtime_settings.d.ts +3 -5
- package/dist/modules/runtime_settings.js +3 -3
- package/dist/modules/settings_merge.d.ts +2 -2
- package/dist/modules/socket_json_client.d.ts +2 -1
- package/dist/modules/types.d.ts +89 -30
- package/dist/modules/utils/errors.js +1 -3
- package/dist/modules/version_notice.d.ts +11 -10
- package/dist/pm2.d.ts +0 -1
- package/dist/pm2.js +56 -35
- package/dist/scripts/analyze-git.js +2 -15
- package/dist/scripts/analyze-orders.d.ts +1 -1
- package/dist/scripts/analyze-orders.js +4 -4
- package/dist/scripts/chart_command.js +2 -2
- package/dist/scripts/check_any.d.ts +4 -0
- package/dist/scripts/check_any.js +53 -21
- package/dist/scripts/diagnose-pool-history.js +1 -6
- package/dist/scripts/divergence-calc.js +6 -6
- package/dist/scripts/run-tests.js +0 -1
- package/dist/scripts/sync-version.js +0 -10
- package/dist/scripts/validate_bots.d.ts +1 -1
- package/dist/scripts/validate_bots.js +3 -3
- package/dist/unlock.js +7 -2
- package/docs/BITSHARES_ONBOARDING.md +8 -12
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +2 -3
- package/docs/COW_INVARIANTS.md +6 -6
- package/docs/DEXBOT_COMPARISON.md +7 -7
- package/docs/EVOLUTION.md +10 -8
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +8 -6
- package/docs/GRID_PRICE_INVARIANT.md +3 -3
- package/docs/GRID_RECALCULATION.md +4 -1
- package/docs/GRID_RECONCILE.md +4 -4
- package/docs/LIFECYCLE.md +11 -11
- package/docs/LOGGING.md +14 -0
- package/docs/MPA_CREDIT_USAGE.md +1 -1
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +12 -4
- package/docs/README.md +3 -3
- package/docs/WORKFLOW.md +1 -0
- package/docs/architecture.md +25 -16
- package/docs/developer_guide.md +7 -2
- package/market_adapter/README.md +6 -4
- package/package.json +6 -9
- package/scripts/README.md +43 -38
- package/tests/README.md +26 -11
- package/dist/scripts/diagnose-kibana-candles.d.ts +0 -3
- package/dist/scripts/diagnose-kibana-candles.js +0 -82
- package/scripts/git-viewer.sh +0 -489
- package/scripts/postinstall.js +0 -16
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { normalizePoolId } from '../../market_adapter/utils/chain.js';
|
|
6
|
-
import { toIntervalLabel, slugPart } from '../../market_adapter/interval_utils.js';
|
|
7
|
-
import { MARKET_ADAPTER } from '../../modules/constants.js';
|
|
8
|
-
import * as kibanaSource from '../../market_adapter/inputs/kibana_source.js';
|
|
9
|
-
import { PATHS } from '../../modules/paths.js';
|
|
10
|
-
import { getStorage } from '../../modules/storage/index.js';
|
|
11
|
-
const { ensureDir, writeJSON } = getStorage();
|
|
12
|
-
import { getErrorMessage } from '../../modules/utils/errors.js';
|
|
13
3
|
/**
|
|
14
|
-
* Fetch LP pool candles from Kibana for AMA optimizer
|
|
4
|
+
* Fetch LP pool candles from Kibana for the AMA optimizer.
|
|
15
5
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
6
|
+
* Thin CLI over the central sequential/window fetch
|
|
7
|
+
* (`market_adapter/inputs/fetch_lp_data.ts` → `fetchCandlesSequentially`).
|
|
8
|
+
* It therefore shares the SAME month-shard cache as `dexbot tv`/`dexbot dw`:
|
|
9
|
+
* a run re-queries only the missing buckets and reuses everything on disk,
|
|
10
|
+
* then exports the whole-history base file as a convenience snapshot.
|
|
18
11
|
*
|
|
19
12
|
* Usage:
|
|
20
13
|
* node dist/analysis/ama_fitting/fetch_lp_candles.js \
|
|
@@ -26,11 +19,16 @@ import { getErrorMessage } from '../../modules/utils/errors.js';
|
|
|
26
19
|
* Defaults: --interval 1h --hours 26280 (3 years)
|
|
27
20
|
* Output: market_adapter/data/lp/<assetA>_<assetB>/lp_pool_<poolShort>_<interval>.json
|
|
28
21
|
*/
|
|
29
|
-
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import { pathToFileURL } from 'node:url';
|
|
24
|
+
import { toIntervalLabel } from '../../market_adapter/interval_utils.js';
|
|
25
|
+
import { MARKET_ADAPTER } from '../../modules/constants.js';
|
|
26
|
+
import { getErrorMessage } from '../../modules/utils/errors.js';
|
|
27
|
+
import { writeJsonAtomic } from '../../market_adapter/utils/atomic_write.js';
|
|
28
|
+
import { loadLpSeriesFromBasePath } from '../../market_adapter/utils/data_discovery.js';
|
|
29
|
+
import { normalizePoolId } from '../../market_adapter/utils/chain.js';
|
|
30
|
+
import { fetchCandlesSequentially, outputPath, } from '../../market_adapter/inputs/fetch_lp_data.js';
|
|
30
31
|
const HOURS_3Y = 3 * 365 * 24; // 26280
|
|
31
|
-
function slugPairFolder(symbolA, symbolB) {
|
|
32
|
-
return `${slugPart(symbolA)}_${slugPart(symbolB)}`;
|
|
33
|
-
}
|
|
34
32
|
function parseArgs() {
|
|
35
33
|
const args = process.argv.slice(2);
|
|
36
34
|
const out = {
|
|
@@ -101,6 +99,8 @@ function parseArgs() {
|
|
|
101
99
|
function printHelp() {
|
|
102
100
|
console.log('fetch_lp_candles.ts — fetch LP pool candles from Kibana for AMA optimizer');
|
|
103
101
|
console.log('');
|
|
102
|
+
console.log('Uses the shared month-shard candle cache (same as dexbot tv / dw).');
|
|
103
|
+
console.log('');
|
|
104
104
|
console.log('Usage:');
|
|
105
105
|
console.log(' node dist/analysis/ama_fitting/fetch_lp_candles.js --pool 1.19.133 \\');
|
|
106
106
|
console.log(' --assetA IOB.XRP --assetAId 1.3.3926 --assetAPrecision 4 \\');
|
|
@@ -155,56 +155,66 @@ async function main() {
|
|
|
155
155
|
const poolId = normalizePoolId(args.pool);
|
|
156
156
|
const lookback = Math.round(args.hours);
|
|
157
157
|
const yearsApprox = (lookback / (365 * 24)).toFixed(1);
|
|
158
|
+
if (!poolId)
|
|
159
|
+
throw new Error(`Invalid --pool: ${args.pool}`);
|
|
158
160
|
console.log(`Fetching LP candles from Kibana`);
|
|
159
161
|
console.log(` Pool: ${poolId}`);
|
|
160
162
|
console.log(` Pair: ${assetA.symbol} / ${assetB.symbol}`);
|
|
161
163
|
console.log(` Interval: ${intervalLabel}`);
|
|
162
164
|
console.log(` Lookback: ${lookback}h (~${yearsApprox} years)`);
|
|
163
165
|
console.log('');
|
|
164
|
-
const
|
|
166
|
+
const defaultOut = outputPath(poolId, intervalSeconds, assetA, assetB);
|
|
167
|
+
const outPath = args.outFile
|
|
168
|
+
? (path.isAbsolute(args.outFile) ? args.outFile : path.join(path.dirname(defaultOut), args.outFile))
|
|
169
|
+
: defaultOut;
|
|
170
|
+
const candles = await fetchCandlesSequentially(poolId, assetA, assetB, {
|
|
165
171
|
intervalSeconds,
|
|
166
172
|
lookbackHours: lookback,
|
|
167
173
|
apiKey: null,
|
|
168
|
-
|
|
169
|
-
});
|
|
174
|
+
chunkMonths: MARKET_ADAPTER.KIBANA_FETCH_CHUNK_MONTHS,
|
|
175
|
+
}, outPath);
|
|
170
176
|
if (!Array.isArray(candles) || candles.length === 0) {
|
|
171
177
|
throw new Error('Kibana returned no candles — check pool ID, asset IDs, and Kibana connectivity');
|
|
172
178
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
// Whole-history export: month shards are the cache, this is the derived
|
|
180
|
+
// snapshot (same meta shape as fetch_lp_data's export). Deriving it from
|
|
181
|
+
// the assembled shards means a narrow re-run can never shrink the file.
|
|
182
|
+
const assembled = loadLpSeriesFromBasePath(outPath);
|
|
183
|
+
const exportCandles = (assembled && assembled.candles.length > 0 ? assembled.candles : candles);
|
|
184
|
+
const firstTs = new Date(exportCandles[0][0]).toISOString();
|
|
185
|
+
const lastTs = new Date(exportCandles[exportCandles.length - 1][0]).toISOString();
|
|
186
|
+
console.log(` Received: ${exportCandles.length} candles (${firstTs} → ${lastTs})`);
|
|
176
187
|
const payload = {
|
|
177
188
|
meta: {
|
|
178
189
|
fetchedAt: new Date().toISOString(),
|
|
179
|
-
source:
|
|
190
|
+
source: `https://kibana.bitshares.dev (bitshares-*, op_type 63, pool ${poolId})`,
|
|
180
191
|
pool: poolId,
|
|
181
192
|
assetA,
|
|
182
193
|
assetB,
|
|
194
|
+
pair: {
|
|
195
|
+
symbols: `${assetA.symbol}/${assetB.symbol}`,
|
|
196
|
+
ids: `${assetA.id}/${assetB.id}`,
|
|
197
|
+
keyBySymbols: `${assetA.symbol}|${assetB.symbol}`,
|
|
198
|
+
keyByIds: `${assetA.id}|${assetB.id}`,
|
|
199
|
+
},
|
|
183
200
|
intervalSeconds,
|
|
184
201
|
lookbackHours: lookback,
|
|
185
|
-
candleCount:
|
|
202
|
+
candleCount: exportCandles.length,
|
|
203
|
+
priceUnit: `${assetB.symbol} per ${assetA.symbol}`,
|
|
186
204
|
format: '[timestamp_ms, open, high, low, close, volume_A]',
|
|
187
205
|
},
|
|
188
|
-
candles,
|
|
206
|
+
candles: exportCandles,
|
|
189
207
|
};
|
|
190
|
-
|
|
191
|
-
const pairFolder = slugPairFolder(assetA.symbol, assetB.symbol);
|
|
192
|
-
const defaultName = `lp_pool_${poolShort}_${intervalLabel}.json`;
|
|
193
|
-
const outName = args.outFile || defaultName;
|
|
194
|
-
const outPath = args.outFile && path.isAbsolute(args.outFile)
|
|
195
|
-
? args.outFile
|
|
196
|
-
: path.join(DATA_DIR, pairFolder, outName);
|
|
197
|
-
const outDir = path.dirname(outPath);
|
|
198
|
-
if (!fs.existsSync(outDir))
|
|
199
|
-
ensureDir(outDir);
|
|
200
|
-
writeJSON(outPath, payload);
|
|
208
|
+
writeJsonAtomic(outPath, payload);
|
|
201
209
|
console.log(` Saved: ${path.relative(process.cwd(), outPath)}`);
|
|
202
210
|
console.log('');
|
|
203
211
|
console.log('Run optimizer:');
|
|
204
212
|
console.log(` npm run build && node dist/analysis/ama_fitting/optimizer_high_resolution.js --data ${path.relative(process.cwd(), outPath)}`);
|
|
205
213
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
214
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
215
|
+
main().catch((err) => {
|
|
216
|
+
console.error('Error:', getErrorMessage(err));
|
|
217
|
+
process.exit(1);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
210
220
|
//# sourceMappingURL=fetch_lp_candles.js.map
|
|
@@ -13,29 +13,6 @@ declare function parseArgs(argv: string[]): {
|
|
|
13
13
|
quiet: boolean;
|
|
14
14
|
help: boolean;
|
|
15
15
|
};
|
|
16
|
-
interface GenerateChartOptions {
|
|
17
|
-
logger?: {
|
|
18
|
-
log: (...args: unknown[]) => void;
|
|
19
|
-
};
|
|
20
|
-
dataFile?: string | null;
|
|
21
|
-
outFile?: string | null;
|
|
22
|
-
strategies?: typeof DEFAULT_STRATEGIES;
|
|
23
|
-
[key: string]: unknown;
|
|
24
|
-
}
|
|
25
|
-
declare function generateChart(options?: GenerateChartOptions): {
|
|
26
|
-
dataFile: string;
|
|
27
|
-
outFile: string;
|
|
28
|
-
amaResults: (Record<string, unknown> & {
|
|
29
|
-
values: number[];
|
|
30
|
-
})[];
|
|
31
|
-
meta: {
|
|
32
|
-
assetA: {};
|
|
33
|
-
assetB: {};
|
|
34
|
-
intervalSeconds: {};
|
|
35
|
-
fetchedAt: {};
|
|
36
|
-
};
|
|
37
|
-
candleArrays: number[][];
|
|
38
|
-
};
|
|
39
16
|
declare function run(argv?: string[]): void;
|
|
40
|
-
export { DEFAULT_STRATEGIES,
|
|
17
|
+
export { DEFAULT_STRATEGIES, parseArgs, run, showHelp };
|
|
41
18
|
//# sourceMappingURL=generate_unified_comparison_chart.d.ts.map
|
|
@@ -6,7 +6,7 @@ import { pathToFileURL } from 'node:url';
|
|
|
6
6
|
import { calculateAMA } from '../../market_adapter/core/strategies/ama.js';
|
|
7
7
|
import { generateHTML } from '../../market_adapter/lp_chart_core.js';
|
|
8
8
|
import { calculateMetrics } from '../../market_adapter/lp_chart_runner.js';
|
|
9
|
-
import {
|
|
9
|
+
import { loadLatestLpSeries, loadLpSeriesFromPath } from '../../market_adapter/utils/data_discovery.js';
|
|
10
10
|
import { toIntervalLabel } from '../../market_adapter/interval_utils.js';
|
|
11
11
|
import { loadCandleFile, normalizeCandle } from '../math_utils.js';
|
|
12
12
|
import { MARKET_ADAPTER } from '../../modules/constants.js';
|
|
@@ -46,14 +46,7 @@ function buildDefaultStrategies() {
|
|
|
46
46
|
}
|
|
47
47
|
const DEFAULT_STRATEGIES = buildDefaultStrategies();
|
|
48
48
|
// ── Data loading (canonical implementations, no local copies) ────────────────
|
|
49
|
-
function
|
|
50
|
-
const resolved = path.resolve(dataFile);
|
|
51
|
-
if (!fs.existsSync(resolved))
|
|
52
|
-
throw new Error(`File not found: ${resolved}`);
|
|
53
|
-
const { candles, meta } = loadCandleFile(resolved);
|
|
54
|
-
if (!Array.isArray(candles) || candles.length === 0) {
|
|
55
|
-
throw new Error('No candles found in file');
|
|
56
|
-
}
|
|
49
|
+
function normalizeCandleRows(candles) {
|
|
57
50
|
// normalizeCandle is the canonical accessor transform (market_adapter/
|
|
58
51
|
// candle_utils.ts via math_utils re-export); it returns seconds-based time.
|
|
59
52
|
const normalized = candles.map((c, i) => {
|
|
@@ -71,7 +64,21 @@ function loadCandles(dataFile) {
|
|
|
71
64
|
volume: c.volume,
|
|
72
65
|
}));
|
|
73
66
|
const candleArrays = normalized.map(c => [c.time * 1000, c.open, c.high, c.low, c.close, c.volume]);
|
|
74
|
-
return {
|
|
67
|
+
return { candleObjects, candleArrays };
|
|
68
|
+
}
|
|
69
|
+
function loadCandles(dataFile) {
|
|
70
|
+
const resolved = path.resolve(dataFile);
|
|
71
|
+
if (!fs.existsSync(resolved))
|
|
72
|
+
throw new Error(`File not found: ${resolved}`);
|
|
73
|
+
// Shard-aware: `--data <shard>` yields the whole family, not one month.
|
|
74
|
+
const series = loadLpSeriesFromPath(resolved);
|
|
75
|
+
if (!series || series.candles.length === 0) {
|
|
76
|
+
throw new Error('No candles found in file');
|
|
77
|
+
}
|
|
78
|
+
// Keep loadCandleFile's meta fallback for non-LP `{data:[...]}` shapes that
|
|
79
|
+
// carry fields at the top level rather than under `meta`.
|
|
80
|
+
const meta = series.meta ?? loadCandleFile(resolved).meta;
|
|
81
|
+
return { dataFile: series.path, meta, ...normalizeCandleRows(series.candles) };
|
|
75
82
|
}
|
|
76
83
|
function defaultChartPath(meta) {
|
|
77
84
|
const intervalSeconds = Number(meta?.intervalSeconds);
|
|
@@ -103,7 +110,7 @@ Options:
|
|
|
103
110
|
Notes:
|
|
104
111
|
- If --data is omitted, the newest lp_pool_*.json under market_adapter/data/lp is used.
|
|
105
112
|
- Accepts several candle JSON shapes: flat [[ts,o,h,l,c,v],...], {candles: [...]}, or {data: [...]}.
|
|
106
|
-
- Separate from Kibana fetching —
|
|
113
|
+
- Separate from Kibana fetching — run 'dexbot tv' (or fetch_lp_candles.ts) to pull data first.
|
|
107
114
|
`);
|
|
108
115
|
}
|
|
109
116
|
// ── Main ───────────────────────────────────────────────────────────────────────
|
|
@@ -133,16 +140,27 @@ function parseArgs(argv) {
|
|
|
133
140
|
}
|
|
134
141
|
function generateChart(options = {}) {
|
|
135
142
|
const logger = options.logger ?? console;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
// Explicit --data wins; otherwise auto-discover and, when month shards are
|
|
144
|
+
// the newest source, assemble the complete series before charting.
|
|
145
|
+
let dataFile;
|
|
146
|
+
let meta;
|
|
147
|
+
let candleObjects;
|
|
148
|
+
let candleArrays;
|
|
149
|
+
if (options.dataFile) {
|
|
150
|
+
({ dataFile, meta, candleObjects, candleArrays } = loadCandles(options.dataFile));
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
const series = loadLatestLpSeries();
|
|
154
|
+
if (!series || series.candles.length === 0) {
|
|
155
|
+
throw new Error(`No LP data found. Use --data <path> or run \`dexbot tv\` first.`);
|
|
156
|
+
}
|
|
157
|
+
dataFile = series.path;
|
|
158
|
+
meta = series.meta;
|
|
159
|
+
({ candleObjects, candleArrays } = normalizeCandleRows(series.candles));
|
|
141
160
|
}
|
|
142
161
|
const strategies = Array.isArray(options.strategies) && options.strategies.length
|
|
143
162
|
? options.strategies
|
|
144
163
|
: [...DEFAULT_STRATEGIES];
|
|
145
|
-
const { meta, candleObjects, candleArrays } = loadCandles(dataFile);
|
|
146
164
|
const closes = candleObjects.map(c => c.close);
|
|
147
165
|
const enrichedMeta = {
|
|
148
166
|
...(meta || {}),
|
|
@@ -202,5 +220,5 @@ function run(argv = process.argv.slice(2)) {
|
|
|
202
220
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
203
221
|
run();
|
|
204
222
|
}
|
|
205
|
-
export { DEFAULT_STRATEGIES,
|
|
223
|
+
export { DEFAULT_STRATEGIES, parseArgs, run, showHelp };
|
|
206
224
|
//# sourceMappingURL=generate_unified_comparison_chart.js.map
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import os from 'node:os';
|
|
5
|
-
import { pathToFileURL
|
|
6
|
-
import {
|
|
5
|
+
import { pathToFileURL } from 'node:url';
|
|
6
|
+
import { isMainThread, parentPort, workerData } from 'node:worker_threads';
|
|
7
7
|
import { calculateAMA, getAmaWarmupBars } from '../../market_adapter/core/strategies/ama.js';
|
|
8
8
|
import { toIntervalLabel } from '../../market_adapter/interval_utils.js';
|
|
9
9
|
import { generateHTML } from '../../market_adapter/lp_chart_core.js';
|
|
10
10
|
import { PATHS } from '../../modules/paths.js';
|
|
11
11
|
import { ensureDir } from '../../modules/order/utils/system.js';
|
|
12
|
-
import { range } from '../math_utils.js';
|
|
12
|
+
import { range, geometricRange, percentile } from '../math_utils.js';
|
|
13
|
+
import { runModuleWorker, splitIntoShards } from '../worker_pool.js';
|
|
13
14
|
import { getStorage } from '../../modules/storage/index.js';
|
|
14
15
|
import { normalizeAssetSymbol } from '../../modules/utils/asset_symbols.js';
|
|
15
16
|
const { readJSON, writeJSON } = getStorage();
|
|
@@ -53,27 +54,6 @@ const AMA_OBJECTIVES = [
|
|
|
53
54
|
function cloneObjectives() {
|
|
54
55
|
return AMA_OBJECTIVES.map((o) => ({ ...o }));
|
|
55
56
|
}
|
|
56
|
-
// ── Parameter ranges ──────────────────────────────────────────────────────────
|
|
57
|
-
function quantize(value, quantum) {
|
|
58
|
-
if (quantum == null || !Number.isFinite(quantum) || quantum <= 0)
|
|
59
|
-
return value;
|
|
60
|
-
return Math.round(value / quantum) * quantum;
|
|
61
|
-
}
|
|
62
|
-
function geometricRange(min, max, count, quantum = null) {
|
|
63
|
-
const out = [];
|
|
64
|
-
const ratio = Math.pow(max / min, 1 / (count - 1));
|
|
65
|
-
for (let i = 0; i < count; i++) {
|
|
66
|
-
let v = min * Math.pow(ratio, i);
|
|
67
|
-
if (i === 0)
|
|
68
|
-
v = min;
|
|
69
|
-
if (i === count - 1)
|
|
70
|
-
v = max;
|
|
71
|
-
v = quantize(v, quantum);
|
|
72
|
-
v = Math.max(min, Math.min(max, v));
|
|
73
|
-
out.push(parseFloat(v.toFixed(6)));
|
|
74
|
-
}
|
|
75
|
-
return [...new Set(out)].sort((a, b) => a - b);
|
|
76
|
-
}
|
|
77
57
|
function buildDimension(cfg) {
|
|
78
58
|
const min = Number(cfg.min);
|
|
79
59
|
const max = Number(cfg.max);
|
|
@@ -96,7 +76,10 @@ function buildDimension(cfg) {
|
|
|
96
76
|
};
|
|
97
77
|
}
|
|
98
78
|
const ratio = Math.pow(max / min, 1 / (count - 1));
|
|
99
|
-
const values = geometricRange(min, max, count,
|
|
79
|
+
const values = geometricRange(min, max, count, {
|
|
80
|
+
decimals: 6,
|
|
81
|
+
quantum: Number.isFinite(quantum) && quantum > 0 ? quantum : null,
|
|
82
|
+
});
|
|
100
83
|
return {
|
|
101
84
|
values,
|
|
102
85
|
meta: {
|
|
@@ -245,19 +228,6 @@ function parseArgs(argv = process.argv.slice(2)) {
|
|
|
245
228
|
}
|
|
246
229
|
return out;
|
|
247
230
|
}
|
|
248
|
-
function percentile(values, q) {
|
|
249
|
-
if (!Array.isArray(values) || values.length === 0)
|
|
250
|
-
return null;
|
|
251
|
-
const sorted = [...values].sort((a, b) => a - b);
|
|
252
|
-
const qq = Math.max(0, Math.min(1, q));
|
|
253
|
-
const pos = (sorted.length - 1) * qq;
|
|
254
|
-
const lo = Math.floor(pos);
|
|
255
|
-
const hi = Math.ceil(pos);
|
|
256
|
-
if (lo === hi)
|
|
257
|
-
return sorted[lo];
|
|
258
|
-
const t = pos - lo;
|
|
259
|
-
return sorted[lo] * (1 - t) + sorted[hi] * t;
|
|
260
|
-
}
|
|
261
231
|
function getAmaObjectivesFromArgs(args) {
|
|
262
232
|
const objectives = cloneObjectives();
|
|
263
233
|
for (const o of objectives) {
|
|
@@ -479,36 +449,17 @@ function runSearchShard(payload, onProgress = null) {
|
|
|
479
449
|
return { workerId, entries, totalCombos, validCombos: valid };
|
|
480
450
|
}
|
|
481
451
|
function spawnShardWorker(payload, onProgress) {
|
|
482
|
-
return
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
worker.on('message', (msg) => {
|
|
487
|
-
if (!msg || typeof msg !== 'object')
|
|
488
|
-
return;
|
|
489
|
-
if (msg.type === 'progress') {
|
|
490
|
-
if (onProgress)
|
|
491
|
-
onProgress(msg);
|
|
492
|
-
return;
|
|
452
|
+
return runModuleWorker(import.meta.url, { type: 'search_shard', payload }, {
|
|
453
|
+
onProgress: (msg) => {
|
|
454
|
+
if (msg && typeof msg === 'object' && msg.type === 'progress') {
|
|
455
|
+
onProgress?.(msg);
|
|
493
456
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
worker.on('exit', (code) => {
|
|
499
|
-
if (code !== 0)
|
|
500
|
-
reject(new Error(`Worker exited with code ${code}`));
|
|
501
|
-
});
|
|
457
|
+
},
|
|
458
|
+
resolveOn: (msg) => msg && typeof msg === 'object' && msg.type === 'done'
|
|
459
|
+
? { done: true, value: msg.result }
|
|
460
|
+
: { done: false },
|
|
502
461
|
});
|
|
503
462
|
}
|
|
504
|
-
function splitIntoShards(values, shardCount) {
|
|
505
|
-
const out = [];
|
|
506
|
-
const size = Math.ceil(values.length / shardCount);
|
|
507
|
-
for (let i = 0; i < values.length; i += size) {
|
|
508
|
-
out.push(values.slice(i, i + size));
|
|
509
|
-
}
|
|
510
|
-
return out.filter((s) => s.length > 0);
|
|
511
|
-
}
|
|
512
463
|
// ── Main ───────────────────────────────────────────────────────────────────────
|
|
513
464
|
async function run() {
|
|
514
465
|
const args = parseArgs();
|
|
@@ -585,7 +536,8 @@ async function run() {
|
|
|
585
536
|
const skipCap = Number.isFinite(args.fixedEr) && Number.isFinite(args.fixedFast);
|
|
586
537
|
const objectiveResults = objectives.map((objective) => {
|
|
587
538
|
const distanceWeight = objective.distanceWeight;
|
|
588
|
-
|
|
539
|
+
// distanceCapQuantile is a fraction in (0, 1]; percentile takes [0, 100].
|
|
540
|
+
const computedCap = skipCap ? null : percentile(maxDistVals, objective.distanceCapQuantile * 100);
|
|
589
541
|
const cappedEntries = skipCap || computedCap == null ? entries : entries.filter((e) => e.area.maxDist <= computedCap);
|
|
590
542
|
let best = null;
|
|
591
543
|
for (const e of cappedEntries) {
|
|
@@ -28,4 +28,16 @@ export declare function baseAnalysisConfig(): AnalysisBaseConfig;
|
|
|
28
28
|
* caller can `continue` to the next token.
|
|
29
29
|
*/
|
|
30
30
|
export declare function consumeCommonAnalysisArg(arg: string, next: () => string, config: AnalysisBaseConfig): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Print the standard analysis-CLI help preamble:
|
|
33
|
+
* `title` / blank / `Usage: node dist/analysis/<usagePath> [options]` / blank /
|
|
34
|
+
* `Options:`. Callers then emit their own option rows (see `helpRow`).
|
|
35
|
+
*/
|
|
36
|
+
export declare function printHelpHeader(title: string, usagePath: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Render one aligned option row for a hand-written help body:
|
|
39
|
+
* two-space indent, `flag` padded to `width`, then `description`.
|
|
40
|
+
* `width` is per-tool so adopting this helper keeps the original column.
|
|
41
|
+
*/
|
|
42
|
+
export declare function helpRow(flag: string, description: string, width: number): string;
|
|
31
43
|
//# sourceMappingURL=analyze_args.d.ts.map
|
|
@@ -38,4 +38,24 @@ export function consumeCommonAnalysisArg(arg, next, config) {
|
|
|
38
38
|
return false;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Print the standard analysis-CLI help preamble:
|
|
43
|
+
* `title` / blank / `Usage: node dist/analysis/<usagePath> [options]` / blank /
|
|
44
|
+
* `Options:`. Callers then emit their own option rows (see `helpRow`).
|
|
45
|
+
*/
|
|
46
|
+
export function printHelpHeader(title, usagePath) {
|
|
47
|
+
console.log(title);
|
|
48
|
+
console.log('');
|
|
49
|
+
console.log(`Usage: node dist/analysis/${usagePath} [options]`);
|
|
50
|
+
console.log('');
|
|
51
|
+
console.log('Options:');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Render one aligned option row for a hand-written help body:
|
|
55
|
+
* two-space indent, `flag` padded to `width`, then `description`.
|
|
56
|
+
* `width` is per-tool so adopting this helper keeps the original column.
|
|
57
|
+
*/
|
|
58
|
+
export function helpRow(flag, description, width) {
|
|
59
|
+
return ` ${flag.padEnd(width)}${description}`;
|
|
60
|
+
}
|
|
41
61
|
//# sourceMappingURL=analyze_args.js.map
|
|
@@ -71,21 +71,6 @@ declare function buildGrid(center: number, params: {
|
|
|
71
71
|
sells: GridOrder[];
|
|
72
72
|
rail: number[];
|
|
73
73
|
};
|
|
74
|
-
/**
|
|
75
|
-
* Mark the held inventory position to `markPrice` in capital units.
|
|
76
|
-
*
|
|
77
|
-
* Carried bags are a REAL risk the drawdown tracker should see bar-by-bar,
|
|
78
|
-
* but their mark is informational for scoring: realized rotation profit plus
|
|
79
|
-
* op fees drive netProfit, and the end-of-run position is reported separately
|
|
80
|
-
* instead of being dumped into totals.
|
|
81
|
-
*/
|
|
82
|
-
declare function markInventoryAtPrice(inventory: {
|
|
83
|
-
units: number;
|
|
84
|
-
cost: number;
|
|
85
|
-
}, exitPrice: number, feeRoundtripPct: number): {
|
|
86
|
-
grossUnits: number;
|
|
87
|
-
profitUnits: number;
|
|
88
|
-
};
|
|
89
74
|
interface SimCandle {
|
|
90
75
|
open?: number;
|
|
91
76
|
high: number;
|
|
@@ -311,5 +296,5 @@ declare function sweepOneAma(strategy: AmaStrategy, candles: SimCandle[], closes
|
|
|
311
296
|
}[];
|
|
312
297
|
evaluated: number;
|
|
313
298
|
};
|
|
314
|
-
export { WEIGHT_PROFILES, allocateFundsByWeights, buildGrid,
|
|
299
|
+
export { WEIGHT_PROFILES, allocateFundsByWeights, buildGrid, simulatePersistentGrid, sweepOneAma };
|
|
315
300
|
//# sourceMappingURL=backtest_ama_sweep.d.ts.map
|