dexbot 1.6.9 → 1.6.11
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 +34 -0
- package/README.md +1 -0
- package/analysis/README.md +50 -12
- package/analysis/bot_fitting/README.md +12 -0
- package/analysis/tradingview/README.md +15 -10
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +10 -36
- package/analysis/trend_detection/README.md +31 -0
- package/claw/modules/chain_queries.ts +9 -4
- package/claw/modules/claw_bridge.ts +9 -9
- 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.js +13 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +2 -1
- package/dist/analysis/analyze_dynamic_weight.js +0 -3
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +52 -8
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +68 -10
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.d.ts +21 -0
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +315 -0
- package/dist/analysis/bot_key_utils.js +17 -17
- package/dist/analysis/fills_cache.d.ts +64 -0
- package/dist/analysis/fills_cache.js +254 -0
- package/dist/analysis/fills_source.js +5 -2
- package/dist/analysis/pnl_report.d.ts +39 -0
- package/dist/analysis/pnl_report.js +325 -0
- package/dist/analysis/resolve_source.d.ts +0 -1
- package/dist/analysis/trade_profitability.d.ts +11 -2
- package/dist/analysis/trade_profitability.js +187 -61
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +0 -3
- package/dist/analysis/tradingview/analyze_tradingview.js +6 -19
- package/dist/analysis/tradingview/grid_reset_config.d.ts +2 -0
- package/dist/analysis/tradingview/grid_reset_config.js +18 -1
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +12 -1
- package/dist/analysis/tradingview/grid_reset_sim.js +60 -11
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +180 -33
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +102 -0
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +725 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +29 -110
- package/dist/analysis/trend_detection/huber_scale_variants.d.ts +34 -0
- package/dist/analysis/trend_detection/huber_scale_variants.js +176 -0
- package/dist/dexbot.js +19 -11
- package/dist/market_adapter/core/market_adapter_service.d.ts +15 -0
- package/dist/market_adapter/core/market_adapter_service.js +64 -5
- package/dist/market_adapter/core/strategies/ama.d.ts +1 -1
- package/dist/market_adapter/core/strategies/ama.js +5 -28
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +2 -2
- package/dist/market_adapter/core/strategies/ama_slope_model.js +12 -10
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +41 -14
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +138 -30
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +1 -2
- package/dist/market_adapter/log_format.js +1 -2
- package/dist/market_adapter/lp_chart_strategy_loader.js +2 -1
- package/dist/market_adapter/market_adapter.d.ts +0 -1
- package/dist/market_adapter/market_adapter.js +2 -27
- package/dist/market_adapter/utils/chain.d.ts +1 -1
- package/dist/market_adapter/utils/chain.js +8 -6
- package/dist/modules/account_bots.js +5 -4
- package/dist/modules/bitshares-native/resolvers.js +5 -0
- package/dist/modules/bot_settings.js +13 -1
- package/dist/modules/chain_orders.js +2 -1
- package/dist/modules/constants.d.ts +9 -1
- package/dist/modules/constants.js +55 -9
- package/dist/modules/credential_policy.js +4 -1
- package/dist/modules/credit_runtime.js +5 -1
- package/dist/modules/dexbot_maintenance_runtime.js +12 -0
- package/dist/modules/order/accounting.js +25 -0
- package/dist/modules/order/format.d.ts +35 -15
- package/dist/modules/order/format.js +62 -16
- package/dist/modules/order/manager.d.ts +1 -0
- package/dist/modules/order/manager.js +22 -1
- package/dist/modules/order/sync_engine.js +15 -1
- package/dist/modules/order/utils/order.d.ts +21 -1
- package/dist/modules/order/utils/order.js +80 -2
- package/dist/modules/order/utils/system.js +11 -1
- package/dist/modules/paths.d.ts +2 -0
- package/dist/modules/paths.js +2 -0
- package/dist/modules/utils/asset_symbols.d.ts +59 -0
- package/dist/modules/utils/asset_symbols.js +128 -0
- package/dist/modules/utils/time_range.d.ts +15 -0
- package/dist/modules/utils/time_range.js +18 -0
- package/dist/scripts/analyze-credit.js +10 -7
- package/dist/scripts/analyze-orders.js +1 -44
- package/dist/scripts/chart_command.js +15 -8
- package/dist/scripts/pnl.d.ts +3 -0
- package/dist/scripts/pnl.js +40 -0
- package/dist/scripts/verify-browser-bundle.js +8 -0
- package/dist/unlock.js +34 -0
- package/docs/DEXBOT_COMPARISON.md +3 -3
- package/docs/EVOLUTION.md +12 -10
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_RECALCULATION.md +33 -17
- package/docs/README.md +2 -2
- package/docs/WORKFLOW.md +1 -0
- package/market_adapter/README.md +6 -28
- package/package.json +1 -1
- package/scripts/README.md +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.6.11] - 2026-10-02 - AMA-Slope Persistence Gate, PnL HTML Report & Fill Cache, Five Order-Engine Safety Fixes
|
|
6
|
+
|
|
7
|
+
### 2026-10-02
|
|
8
|
+
|
|
9
|
+
- **Feat(market-adapter)**: gate AMA-slope resets behind a 3-bar persistence window and shorten the Huber lookback to 16 — two coupled default changes measured on a live 1h market-pair pool (`docs/AMA_SLOPE_WINDOW.md`). `DYNAMIC_WEIGHT_AMA_LOOKBACK_BARS` 20 → 16 buys a faster slope signal (AMA group delay 10 → 8 bars, reversal lag 22 → 20, range-tilt wrong-way 13.7% → 12.6%) at ~8% noisier bar-to-bar slope; a new persistence gate on the slope-delta reset trigger (trigger B) — `AMA_SLOPE_PERSIST_ENABLED` (true) + `AMA_SLOPE_PERSIST_BARS` (3) — requires 3 consecutive confirming bars in the same direction before the reset fires, absorbing the shorter window's extra noise. Net vs the old 20h/ungated default: resets −35% (1.45 → 0.95/day), whipsaw ~52% → ~17%, lag and tilt unchanged; the independent price/Drift trigger is unaffected. Per bot/market override via `amaSlope.persistBars` / `amaSlope.persistEnabled`; `1` = legacy fire-on-first-crossing (values `< 1` fall through to the global default). The gate is mirrored everywhere the decision path is replayed so all consumers stay on one logic path: `resolveAmaSlopePersistBars` / `advanceAmaSlopePersistence` in the service (counters persist across restarts via `normalizePersistedAmaSlopeDiagnostics` and clear on every successful reset, bootstrap included), `grid_reset_config` resolves and exports `slopePersistBars` (same override chain), `grid_reset_sim` implements the gate and its panel prints `persist K`, and the backtests follow the production default unless pinned (the fitting harness gains an optional `bandTilt` hook). New tool `analysis/trend_detection/backtest_ama_slope_huber.ts` sweeps the lookback and reports lag, reset churn and noise metrics (`--data` required). Tests: new `test_grid_reset_sim_gate.ts` (K-bar latency, 1-bar blip filtered, direction flip restarts the counter) and `testAmaSlopePersistenceGate`; existing slope-trigger tests pinned to legacy (`persistBars` 1). Verified: `tsc` clean, 305/305 tests, browser bundle 40/40 (`market_adapter/core/market_adapter_service.ts`, `analysis/tradingview/grid_reset_sim.ts`, `modules/constants.ts`, `docs/AMA_SLOPE_WINDOW.md`, `tests/test_grid_reset_sim_gate.ts`).
|
|
10
|
+
|
|
11
|
+
- **Refactor(ama)**: remove the two EMA filters and align research charts with the live engine — the AMA had accreted two independent EMA filters that both add lag to address noise the estimator now handles lag-free (the slope is a Huber-robust regression and small residuals are dead-banded): the live `ama.erSmoothPeriod` (an EMA over the raw Efficiency Ratio inside the AMA) and the research `amaEmaSpan` (`--ema`, a post-AMA input EMA in the dynamic-weight chart). Both are removed so the live engine and both research charts run one canonical 3-parameter Kaufman AMA. Live: `ama.ts` gains the 3-param constructor and drops `erSmoothAlpha`/`effectiveER` and the ER-smoothing convergence term from `getAmaWarmupBars`; `AMA_ER_SMOOTH_FAST_PERIOD` is dropped from `constants.ts`; `market_adapter.ts` / `market_adapter_service.ts` / `fetch_cex_synthetic_data.ts` / `log_format.ts` drop the ER-smoothing resolution, warmup, payload fields and the `/esN` log suffix. Research: `analyze_dynamic_weight.ts` + `dynamic_weight_chart_generator.ts` drop the `ema` knob, its Raw reference line and `--ema`; `bot_key_utils` / `resolve_source` / `grid_reset_config` stop threading `erSmoothPeriod`. Two chart divergences from the live regime gate surfaced while verifying parity are also fixed: `peNodes` (the canonical key, not `pNodes`) is passed to `bilinearInterpolate`, and the per-bar multiplier is clamped to 1.0 with 3-decimal rounding before the absolute-threshold dead-band; the AMA clip threshold always comes from `computeAmaSlopeClipThreshold`, so changing the lookback with `clip% = 0` no longer keeps a stale percentile cap. Configs still carrying `ama.erSmoothPeriod` are ignored (the default was 0, so no live behavior change in practice). Docs and tests updated. Verified: `tsc` clean, full suite 303 pass / 0 fail, browser bundle 40/40 (`market_adapter/core/strategies/ama.ts`, `modules/constants.ts`, `analysis/analyze_dynamic_weight.ts`, `analysis/dynamic_weight_chart_generator.ts`).
|
|
12
|
+
|
|
13
|
+
- **Feat(analysis)**: research tooling and findings for the AMA-slope scale bias and lookback drawdown — two research surfaces, both default-preserving and production-untouched. Scale bias: the canonical estimator's robust scale is a plug-in 1.4826·MAD of the fit's own residuals, so with two fitted parameters it reads low by ~1/(bars−1) (~13% at 8 bars, ~7% at 16) and the effective Huber constant is ~1.25 at the 16-bar window, not the nominal 1.345; `analysis/trend_detection/huber_scale_variants.ts` adds three scale modes (`none` reproduces production byte-for-byte, `df` applies the sqrt(n/(n−2)) correction, `mscale` a Huber proposal-2 M-scale) plus an outlier-fraction diagnostic, exposed via `--scale-mode` on `backtest_ama_slope_huber.ts`. Measured: compensating is decision-neutral (wobble ≤0.2%, AMA lag unchanged, resets within ≤5%, wrong-way within noise) and trades away more robustness (~0.8% RMS under 10% contamination) than it recovers in efficiency (~0.4% clean), so production keeps the uncompensated plug-in scale; the `DYNAMIC_WEIGHT_AMA_HUBER` comment records this so the next reader does not "correct" it, and a guard test asserts `none == computeHuberWindowSlopePct` bar-for-bar. Lookback drawdown: `simulatePersistentGrid` gains `params.lookbackBars` and a `--lookback` flag (unset falls back to the centralized constant), and `backtest_lookback_drawdown.ts` runs paired persistent-grid comparisons across a lookback set over one geometry grid. Finding: the window has a real per-pool effect on realized drawdown and net capture but no stable sign across pools (16h beat 12h on a long-lived liquid pool, reversed on a shorter one), so it strengthens keeping the shipped 16h without converting it into a general economic proof. Both are documented in `docs/AMA_SLOPE_WINDOW.md` with reproduction commands. Behaviour: research-only; no production logic changed (one code comment). Verified: `npm run build && npm run build:tests && node dist/tests/test_huber_scale_variants.js` (`analysis/trend_detection/huber_scale_variants.ts`, `analysis/trend_detection/backtest_lookback_drawdown.ts`, `docs/AMA_SLOPE_WINDOW.md`).
|
|
14
|
+
|
|
15
|
+
- **Feat(pnl)**: add a self-contained HTML PnL report and a per-account month-shard fill cache — `dexbot pnl` was terminal-only; a self-contained HTML report now renders per-pair 2×2 card blocks, a metrics grid and a collapsible realized-lot table (`analysis/pnl_report.ts`), wired through a thin `scripts/pnl.ts` entry and the `dexbot pnl` command. The analyzer gains `--month` (default 3), a `--pair BASE/QUOTE` filter and `--html`/`--report`, and its terminal output now shows `Net inventory delta`. Per-account `fill_order` fetches are cached in calendar-month shards (`analysis/fills_cache.ts`): settled months answer from disk, only the unsettled tail re-queries Kibana, and `--refresh-account` bypasses coverage while still merging. Account resolution checks local bot profiles before the chain (`analysis/account_resolver.ts`), and on-chain-resolved asset symbols are cached so pair filters work for non-static assets (`analysis/fills_source.ts`); `PATHS.ANALYSIS.CACHE_DIR` is added for the shard root. Doc updates: `README`, `analysis/README`, `scripts/README`, `docs/README`, `docs/WORKFLOW`, `docs/EVOLUTION`. Risk: the default lookback for the analyzer / `analysis:trade-pnl` changes from 7 days to 3 months. Verified: `tsc` root + tests clean; `tests/test_pnl_report.ts`, `tests/test_fills_cache.ts`, `tests/test_trade_profitability_fees.ts`, `tests/test_paths.ts` pass; `dexbot pnl --help` and bad-flag/missing-value paths exit correctly (`analysis/pnl_report.ts`, `analysis/fills_cache.ts`, `scripts/pnl.ts`, `docs/WORKFLOW.md`).
|
|
16
|
+
|
|
17
|
+
- **Refactor(format)**: share the 4-significant-figure funds formatter and the month→hours helper — `formatFundsValue` lived privately in `scripts/analyze-orders.ts` and trimmed trailing zeros, so four valid digits rendered as `"1.01K"` instead of `"1.010K"`, and the PnL report needed the same rule. It moves into `modules/order/format.ts` (keeps significant trailing zeros, still caps large magnitudes with K/M), and the fixed 730h/month lookback conversion shared by the chart and PnL commands is extracted into `modules/utils/time_range.ts` so they cannot disagree on `--month N`. Behavioral impact: `dexbot order` now keeps significant trailing zeros (e.g. `10000` → `"10.00K"`, `1500000` → `"1.500M"`). No caller changes beyond the import; the `format.ts` TOC is realigned to its 15 exports. Verified: `tsc` root clean; `tests/test_analyze_orders_dynamic_weight.ts` and `tests/test_dw_cli.ts` pass (`modules/order/format.ts`, `modules/utils/time_range.ts`, `scripts/analyze-orders.ts`).
|
|
18
|
+
|
|
19
|
+
- **Fix(order-engine)**: five order-engine and lifecycle safety fixes — (1) **Stop could leave a live worker behind over the running orders** (`unlock.ts`): `stop` returned as soon as the monolithic wrapper exited, but `start`'s already-running guard only checks the supervisor pid file, which is wiped on wrapper exit, so a fast stop→start could spawn a SECOND worker trading the same live orders (duplicate trades); after the wrapper exits, stop now polls `/proc` up to 15s until no dexbot worker remains (best-effort/no-op off Linux). (2) **Live `bots.json` changes did not take effect until the next fill or the 240-min fetch** (`modules/dexbot_maintenance_runtime.ts`): config pickup logged "targeted maintenance will place missing / cancel excess orders" but never ran it; it now fires the targeted drift reconciliation immediately, fire-and-forget (same callee and cooldown as the poll tick, serialized via the fill-processing lock). (3) **Live-but-slotless chain orders were invisible to fund accounting** (`modules/order/accounting.ts`): an order resting on chain without a grid slot (out-of-grid/boundary-unknown deferral) locks real funds, but `recalculateFunds` counted only grid orders, so every orphan produced a fund-invariant violation equal to its size (triggering futile recovery resyncs) and sizing could double-spend the orphan-locked funds; unmatched chain orders are now added to the on-chain committed totals (`chainBuy`/`chainSell`) with type/size validation, grid totals unchanged. (4) **An adopted orphan was then double-counted** (`modules/order/sync_engine.ts`): with (3) counting orphans as committed, adopting one into a slot left the stale record in `_lastUnmatchedChainOrders`, so it was counted twice (slot + list); both success exits of `adoptChainOrderIntoSlot` and the `createOrder` materialize branch now prune the deferred-orphan record on adoption. (5) **Freshly placed orders could be cancelled seconds after placement** (`modules/constants.ts`, `modules/order/utils/order.ts`, `modules/order/manager.ts`): spread correction and surplus sweeps run on different count snapshots within one cycle, so a fill between them made the second controller cancel what the first had just placed (fee bleed, empty levels, no net change); a new 15-minute `SURPLUS_CANCEL_GRACE_MS` window timestamps placements (`_placedAt`) when a slot gains a new `orderId`, and surplus/cancel-only cancellations skip orders inside the window and leave them queued to re-drain after it expires, covering both the batched and serial cancel paths (the batch path bypasses the per-entry check, so the drain filters fresh placements before batching); load contexts (`'grid-load'`/`'grid-init'`) are excluded so restarts do not suppress sweeps. Verified by `tests/test_accounting_logic.ts` and `tests/test_surplus_cancel_grace.ts`; `npm test` 309 files, 0 failures; `tsc --noEmit` clean (`unlock.ts`, `modules/dexbot_maintenance_runtime.ts`, `modules/order/accounting.ts`, `modules/order/sync_engine.ts`, `modules/order/manager.ts`, `tests/test_surplus_cancel_grace.ts`).
|
|
20
|
+
|
|
21
|
+
## [1.6.10] - 2026-10-01 - Huber-Robust AMA Slope, Asset-Pair Canonicalization, TradingView Indicator Ownership & View Preservation
|
|
22
|
+
|
|
23
|
+
### 2026-10-01
|
|
24
|
+
|
|
25
|
+
- **Feat(market-adapter)**: derive the AMA slope as a Huber-robust regression — the slope was a two-point endpoint estimate, `(ama[i] - ama[i-lookback]) / ama[i-lookback] / lookback`, so the window-edge bar carried full weight and one anomalous hour moved the reading as much as a tenth of the window; averaging the per-bar returns cannot help because their telescoping sum is algebraically identical to the endpoint difference. It is now a Huber-robust linear regression of `ln(AMA)` over the same window (uniform weights, no kernel), reported as log-return per bar × 100 — measured at a 20-bar window, a 1/3/5/10% single-bar AMA impulse moves the old endpoint reading by 0.050/0.150/0.250/0.499 %/bar (7×–70× the 0.0072 %/bar reset gate) while the bounded-influence fit barely moves, its second-difference energy ~25× lower than an order-statistic median's because its influence function is continuous rather than a discrete order statistic. Parameters live once in `modules/constants.ts` (`MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_HUBER`: C 1.345, 5 IRLS passes, scale floor 1e-6, zero epsilon 1e-9, aliased `AMA_SLOPE_HUBER`) and the definition once in `dynamic_weight_series.ts` (`computeHuberWindowSlopePct`), read by the dynamic-weight series, the AMA slope model, both clip paths, the grid-reset replay, the backtests and the browser charts (the generated HTML injects the same constant, so page and runtime cannot drift). Two fixes fall out of the shared definition: the estimator rejects non-positive values anywhere in the window (`Number(null) === 0` made a pre-warmup hole read as a zero price and produce a bogus −100% return), and `simulateGridResetSeries` keeps its optional `cfg.slopeEstimator` seam defaulting to the canonical estimator, so the plotted tilt and the replayed Δs trigger measure one quantity by construction. Operational note: `slopePct` is a different quantity from any pre-Huber reading, so the first post-deploy cycle compares Huber against the persisted baseline; magnitudes agree closely (delta below the reset gate on 98% of bars, p50 0.00043, p90 0.00277), i.e. roughly one whitelisted bot in fifty costs one extra recenter, once, and no version marker suppresses it. Tests were converted, not weakened (geometric-ramp fixtures in place of the 0 %/bar order-statistic fixtures, a browser-execution guard asserting the generated estimator matches the Node module bar for bar). Validation: `tsc` src+tests clean, `node dist/scripts/run-tests.js` exit 0, `verify:browser-bundle` 40/40 (`market_adapter/core/strategies/ama_slope_model.ts`, `market_adapter/core/strategies/dynamic_weight_series.ts`, `modules/constants.ts`, `analysis/tradingview/grid_reset_sim.ts`, `docs/GRID_RECALCULATION.md`, `tests/test_ama_slope_model.ts`, `tests/test_backtest_bot_fitting_logic.ts`).
|
|
26
|
+
|
|
27
|
+
- **Feat(asset-symbols)**: centralize uppercase canonicalization of asset pairs — BitShares stores symbols UPPERCASE but a node answers a lowercase lookup without error, so a mis-cased `assetA`/`assetB` is a silent-wrong-answer bug rather than a loud one: the lowercase spelling travels on into the resolved symbol, cache keys, Kibana query terms, chart titles and the exported HTML. Two real defects came out of this: `dexbot tv`/`dw` forwarded the raw CLI string as the asset symbol, and the market-profile lookup in `analysis/bot_key_utils` compared `assetA`/`assetB` with a strict `===`, so a case-only difference between `bots.json` and `market_profiles.json` silently dropped the whole AMA/grid config. New `modules/utils/asset_symbols.ts` is the single definition of the rule (`normalizeAssetSymbol`/`normalizeAssetRef`, `isAssetObjectId`, `isSameAssetSymbol`, `splitPairTarget`, `canonicalizeBotAssetSymbols`); object ids (`1.3.x`) pass through verbatim so ref-routing callers keep their `get_assets` vs `lookup_asset_symbols` branch and only real symbols are rewritten. Applied at every boundary that accepts a pair from a human or hands a symbol to the chain (chain/order/system resolvers, the `bot_settings.ts` and `bot_key_utils.ts` read funnels sharing `canonicalizeBotAssetSymbols`, credit/credential cache keys, `dexbot.ts` collateral, `scripts/{analyze-credit,chart_command}.ts`, `claw/modules/{claw_bridge,chain_queries}.ts`), and de-duplicates the ad-hoc uppercase copies in `optimizer_high_resolution.ts`. Behavioral impact: a lowercase pair is normalized end to end, so `assetA === 'BTS'` checks, `getBtsSide` and market-profile matching behave identically for hand-edited lowercase `bots.json`; `botKey` is unaffected (`createBotKey` already ran the case-insensitive `sanitizeKey`) and no config file is rewritten. Coverage: `tests/test_asset_symbol_normalization.ts` (uppercase-on-the-wire at every boundary, id pass-through, non-mutation, `debtPolicy` handling, claw pair contract); `npm test` 300 pass / 0 fail, `verify:browser-bundle` 39 pass, `tsc --noEmit` clean for root and claw.
|
|
28
|
+
|
|
29
|
+
- **Chore(market-adapter)**: raise the AMA-slope lookback default from 9 to 20 bars — measured over the real 1h pools, 20 vs 9 cuts the slope's bar-to-bar wobble ~34% and slope-driven grid resets ~19% at an unchanged band-tilt magnitude; the cost is freshness, with the window centre moving from ~4.5 to ~10 bars back. The whole 5–32 range was measured rather than guessed: noise and resets fall monotonically with the window and lag grows linearly, with no knee, so 20 is a deliberate point on a straight dial. Scope note: the constant is not only the grid-reset trigger window, it is also the default for the live dynamic-weight / grid-range-scaling slope (`ama_slope_model.ts`), so the directional weight shift follows the same longer average — a live trading behaviour change, not a reset-only change. Operational impact: `readyBars = erPeriod + lookbackBars`, so post-restart convergence is ~11 bars longer, and persisted slope snapshots are re-normalized through `normalizePersistedAmaSlopeDiagnostics` on the first cycle after restart — watch that first restart for one off-cycle Δs reset. The gitignored deployment override in `profiles/general.settings.json` was set to 20 as well, so the code default and the running config agree (`modules/constants.ts`).
|
|
30
|
+
|
|
31
|
+
- **Fix(tradingview)**: share one AMA-slope lookback across the band and the reset replay — the chart resolved the slope window twice: `computeRangeBand` read the embedded constant (`payload.rangeSlope.lookbackBars`) while `buildGridResetSeries` passed the bot-configured `gridSimCfg.lookbackBars` (`grid_reset_config` had already resolved it from the bot's own `amaSlope.lookbackBars`), so a bot with its own lookback got it in the replayed Δs trigger but not in the plotted range band, silently misrepresenting the bot. Both now route through one `resolveSlopeLookbackBars()` that prefers the resolved grid-sim value and falls back to the embedded constant for pool/pair charts, which carry no grid-sim data. No UI change: the untilted band stays span-symmetric, the toolbar is unchanged, and the reset panel reports exactly what it did before. Chart-only, no runtime or bot behaviour change. Verified: `typecheck` + `build:tests`, `tests/test_tradingview_chart_storage_key.ts` (16 checks), and a local Firefox check that a bot-configured 32h lookback paints the independently computed 32h geometry rather than the constant's (`analysis/tradingview/tradingview_uplot_chart_generator.ts`, `analysis/tradingview/README.md`, `tests/test_tradingview_chart_storage_key.ts`).
|
|
32
|
+
|
|
33
|
+
- **Fix(tradingview)**: keep the chart view when toggling Range / Scale — the `Scale` toggle cleared `manualYRange` and both toggles rerendered without keeping the X range, so the rerender's X restore fired the rAF price refit, which follows the band envelope (`visiblePriceRange` returns the band when Range + Scale + AMA are on); the price axis jumped to the band fit on set and back to the candle fit on unset though the data and the visible window were unchanged. New `captureView()`/`preserveView(fn)` snapshot X and Y, run the toggle, then re-assert X and restore Y through a one-shot `pendingViewY` applied inside the refit's own rAF after the autofit, so the refit cannot win the frame; `Range` on/off, `Scale` on/off and the grid-span slider are wrapped in `preserveView(...)`. It deliberately does not set `manualYRange`, so a later X pan still autofits and a user price lock is respected; the band axis-fit lands on the next autofit (reload, timeframe switch, X pan) or a double-click of the price axis. Verified (Playwright, X/Y scale + axis-pixel diffs): both axes stay byte-identical across every toggle and a span-slider drag, and a manual Y lock still blocks the autofit. Risk: low — view behaviour only, no band/AMA/order-math change (`analysis/tradingview/tradingview_uplot_chart_generator.ts`, `analysis/tradingview/README.md`).
|
|
34
|
+
|
|
35
|
+
- **Feat(tradingview)**: auto opt-in for Range/Scale and widen the span slider to 1.3x-2.1x — the band min/max are built from the live AMA price and Scale additionally sizes it by AMA slope, but the toggles were independent, so Scale-on with Range/AMA off produced a silently dead toggle (the draw hook and the axis fit both bail out on `!currentAmaEnabled`). New `autoOptInAma()` pushes the dependency one way (Range → AMA, Scale → Range + AMA; switching an indicator off never disables its dependencies) and returns whether AMA actually flipped, so the caller takes the AMA-toggle render path (`rerender(false)`, series added) instead of the keep-view one; switching AMA off takes Range and Scale down with it, and the same chain is re-applied when hydrating localStorage state, so a chart saved with Scale on and AMA off cannot silently come back with a working AMA. Behavior note: a chart generated with `--range` or `--range-scale` plus `--no-ama` now renders the AMA line (that combination was already a dead band). The span slider range moves 1.2x-2.0x → 1.3x-2.1x (default 1.55x unchanged); the bounds, previously hardcoded in six places and already drifted once, are now `RANGE_SPAN_MIN/MAX/DEFAULT` at module scope interpolated into the generated page, so slider, tooltip and every clamp share one source of truth (the 0.05 step still lands exactly on 2.10). Verified: `tsc --noEmit`, the generated page's inline script through `node --check`, a slider/clamp spot-check in a regenerated chart (`min="1.3" max="2.1"`), `tests/test_tradingview_chart_storage_key.ts` (14 checks) (`analysis/tradingview/tradingview_uplot_chart_generator.ts`, `analysis/tradingview/README.md`).
|
|
36
|
+
|
|
37
|
+
- **Refactor(tradingview)**: drop the Range/Scale/AMA on-off CLI flags — `--range`, `--no-range`, `--range-scale` and `--no-ama` only set indicator state that the in-chart toolbar owns and persists per chart (localStorage), so a chart regenerated with a different flag combination silently overrode the user's choice; worse, they could disagree (`--no-ama` with the range highlight on produced a dead band, since the band min/max are built from the AMA price). The four flags are gone from the config, the defaults, the parser and the payload in `analyze_tradingview.ts` — and no longer warn, since indicator state has exactly one owner. AMA stays auto-enabled for `gridPrice` `ama`/`ama1-4` bots as before; only the manual override is gone. `rangeEnabled`/`rangeScaleEnabled` are pinned off at generation time (already their effective default) while the payload keys stay so state hydration keeps its shape. `--range-span` and `--no-sma`/`--no-vwap` are untouched: the span has a real generation-time default derived from the bot grid ratio, and the other two are plain switches for indicators with no dependencies. Docs: `analysis/tradingview/README.md` + `analysis/README.md`; historical CHANGELOG entries keep the old flags, since they record what those releases shipped. Verified: `npx tsc --noEmit`, a regenerated chart ignores the removed flags and renders the range/ama toggles unchecked with payload `rangeEnabled`/`rangeScaleEnabled` false, the inline script through `node --check`, `tests/test_tradingview_chart_storage_key.ts` (14 checks) (`analysis/tradingview/analyze_tradingview.ts`, `analysis/tradingview/tradingview_uplot_chart_generator.ts`).
|
|
38
|
+
|
|
5
39
|
## [1.6.9] - 2026-09-30 - Market-Adapter Cycle CPU & Off-Hour Idle, Grid Spread-Tightening Correction
|
|
6
40
|
|
|
7
41
|
### 2026-09-29
|
package/README.md
CHANGED
|
@@ -338,6 +338,7 @@ dexbot enable {all|<bot>} # Enable bot in config
|
|
|
338
338
|
dexbot stat # Runtime status (unlock or PM2)
|
|
339
339
|
dexbot order [<bot>] # Analyze order grids (--export → HTML to analysis/charts/)
|
|
340
340
|
dexbot tv <bot|pool|A/B> # TradingView 1h chart with AMA overlay (default: 3 months)
|
|
341
|
+
dexbot pnl <bot|account> # HTML PnL report (--month N, optional --pair A/B)
|
|
341
342
|
dexbot credit [<bot>] # Live summed MPA + borrowed-credit positions
|
|
342
343
|
dexbot export <bot> # Export trades + settings (CSV/JSON) for analysis/
|
|
343
344
|
|
package/analysis/README.md
CHANGED
|
@@ -21,6 +21,7 @@ Tools that inspect DEXBot trading behavior and the market data it operates on. O
|
|
|
21
21
|
| Tool | Ask this when… | One-line command |
|
|
22
22
|
|------|----------------|------------------|
|
|
23
23
|
| [`trade_profitability.ts`](#trade-profitability-analyzer-trade_profitabilityts) | "Is my bot making money?" — PnL, R-multiples, drawdown | `npm run analysis:trade-pnl -- <account-id>` |
|
|
24
|
+
| [`dexbot pnl`](#pnl-html-report-dexbot-pnl) | "Give me a readable PnL report" — self-contained HTML with a lot table | `dexbot pnl <bot\|account> --month 3` |
|
|
24
25
|
| [`grid_correction_check.ts`](#last-fill-guard-check-grid_correction_checkts) | "Are fills respecting the pivot ± half-increment guard?" | `npm run analysis:grid-check -- --bot-key <bot-key>` |
|
|
25
26
|
| [`analyze_risk_profile.ts`](#risk-profile-analyzer-analyze_risk_profilets) | "How wide should my Safe Range clamps be?" | `node dist/analysis/analyze_risk_profile.js --bot-key <bot-key>` |
|
|
26
27
|
| [`analyze_trade_heatmap.ts`](#trade-heatmap-analyze_trade_heatmapts) | "Where did trade volume cluster vs the AMA?" | `node dist/analysis/analyze_trade_heatmap.js --bot-key <bot-key>` |
|
|
@@ -130,20 +131,28 @@ Metrics include:
|
|
|
130
131
|
|
|
131
132
|
Fetches `fill_order` operations for a BitShares account from Kibana within a specified time range, then computes realized PnL via sequential (LIFO) or FIFO inventory tracking per asset pair.
|
|
132
133
|
|
|
133
|
-
**Pipeline:** Kibana fill query → on-chain asset precision resolution → buy/sell classification → chronological matching (sequential LIFO by default) → per-pair summary + optional per-match detail.
|
|
134
|
+
**Pipeline:** Kibana fill query → on-chain asset precision resolution → buy/sell classification → chronological matching (sequential LIFO by default) → per-pair summary + optional per-match detail, or a self-contained HTML report (`--html`).
|
|
134
135
|
|
|
135
|
-
**Account resolution:** an account name
|
|
136
|
+
**Account resolution:** a bot profile name, an account name, or a bare `1.2.x` ID is resolved through the shared `account_resolver.ts` helper. A local bot profile is checked **first** (no chain call), then a stored `accountId`, then the chain; the resolved ID is stamped onto the matching `profiles/bots.json` entry, so later runs resolve offline. `--refresh-account` forces a fresh lookup.
|
|
137
|
+
|
|
138
|
+
`dexbot pnl` is the HTML front door (see [`scripts/README.md`](../scripts/README.md)); the raw analyzer below defaults to terminal tables.
|
|
136
139
|
|
|
137
140
|
```bash
|
|
138
|
-
#
|
|
141
|
+
# HTML report for a local bot, last 3 months (dexbot pnl wraps this)
|
|
142
|
+
dexbot pnl my-bot --month 3
|
|
143
|
+
|
|
144
|
+
# HTML report for a raw account, filtered to one pair
|
|
145
|
+
dexbot pnl 1.2.123456 --month 6 --pair TOKENA/BTS
|
|
146
|
+
|
|
147
|
+
# Terminal output: account by ID, last 3 months (default)
|
|
139
148
|
node dist/analysis/trade_profitability.js 1.2.123456
|
|
140
149
|
|
|
141
|
-
# Account by name (
|
|
142
|
-
node dist/analysis/trade_profitability.js "my-account-name" --
|
|
150
|
+
# Account by profile/account name (local profiles first)
|
|
151
|
+
node dist/analysis/trade_profitability.js "my-account-name" --month 1
|
|
143
152
|
|
|
144
|
-
# Absolute window with
|
|
153
|
+
# Absolute window with pair filter
|
|
145
154
|
node dist/analysis/trade_profitability.js 1.2.123456 \
|
|
146
|
-
--start 2026-07-01 --end 2026-07-07 --
|
|
155
|
+
--start 2026-07-01 --end 2026-07-07 --pair TOKENA/BTS
|
|
147
156
|
|
|
148
157
|
# Export trade log and full analysis
|
|
149
158
|
node dist/analysis/trade_profitability.js 1.2.123456 \
|
|
@@ -158,25 +167,31 @@ node dist/analysis/trade_profitability.js 1.2.123456 \
|
|
|
158
167
|
|
|
159
168
|
| Flag | Default | Description |
|
|
160
169
|
|------|---------|-------------|
|
|
170
|
+
| `--month <n>` | `3` | Lookback months (730 h each; alias `--months`) |
|
|
161
171
|
| `--start <iso>` | — | Start time (ISO 8601) |
|
|
162
172
|
| `--end <iso>` | — | End time |
|
|
163
|
-
| `--hours <n>` |
|
|
173
|
+
| `--hours <n>` | — | Lookback hours (alternative to month/start/end) |
|
|
174
|
+
| `--pair <BASE/QUOTE>` | all | Filter to one pair by symbol or `1.3.x` id |
|
|
164
175
|
| `--asset <id>` | all | Filter to one base asset ID |
|
|
165
|
-
| `--refresh-account` | off | Force re-resolution and
|
|
176
|
+
| `--refresh-account` | off | Force re-resolution and bypass the fills cache (re-query the range) |
|
|
177
|
+
| `--html` | off | Write a self-contained HTML report instead of terminal tables |
|
|
178
|
+
| `--report <file>` | auto | Override the report path (implies `--html`) |
|
|
166
179
|
| `--csv <file>` | — | Export chronologically sorted trade list |
|
|
167
180
|
| `--json <file>` | — | Export full analysis with per-pair PnL data |
|
|
168
181
|
| `--match-mode <mode>` | `sequential` | Matching mode: `sequential` (LIFO, default) or `fifo` |
|
|
169
|
-
| `--trades` | off | Show per-order PnL detail (
|
|
182
|
+
| `--trades` | off | Show per-order PnL detail (terminal mode only) |
|
|
170
183
|
| `--fee-per-order <bts>` | `0.09652` | Blockchain fee per limit_order_create op (BTS); approximate |
|
|
171
184
|
| `--verbose` | off | Print per-pair trade counts during processing |
|
|
172
185
|
|
|
173
186
|
</details>
|
|
174
187
|
|
|
188
|
+
**Fill cache:** per-account `fill_order` fetches are cached in calendar-month shards under `<analysis>/cache/fills/<accountId>.shard_YYYY-MM.json` (see `fills_cache.ts`). A settled month is answered from disk with zero queries; only the still-unsettled tail (the last ~6 h before the previous query, where Kibana may still index late fills) is re-queried. `--refresh-account` ignores coverage and re-queries the requested range (merging, so it never drops fills outside that span). Delete the shard files to reset the cache.
|
|
189
|
+
|
|
175
190
|
**Asset precision handling:**
|
|
176
191
|
|
|
177
192
|
1. Assets listed in the static `ASSETS` table (BTS, TWENTIX, XBTSX.*, HONEST.*, IOB.*, etc.) resolve instantly.
|
|
178
193
|
2. Unknown assets are resolved on-chain via `get_assets` against the built-in node pool, with results cached at runtime.
|
|
179
|
-
3. If resolution fails or an asset is not found on chain, the affected fills are **skipped** with a warning (no abort).
|
|
194
|
+
3. If resolution fails or an asset is not found on chain, the affected fills are **skipped** with a warning (no abort). Symbols learned on-chain are cached too, so `--pair SYMBOL/QUOTE` works even for assets absent from the static table.
|
|
180
195
|
|
|
181
196
|
**PnL methodology:**
|
|
182
197
|
|
|
@@ -220,6 +235,27 @@ node dist/analysis/trade_profitability.js 1.2.123456 \
|
|
|
220
235
|
|
|
221
236
|
</details>
|
|
222
237
|
|
|
238
|
+
### PnL HTML Report (`dexbot pnl`)
|
|
239
|
+
|
|
240
|
+
`dexbot pnl` is the HTML front door: it resolves the account, fetches fills (through the fill cache), computes the same realized-lot PnL as the terminal analyzer, and renders a single self-contained HTML file via `analysis/pnl_report.ts`. No network, CDN, or sibling assets — it opens from a `file://` link anywhere. The file lands under the analysis `charts/` directory (or the path given to `--report`).
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
# Local bot profile, last 3 months
|
|
244
|
+
dexbot pnl my-bot
|
|
245
|
+
|
|
246
|
+
# Raw account, one pair, generated path printed on exit
|
|
247
|
+
dexbot pnl 1.2.123456 --month 6 --pair TOKENA/BTS
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Per pair the report shows:
|
|
251
|
+
|
|
252
|
+
- **Hero** — account (bot name + `1.2.x` id), period, pair/lot counts, match mode, active filters.
|
|
253
|
+
- **Card blocks (2x2 left + 2x2 right)** — left = money (Gross PnL, Net PnL, Volume, Fees); right = position/activity (Realized lots, Net inventory Δ, Avg buy/sell, Unmatched sold). When both market and blockchain fees exist they collapse into one `Fees` card so the block stays 2x2.
|
|
254
|
+
- **Metrics grid** — Edge, Risk, Distribution, Behavior & activity: the same metric set as the terminal output (see the metrics glossary above).
|
|
255
|
+
- **Realized lots table** — collapsible per-match detail (entry/exit time, prices, gross/net PnL, fees, maker/taker legs), capped at 2,000 rows — use `--csv` for the full list.
|
|
256
|
+
|
|
257
|
+
All amounts use the shared 4-significant-figure formatter (compact `K`/`M`, significant trailing zeros kept) — the same one `dexbot order` uses. `--refresh-account` re-resolves the account and bypasses the fill cache (see [Fill cache](#trade-profitability-analyzer-trade_profitabilityts)).
|
|
258
|
+
|
|
223
259
|
### LAST-FILL-GUARD Check (`grid_correction_check.ts`)
|
|
224
260
|
|
|
225
261
|
Validates LAST-FILL-GUARD discipline from the same Kibana fill pipeline as `trade_profitability.ts`. For a previous fill at price `x` and grid increment `i`, the next order must satisfy `BUY < x × (1 − i/2/100)` and `SELL > x × (1 + i/2/100)`, regardless of the previous fill's side. A violation is a buy or sell fill inside the prohibited half-increment band around its pivot.
|
|
@@ -306,7 +342,7 @@ node dist/analysis/analyze_trade_heatmap.js \
|
|
|
306
342
|
|
|
307
343
|
### TradingView Chart (`tradingview/analyze_tradingview.ts`)
|
|
308
344
|
|
|
309
|
-
Generates a standalone TradingView-style HTML chart with candle OHLC, SMA, AMA, VWMA, and volume panel. For AMA-grid bots it also replays the market adapter's grid resets (AMA-price Δ / AMA-slope Δ) using the thresholds resolved from `general.settings` / `market_adapter_settings` — see [tradingview/README.md](tradingview/README.md#grid-reset-simulation) and [docs/GRID_RECALCULATION.md](../docs/GRID_RECALCULATION.md). See [tradingview/README.md](tradingview/README.md) for full documentation.
|
|
345
|
+
Generates a standalone TradingView-style HTML chart with candle OHLC, SMA, AMA, VWMA, and volume panel. For AMA-grid bots it also replays the market adapter's grid resets (AMA-price Δ / AMA-slope Δ) using the thresholds resolved from `general.settings` / `market_adapter_settings` — see [tradingview/README.md](tradingview/README.md#grid-reset-simulation) and [docs/GRID_RECALCULATION.md](../docs/GRID_RECALCULATION.md). Indicator state is set in the chart toolbar, not on the command line (`SMA`, `AMA`, `VWMA`, `Range`, `Scale` checkboxes; `Range` / `Scale` opt into the AMA they are derived from), and the toolbar choice is remembered per chart in the browser. See [tradingview/README.md](tradingview/README.md) for full documentation.
|
|
310
346
|
|
|
311
347
|
# Recommended one-step: bot, pool, or pair (fetches candles + renders, default 3 months)
|
|
312
348
|
dexbot tv <bot-key>
|
|
@@ -492,6 +528,8 @@ Details: [bot_fitting/README.md](bot_fitting/README.md)
|
|
|
492
528
|
| `account_resolver.ts` | Account resolution for all tools: `preferredAccount` / `--account` → `1.2.x`, stamping the result into `profiles/bots.json` |
|
|
493
529
|
| `chain_pool.ts` | Ephemeral read-only chain client over the built-in node pool (account + asset lookups) |
|
|
494
530
|
| `fills_source.ts` | Shared `fill_order` Kibana fetch/query and the static asset-precision table + on-chain cache |
|
|
531
|
+
| `fills_cache.ts` | Per-account month-shard cache for `fill_order` fetches (settled months reused, unsettled tail refreshed) |
|
|
532
|
+
| `pnl_report.ts` | Self-contained HTML PnL renderer: hero, card blocks, metrics grid, realized-lots table |
|
|
495
533
|
|
|
496
534
|
On-chain account and asset lookups in the fill-based tools go through `account_resolver.ts` / `fills_source.ts` (both built on `chain_pool.ts`): tool scripts must not open their own read-only clients or carry their own node list. The batch backfill `resolve_bot_accounts.ts` is the exception — it reuses the production chain client over one connection.
|
|
497
535
|
|
|
@@ -14,6 +14,9 @@ For each of the 4 AMA strategies, it searches for best:
|
|
|
14
14
|
|
|
15
15
|
- `backtest_bot_fitting.ts` — lightweight sweep across spread / increment / ratio with unit-size percentage-point accounting and risk scoring
|
|
16
16
|
- `backtest_ama_sweep.ts` — persistent grid simulation with capital-weighted sizing, weight profiles, and worker-thread parallelization
|
|
17
|
+
- `backtest_lookback_drawdown.ts` — paired Huber-lookback comparison of
|
|
18
|
+
drawdown / net capture / reset churn (geometry fixed); see
|
|
19
|
+
`docs/AMA_SLOPE_WINDOW.md`
|
|
17
20
|
- `shared_utils.ts` — shared helpers (argument parsing, data loading, formatting)
|
|
18
21
|
|
|
19
22
|
Both simulators share the same production grid model (ported once in
|
|
@@ -84,8 +87,17 @@ node dist/analysis/bot_fitting/backtest_bot_fitting.js \
|
|
|
84
87
|
node dist/analysis/bot_fitting/backtest_ama_sweep.js \
|
|
85
88
|
--data <path-to-lp-candles.json> \
|
|
86
89
|
--results <path-to-optimization-results.json>
|
|
90
|
+
|
|
91
|
+
# Paired lookback drawdown comparison (no --results needed)
|
|
92
|
+
node dist/analysis/bot_fitting/backtest_lookback_drawdown.js \
|
|
93
|
+
--data market_adapter/data/lp/<market-pair> \
|
|
94
|
+
--lookbacks 12,14,16,20
|
|
87
95
|
```
|
|
88
96
|
|
|
97
|
+
> `backtest_ama_sweep.ts` accepts `--lookback <bars>` to override the slope
|
|
98
|
+
> window (`DYNAMIC_WEIGHT_AMA_LOOKBACK_BARS`); `backtest_lookback_drawdown.ts`
|
|
99
|
+
> builds on it and reports the paired per-lookback deltas.
|
|
100
|
+
|
|
89
101
|
> `backtest_bot_fitting.ts` auto-derives `--results` from the `--data` filename
|
|
90
102
|
> (`analysis/ama_fitting/optimization_results_<base>_w<λ1>_<λ2>_<λ3>_<λ4>.json`,
|
|
91
103
|
> newest `_w*` file matching the base name; falls back to the legacy
|
|
@@ -38,9 +38,9 @@ The sections below cover manual usage (explicit candle files, direct runner flag
|
|
|
38
38
|
- Pair-orientation switcher for `A/B` and `B/A`
|
|
39
39
|
- SMA overlay
|
|
40
40
|
- AMA preset buttons `1–4` (one-click AMA1–4, active preset highlighted); numeric inputs kept
|
|
41
|
-
- Bot-grid range highlight, off by default (the bot's min/max around AMA with live asymmetric tilt; red above AMA, green below)
|
|
41
|
+
- Bot-grid range highlight, off by default (the bot's min/max around AMA with live asymmetric tilt; red above AMA, green below). `Range` and `Scale` are AMA-derived, so turning one on opts into what it needs: `Range` → `AMA`, `Scale` → `Range` + `AMA`; turning `AMA` off takes `Range` and `Scale` back down with it, so the toggles never sit in a dead state. One-way opt-in is re-applied on load, so a chart saved with `Scale` on renders its band.
|
|
42
42
|
- Grid-reset simulation (AMA bots, on by default): replays the market adapter's two recentering triggers over the candle history — the accepted grid center as a step line, the simulated grid range around it, and a marker per reset (`init` = first AMA snapshot, `Δ1` = AMA-price Δ, `Δs` = AMA-slope Δ). Thresholds come from the live config chain; a bottom-left panel shows the values, where they came from, and the reset counts (see [Grid-Reset Simulation](#grid-reset-simulation))
|
|
43
|
-
- Range-scale switch: fit the price axis to the range band
|
|
43
|
+
- Range-scale switch: fit the price axis to the range band. Toggling `Range` / `Scale` (or dragging the grid-span slider) keeps the current view — the price axis is not refitted under the cursor; the band-fit applies on the next autofit (reload, timeframe switch, x pan) or immediately on a double-click of the price axis. Opting into `Scale`/`Range` also opts into the indicators they need (see above)
|
|
44
44
|
- VWMA overlay
|
|
45
45
|
- Order overlay for bot charts (active grid buys/sells as dashed levels, reserve line at the lowest grid buy, ceiling line at the highest grid sell, spread label; pair-aware, toggle in-chart)
|
|
46
46
|
- Market panel (top-right): `SELL` / `Market` / `BUY` rows with distance-to-market %
|
|
@@ -175,6 +175,8 @@ market_adapter/data/lp/<pair>/lp_pool_<id>_<interval>.json
|
|
|
175
175
|
|
|
176
176
|
## CLI Flags
|
|
177
177
|
|
|
178
|
+
Indicator on/off state is not a generation-time flag: `SMA`, `VWMA`, `AMA`, `Range` and `Scale` are in-chart toolbar toggles, persisted per chart in `localStorage`, and `Range` / `Scale` opt into the AMA they are derived from. The `--range`, `--no-range`, `--range-scale` and `--no-ama` flags were removed — they duplicated the toolbar and could disagree with it (`--no-ama` on a chart with a range band produced a dead band). Nothing in this table sets an indicator on or off; only `--range-span` sizes the band.
|
|
179
|
+
|
|
178
180
|
| Flag | Description | Default |
|
|
179
181
|
|------|-------------|---------|
|
|
180
182
|
| `--source <json\|market_adapter>` | Data source type | `json` |
|
|
@@ -189,16 +191,12 @@ market_adapter/data/lp/<pair>/lp_pool_<id>_<interval>.json
|
|
|
189
191
|
| `--ama-slow-period <n>` | AMA slow period | `83.6` |
|
|
190
192
|
| `--vwap-bars <n>` | Rolling VWMA window | `500` |
|
|
191
193
|
| `--no-sma` | Disable SMA | — |
|
|
192
|
-
| `--no-ama` | Disable AMA | — |
|
|
193
194
|
| `--no-vwap` | Disable VWMA | — |
|
|
194
|
-
| `--range` | Enable range highlight (off by default; toggle in-chart) | off |
|
|
195
|
-
| `--no-range` | Disable range highlight | — |
|
|
196
|
-
| `--range-scale` | Range Scaling: size the band by AMA slope like the grid build + fit price axis to it | — |
|
|
197
195
|
| `--no-grid-reset` | Render without the grid-reset simulation (toggle it back in the chart) | on for AMA bots |
|
|
198
196
|
| `--grid-delta-pct <n>` | Override the AMA-price Δ threshold for the simulation (skips config resolution) | config |
|
|
199
197
|
| `--grid-slope-delta-pct <n>` | Override the AMA-slope Δ threshold for the simulation, in %/bar | config |
|
|
200
198
|
| `--grid-warmup <bars>` | Override the simulation start bar (skipped before the first accepted center) | AMA warmup |
|
|
201
|
-
| `--range-span <mult>` | x-range around AMA, 1.
|
|
199
|
+
| `--range-span <mult>` | x-range around AMA, 1.3–2.1 (default: bot grid setting) | bot grid |
|
|
202
200
|
| `--orders-file <path>` | Order-grid JSON override for the overlay (default: `profiles/orders/<botKey>.json`) | bot orders |
|
|
203
201
|
| `--no-orders` | Disable the order overlay (levels, reserve/ceiling lines, spread label) | — |
|
|
204
202
|
| `--update-marker-ts <sec>` | Draw an "updated from here" line at the given unix timestamp | — |
|
|
@@ -273,13 +271,20 @@ so the chart cannot drift from the runtime. The panel labels the winning layer;
|
|
|
273
271
|
|
|
274
272
|
The replay runs in the page, so the AMA series (and therefore the trigger
|
|
275
273
|
points) follows the AMA inputs and preset buttons; the gating parameters that
|
|
276
|
-
would come from config (`erPeriod`, lookback, warmup, clip percentile) are fixed
|
|
277
|
-
at generation time.
|
|
278
|
-
|
|
274
|
+
would come from config (`erPeriod`, lookback, warmup, clip percentile, persistence gate) are fixed
|
|
275
|
+
at generation time. One slope window is shared by every consumer: the resolved
|
|
276
|
+
`lookbackBars` drives both the replayed `Δs` trigger and the `Scale` band tilt,
|
|
277
|
+
so a bot-configured lookback can no longer leave the plotted band measuring a
|
|
278
|
+
different slope than the trigger does (the shared constant remains the fallback
|
|
279
|
+
for pool/pair charts, which carry no grid-sim data), and both average with the
|
|
280
|
+
chart's selected slope model (see Notes). The replay uses the
|
|
281
|
+
canonical `simulateGridResetSeries()` from
|
|
282
|
+
`analysis/tradingview/grid_reset_sim.ts`, embedded verbatim via
|
|
279
283
|
`embedFunctionSources` — not a hand copy of the adapter logic.
|
|
280
284
|
|
|
281
285
|
## Notes
|
|
282
286
|
|
|
287
|
+
- **Slope averaging.** The AMA slope is a **Huber-robust linear regression of `ln(AMA)` over the lookback window** — `computeHuberWindowSlopePct` in `market_adapter/core/strategies/dynamic_weight_series.ts`, which is the live adapter's own definition and is embedded here verbatim, so the chart and the bot run one logic path. Its tuning (`C`, `ITERATIONS`, `SCALE_FLOOR`, `ZERO_EPSILON`) is centralized in `MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_HUBER` and injected into the page as `const AMA_SLOPE_HUBER`, so a constant change flows to both. The output is in %/bar over the same window, so the tilt scale (`clamp(slope/maxSlopePct) * maxSlopeOffset`) and the `Δs` gate (`|Δslope| >= 8% of maxSlopePct`) keep their existing units. Measured on the repo's 1h pools with the shipped AMA preset at the shipped 16-bar window: a single-bar AMA impulse is **strongly bounded** (a 1%/3%/5%/10% one-bar spike shifts the two-point endpoint reading by ≈ `spike/lookbackBars` %/bar ≈ 0.06/0.19/0.31/0.63 — 8x to 80x the reset gate — while the robust fit barely moves), and the fit is the smoothest robust option measured (second-difference energy ~25x lower than the old median's). Set `CHART_SLOPE_ESTIMATOR = 'endpoint'` in the page to render the reference two-point definition instead (kept in the core for comparison); the live adapter does not use it.
|
|
283
288
|
- The chart embeds the vendored `uPlot` runtime inline (no CDN, no sibling `uplot/` dir, no DEXBot2 install needed). Each export is a single self-contained HTML file that renders anywhere, even after being copied or mailed to a machine without DEXBot2.
|
|
284
289
|
- The displayed indicators are computed from the 1h base candles and then sampled onto the selected timeframe.
|
|
285
290
|
- The current volume-weighted overlay is a rolling `VWMA`, not a session-reset VWAP.
|
|
@@ -96,8 +96,7 @@ Output: `analysis/charts/dynamic_weight_chart.html` (open in browser)
|
|
|
96
96
|
| `--chart` | `analysis/charts/dynamic_weight_chart.html` | Output HTML path |
|
|
97
97
|
| `--alpha` | `0.5` | Initial α blend (0 = pure Kalman, 1 = pure AMA) |
|
|
98
98
|
| `--dw` | `0.50` | Initial displacement weight (0 = pure velocity, 1 = full displacement) |
|
|
99
|
-
| `--lb` | `
|
|
100
|
-
| `--ema` | `0` | Initial AMA input EMA span in bars (0 = off, 0-32) |
|
|
99
|
+
| `--lb` | `16` | Initial lookback bars (1-32) for AMA slope calculation |
|
|
101
100
|
| `--gain` | `1.0` | Initial gain multiplier |
|
|
102
101
|
| `--clip` | `10` | Initial clip percentile |
|
|
103
102
|
| `--quiet` | `false` | Suppress console output |
|
|
@@ -115,7 +114,6 @@ All panels share aligned vertical time grid lines, and the bottom output panel s
|
|
|
115
114
|
|
|
116
115
|
### Panel 2 — AMA Slope Input (14%)
|
|
117
116
|
- **Orange line**: AMA3 slope percentage
|
|
118
|
-
- **Gray dashed line**: raw (unfiltered) slope — the reference when the `ema` knob > 0
|
|
119
117
|
- Shows the directional strength of the slow KAMA's trend movement
|
|
120
118
|
- Values outside the clip threshold are flattened before entering the offset formula
|
|
121
119
|
- Background shading mirrors the output signal direction
|
|
@@ -155,7 +153,7 @@ All panels share aligned vertical time grid lines, and the bottom output panel s
|
|
|
155
153
|
- `kf = 100` → current adaptive EMA result
|
|
156
154
|
- `kf > 100` → pushes further toward the adaptive signal (up to 200)
|
|
157
155
|
|
|
158
|
-
**dsp (displacement scale)**: Controls how fast displacement confidence saturates. Smaller values make it saturate faster (less displacement needed for full confidence); larger values require more displacement. The live adapter clamps `
|
|
156
|
+
**dsp (displacement scale)**: Controls how fast displacement confidence saturates. Smaller values make it saturate faster (less displacement needed for full confidence); larger values require more displacement. The live default is `1.0` (`DYNAMIC_WEIGHT_DISP_SCALE_MIN_PCT`); neither the live adapter nor the chart clamps it above or below that, so the slider's `0.25` floor is usable in both.
|
|
159
157
|
|
|
160
158
|
**Latched signal (cf)**: Prevents the output from flip-flopping on every bar. It holds the last direction for `cf` bars before allowing a reversal:
|
|
161
159
|
- `cf = 0` → raw signal (instant flips)
|
|
@@ -167,11 +165,10 @@ All panels share aligned vertical time grid lines, and the bottom output panel s
|
|
|
167
165
|
| Knob | Range | Default | Purpose |
|
|
168
166
|
|------|-------|---------|---------|
|
|
169
167
|
| **nz%** | 0–1 | 0.00 | Neutral zone: dead-band below which offset is forced to 0 |
|
|
170
|
-
| **lb** | 1–32 |
|
|
171
|
-
| **
|
|
172
|
-
| **amaS%** | 0.06–0.12 | 0.09 | Logarithmic. Gear ratio for average per-bar AMA slope saturation |
|
|
168
|
+
| **lb** | 1–32 | 16 | Logarithmic. Lookback bars for AMA slope calculation |
|
|
169
|
+
| **amaS%** | 0.06–0.12 | 0.09 | Logarithmic. Gear ratio for per-bar AMA slope saturation |
|
|
173
170
|
| **kalS%** | 0.5–1.5 | 1.11 | Logarithmic. Gear ratio for Kalman composite saturation |
|
|
174
|
-
| **clip%** | 0–
|
|
171
|
+
| **clip%** | 0–20 | 10 | Percentile clip: filters extreme inputs (0 = off) |
|
|
175
172
|
|
|
176
173
|
### Output Controls
|
|
177
174
|
| Knob | Range | Default | Purpose |
|
|
@@ -182,7 +179,7 @@ All panels share aligned vertical time grid lines, and the bottom output panel s
|
|
|
182
179
|
|
|
183
180
|
## Copy / Paste Parameters
|
|
184
181
|
|
|
185
|
-
The **copy** button serializes all knob values (α, dw, kf, kfd, dsp, kdt, kfs, cf, lb,
|
|
182
|
+
The **copy** button serializes all knob values (α, dw, kf, kfd, dsp, kdt, kfs, cf, lb, amaS%, kalS%, th%, gain, clip%, nz%, regi) to JSON and writes them to both the clipboard and `localStorage`.
|
|
186
183
|
|
|
187
184
|
The **paste** button first checks `localStorage` for parameters from a previous copy in the same browser session. If none found, it prompts for Ctrl+V input. A confirmation popup shows the parsed values before applying them. Click **Apply** to set the knobs, **Cancel** or press **Escape** to dismiss.
|
|
188
185
|
|
|
@@ -192,7 +189,7 @@ The **paste** button first checks `localStorage` for parameters from a previous
|
|
|
192
189
|
|
|
193
190
|
### AMA slope
|
|
194
191
|
|
|
195
|
-
Taking the slope of the AMA produces a signal that is already noise-filtered at the source — a near-zero slope genuinely means sideways, not oscillation that happened to average out. The
|
|
192
|
+
Taking the slope of the AMA produces a signal that is already noise-filtered at the source — a near-zero slope genuinely means sideways, not oscillation that happened to average out. The canonical slope is a Huber-robust linear regression of `ln(AMA)` over the lookback window (per-bar log-return ×100, `MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_HUBER`), so a single outlier bar is discounted instead of getting full endpoint weight; the same estimator runs in the live adapter, both research charts, and the reset replay. The neutral zone (`nz%` knob) dead-bands any remaining micro-slope residuals.
|
|
196
193
|
|
|
197
194
|
### Kalman filter
|
|
198
195
|
|
|
@@ -287,7 +284,6 @@ The lookup table can be customized per-market or per-bot (see [Custom Configurat
|
|
|
287
284
|
## Formulas
|
|
288
285
|
|
|
289
286
|
### AMA Offset
|
|
290
|
-
With `ema` > 0, `AMA_now` / `AMA_lb_bars_ago` below are read from the EMA-filtered AMA input instead of the raw AMA series (everything else identical):
|
|
291
287
|
```
|
|
292
288
|
amaSlope% = ((AMA_now − AMA_lb_bars_ago) / AMA_lb_bars_ago × 100) / lb
|
|
293
289
|
amaClip = clamp(amaSlope%, ±clipThreshold) // percentile-based clip
|
|
@@ -360,31 +356,10 @@ Formula: `kalComp = clippedV × (1 − dw + dw × dispConf × momAlign)`
|
|
|
360
356
|
### lb (lookback bars)
|
|
361
357
|
Number of bars to look back when computing AMA slope:
|
|
362
358
|
- `lb = 4`: Very short-term, highly responsive to recent price action
|
|
363
|
-
- `lb =
|
|
359
|
+
- `lb = 16` (default): ~16 hours of hourly candles, balanced responsiveness and smoothing
|
|
364
360
|
- `lb = 32`: ~1.3 days of hourly candles, stable but slower to react
|
|
365
361
|
|
|
366
|
-
AMA slope is
|
|
367
|
-
|
|
368
|
-
### ema (AMA input EMA span)
|
|
369
|
-
Optional low-pass EMA over the AMA values before the slope is taken (span in bars, α = 2/(span+1), `0` = off). Because differencing and an EMA are both linear filters, they commute — smoothing the AMA input produces exactly the smoothed slope series, modulo the seeding transient.
|
|
370
|
-
|
|
371
|
-
| `ema` | noise reduction* | added lag | verdict |
|
|
372
|
-
|---|---|---|---|
|
|
373
|
-
| 0 | 1× (off) | 0 bars | default, current behavior |
|
|
374
|
-
| 4 | ~2× | ~+1.5 bars | light |
|
|
375
|
-
| 9 (= lb) | ~3× | ~+4 bars | sweet spot |
|
|
376
|
-
| 16 | ~4× | ~+7.5 bars | heavy but usable |
|
|
377
|
-
| 32 | ~5.7× | ~+15.5 bars | upper-bound demo, too laggy to trade |
|
|
378
|
-
|
|
379
|
-
\* standard-deviation reduction for white-ish noise ≈ `sqrt(span)`; lag ≈ `(span-1)/2` bars (EMA group delay) on top of the slope window's `(lb-1)/2`.
|
|
380
|
-
|
|
381
|
-
Measured on ~8.7k hourly bars with the default AMA profile (`lb = 9`): the slow AMA's slope is dominated by low-frequency moves rather than white noise, so the `sqrt(span)` rule overstates the standard-deviation gain — `ema = 9` cut slope std only ~3% but trimmed the largest peaks ~22% and zero-crossings 86 → 74; `ema = 32` cut std ~11%, peaks ~48%, crossings 86 → 44, with a measured lag of ~3 bars at span 9 (theory 4). On this input the knob acts mainly as a peak-trimmer and sign-flip reducer, not as a general noise killer.
|
|
382
|
-
|
|
383
|
-
Effects while tuning:
|
|
384
|
-
- Zero-crossings get rarer, so the `cf` latch matters less and the `nz%` dead-band sits on a smooth curve instead of on noise.
|
|
385
|
-
- |slope| peaks shrink, so the same `amaS%` reaches full offset strength less often — expect to lower `amaS%` (or raise `gain`) to restore output amplitude. The `clip%` percentile pool is rebuilt from the filtered input, which partially self-compensates.
|
|
386
|
-
- Keep total lag in mind: ~`lb/2 + ema/2` bars before the slope reflects a move; at defaults that is ~8 bars (~8 h on the 1 h chart).
|
|
387
|
-
- Panel 2 plots the smoothed slope (orange) over the raw slope (gray dashed) so the noise/lag trade-off is directly visible.
|
|
362
|
+
AMA slope is a per-bar log-return (Huber regression of `ln(AMA)`), not the cumulative move across the full lookback. Lower values = more noise, faster reaction. Higher values = smoother signals, more lag without adding gain just because the measurement window is longer.
|
|
388
363
|
|
|
389
364
|
### regi (regime sensitivity)
|
|
390
365
|
- 0 = regime multiplier is always 1.0 (Hurst+PE ignored)
|
|
@@ -415,8 +390,7 @@ The 3×3 regime multiplier table can be customized per-market or per-bot (defaul
|
|
|
415
390
|
Candle Data
|
|
416
391
|
├── AMA3 (slow KAMA, erPeriod=781)
|
|
417
392
|
│ ├── calculateAMA() → AMA3 values per bar [price panel overlay]
|
|
418
|
-
│ ├──
|
|
419
|
-
│ ├── computeAmaSlopeWeights() → slope%
|
|
393
|
+
│ ├── computeAmaSlopeWeights() → Huber slope% (ln-return per bar)
|
|
420
394
|
│ └── Percentile clip → amaClip → amaOff
|
|
421
395
|
│
|
|
422
396
|
├── Kalman Filter (tactical + modal)
|
|
@@ -17,6 +17,37 @@ This folder contains the chart generators and re-export shims used by the analys
|
|
|
17
17
|
- `regime_chart_generator.ts`
|
|
18
18
|
- `volatility_chart_generator.ts`
|
|
19
19
|
|
|
20
|
+
## Backtests
|
|
21
|
+
|
|
22
|
+
- `huber_scale_variants.ts` — research-only Huber scale variants (`none`/`df`/
|
|
23
|
+
`mscale`) plus an outlier-fraction diagnostic; the canonical estimator lives in
|
|
24
|
+
`market_adapter/core/strategies/dynamic_weight_series.ts` and is untouched.
|
|
25
|
+
- `backtest_ama_slope_huber.ts` — sweeps the Huber slope lookback window
|
|
26
|
+
(`--lookback`, default 8..28 bars; the live default is
|
|
27
|
+
`DYNAMIC_WEIGHT_AMA_LOOKBACK_BARS` = 16) over an LP candle
|
|
28
|
+
shard directory and reports **lag** (cross-correlation group delay vs centred
|
|
29
|
+
price/AMA slope, plus reversal-confirmation delay), **resets** (the canonical
|
|
30
|
+
`simulateGridResetSeries` drift + slope-delta decision path: counts, reason
|
|
31
|
+
split, rate, gap distribution, whipsaws) and **noise** (slope std, bar-to-bar
|
|
32
|
+
wobble, second-difference energy, zero-crossing rate, saturation, range tilt).
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm run build
|
|
36
|
+
node dist/analysis/trend_detection/backtest_ama_slope_huber.js \
|
|
37
|
+
--data market_adapter/data/lp/<market-pair> --lookback 8:28:2
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Run `--help` for the full option list (AMA preset/overrides, reset thresholds,
|
|
41
|
+
confirmation gate, whipsaw definition, `--scale-mode`, JSON output path).
|
|
42
|
+
|
|
43
|
+
`--scale-mode none|df|mscale` swaps the Huber robust-scale estimate (production
|
|
44
|
+
is `none`); see `huber_scale_variants.ts` and `docs/AMA_SLOPE_WINDOW.md` for
|
|
45
|
+
why the plug-in scale is kept.
|
|
46
|
+
|
|
47
|
+
`revLag` is measured against a centred reference whose half-window is
|
|
48
|
+
`--truth-window` (default = max lookback), so compare it across runs only at a
|
|
49
|
+
fixed truth window; `amaLag` (cross-correlation group delay) is reference-robust.
|
|
50
|
+
|
|
20
51
|
The Kalman/Hurst/PE analyzers below are re-export shims; the implementations live in `market_adapter/core/signals/` and are shared with the live market adapter:
|
|
21
52
|
|
|
22
53
|
- `hurst_analyzer.ts` → `market_adapter/core/signals/hurst_analyzer.ts`
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import * as client from './bitshares_client.js';
|
|
4
4
|
const { BitShares, waitForConnected } = client;
|
|
5
5
|
import { loadDexbotOrderSystemUtils, loadDexbotOrderUtils } from './dexbot_bridge.js';
|
|
6
|
+
import { normalizeAssetRef } from '../../modules/utils/asset_symbols.js';
|
|
6
7
|
function getDexbotSystem() {
|
|
7
8
|
return loadDexbotOrderSystemUtils();
|
|
8
9
|
}
|
|
@@ -40,15 +41,19 @@ async function getDynamicGlobalProperties() {
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
async function getAsset(symbolOrId: any) {
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
// Symbols arrive from a user-supplied `pair: "BASE/QUOTE"` option; BitShares
|
|
45
|
+
// answers lowercase lookups without error, so canonicalize before the id
|
|
46
|
+
// test and both lookup paths.
|
|
47
|
+
const ref = normalizeAssetRef(symbolOrId);
|
|
48
|
+
if (/^1\.3\.\d+$/.test(ref)) {
|
|
49
|
+
const assets = await dbCall('get_assets', [[ref]]);
|
|
45
50
|
return assets[0] || null;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
try {
|
|
49
|
-
return await getDexbotSystem().lookupAsset(BitShares,
|
|
54
|
+
return await getDexbotSystem().lookupAsset(BitShares, ref);
|
|
50
55
|
} catch {
|
|
51
|
-
const assets = await dbCall('lookup_asset_symbols', [[
|
|
56
|
+
const assets = await dbCall('lookup_asset_symbols', [[ref]]);
|
|
52
57
|
return assets[0] || null;
|
|
53
58
|
}
|
|
54
59
|
}
|
|
@@ -6,6 +6,7 @@ import { createClawInfrastructure } from './claw_infra.js';
|
|
|
6
6
|
import { describeClawBridge } from './claw_manifest.js';
|
|
7
7
|
import { describeMemuBridge, runMemuCommand } from './memu_bridge.js';
|
|
8
8
|
import { clone } from './utils.js';
|
|
9
|
+
import { splitPairTarget } from '../../modules/utils/asset_symbols.js';
|
|
9
10
|
import { adjustMpaCollateral, borrowMpa, cancelLimitOrder, createLimitOrder, executeBatch, getMpaPosition, getOpenOrders, repayMpaDebt, buildUpdateLimitOrderOperation, updateLimitOrder, settleMpa } from './chain_actions.js';
|
|
10
11
|
import { buildCloseShortPlan, buildOpenShortPlan, buildTakeProfitPlan, closeShortOnBts, openShortOnBts, placeTakeProfitBuyOrderOnBts } from './short_mpa_strategy.js';
|
|
11
12
|
import { launcherRun, launcherDrystart, launcherReset, launcherDisable, launcherPm2Start, launcherPm2Stop, launcherPm2Delete, launcherPm2Restart } from './claw_launcher.js';
|
|
@@ -24,20 +25,19 @@ function stripPrivateKey(options: ClawBridgeOptions = {}): ClawBridgeOptions {
|
|
|
24
25
|
* Split a "BASE/QUOTE" pair string into { baseSymbol, quoteSymbol }.
|
|
25
26
|
* Throws if the value is not a two-segment BASE/QUOTE string — extra segments
|
|
26
27
|
* are rejected instead of being silently dropped.
|
|
28
|
+
* Both assetA and assetB are canonicalized to UPPERCASE (BitShares' on-chain
|
|
29
|
+
* spelling) by the shared splitter, so a lowercase pair and its uppercase
|
|
30
|
+
* spelling are one pair; only the error contract is claw's own.
|
|
27
31
|
*/
|
|
28
32
|
function splitPair(pairValue: string) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const segments = pairValue.split('/');
|
|
34
|
-
if (segments.length !== 2 || !segments[0] || !segments[1]) {
|
|
33
|
+
const segments = splitPairTarget(pairValue);
|
|
34
|
+
if (segments.length !== 2) {
|
|
35
35
|
throw new Error('pair must be provided as BASE/QUOTE');
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
return {
|
|
39
|
-
baseSymbol: segments[0]
|
|
40
|
-
quoteSymbol: segments[1]
|
|
39
|
+
baseSymbol: segments[0],
|
|
40
|
+
quoteSymbol: segments[1]
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -399,5 +399,5 @@ async function runClawCommand(command: string, options: ClawBridgeOptions = {}):
|
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
-
export { createClawBridge, describeClawBridge, describeRuntimeManifest, runClawCommand }
|
|
402
|
+
export { createClawBridge, describeClawBridge, describeRuntimeManifest, runClawCommand, splitPair }
|
|
403
403
|
|
package/claw/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* private copy of this decision tree, of the chain lookup and of the node
|
|
11
11
|
* handling — all of it lives here now.
|
|
12
12
|
*/
|
|
13
|
-
import { findBotKeyByAccountRef, loadBotMeta, persistBotAccountId } from './bot_key_utils.js';
|
|
13
|
+
import { findBotKeyByAccountRef, loadBotMeta, persistBotAccountId, resolveBotKey } from './bot_key_utils.js';
|
|
14
14
|
import { withReadOnlyClient } from './chain_pool.js';
|
|
15
15
|
const ACCOUNT_ID_RE = /^1\.2\.\d+$/;
|
|
16
16
|
/** Default lookup: ephemeral read-only client over the built-in node pool. */
|
|
@@ -112,6 +112,18 @@ async function resolveAccountRef(accountRef, options = {}) {
|
|
|
112
112
|
if (ACCOUNT_ID_RE.test(ref)) {
|
|
113
113
|
return { accountId: ref, botKey: null, botMeta: null, source: 'typed-id', reason: null };
|
|
114
114
|
}
|
|
115
|
+
// Local profile first: a bot whose profile name/key matches the reference
|
|
116
|
+
// resolves through its stored accountId/preferredAccount without any chain
|
|
117
|
+
// lookup. This is what lets `dexbot pnl <bot>` work offline and avoids
|
|
118
|
+
// treating a bot name as a chain account name.
|
|
119
|
+
try {
|
|
120
|
+
const botKey = resolveBotKey(ref, options.botsFile);
|
|
121
|
+
if (botKey)
|
|
122
|
+
return resolveBotAccount(botKey, options);
|
|
123
|
+
}
|
|
124
|
+
catch (_) {
|
|
125
|
+
// bots.json issues must never break resolution; fall through to chain.
|
|
126
|
+
}
|
|
115
127
|
// A bot claiming this name is the persist target; its preferredAccount is
|
|
116
128
|
// the same name, so resolveBotAccount owns the whole decision tree.
|
|
117
129
|
let match = null;
|