dexbot 1.6.4 → 1.6.6
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 +75 -3
- package/README.md +109 -40
- package/analysis/README.md +19 -17
- package/analysis/account_resolver.ts +1 -11
- package/analysis/analyze_dynamic_weight.ts +9 -3
- package/analysis/bot_usage/kibana_bot_queries.ts +1 -1
- package/analysis/chain_pool.ts +1 -1
- package/analysis/fills_source.ts +0 -6
- package/analysis/grid_correction_check.ts +20 -26
- package/analysis/resolve_source.ts +1 -1
- package/analysis/trade_profitability.ts +2 -5
- package/analysis/tradingview/analyze_tradingview.ts +5 -0
- package/analysis/tradingview/tradingview_uplot_chart_generator.ts +2 -2
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +35 -2
- package/analysis/trend_detection/README.md +1 -3
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +82 -10
- package/analysis/trend_detection/package.json +1 -1
- package/claw/modules/dexbot_profiles.ts +4 -3
- 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/claw/tests/test_claw_mcp_transport.ts +2 -2
- package/claw/tests/test_dexbot_profiles.ts +18 -1
- package/dist/analysis/account_resolver.d.ts +1 -4
- package/dist/analysis/account_resolver.d.ts.map +1 -1
- package/dist/analysis/account_resolver.js +1 -1
- package/dist/analysis/account_resolver.js.map +1 -1
- package/dist/analysis/analyze_dynamic_weight.js +9 -3
- package/dist/analysis/analyze_dynamic_weight.js.map +1 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -2
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js +1 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +1 -1
- package/dist/analysis/chain_pool.d.ts +1 -3
- package/dist/analysis/chain_pool.d.ts.map +1 -1
- package/dist/analysis/chain_pool.js +1 -1
- package/dist/analysis/chain_pool.js.map +1 -1
- package/dist/analysis/fills_source.d.ts +1 -51
- package/dist/analysis/fills_source.d.ts.map +1 -1
- package/dist/analysis/fills_source.js +1 -1
- package/dist/analysis/fills_source.js.map +1 -1
- package/dist/analysis/grid_correction_check.d.ts +2 -3
- package/dist/analysis/grid_correction_check.d.ts.map +1 -1
- package/dist/analysis/grid_correction_check.js +18 -26
- package/dist/analysis/grid_correction_check.js.map +1 -1
- package/dist/analysis/resolve_source.d.ts +1 -1
- package/dist/analysis/resolve_source.d.ts.map +1 -1
- package/dist/analysis/trade_profitability.d.ts.map +1 -1
- package/dist/analysis/trade_profitability.js +2 -7
- package/dist/analysis/trade_profitability.js.map +1 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +1 -1
- package/dist/analysis/tradingview/analyze_tradingview.js +5 -0
- package/dist/analysis/tradingview/analyze_tradingview.js.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +2 -2
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +1 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +82 -10
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +1 -1
- package/dist/dexbot.d.ts.map +1 -1
- package/dist/dexbot.js +85 -140
- package/dist/dexbot.js.map +1 -1
- package/dist/market_adapter/core/asymmetric_bounds.d.ts +2 -2
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +1 -1
- package/dist/market_adapter/core/asymmetric_bounds.js +15 -12
- package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -1
- package/dist/market_adapter/core/kibana_candles.d.ts +1 -15
- package/dist/market_adapter/core/kibana_candles.d.ts.map +1 -1
- package/dist/market_adapter/core/kibana_candles.js +1 -1
- package/dist/market_adapter/core/kibana_candles.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +1 -35
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js +10 -54
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts +1 -8
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +1 -1
- package/dist/market_adapter/inputs/kibana_feed_source.js +1 -1
- package/dist/market_adapter/inputs/kibana_feed_source.js.map +1 -1
- package/dist/market_adapter/inputs/window_cache.d.ts +2 -63
- package/dist/market_adapter/inputs/window_cache.d.ts.map +1 -1
- package/dist/market_adapter/inputs/window_cache.js +22 -102
- package/dist/market_adapter/inputs/window_cache.js.map +1 -1
- package/dist/market_adapter/interval_utils.d.ts +1 -1
- package/dist/market_adapter/interval_utils.js +1 -1
- package/dist/modules/account_bots.d.ts +70 -6
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +353 -149
- package/dist/modules/account_bots.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +0 -31
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -1
- package/dist/modules/bot_defaults.d.ts +98 -0
- package/dist/modules/bot_defaults.d.ts.map +1 -0
- package/dist/modules/bot_defaults.js +169 -0
- package/dist/modules/bot_defaults.js.map +1 -0
- package/dist/modules/bot_settings.d.ts.map +1 -1
- package/dist/modules/bot_settings.js +4 -1
- package/dist/modules/bot_settings.js.map +1 -1
- package/dist/modules/config.d.ts +1 -0
- package/dist/modules/config.d.ts.map +1 -1
- package/dist/modules/config.js +1 -0
- package/dist/modules/config.js.map +1 -1
- package/dist/modules/constants.d.ts +11 -2
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +40 -27
- package/dist/modules/constants.js.map +1 -1
- package/dist/modules/credit_runtime.d.ts +0 -2
- package/dist/modules/credit_runtime.d.ts.map +1 -1
- package/dist/modules/credit_runtime.js +1 -10
- package/dist/modules/credit_runtime.js.map +1 -1
- package/dist/modules/dexbot_class.d.ts +13 -10
- package/dist/modules/dexbot_class.d.ts.map +1 -1
- package/dist/modules/dexbot_class.js +0 -9
- package/dist/modules/dexbot_class.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts +13 -0
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_cow_runtime.js +13 -1
- package/dist/modules/dexbot_cow_runtime.js.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts +1 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.js +9 -4
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
- package/dist/modules/launcher/adapter_requirement.js +1 -1
- package/dist/modules/launcher/launch_modes.d.ts +17 -1
- package/dist/modules/launcher/launch_modes.d.ts.map +1 -1
- package/dist/modules/launcher/launch_modes.js +18 -1
- package/dist/modules/launcher/launch_modes.js.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.js +8 -1
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
- package/dist/modules/market_adapter_whitelist.d.ts +40 -1
- package/dist/modules/market_adapter_whitelist.d.ts.map +1 -1
- package/dist/modules/market_adapter_whitelist.js +161 -11
- package/dist/modules/market_adapter_whitelist.js.map +1 -1
- package/dist/modules/order/accounting.d.ts +4 -18
- package/dist/modules/order/accounting.d.ts.map +1 -1
- package/dist/modules/order/accounting.js +4 -34
- package/dist/modules/order/accounting.js.map +1 -1
- package/dist/modules/order/export.d.ts +9 -12
- package/dist/modules/order/export.d.ts.map +1 -1
- package/dist/modules/order/export.js +9 -12
- package/dist/modules/order/export.js.map +1 -1
- package/dist/modules/order/grid.d.ts +44 -40
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +66 -48
- package/dist/modules/order/grid.js.map +1 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile.js +111 -20
- package/dist/modules/order/grid_reconcile.js.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts +5 -3
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.js +18 -3
- package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
- package/dist/modules/order/manager.d.ts +0 -8
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +3 -12
- package/dist/modules/order/manager.js.map +1 -1
- package/dist/modules/order/utils/order.d.ts +22 -7
- package/dist/modules/order/utils/order.d.ts.map +1 -1
- package/dist/modules/order/utils/order.js +103 -21
- package/dist/modules/order/utils/order.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts +5 -1
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +5 -2
- package/dist/modules/order/utils/system.js.map +1 -1
- package/dist/modules/order/utils/withPoolRef.d.ts +12 -0
- package/dist/modules/order/utils/withPoolRef.d.ts.map +1 -1
- package/dist/modules/order/utils/withPoolRef.js +17 -0
- package/dist/modules/order/utils/withPoolRef.js.map +1 -1
- package/dist/modules/order/working_grid.d.ts +8 -13
- package/dist/modules/order/working_grid.d.ts.map +1 -1
- package/dist/modules/order/working_grid.js +8 -29
- package/dist/modules/order/working_grid.js.map +1 -1
- package/dist/modules/settings_merge.d.ts +10 -1
- package/dist/modules/settings_merge.d.ts.map +1 -1
- package/dist/modules/settings_merge.js +27 -17
- package/dist/modules/settings_merge.js.map +1 -1
- package/dist/modules/validate_profiles.d.ts.map +1 -1
- package/dist/modules/validate_profiles.js +4 -3
- package/dist/modules/validate_profiles.js.map +1 -1
- package/dist/scripts/chart_command.d.ts +48 -0
- package/dist/scripts/chart_command.d.ts.map +1 -0
- package/dist/scripts/chart_command.js +504 -0
- package/dist/scripts/chart_command.js.map +1 -0
- package/dist/scripts/dw.d.ts +3 -0
- package/dist/scripts/dw.d.ts.map +1 -0
- package/dist/scripts/dw.js +30 -0
- package/dist/scripts/dw.js.map +1 -0
- package/dist/scripts/sync-version.js +0 -22
- package/dist/scripts/sync-version.js.map +1 -1
- package/dist/scripts/tv.d.ts +1 -31
- package/dist/scripts/tv.d.ts.map +1 -1
- package/dist/scripts/tv.js +10 -463
- package/dist/scripts/tv.js.map +1 -1
- package/dist/scripts/update.js +99 -62
- package/dist/scripts/update.js.map +1 -1
- package/dist/scripts/update_dist_freshness.d.ts +58 -0
- package/dist/scripts/update_dist_freshness.d.ts.map +1 -0
- package/dist/scripts/update_dist_freshness.js +144 -0
- package/dist/scripts/update_dist_freshness.js.map +1 -0
- package/dist/unlock.js +1 -1
- package/dist/unlock.js.map +1 -1
- package/docs/BITSHARES_ONBOARDING.md +16 -10
- package/docs/COW_INVARIANTS.md +1 -0
- package/docs/DEXBOT_COMPARISON.md +11 -11
- package/docs/EVOLUTION.md +9 -7
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +4 -4
- package/docs/GRID_PRICE_INVARIANT.md +518 -0
- package/docs/GRID_RECALCULATION.md +20 -24
- package/docs/GRID_RECONCILE.md +62 -41
- package/docs/LOGGING.md +1 -0
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +556 -0
- package/docs/README.md +18 -18
- package/docs/WORKFLOW.md +13 -8
- package/docs/architecture.md +42 -40
- package/docs/developer_guide.md +5 -8
- package/market_adapter/README.md +45 -65
- package/modules/README.md +3 -2
- package/package.json +7 -4
- package/scripts/README.md +18 -34
- package/scripts/reset-settings.sh +1 -1
- package/analysis/ama_fitting/package.json +0 -12
- package/analysis/analyze_derivatives.ts +0 -320
- package/analysis/derivative_chart_generator.ts +0 -874
- package/analysis/trend_detection/SIGNAL_DOCUMENTATION.md +0 -403
- package/analysis/trend_detection/derivative_analyzer.ts +0 -1059
- package/dist/analysis/analyze_derivatives.d.ts +0 -68
- package/dist/analysis/analyze_derivatives.d.ts.map +0 -1
- package/dist/analysis/analyze_derivatives.js +0 -287
- package/dist/analysis/analyze_derivatives.js.map +0 -1
- package/dist/analysis/derivative_chart_generator.d.ts +0 -12
- package/dist/analysis/derivative_chart_generator.d.ts.map +0 -1
- package/dist/analysis/derivative_chart_generator.js +0 -891
- package/dist/analysis/derivative_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts +0 -248
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/derivative_analyzer.js +0 -910
- package/dist/analysis/trend_detection/derivative_analyzer.js.map +0 -1
- package/dist/scripts/generate_market_adapter_whitelist.d.ts +0 -15
- package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +0 -1
- package/dist/scripts/generate_market_adapter_whitelist.js +0 -191
- package/dist/scripts/generate_market_adapter_whitelist.js.map +0 -1
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* DERIVATIVE TREND ANALYSIS
|
|
6
|
-
*
|
|
7
|
-
* Runs DerivativeAnalyzer over candle data and generates an interactive HTML chart.
|
|
8
|
-
* Trend is detected from SMA, MACD, and RSI only.
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
* node dist/analysis/analyze_derivatives.js \\
|
|
12
|
-
* --source json \
|
|
13
|
-
* --file market_adapter/data/lp/<path>/<to>/<lp-candles>.json
|
|
14
|
-
*
|
|
15
|
-
* node dist/analysis/analyze_derivatives.js \\
|
|
16
|
-
* --source market_adapter \
|
|
17
|
-
* --bot-key <bot>
|
|
18
|
-
*
|
|
19
|
-
* Output:
|
|
20
|
-
* analysis/charts/derivative_chart.html
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import path from 'node:path';
|
|
25
|
-
import { pathToFileURL } from 'node:url';
|
|
26
|
-
import { DerivativeAnalyzer } from './trend_detection/derivative_analyzer.js';
|
|
27
|
-
import { generateHTML } from './derivative_chart_generator.js';
|
|
28
|
-
import { writeChartFile } from './chart_utils.js';
|
|
29
|
-
import { PATHS } from '../modules/paths.js';
|
|
30
|
-
import { resolveSource, listAvailableBots, type SourceConfig } from './resolve_source.js';
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
interface CliConfig {
|
|
34
|
-
source: { type: string; config: SourceConfig };
|
|
35
|
-
slowSmaPeriod: number;
|
|
36
|
-
fastSmaPeriod: number | undefined;
|
|
37
|
-
minBarsForConfirmation: number;
|
|
38
|
-
macdFastPeriod: number;
|
|
39
|
-
macdSlowPeriod: number;
|
|
40
|
-
macdSignalPeriod: number;
|
|
41
|
-
macdMinHist: number;
|
|
42
|
-
trendFilter: boolean;
|
|
43
|
-
trendFilterMinBars: number;
|
|
44
|
-
momentumGateEnabled: boolean;
|
|
45
|
-
momentumGateMinBars: number;
|
|
46
|
-
momentumGateRsiZone: number;
|
|
47
|
-
fastSmaCommitmentBars: number;
|
|
48
|
-
priceRegimeGate: boolean;
|
|
49
|
-
priceRegimeMinDistancePct: number;
|
|
50
|
-
rsiPeriod: number;
|
|
51
|
-
interpConfirmBars: number;
|
|
52
|
-
interpHoldBars: number;
|
|
53
|
-
rsiZone: number;
|
|
54
|
-
rsiExtreme: number;
|
|
55
|
-
chartFile: string;
|
|
56
|
-
quiet: boolean;
|
|
57
|
-
listBots: boolean;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
interface PriceSource {
|
|
61
|
-
name: string;
|
|
62
|
-
fetchCandles(): Promise<any[]>;
|
|
63
|
-
extractMarketPrice(candle: any): { marketPrice: any; timestamp: any };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function parseArgs(): CliConfig {
|
|
67
|
-
const args = process.argv.slice(2);
|
|
68
|
-
const config: CliConfig = {
|
|
69
|
-
source: { type: 'market_adapter', config: { botKey: '' } },
|
|
70
|
-
slowSmaPeriod: 500,
|
|
71
|
-
fastSmaPeriod: undefined,
|
|
72
|
-
minBarsForConfirmation: 3,
|
|
73
|
-
macdFastPeriod: 12,
|
|
74
|
-
macdSlowPeriod: 26,
|
|
75
|
-
macdSignalPeriod: 9,
|
|
76
|
-
macdMinHist: 0.02,
|
|
77
|
-
trendFilter: false,
|
|
78
|
-
trendFilterMinBars: 3,
|
|
79
|
-
momentumGateEnabled: false,
|
|
80
|
-
momentumGateMinBars: 3,
|
|
81
|
-
momentumGateRsiZone: 35,
|
|
82
|
-
fastSmaCommitmentBars: 2,
|
|
83
|
-
priceRegimeGate: true,
|
|
84
|
-
priceRegimeMinDistancePct: 0.35,
|
|
85
|
-
rsiPeriod: 14,
|
|
86
|
-
interpConfirmBars: 3,
|
|
87
|
-
interpHoldBars: 3,
|
|
88
|
-
rsiZone: 10,
|
|
89
|
-
rsiExtreme: 90,
|
|
90
|
-
chartFile: path.join(PATHS.ANALYSIS.CHARTS_DIR, 'derivative_chart.html'),
|
|
91
|
-
quiet: false,
|
|
92
|
-
listBots: false,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
for (let i = 0; i < args.length; i++) {
|
|
96
|
-
const arg = args[i];
|
|
97
|
-
if (arg === '--source') config.source.type = args[++i];
|
|
98
|
-
else if (arg === '--bot-key') config.source.config.botKey = args[++i];
|
|
99
|
-
else if (arg === '--file') { config.source.config.filePath = args[++i]; config.source.type = 'json'; }
|
|
100
|
-
else if (arg === '--sma') config.slowSmaPeriod = parseInt(args[++i]);
|
|
101
|
-
else if (arg === '--fast-sma') config.fastSmaPeriod = parseInt(args[++i]);
|
|
102
|
-
else if (arg === '--confirm') config.minBarsForConfirmation = parseInt(args[++i]);
|
|
103
|
-
else if (arg === '--macd-fast') { config.macdFastPeriod = parseInt(args[++i]); }
|
|
104
|
-
else if (arg === '--macd-slow') { config.macdSlowPeriod = parseInt(args[++i]); }
|
|
105
|
-
else if (arg === '--macd-signal'){ config.macdSignalPeriod = parseInt(args[++i]); }
|
|
106
|
-
else if (arg === '--macd-min-hist') { config.macdMinHist = parseFloat(args[++i]); }
|
|
107
|
-
else if (arg === '--rsi') { const v = parseInt(args[i + 1]); if (!isNaN(v)) { config.rsiPeriod = v; i++; } }
|
|
108
|
-
else if (arg === '--interp-confirm') config.interpConfirmBars = parseInt(args[++i]);
|
|
109
|
-
else if (arg === '--interp-hold') config.interpHoldBars = parseInt(args[++i]);
|
|
110
|
-
else if (arg === '--rsi-zone') config.rsiZone = parseFloat(args[++i]);
|
|
111
|
-
else if (arg === '--rsi-extreme') config.rsiExtreme = parseFloat(args[++i]);
|
|
112
|
-
else if (arg === '--trend-filter') config.trendFilter = true;
|
|
113
|
-
else if (arg === '--trend-filter-min-bars') config.trendFilterMinBars = parseInt(args[++i]);
|
|
114
|
-
else if (arg === '--momentum-gate') config.momentumGateEnabled = true;
|
|
115
|
-
else if (arg === '--momentum-gate-bars') config.momentumGateMinBars = parseInt(args[++i]);
|
|
116
|
-
else if (arg === '--momentum-gate-rsi-zone') config.momentumGateRsiZone = parseFloat(args[++i]);
|
|
117
|
-
else if (arg === '--fast-sma-commitment-bars') config.fastSmaCommitmentBars = parseInt(args[++i]);
|
|
118
|
-
else if (arg === '--no-price-regime-gate') config.priceRegimeGate = false;
|
|
119
|
-
else if (arg === '--price-regime-buffer-pct') config.priceRegimeMinDistancePct = parseFloat(args[++i]);
|
|
120
|
-
else if (arg === '--chart') config.chartFile = args[++i];
|
|
121
|
-
else if (arg === '--list-bots') config.listBots = true;
|
|
122
|
-
else if (arg === '--quiet') config.quiet = true;
|
|
123
|
-
else if (arg === '--help' || arg === '-h') { showHelp(); process.exit(0); }
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return config;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function showHelp() {
|
|
130
|
-
console.log(`
|
|
131
|
-
Derivative Trend Analysis
|
|
132
|
-
|
|
133
|
-
Analyzes candle data using SMA, MACD, and RSI as trend signals.
|
|
134
|
-
Generates an interactive HTML chart.
|
|
135
|
-
|
|
136
|
-
Usage:
|
|
137
|
-
node dist/analysis/analyze_derivatives.js \\
|
|
138
|
-
--source <type> \\
|
|
139
|
-
[--bot-key KEY] [--file PATH]
|
|
140
|
-
|
|
141
|
-
Sources:
|
|
142
|
-
market_adapter Use market_adapter state (default) --bot-key KEY
|
|
143
|
-
json JSON candles file --file path/to/file.json
|
|
144
|
-
|
|
145
|
-
Analyzer options:
|
|
146
|
-
Core indicators:
|
|
147
|
-
--sma N SMA period (default 500)
|
|
148
|
-
--fast-sma N Fast SMA period (optional, enables trend filter source + fast-SMA commitment)
|
|
149
|
-
--macd-fast N MACD fast period (default 12)
|
|
150
|
-
--macd-slow N MACD slow period (default 26)
|
|
151
|
-
--macd-signal N MACD signal period (default 9)
|
|
152
|
-
--macd-min-hist N MACD histogram/line threshold (default 0.02)
|
|
153
|
-
--rsi [N] RSI period (default 14)
|
|
154
|
-
--rsi-zone N RSI bull/bear zone offset from 50 (default 10)
|
|
155
|
-
--rsi-extreme N RSI extreme threshold (default 90)
|
|
156
|
-
|
|
157
|
-
Confirmation and hysteresis:
|
|
158
|
-
--confirm N Bars required for confirmation (default 3)
|
|
159
|
-
--interp-confirm N Bars required to confirm BULL/BEAR (default 3)
|
|
160
|
-
--interp-hold N Bars to hold confirmed BULL/BEAR downgrades (default 3)
|
|
161
|
-
|
|
162
|
-
Trend filters and gates:
|
|
163
|
-
--trend-filter Enable derivative trend filter
|
|
164
|
-
--trend-filter-min-bars N Sustained bars for trend filter (default 3)
|
|
165
|
-
--momentum-gate Enable MACD+RSI recovery gate
|
|
166
|
-
--momentum-gate-bars N Momentum gate persistence (default 3)
|
|
167
|
-
--momentum-gate-rsi-zone N RSI divergence threshold (default 35)
|
|
168
|
-
--fast-sma-commitment-bars N Consecutive bars price must stay beyond fastSMA (default 2)
|
|
169
|
-
--no-price-regime-gate Disable slow-SMA macro regime gate
|
|
170
|
-
--price-regime-buffer-pct N Required slow-SMA clearance in % (default 0.35)
|
|
171
|
-
|
|
172
|
-
Source input:
|
|
173
|
-
--source <type> Data source (default market_adapter)
|
|
174
|
-
--bot-key KEY Market adapter bot key (required)
|
|
175
|
-
--file PATH JSON candle input
|
|
176
|
-
|
|
177
|
-
Output:
|
|
178
|
-
--chart FILE Chart output path (default: <analysis charts dir>/derivative_chart.html)
|
|
179
|
-
--list-bots List available bot keys from bots.json
|
|
180
|
-
--quiet Suppress log output
|
|
181
|
-
`);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
async function analyze(source: PriceSource, config: CliConfig): Promise<{
|
|
185
|
-
config: {
|
|
186
|
-
source: string;
|
|
187
|
-
slowSmaPeriod: number;
|
|
188
|
-
fastSmaPeriod: number | undefined;
|
|
189
|
-
macdFastPeriod: number;
|
|
190
|
-
macdSlowPeriod: number;
|
|
191
|
-
macdSignalPeriod: number;
|
|
192
|
-
macdMinHist: number;
|
|
193
|
-
trendFilter: boolean;
|
|
194
|
-
trendFilterMinBars: number;
|
|
195
|
-
momentumGateEnabled: boolean;
|
|
196
|
-
momentumGateMinBars: number;
|
|
197
|
-
momentumGateRsiZone: number;
|
|
198
|
-
fastSmaCommitmentBars: number;
|
|
199
|
-
priceRegimeGate: boolean;
|
|
200
|
-
priceRegimeMinDistancePct: number;
|
|
201
|
-
rsiPeriod: number;
|
|
202
|
-
interpConfirmBars: number;
|
|
203
|
-
interpHoldBars: number;
|
|
204
|
-
rsiZone: number;
|
|
205
|
-
rsiExtreme: number;
|
|
206
|
-
minBarsForConfirmation: number;
|
|
207
|
-
};
|
|
208
|
-
allResults: any[];
|
|
209
|
-
lastAnalysis: any;
|
|
210
|
-
}> {
|
|
211
|
-
if (!config.quiet) console.log(`[Derivatives] Loading candles from ${source.name}...`);
|
|
212
|
-
|
|
213
|
-
const candles = await source.fetchCandles();
|
|
214
|
-
if (!Array.isArray(candles) || candles.length === 0) {
|
|
215
|
-
throw new Error('No candles returned from source');
|
|
216
|
-
}
|
|
217
|
-
if (!config.quiet) console.log(`[Derivatives] Loaded ${candles.length} candles`);
|
|
218
|
-
|
|
219
|
-
const analyzer = new DerivativeAnalyzer({
|
|
220
|
-
slowSmaPeriod: config.slowSmaPeriod,
|
|
221
|
-
fastSmaPeriod: config.fastSmaPeriod,
|
|
222
|
-
macdFastPeriod: config.macdFastPeriod,
|
|
223
|
-
macdSlowPeriod: config.macdSlowPeriod,
|
|
224
|
-
macdSignalPeriod: config.macdSignalPeriod,
|
|
225
|
-
macdMinHist: config.macdMinHist,
|
|
226
|
-
trendFilterEnabled: config.trendFilter,
|
|
227
|
-
trendFilterMinBars: config.trendFilterMinBars,
|
|
228
|
-
momentumGateEnabled: config.momentumGateEnabled,
|
|
229
|
-
momentumGateMinBars: config.momentumGateMinBars,
|
|
230
|
-
momentumGateRsiZone: config.momentumGateRsiZone,
|
|
231
|
-
fastSmaCommitmentBars: config.fastSmaCommitmentBars,
|
|
232
|
-
priceRegimeGateEnabled: config.priceRegimeGate,
|
|
233
|
-
priceRegimeMinDistancePct: config.priceRegimeMinDistancePct,
|
|
234
|
-
rsiPeriod: config.rsiPeriod,
|
|
235
|
-
interpConfirmBars: config.interpConfirmBars,
|
|
236
|
-
interpHoldBars: config.interpHoldBars,
|
|
237
|
-
rsiBullThreshold: 50 + config.rsiZone,
|
|
238
|
-
rsiBearThreshold: 50 - config.rsiZone,
|
|
239
|
-
rsiOverboughtLevel: config.rsiExtreme,
|
|
240
|
-
rsiOversoldLevel: 100 - config.rsiExtreme,
|
|
241
|
-
minBarsForConfirmation: config.minBarsForConfirmation,
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
const allResults: any[] = [];
|
|
245
|
-
for (let i = 0; i < candles.length; i++) {
|
|
246
|
-
const { marketPrice, timestamp } = source.extractMarketPrice(candles[i]);
|
|
247
|
-
try {
|
|
248
|
-
allResults.push(analyzer.update(marketPrice, timestamp));
|
|
249
|
-
} catch (err: unknown) {
|
|
250
|
-
throw new Error(`Failed at candle ${i}: ${(err as any)?.message ?? err}`);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const last = allResults[allResults.length - 1];
|
|
255
|
-
if (!config.quiet) {
|
|
256
|
-
const parts: string[] = [];
|
|
257
|
-
if (config.slowSmaPeriod) parts.push(`SMA(${config.slowSmaPeriod}): ${last.smaRawTrend} (${last.smaBarsInTrend} bars)`);
|
|
258
|
-
if (config.fastSmaPeriod) parts.push(`fastSMA(${config.fastSmaPeriod}): ${last.fastSmaRawTrend} (${last.fastSmaBarsInTrend} bars)`);
|
|
259
|
-
parts.push(`MACD: ${last.macdTrend} hist=${last.macdHistogram}`);
|
|
260
|
-
parts.push(`RSI(${config.rsiPeriod}): ${last.rsi !== null ? last.rsi.toFixed(1) : 'n/a'} [${last.rsiZone}]`);
|
|
261
|
-
console.log(`[Derivatives] Done — ${last.isReady ? '' : '(warming up) '}${parts.join(' ')}`);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return {
|
|
265
|
-
config: {
|
|
266
|
-
source: source.name,
|
|
267
|
-
slowSmaPeriod: config.slowSmaPeriod,
|
|
268
|
-
fastSmaPeriod: config.fastSmaPeriod,
|
|
269
|
-
macdFastPeriod: config.macdFastPeriod,
|
|
270
|
-
macdSlowPeriod: config.macdSlowPeriod,
|
|
271
|
-
macdSignalPeriod: config.macdSignalPeriod,
|
|
272
|
-
macdMinHist: config.macdMinHist,
|
|
273
|
-
trendFilter: config.trendFilter,
|
|
274
|
-
trendFilterMinBars: config.trendFilterMinBars,
|
|
275
|
-
momentumGateEnabled: config.momentumGateEnabled,
|
|
276
|
-
momentumGateMinBars: config.momentumGateMinBars,
|
|
277
|
-
momentumGateRsiZone: config.momentumGateRsiZone,
|
|
278
|
-
fastSmaCommitmentBars: config.fastSmaCommitmentBars,
|
|
279
|
-
priceRegimeGate: config.priceRegimeGate,
|
|
280
|
-
priceRegimeMinDistancePct: config.priceRegimeMinDistancePct,
|
|
281
|
-
rsiPeriod: config.rsiPeriod,
|
|
282
|
-
interpConfirmBars: config.interpConfirmBars,
|
|
283
|
-
interpHoldBars: config.interpHoldBars,
|
|
284
|
-
rsiZone: config.rsiZone,
|
|
285
|
-
rsiExtreme: config.rsiExtreme,
|
|
286
|
-
minBarsForConfirmation: config.minBarsForConfirmation,
|
|
287
|
-
},
|
|
288
|
-
allResults,
|
|
289
|
-
lastAnalysis: last,
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
async function main(): Promise<void> {
|
|
294
|
-
const config = parseArgs();
|
|
295
|
-
|
|
296
|
-
try {
|
|
297
|
-
if (config.listBots) {
|
|
298
|
-
listAvailableBots();
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const { source } = resolveSource({ ...config.source.config, type: config.source.type }, { quiet: config.quiet });
|
|
303
|
-
const report = await analyze(source, config);
|
|
304
|
-
|
|
305
|
-
const html = generateHTML(report, 'Derivative Trend Analysis');
|
|
306
|
-
writeChartFile(config.chartFile, html);
|
|
307
|
-
|
|
308
|
-
if (!config.quiet) console.log(`[Derivatives] ✓ Chart saved to ${config.chartFile}`);
|
|
309
|
-
} catch (err: unknown) {
|
|
310
|
-
console.error(`[Derivatives] Error: ${(err as any)?.message ?? err}`);
|
|
311
|
-
process.exit(1);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
316
|
-
main().catch((err: unknown) => { console.error(err); process.exit(1); });
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
export { analyze }
|
|
320
|
-
|