dexbot 1.6.15 → 1.6.16
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 +26 -0
- package/README.md +4 -4
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +3 -2
- package/claw/modules/chain_queries.ts +3 -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/dist/analysis/ama_fitting/fetch_lp_candles.js +8 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts +50 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +33 -7
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +8 -6
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +8 -10
- package/dist/analysis/bot_key_utils.js +9 -7
- package/dist/analysis/chart_utils.d.ts +9 -2
- package/dist/analysis/chart_utils.js +51 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +2 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +19 -5
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +21 -2
- package/dist/analysis/trend_detection/kalman_chart_generator.js +1 -0
- package/dist/analysis/trend_detection/regime_chart_generator.js +1 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js +1 -0
- package/dist/dexbot.js +89 -138
- package/dist/market_adapter/inputs/fetch_book_data.js +36 -12
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +6 -0
- package/dist/market_adapter/inputs/fetch_lp_data.js +65 -19
- package/dist/market_adapter/inputs/kibana_feed_source.js +45 -12
- package/dist/market_adapter/inputs/window_cache.d.ts +14 -1
- package/dist/market_adapter/inputs/window_cache.js +53 -17
- package/dist/market_adapter/lp_chart_core.js +1 -0
- package/dist/market_adapter/utils/chain.js +4 -3
- package/dist/market_adapter/utils/pair_orientation.d.ts +60 -0
- package/dist/market_adapter/utils/pair_orientation.js +142 -0
- package/dist/modules/account_bots.d.ts +37 -3
- package/dist/modules/account_bots.js +77 -37
- package/dist/modules/account_orders.d.ts +4 -1
- package/dist/modules/account_orders.js +4 -1
- package/dist/modules/bitshares-native/resolvers.js +3 -3
- package/dist/modules/bitshares_client.d.ts +12 -10
- package/dist/modules/bitshares_client.js +12 -10
- package/dist/modules/bot_settings.js +3 -3
- package/dist/modules/chain_keys.d.ts +5 -1
- package/dist/modules/chain_keys.js +5 -1
- package/dist/modules/chain_orders.d.ts +6 -2
- package/dist/modules/chain_orders.js +6 -2
- package/dist/modules/constants.d.ts +5 -0
- package/dist/modules/constants.js +7 -1
- package/dist/modules/dexbot_class.d.ts +3 -1
- package/dist/modules/dexbot_class.js +3 -1
- package/dist/modules/graceful_shutdown.d.ts +6 -2
- package/dist/modules/graceful_shutdown.js +6 -2
- package/dist/modules/launcher/bot_supervisor.js +4 -0
- package/dist/modules/launcher/launch_modes.js +6 -3
- package/dist/modules/launcher/monolithic_runtime.d.ts +39 -1
- package/dist/modules/launcher/monolithic_runtime.js +60 -1
- package/dist/modules/launcher/runtime_mode.d.ts +79 -0
- package/dist/modules/launcher/runtime_mode.js +223 -0
- package/dist/modules/market_adapter_whitelist.d.ts +8 -0
- package/dist/modules/market_adapter_whitelist.js +8 -0
- package/dist/modules/order/accounting.d.ts +15 -1
- package/dist/modules/order/accounting.js +15 -1
- package/dist/modules/order/async_lock.d.ts +9 -3
- package/dist/modules/order/async_lock.js +9 -3
- package/dist/modules/order/export.d.ts +0 -5
- package/dist/modules/order/export.js +0 -5
- package/dist/modules/order/format.d.ts +6 -4
- package/dist/modules/order/format.js +6 -4
- package/dist/modules/order/grid.d.ts +29 -18
- package/dist/modules/order/grid.js +29 -18
- package/dist/modules/order/index.d.ts +1 -1
- package/dist/modules/order/index.js +1 -1
- package/dist/modules/order/logger_state.d.ts +1 -1
- package/dist/modules/order/logger_state.js +1 -1
- package/dist/modules/order/sync_engine.d.ts +26 -11
- package/dist/modules/order/sync_engine.js +26 -11
- package/dist/modules/order/utils/math.d.ts +59 -21
- package/dist/modules/order/utils/math.js +59 -21
- package/dist/modules/order/utils/order.d.ts +64 -20
- package/dist/modules/order/utils/order.js +64 -20
- package/dist/modules/order/utils/system.d.ts +41 -11
- package/dist/modules/order/utils/system.js +41 -11
- package/dist/modules/order/utils/validate.d.ts +5 -2
- package/dist/modules/order/utils/validate.js +5 -2
- package/dist/modules/utils/asset_symbols.d.ts +5 -5
- package/dist/modules/utils/asset_symbols.js +5 -5
- package/dist/modules/utils/errors.d.ts +2 -1
- package/dist/modules/utils/errors.js +2 -1
- package/dist/scripts/rich_list.d.ts +32 -0
- package/dist/scripts/rich_list.js +16 -8
- package/dist/unlock.js +49 -18
- package/docs/BITSHARES_ONBOARDING.md +7 -0
- package/docs/COW_INVARIANTS.md +1 -1
- package/docs/DEXBOT_COMPARISON.md +5 -5
- package/docs/EVOLUTION.md +8 -7
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +3 -3
- package/docs/GRID_RECALCULATION.md +18 -6
- package/docs/LIFECYCLE.md +8 -8
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +4 -4
- package/docs/README.md +1 -1
- package/docs/WORKFLOW.md +5 -5
- package/market_adapter/README.md +10 -3
- package/package.json +3 -1
- package/tests/README.md +29 -0
|
@@ -158,13 +158,19 @@ node dist/market_adapter/market_adapter.js --deltaPercent 2
|
|
|
158
158
|
```json
|
|
159
159
|
{
|
|
160
160
|
"ama": {
|
|
161
|
-
"erPeriod":
|
|
162
|
-
"fastPeriod": 2,
|
|
163
|
-
"slowPeriod":
|
|
161
|
+
"erPeriod": 781, // Efficiency Ratio lookback period (candles)
|
|
162
|
+
"fastPeriod": 5.2, // Fast smoothing period for trending markets
|
|
163
|
+
"slowPeriod": 83.6 // Slow smoothing period for choppy markets
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
```
|
|
167
167
|
|
|
168
|
+
> Optional. A bot-level `ama` block overrides the preset (or matched pair profile)
|
|
169
|
+
> field by field, and supplying any period marks the bot's AMA as `custom` in the
|
|
170
|
+
> adapter state. The values above are the fitted `AMA3` built-in defaults
|
|
171
|
+
> (`MARKET_ADAPTER.AMAS`): `erPeriod: 781` and `fastPeriod: 5.2` are shared, while
|
|
172
|
+
> `slowPeriod` runs `62.1` (AMA1) to `96.9` (AMA4).
|
|
173
|
+
|
|
168
174
|
> **`gridPrice` is the only switch.** A bot is AMA-driven when `gridPrice` says
|
|
169
175
|
> so — `usesAmaGridPrice()`, the source of truth shared by the bot, maintenance
|
|
170
176
|
> and launcher runtimes. There is deliberately no `ama.enabled`: a second switch
|
|
@@ -199,9 +205,15 @@ The pool is fetched directly by ID, bypassing pool discovery. Useful when the tr
|
|
|
199
205
|
- Higher = more lag, filters noise
|
|
200
206
|
- Built-in presets range from `AMA1` (fastest) to `AMA4` (slowest) — see `MARKET_ADAPTER.AMAS` in `modules/constants.ts` for the exact `slowPeriod` values
|
|
201
207
|
|
|
202
|
-
AMA parameters
|
|
203
|
-
|
|
204
|
-
|
|
208
|
+
AMA parameters resolve in this order: a matched pair profile in
|
|
209
|
+
`profiles/market_profiles.json` wins for that pair; otherwise the bot's own `ama`
|
|
210
|
+
block overrides the preset field by field; any period the bot does not supply is
|
|
211
|
+
taken from the preset named by `gridPrice` (`"ama"` → the pair's `defaultAma`,
|
|
212
|
+
which falls back to `AMA3`; `"ama1"`–`"ama4"` → that exact preset); and any
|
|
213
|
+
remaining missing field falls back to the built-in `MARKET_ADAPTER.AMAS` defaults
|
|
214
|
+
(`modules/constants.ts`, default key `AMA3`). A bot that hand-writes any of the
|
|
215
|
+
three periods is reported as `custom` in the adapter state rather than by a preset
|
|
216
|
+
name.
|
|
205
217
|
|
|
206
218
|
### How It Works
|
|
207
219
|
|
package/docs/LIFECYCLE.md
CHANGED
|
@@ -90,7 +90,7 @@ sequenceDiagram
|
|
|
90
90
|
participant CO as chain_orders (broadcast)
|
|
91
91
|
participant STORE as Storage
|
|
92
92
|
|
|
93
|
-
CH->>Q: enqueue fill(s) (dexbot_fill_runtime.ts:
|
|
93
|
+
CH->>Q: enqueue fill(s) (dexbot_fill_runtime.ts:463)
|
|
94
94
|
FR->>FR: drain queue -> _processFillsWithBatching
|
|
95
95
|
FR->>OM: processFilledOrders() (manager.ts)
|
|
96
96
|
OM->>AC: processFillAccounting() (single call, batch)
|
|
@@ -134,9 +134,9 @@ sequenceDiagram
|
|
|
134
134
|
participant STORE as Storage
|
|
135
135
|
|
|
136
136
|
MA->>CL: AMA center snapshot updated
|
|
137
|
-
CL->>CL: _performPeriodicGridChecks() (dexbot_class.ts:
|
|
137
|
+
CL->>CL: _performPeriodicGridChecks() (dexbot_class.ts:1747)
|
|
138
138
|
CL->>RT: performPeriodicGridChecks() (dexbot_maintenance_runtime.ts:1677)
|
|
139
|
-
RT->>RT: runGridMaintenance(bot,'periodic') (dexbot_maintenance_runtime.ts:
|
|
139
|
+
RT->>RT: runGridMaintenance(bot,'periodic') (dexbot_maintenance_runtime.ts:2981)
|
|
140
140
|
RT->>RT: executeMaintenanceLogic() (dexbot_maintenance_runtime.ts:2462)
|
|
141
141
|
RT->>AC: recalculate funds from balances
|
|
142
142
|
RT->>GD: promote AMA center -> grid center
|
|
@@ -157,13 +157,13 @@ The AMA signal stack (AMA/Kalman/Hurst/PE) is *research-tuned* in `analysis/` an
|
|
|
157
157
|
the parameters.
|
|
158
158
|
|
|
159
159
|
> Note: `runMaintenance()` is a **different** subsystem — the credit/MPA debt
|
|
160
|
-
> runtime (`modules/credit_runtime.ts:
|
|
161
|
-
> `_runCreditRuntimeMaintenance` at `dexbot_class.ts:
|
|
160
|
+
> runtime (`modules/credit_runtime.ts:3623`, reached via
|
|
161
|
+
> `_runCreditRuntimeMaintenance` at `dexbot_class.ts:1864`). The grid maintenance
|
|
162
162
|
> chain above is the one that matters for order/price upkeep.
|
|
163
163
|
|
|
164
|
-
References: `modules/dexbot_class.ts:
|
|
164
|
+
References: `modules/dexbot_class.ts:1747` (`_performPeriodicGridChecks`) →
|
|
165
165
|
`modules/dexbot_maintenance_runtime.ts:1677` (`performPeriodicGridChecks`) →
|
|
166
|
-
`:
|
|
166
|
+
`:2981` (`runGridMaintenance`) → `:2462` (`executeMaintenanceLogic`),
|
|
167
167
|
`docs/GRID_RECALCULATION.md`, `docs/GRID_RECONCILE.md`.
|
|
168
168
|
|
|
169
169
|
---
|
|
@@ -192,7 +192,7 @@ enforced*, not compiler-enforced — learn them or you will introduce fund bugs.
|
|
|
192
192
|
| How a fill becomes orders | `modules/dexbot_fill_runtime.ts` → `modules/order/manager.ts` |
|
|
193
193
|
| Grid math / recalculation | `modules/order/grid.ts`, `docs/GRID_RECALCULATION.md` |
|
|
194
194
|
| Funds & accounting | `modules/order/accounting.ts`, `docs/FUND_MOVEMENT_AND_ACCOUNTING.md` |
|
|
195
|
-
| Periodic loop & AMA hook | `modules/dexbot_maintenance_runtime.ts`, `modules/dexbot_class.ts:
|
|
195
|
+
| Periodic loop & AMA hook | `modules/dexbot_maintenance_runtime.ts`, `modules/dexbot_class.ts:1747` |
|
|
196
196
|
| Market signal source | `market_adapter/market_adapter.ts`, `analysis/README.md` |
|
|
197
197
|
| Startup & orchestration | `modules/dexbot_class.ts`, `docs/developer_guide.md` §"Startup Sequence" |
|
|
198
198
|
| Why COW exists | `docs/architecture.md` §"Copy-on-Write (COW) Grid Pattern", `docs/COW_INVARIANTS.md` |
|
|
@@ -157,7 +157,7 @@ plans, `LANDED`/`REVERTED`/`SUPERSEDED` statuses, commit hashes, and verificatio
|
|
|
157
157
|
|
|
158
158
|
### 1. Gap-Band Orphan — Prevention Plan (P1–P6)
|
|
159
159
|
|
|
160
|
-
> **Source:** `GAP_BAND_ORPHAN_PREVENTION_PLAN.md` · **Status:** implemented `f94d6ec4` (2026-08-29), with subsequent amendments — landing map below.
|
|
160
|
+
> **Source:** former `GAP_BAND_ORPHAN_PREVENTION_PLAN.md` (deleted 2026-08-31; merged here) · **Status:** implemented `f94d6ec4` (2026-08-29), with subsequent amendments — landing map below.
|
|
161
161
|
|
|
162
162
|
**Landing map (corrected 2026-08-31):**
|
|
163
163
|
- **P1** — landed `f94d6ec4` (same-batch CANCEL injection in `COWRebalanceEngine.execute` + `_assertGapBandIntactPostCommit` cancelOnly). **REVERTED `e2898e51`** ("remove placement guards that interfered with normal operation") — both sites removed; stranding is now handled by `calculateIdealBoundary` + `LAST-FILL-GUARD` + adoption path (P3 gate removed `e7231534`).
|
|
@@ -226,7 +226,7 @@ Sequence `Restored boundary index: 131` *then* `[SNAPSHOT-REJECT] Deleting corru
|
|
|
226
226
|
|
|
227
227
|
### 2. Ladder Recenter Orphan — Root Cause (Aug 26–30 2026)
|
|
228
228
|
|
|
229
|
-
> **Source:** `LADDER_RECENTER_ORPHAN_ROOT_CAUSE.md` · **Status:** fixes #1–#7 landed 2026-08-30.
|
|
229
|
+
> **Source:** former `LADDER_RECENTER_ORPHAN_ROOT_CAUSE.md` (deleted 2026-08-31; merged here) · **Status:** fixes #1–#7 landed 2026-08-30.
|
|
230
230
|
|
|
231
231
|
#### 2.1 Symptom
|
|
232
232
|
|
|
@@ -317,7 +317,7 @@ Throttle `Structural resync defer` to first/last per cap window (was 120/30s); l
|
|
|
317
317
|
|
|
318
318
|
### 3. Orphan-Fill & Fund-Invariant — Root Cause & Fix Plan
|
|
319
319
|
|
|
320
|
-
> **Source:** `ORPHAN_FILL_INVARIANT_ROOT_CAUSE_AND_FIX.md` · **Status:** P0s + rotation landed `1b27f6eb`/`4838bcb0`/`d808c052`; P1 atomicity partial; duplicate-cancel hard-error and P2 counters still open.
|
|
320
|
+
> **Source:** former `ORPHAN_FILL_INVARIANT_ROOT_CAUSE_AND_FIX.md` (deleted 2026-08-31; merged here) · **Status:** P0s + rotation landed `1b27f6eb`/`4838bcb0`/`d808c052`; P1 atomicity partial; duplicate-cancel hard-error and P2 counters still open.
|
|
321
321
|
> **Scope:** `dexbot_cow_runtime.ts`, `sync_engine.ts`, `chain_orders.ts`, `dexbot_state_recovery.ts`, `dexbot_maintenance_runtime.ts`, `strategy.ts`, `constants.ts` · **Evidence:** `profiles/logs/<bot>.log` Aug 28 17:40–17:57, Aug 29 15:13–15:19.
|
|
322
322
|
|
|
323
323
|
#### 3.1 TL;DR — one cascade
|
|
@@ -388,7 +388,7 @@ All eight surface through `getMetrics()`; the five baseline counters via the exi
|
|
|
388
388
|
|
|
389
389
|
### 4. Price-First Alignment Plan
|
|
390
390
|
|
|
391
|
-
> **Source:** `PRICE_FIRST_ALIGNMENT_PLAN.md` · **Status:** Phase 1 shipped and live as shadow telemetry; Phase 2 projection was enabled (`1bbf1a23`) then **removed** (`3713c496`) after a live-bot incident — the anchor veto overrode chain evidence and drove destructive gap-band cancels. The anchor is now observability-only; the boundary is chain-evidence-derived. Phase 3 is moot (no second write path to retire); boundary geometry is pinned by `tests/test_boundary_anchor_recovery.ts` (ANCHOR-001..004) and `tests/test_grid_price_slot_invariant.ts`.
|
|
391
|
+
> **Source:** former `PRICE_FIRST_ALIGNMENT_PLAN.md` (deleted 2026-08-31; merged here) · **Status:** Phase 1 shipped and live as shadow telemetry; Phase 2 projection was enabled (`1bbf1a23`) then **removed** (`3713c496`) after a live-bot incident — the anchor veto overrode chain evidence and drove destructive gap-band cancels. The anchor is now observability-only; the boundary is chain-evidence-derived. Phase 3 is moot (no second write path to retire); boundary geometry is pinned by `tests/test_boundary_anchor_recovery.ts` (ANCHOR-001..004) and `tests/test_grid_price_slot_invariant.ts`.
|
|
392
392
|
> **Scope:** grid boundary state `modules/order/` · **Related:** three-layer crawl/anchor/guard fix.
|
|
393
393
|
|
|
394
394
|
#### 4.1 Goal
|
package/docs/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This directory contains the comprehensive technical documentation for the DEXBot2 trading bot. It is designed to guide developers from high-level architecture down to the nuances of fund accounting and state management.
|
|
4
4
|
|
|
5
|
-
**Version context:** v1.6.
|
|
5
|
+
**Version context:** v1.6.16 (released).
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
package/docs/WORKFLOW.md
CHANGED
|
@@ -257,12 +257,12 @@ the canonical name is preferred in scripts and docs.
|
|
|
257
257
|
| `dexbot dw <target>` | — | Dynamic-weight research chart: same targets/flags as `tv` |
|
|
258
258
|
| `dexbot pnl <account>` | — | HTML PnL report for a bot/account over `--month N`, optional `--pair BASE/QUOTE` filter |
|
|
259
259
|
| `dexbot git` | — | Analyze repository git history and write an added/deleted-lines HTML chart (`repo-stats.html`; source checkouts only) |
|
|
260
|
-
| `dexbot status` | `stat`, `stats` | Unified runtime health — daemon, adapter, bots |
|
|
260
|
+
| `dexbot status` | `stat`, `stats` | Unified runtime health — daemon, adapter, bots. Whole-runtime: an optional bot name is validated, then ignored |
|
|
261
261
|
| `dexbot start` | `unlock` | Run credential daemon + bot (equivalent to running the `unlock` runtime, `dist/unlock.js`) |
|
|
262
|
-
| `dexbot stop` | `stp`, `stopall` | Stop the
|
|
263
|
-
| `dexbot reload` | `reloadall` | Reload
|
|
264
|
-
| `dexbot restart` | `restartall` | Restart the
|
|
265
|
-
| `dexbot delete` | — | Shut down and clean up the monolithic runtime
|
|
262
|
+
| `dexbot stop [<bot>]` | `stp`, `stopall` | Stop the runtime. Monolithic: whole runtime (a bot argument folds into it with a notice); `--isolated`: just that bot |
|
|
263
|
+
| `dexbot reload [<bot>]` | `reloadall` | Reload without touching the credential daemon. Same per-bot target rules as `stop` |
|
|
264
|
+
| `dexbot restart [<bot>]` | `restartall` | Restart and re-unlock the credential daemon. Same per-bot target rules as `stop` |
|
|
265
|
+
| `dexbot delete` | — | Shut down and clean up the monolithic runtime. Whole-runtime only; rejects a bot argument |
|
|
266
266
|
| `dexbot clear` | — | Delete `*.log`, rotated `*.log.*` and `*.jsonl*` from the logs directory (`<profiles>/logs`) |
|
|
267
267
|
| `dexbot clear-orders` | — | Delete all persisted order files (`<profiles>/orders`); grids regenerate on next start |
|
|
268
268
|
| `dexbot clear-market-adapter` | — | Delete market adapter data, state (incl. `market_adapter.lock`), and adapter logs |
|
package/market_adapter/README.md
CHANGED
|
@@ -240,13 +240,18 @@ Pair-specific AMA profiles live in `profiles/market_profiles.json`:
|
|
|
240
240
|
"intervalSeconds": 3600,
|
|
241
241
|
"defaultAma": "AMA1",
|
|
242
242
|
"amas": {
|
|
243
|
-
"AMA1": { "erPeriod":
|
|
244
|
-
"AMA2": { "erPeriod":
|
|
243
|
+
"AMA1": { "erPeriod": 781, "fastPeriod": 5.2, "slowPeriod": 62.1 },
|
|
244
|
+
"AMA2": { "erPeriod": 781, "fastPeriod": 5.2, "slowPeriod": 72.0 }
|
|
245
245
|
}
|
|
246
246
|
}]
|
|
247
247
|
}
|
|
248
248
|
```
|
|
249
249
|
|
|
250
|
+
> The `amas` periods above are the fitted built-in presets (`MARKET_ADAPTER.AMAS`),
|
|
251
|
+
> shown here only to make the shape concrete. A real pair profile needs just the
|
|
252
|
+
> fields it changes — e.g. `"AMA3": { "slowPeriod": 90 }` keeps the built-in
|
|
253
|
+
> `erPeriod`/`fastPeriod` and overrides only `slowPeriod`.
|
|
254
|
+
|
|
250
255
|
`profiles/market_adapter_settings.json` layers:
|
|
251
256
|
|
|
252
257
|
```json
|
|
@@ -580,6 +585,7 @@ Typical fields:
|
|
|
580
585
|
market_adapter/
|
|
581
586
|
|-- market_adapter.ts main adapter daemon
|
|
582
587
|
|-- ama_signal_runner.ts one-cycle JSON signal CLI
|
|
588
|
+
|-- cli_args.ts shared CLI argument walker
|
|
583
589
|
|-- candle_utils.ts candle transforms, gap detection, pruning
|
|
584
590
|
|-- interval_utils.ts shared interval label + chain-time helpers
|
|
585
591
|
|-- lp_chart_core.ts chart HTML renderer
|
|
@@ -623,6 +629,7 @@ market_adapter/
|
|
|
623
629
|
| |-- file_lock.ts single-instance file lock
|
|
624
630
|
| |-- file_json_cache.ts write-through JSON read cache
|
|
625
631
|
| |-- month_shards.ts calendar-month shard naming + coverage-span primitives (shared by candle and fills caches)
|
|
632
|
+
| |-- pair_orientation.ts canonical pair orientation + reciprocal inversion helpers
|
|
626
633
|
| |-- data_discovery.ts data directory auto-discovery + shard-family assembly
|
|
627
634
|
| |-- atomic_write.ts atomic file write utility
|
|
628
635
|
| |-- dynamic_grid_snapshot.ts dynamic grid snapshot helpers
|
|
@@ -863,7 +870,7 @@ closed 1h candles.
|
|
|
863
870
|
|
|
864
871
|
#### Shared Month-Shard Cache and Fetch Robustness
|
|
865
872
|
|
|
866
|
-
Pool, book, and feed candle fetches share one cache entry point (`runCachedWindows` in `market_adapter/inputs/window_cache.ts`): candles live in fixed calendar-month shards (`<base>.shard_YYYY-MM.json`, UTC) whose names never shift, so a run loads only the shards overlapping its requested range, queries only genuinely missing buckets plus a bounded tail refresh, and rewrites only shards that gained buckets or query coverage — pure-reuse runs perform zero writes and zero deletes. Shard metas record the ranges actually queried (`meta.queriedRanges`, monotonically unioned) together with `at`, the time each query ran; spans merge only when they assert the same verification time, so per-bucket freshness stays exact. A missing range is pruned only when recorded query coverage genuinely covers it — the absence of local buckets alone never certifies history as empty — and only once the range ended more than `GAP_SETTLE_HORIZON_MS` ago, judged per gap rather than per window (a month-old gap at the leading edge of the newest window is as settled as one in a fully past window). The tail window re-queries only buckets that no query has seen `TAIL_SETTLE_LAG_MS` after they closed (`settleCoverage`), so a rerun costs ~lag+elapsed hours instead of a fixed 48h, and the refresh never reaches back past `TAIL_REFRESH_HOURS` (an unsettled bucket must be refreshed because index lag is still open, but a coverage hole older than 48h is past any plausible lag and must not drag the boundary back weeks); caches without `at` fall back to that fixed window. Clusters of gaps within `GAP_MERGE_TOLERANCE_BUCKETS` collapse into one query, and the sub-range path is bounded by merged span hours rather than gap count, so one extra small hole can no longer escalate a run to a full-window fetch. Because spans merge only on an identical `at`, a shard gains one span per re-verifying run; the persisted list is capped at `MAX_COVERAGE_SPANS` by dropping the oldest spans, which can never invent emptiness (it can only make those buckets look unsettled, bounded by the same 48h ceiling). A run that re-verifies the tail therefore rewrites that shard even when the candles come back identical — the moved verification time is the news, and skipping the write would throw it away; pure-reuse runs still write nothing. Partial windows merge into the run output but are never persisted. Stable month shards are the only supported cache format; obsolete run-relative cache files are ignored. Every range fetch runs through `fetchRangeWithRetry` (per-range attempts + linear backoff + abort-signal timeout; the LP path keeps a 4-attempt budget), one-shot Kibana queries retry transient errors (3 attempts), paged fetchers cap at `kibanaMaxPages` (500), and bidirectional fetches tolerate a one-direction failure.
|
|
873
|
+
Pool, book, and feed candle fetches share one cache entry point (`runCachedWindows` in `market_adapter/inputs/window_cache.ts`): candles live in fixed calendar-month shards (`<base>.shard_YYYY-MM.json`, UTC) whose names never shift, so a run loads only the shards overlapping its requested range, queries only genuinely missing buckets plus a bounded tail refresh, and rewrites only shards that gained buckets or query coverage — pure-reuse runs perform zero writes and zero deletes. Shard metas record the ranges actually queried (`meta.queriedRanges`, monotonically unioned) together with `at`, the time each query ran; spans merge only when they assert the same verification time, so per-bucket freshness stays exact. A missing range is pruned only when recorded query coverage genuinely covers it — the absence of local buckets alone never certifies history as empty — and only once the range ended more than `GAP_SETTLE_HORIZON_MS` ago, judged per gap rather than per window (a month-old gap at the leading edge of the newest window is as settled as one in a fully past window). The tail window re-queries only buckets that no query has seen `TAIL_SETTLE_LAG_MS` after they closed (`settleCoverage`), so a rerun costs ~lag+elapsed hours instead of a fixed 48h, and the refresh never reaches back past `TAIL_REFRESH_HOURS` (an unsettled bucket must be refreshed because index lag is still open, but a coverage hole older than 48h is past any plausible lag and must not drag the boundary back weeks); caches without `at` fall back to that fixed window. Clusters of gaps within `GAP_MERGE_TOLERANCE_BUCKETS` collapse into one query, and the sub-range path is bounded by merged span hours rather than gap count, so one extra small hole can no longer escalate a run to a full-window fetch. Because spans merge only on an identical `at`, a shard gains one span per re-verifying run; the persisted list is capped at `MAX_COVERAGE_SPANS` by dropping the oldest spans, which can never invent emptiness (it can only make those buckets look unsettled, bounded by the same 48h ceiling). A run that re-verifies the tail therefore rewrites that shard even when the candles come back identical — the moved verification time is the news, and skipping the write would throw it away; pure-reuse runs still write nothing. Partial windows merge into the run output but are never persisted. Stable month shards are the only supported cache format; obsolete run-relative cache files are ignored. Pair orientation is canonicalized (the lower asset id is always leg A on disk), so `bts/iob.xrp` and `iob.xrp/bts` share one shard family: the fetch queries the canonical side and the result is inverted back for the requested side (inverse volume uses the same base×close approximation as the TV chart's inverse view). A legacy inverse-orientation family is read once as a migration source and folded into the canonical shards instead of being re-fetched. Every range fetch runs through `fetchRangeWithRetry` (per-range attempts + linear backoff + abort-signal timeout; the LP path keeps a 4-attempt budget), one-shot Kibana queries retry transient errors (3 attempts), paged fetchers cap at `kibanaMaxPages` (500), and bidirectional fetches tolerate a one-direction failure.
|
|
867
874
|
|
|
868
875
|
#### AMA Warmup Window — Why Candle Length Matters
|
|
869
876
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dexbot",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.16",
|
|
4
4
|
"description": "The first open source trading bot with zero runtime dependencies and a fully adaptive market making strategy.",
|
|
5
5
|
"main": "dist/modules/dexbot_class.js",
|
|
6
6
|
"exports": {
|
|
@@ -109,6 +109,7 @@
|
|
|
109
109
|
"verify:browser-bundle": "npm run build && node dist/scripts/verify-browser-bundle.js",
|
|
110
110
|
"test": "npm run build && npm run build:tests && npm run build --prefix claw && node dist/scripts/run-tests.js",
|
|
111
111
|
"test:live": "RUN_LIVE_BITSHARES_TESTS=1 npm run build && npm run build:tests && npm run build --prefix claw && node dist/scripts/run-tests.js",
|
|
112
|
+
"test:playwright": "npm run build && NODE_PATH=\"$(npm root -g)\" playwright test --config tests/playwright/playwright.config.mjs",
|
|
112
113
|
"clean": "node scripts/clean-dist.js",
|
|
113
114
|
"build": "echo \"tsc is compiling ...\" && tsc && chmod +x dist/dexbot.js dist/bot.js dist/unlock.js dist/pm2.js dist/credential-daemon.js",
|
|
114
115
|
"build:clean": "npm run clean && npm run build",
|
|
@@ -157,6 +158,7 @@
|
|
|
157
158
|
"./dist/modules/launcher/status_reporting.js": false,
|
|
158
159
|
"./dist/modules/launcher/supervisor_control.js": false,
|
|
159
160
|
"./dist/modules/launcher/monolithic_runtime.js": false,
|
|
161
|
+
"./dist/modules/launcher/runtime_mode.js": false,
|
|
160
162
|
"./dist/modules/launcher/market_adapter_runtime.js": false,
|
|
161
163
|
"./dist/modules/launcher/market_adapter_watchdog.js": false,
|
|
162
164
|
"./dist/modules/launcher/foreign_cred_daemon.js": false,
|
package/tests/README.md
CHANGED
|
@@ -108,6 +108,35 @@ PM2 lifecycle, startup ordering, bot supervision, launcher version reporting.
|
|
|
108
108
|
Interactive tools and performance benchmarks (not part of CI).
|
|
109
109
|
*Examples:* `connection_test.ts`, `diag_adapter_client.ts`, `diag_ws_nodes.ts`, `diag_ws_lifecycle.ts`, `benchmark_cow.ts`, `sim_batching.ts`, `repro_phantom_orders.ts`
|
|
110
110
|
|
|
111
|
+
### Browser Charts (Playwright)
|
|
112
|
+
End-to-end tests for the generated HTML charts (currently the `dexbot tv`
|
|
113
|
+
TradingView exporter). These load a real chart page in Firefox and assert on
|
|
114
|
+
canvas draw work and pixels, so they live under `tests/playwright/` as
|
|
115
|
+
`.spec.mjs` files and are **not** picked up by the plain `node` runner.
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm run test:playwright # builds, then runs tests/playwright
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The runner and browsers come from a global Playwright install (the repo keeps
|
|
122
|
+
zero runtime deps); `test:playwright` points `NODE_PATH` at `npm root -g`, and
|
|
123
|
+
the spec resolves `playwright/test` dynamically. That inline `NODE_PATH=` is
|
|
124
|
+
POSIX-shell syntax (Linux/macOS); on Windows set it in your shell
|
|
125
|
+
(`$env:NODE_PATH=(npm root -g)`) or add a local `playwright` devDependency.
|
|
126
|
+
**Firefox is the default target** (set in
|
|
127
|
+
`tests/playwright/playwright.config.mjs`) because that is the browser the
|
|
128
|
+
generated charts are hand-checked in. If Playwright or the Firefox build is
|
|
129
|
+
missing: `npm i -g playwright && npx playwright install firefox`.
|
|
130
|
+
|
|
131
|
+
`tv_chart_perf.spec.mjs` pins the range-band draw hook to the visible bar
|
|
132
|
+
window: it counts `CanvasRenderingContext2D.lineTo` calls to prove the band's
|
|
133
|
+
per-redraw cost scales with the viewport (not the full series), and diffs
|
|
134
|
+
canvas pixels to prove the band still spans the plot when zoomed in. By default
|
|
135
|
+
it generates a synthetic TV page; set `TV_CHART_HTML=<path>` to run the load
|
|
136
|
+
check against any already-generated chart HTML (the uPlot interception is
|
|
137
|
+
generic; the Range-band assertions are skipped when the page has no Range
|
|
138
|
+
toggle).
|
|
139
|
+
|
|
111
140
|
### Edge Cases & Regression
|
|
112
141
|
Tests targeting specific bugs, race conditions, and failure modes.
|
|
113
142
|
*Examples:* `test_critical_bug_fixes.ts`, `test_race_condition_fixes_batch1.ts`, `test_patch17_invariants.ts`, `test_shutdown_reentrancy.ts`, `test_multifill_opposite_partial.ts`, `test_correction_queue_staleness.ts`, `test_spread_pure_fund_driven.ts`, `test_spread_correction_resilience.ts`, `test_sync_lock_id_verification.ts`
|