dexbot 1.6.17 → 1.6.18

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.
Files changed (101) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/analysis/README.md +10 -9
  3. package/analysis/ama_fitting/README.md +2 -2
  4. package/analysis/bot_fitting/README.md +3 -3
  5. package/claw/package.json +1 -1
  6. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  7. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  8. package/dist/analysis/analyze_args.d.ts +2 -1
  9. package/dist/analysis/fills_source.d.ts +1 -8
  10. package/dist/analysis/fills_source.js +1 -1
  11. package/dist/analysis/grid_correction_check.d.ts +9 -6
  12. package/dist/analysis/grid_correction_check.js +56 -64
  13. package/dist/analysis/math_utils.d.ts +1 -1
  14. package/dist/analysis/trade_profitability.d.ts +1 -1
  15. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +3 -3
  16. package/dist/analysis/trend_detection/huber_scale_variants.d.ts +4 -3
  17. package/dist/market_adapter/cli_args.d.ts +6 -1
  18. package/dist/market_adapter/cli_args.js +16 -2
  19. package/dist/market_adapter/core/kibana_candles.d.ts +5 -1
  20. package/dist/market_adapter/core/kibana_candles.js +3 -1
  21. package/dist/market_adapter/core/strategies/regime_gate.d.ts +7 -1
  22. package/dist/market_adapter/core/strategies/regime_gate.js +3 -1
  23. package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +7 -2
  24. package/dist/market_adapter/inputs/cex_candle_parsing.js +3 -1
  25. package/dist/market_adapter/inputs/fetch_book_data.d.ts +7 -1
  26. package/dist/market_adapter/inputs/fetch_book_data.js +3 -1
  27. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +2 -11
  28. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +26 -1
  29. package/dist/market_adapter/inputs/fetch_lp_data.js +62 -52
  30. package/dist/market_adapter/inputs/kibana_feed_source.d.ts +14 -2
  31. package/dist/market_adapter/inputs/kibana_feed_source.js +14 -1
  32. package/dist/market_adapter/inputs/window_cache.d.ts +14 -3
  33. package/dist/market_adapter/inputs/window_cache.js +14 -1
  34. package/dist/market_adapter/lp_chart_runner.d.ts +12 -9
  35. package/dist/market_adapter/lp_chart_runner.js +3 -1
  36. package/dist/market_adapter/lp_chart_strategy_loader.d.ts +5 -1
  37. package/dist/market_adapter/lp_chart_strategy_loader.js +3 -1
  38. package/dist/market_adapter/market_adapter.d.ts +10 -2
  39. package/dist/market_adapter/market_adapter.js +10 -11
  40. package/dist/market_adapter/utils/chain.d.ts +2 -3
  41. package/dist/market_adapter/utils/file_json_cache.d.ts +5 -1
  42. package/dist/market_adapter/utils/file_json_cache.js +3 -1
  43. package/dist/market_adapter/utils/file_lock.js +1 -1
  44. package/dist/market_adapter/utils/native_history.d.ts +7 -3
  45. package/dist/market_adapter/utils/native_history.js +3 -1
  46. package/dist/market_adapter/utils/pair_orientation.d.ts +2 -2
  47. package/dist/modules/bots_file_lock.d.ts +2 -2
  48. package/dist/modules/bots_file_lock.js +2 -2
  49. package/dist/modules/constants.js +6 -3
  50. package/dist/modules/dexbot_class.d.ts +8 -0
  51. package/dist/modules/dexbot_class.js +10 -0
  52. package/dist/modules/dexbot_cow_runtime.d.ts +62 -1
  53. package/dist/modules/dexbot_cow_runtime.js +461 -43
  54. package/dist/modules/dexbot_credential_client.d.ts +5 -0
  55. package/dist/modules/dexbot_maintenance_runtime.js +56 -9
  56. package/dist/modules/dexbot_startup_runtime.js +7 -1
  57. package/dist/modules/graceful_shutdown.d.ts +2 -2
  58. package/dist/modules/graceful_shutdown.js +2 -2
  59. package/dist/modules/launcher/runtime_mode.d.ts +4 -3
  60. package/dist/modules/node_manager.d.ts +1 -1
  61. package/dist/modules/node_manager.js +1 -1
  62. package/dist/modules/order/accounting.js +2 -1
  63. package/dist/modules/order/export.d.ts +2 -2
  64. package/dist/modules/order/export.js +2 -2
  65. package/dist/modules/order/grid.d.ts +19 -14
  66. package/dist/modules/order/grid.js +262 -61
  67. package/dist/modules/order/grid_reconcile.js +5 -1
  68. package/dist/modules/order/grid_reconcile_internal.js +2 -1
  69. package/dist/modules/order/index.d.ts +9 -3
  70. package/dist/modules/order/manager.d.ts +10 -0
  71. package/dist/modules/order/manager.js +41 -11
  72. package/dist/modules/order/strategy.js +22 -2
  73. package/dist/modules/order/sync_engine.d.ts +12 -1
  74. package/dist/modules/order/sync_engine.js +135 -20
  75. package/dist/modules/order/utils/math.d.ts +8 -9
  76. package/dist/modules/order/utils/math.js +24 -13
  77. package/dist/modules/order/utils/order.d.ts +52 -11
  78. package/dist/modules/order/utils/order.js +137 -21
  79. package/dist/modules/order/utils/system.d.ts +73 -29
  80. package/dist/modules/order/utils/system.js +239 -48
  81. package/dist/modules/order/utils/validate.d.ts +1 -0
  82. package/dist/modules/order/utils/validate.js +4 -1
  83. package/dist/modules/storage/index.d.ts +3 -2
  84. package/dist/modules/storage/index.js +3 -2
  85. package/dist/modules/types.d.ts +9 -0
  86. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
  87. package/docs/COW_INVARIANTS.md +20 -10
  88. package/docs/DEXBOT_COMPARISON.md +5 -5
  89. package/docs/EVOLUTION.md +9 -8
  90. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +11 -11
  91. package/docs/GRID_PRICE_INVARIANT.md +24 -4
  92. package/docs/GRID_RECONCILE.md +5 -5
  93. package/docs/LIFECYCLE.md +11 -11
  94. package/docs/LOGGING.md +15 -2
  95. package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +123 -36
  96. package/docs/README.md +1 -1
  97. package/docs/architecture.md +115 -13
  98. package/docs/developer_guide.md +12 -0
  99. package/market_adapter/README.md +9 -4
  100. package/modules/README.md +18 -14
  101. package/package.json +4 -3
@@ -405,6 +405,10 @@ node dist/market_adapter/inputs/fetch_lp_data.js --pool <poolId> --precA <precA>
405
405
  npm run lp:chart -- --data market_adapter/data/lp/<pair>/lp_pool_<id>_<interval>.json
406
406
  ```
407
407
 
408
+ The LP exporter also accepts `--chunkMonths <n>` (fetch window size in months),
409
+ `--apiKey <key>` (Kibana API key when the endpoint requires auth), `--out <file>`
410
+ (explicit output path), and `--help`. Unknown flags are rejected.
411
+
408
412
  Research and calibration:
409
413
 
410
414
  ```bash
@@ -445,8 +449,9 @@ operation:
445
449
  node dist/market_adapter/market_adapter.js
446
450
  ```
447
451
 
448
- The adapter acts only on closed 1h candles. It can poll more often, but live
449
- updates wait for the next completed candle.
452
+ The adapter acts only on closed candles at the configured interval (default
453
+ 1h). It can poll more often, but live updates wait for the next completed
454
+ candle.
450
455
 
451
456
  ### Signal Pipeline
452
457
 
@@ -485,7 +490,7 @@ Per cycle, per processed bot, the adapter can produce:
485
490
  4. Read `startPrice` to choose the candle source: `pool`, `book`, or fixed.
486
491
  5. Sync candle data from Kibana or native BitShares data, using the selected source.
487
492
  6. Repair missing candle gaps: auto-fill gaps ≤24 candles directly (no Kibana), query Kibana only for gaps beyond that threshold. Kibana returning empty is treated as verified no-trade. Writes are suppressed while gaps remain unresolved.
488
- 7. Ignore still-forming 1h candles.
493
+ 7. Ignore still-forming candles at the configured interval.
489
494
  8. Compute AMA center, trend, ATR, weights, and collateral hint.
490
495
  9. Persist the first accepted center, compare center delta, and compare whitelisted range-scaling slope delta.
491
496
  10. Suppress live writes if the bot is not whitelisted or candle data is stale.
@@ -866,7 +871,7 @@ are merged in, or an empty response is treated as verified no-trade (all gaps
866
871
  in the queried window are synthesized). Gaps remaining after both steps
867
872
  suppress writes via `unresolved_candle_gaps` until repaired on a future cycle.
868
873
  The adapter prunes old candles to the required AMA window and acts only on
869
- closed 1h candles.
874
+ closed candles at the configured interval.
870
875
 
871
876
  #### Shared Month-Shard Cache and Fetch Robustness
872
877
 
package/modules/README.md CHANGED
@@ -38,7 +38,7 @@ modules/
38
38
  ├── cli_start_onboarding.ts first-run setup routing for `dexbot start`
39
39
  ├── cli_start_output.ts launcher notice formatting
40
40
  ├── cli_colors.ts shared CLI color helpers
41
- ├── credential_runtime.ts credential daemon lifecycle
41
+ ├── credential_runtime.ts daemon socket/path helpers + private-path security
42
42
  ├── credential_policy.ts signing policy validation
43
43
  ├── credential_session_cache.ts encrypted session cache
44
44
  ├── constants.ts central config and tuning params
@@ -46,6 +46,7 @@ modules/
46
46
  ├── config.ts load-time process.env snapshot
47
47
  ├── env.ts isBrowser/hasProcess detection
48
48
  ├── runtime.ts process abstraction singleton
49
+ ├── lazy_shim.ts lazy named-export passthrough (require-on-call)
49
50
  ├── runtime_settings.ts per-bot runtime settings resolver
50
51
  ├── paths.ts guarded path resolution
51
52
  ├── path_api.ts portable path abstraction for ESM/browser
@@ -62,11 +63,11 @@ modules/
62
63
  ├── bots_file_lock.ts profile write serialization
63
64
  ├── account_bots.ts bots.json read/write
64
65
  ├── broadcast_failure.ts broadcast failure classification
65
- ├── chain_keys.ts blockchain key helpers
66
- ├── daemon_node_health.ts daemon-side node health checks
67
- ├── node_failure_ledger.ts node failure tracking
68
- ├── node_health_cache.ts node health tracking
69
- ├── socket_json_client.ts JSON-RPC socket client
66
+ ├── chain_keys.ts master-password vault + signing-key retrieval
67
+ ├── daemon_node_health.ts daemon-side node failure ledger (shared rules)
68
+ ├── node_failure_ledger.ts node failure counting shared by bot + daemon
69
+ ├── node_health_cache.ts shared node-health cache file I/O + ordering
70
+ ├── socket_json_client.ts newline-delimited JSON Unix-socket client
70
71
  ├── market_adapter_whitelist.ts adapter whitelist I/O
71
72
  ├── types.ts shared type definitions
72
73
  │
@@ -83,7 +84,7 @@ modules/
83
84
  ├── storage/ portable storage abstraction
84
85
  │ ├── index.ts barrel export
85
86
  │ ├── types.ts storage adapter interface
86
- │ ├── browser_adapter.ts in-memory Map-based adapter
87
+ │ ├── browser_adapter.ts in-memory Map backed by IndexedDB
87
88
  │ └── node_adapter.ts fs.*Sync based adapter
88
89
  │
89
90
  ├── order/ order lifecycle and grid management
@@ -93,9 +94,9 @@ modules/
93
94
  │ ├── strategy.ts grid rebalancing, consolidation, rotation
94
95
  │ ├── accounting.ts fund tracking, fee accounting
95
96
  │ ├── sync_engine.ts blockchain sync, fill detection, reconciliation
96
- │ ├── genesis_policy.ts missing-ladder refusal + rebuild/halt policy ([doc](../docs/GRID_PRICE_INVARIANT.md))
97
- │ ├── grid_reconcile.ts startup grid reconciliation ([doc](../docs/GRID_RECONCILE.md))
98
- │ ├── grid_reconcile_internal.ts internal grid reconciliation helpers
97
+ │ ├── genesis_policy.ts missing-ladder refusal + rebuild policy (docs/GRID_PRICE_INVARIANT.md)
98
+ │ ├── grid_reconcile.ts startup grid reconciliation (docs/GRID_RECONCILE.md)
99
+ │ ├── grid_reconcile_internal.ts internal grid reconciliation helpers
99
100
  │ ├── index.ts barrel export
100
101
  │ ├── logger.ts order-scoped logging
101
102
  │ ├── logger_state.ts logger state management
@@ -126,6 +127,7 @@ modules/
126
127
  │ ├── market_adapter_watchdog.ts adapter process watchdog
127
128
  │ ├── monolithic_runtime.ts monolithic bot runtime
128
129
  │ ├── runtime_entry.ts bot process entry
130
+ │ ├── runtime_mode.ts runtime mode detection and status routing
129
131
  │ ├── status_reporting.ts process status reporter
130
132
  │ └── supervisor_control.ts supervisor orchestration
131
133
  │
@@ -142,14 +144,14 @@ modules/
142
144
  │ └── crypto/ cryptographic primitives
143
145
  │
144
146
  └── utils/
145
- ├── asset_symbols.ts asset symbol/object-id canonicalization helpers
147
+ ├── asset_symbols.ts asset symbol/object-id canonicalization helpers
146
148
  ├── base58check.ts Base58Check encoding
147
149
  ├── build_dir.ts BUILD_DIR constant helper
148
150
  ├── chain_logs.ts shared chain log helpers
149
151
  ├── errors.ts getErrorMessage helper
150
152
  ├── sanitize_key.ts shared sanitizeKey helper
151
153
  ├── text_width.ts display-width-aware text measurement (CJK/emoji tables)
152
- └── time_range.ts month→hour lookback conversion (analysis range flags)
154
+ └── time_range.ts month→hour lookback conversion (analysis range flags)
153
155
  ```
154
156
 
155
157
  ## Key Relationships
@@ -178,10 +180,10 @@ External consumers — other parts of DEXBot2 interact with modules through thes
178
180
 
179
181
  ## Design Principles
180
182
 
181
- - **Zero runtime dependencies** — no npm trading/blockchain libraries; the native client, crypto, and serialization are all in `bitshares-native/`. This eliminates supply-chain risk and keeps the bot fully self-contained.
183
+ - **Zero runtime dependencies** — no npm trading/blockchain libraries; the native client and serialization live in `bitshares-native/`, and the cross-environment crypto providers (Web Crypto / Node crypto plus pure-JS fallbacks) in `crypto/`. `package.json` declares no `dependencies`, which eliminates supply-chain risk and keeps the bot fully self-contained.
182
184
  - **Copy-on-write** — `order/working_grid.ts` provides isolated COW mutations; master grid is immutable during rebalance. The grid is never modified in-place; a working copy is built, mutated, and committed atomically only after blockchain operations succeed.
183
185
  - **Fund-driven sizing, fill-driven boundary** — available funds set order sizing and budget allocation, not the boundary position; no forced allocations. The boundary moves only through boundary crawl on fills or spread promotion onto orders placed in the same atomic batch.
184
- - **Replay-safe accounting** — fill processing in `dexbot_fill_runtime.ts` uses `processed_fill_store.ts` to prevent double-counting. If the bot restarts mid-fill, it can safely replay without creating duplicate orders.
186
+ - **Replay-safe accounting** — `dexbot_class.ts` constructs `order/processed_fill_store.ts`, `dexbot_fill_runtime.ts` configures it and hands it to the `OrderManager`, and `order/accounting.ts` consults it before counting a fill. If the bot restarts mid-fill, it can safely replay without creating duplicate orders.
185
187
  - **Daemon-backed signing** — the credential daemon holds decrypted keys; modules never handle raw private keys. If the main bot crashes, keys stay encrypted on disk — only the small daemon process sees them.
186
188
  - **Gap-slot batch processing** — each fill batch and broadcast is capped at the current grid's gap-slot count + 1. A queue at or below that depth is processed as one unified batch; deeper queues are chunked at the same deterministic cap.
187
189
 
@@ -194,5 +196,7 @@ External consumers — other parts of DEXBot2 interact with modules through thes
194
196
  - [Fund movement & accounting](../docs/FUND_MOVEMENT_AND_ACCOUNTING.md) — fund tracking algorithms and formulas
195
197
  - [Credential security](../docs/CREDENTIAL_SECURITY.md) — key handling and daemon-backed signing details
196
198
  - [Grid recalculation](../docs/GRID_RECALCULATION.md) — when and how the grid resets or regenerates
199
+ - [Grid price invariant](../docs/GRID_PRICE_INVARIANT.md) — genesis ladder as the only authoritative slot price
200
+ - [Grid reconcile](../docs/GRID_RECONCILE.md) — startup reconciliation of the persisted grid
197
201
  - [Market adapter](../market_adapter/README.md) — AMA pricing, dynamic weights, and signal pipeline
198
202
  - [Claw bridge](../claw/README.md) — AI layer integration and command dispatch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dexbot",
3
- "version": "1.6.17",
3
+ "version": "1.6.18",
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,14 +109,15 @@
109
109
  "version:sync": "npm run build && node dist/scripts/sync-version.js",
110
110
  "version:check": "npm run build && node dist/scripts/sync-version.js --check",
111
111
  "verify:browser-bundle": "npm run build && node dist/scripts/verify-browser-bundle.js",
112
- "test": "npm run build && npm run build:tests && npm run build --prefix claw && node dist/scripts/run-tests.js",
113
- "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": "npm run build && npm run build:tests && npm run build --prefix claw && npm run typecheck:analysis && node dist/scripts/run-tests.js",
113
+ "test:live": "RUN_LIVE_BITSHARES_TESTS=1 npm run build && npm run build:tests && npm run build --prefix claw && npm run typecheck:analysis && node dist/scripts/run-tests.js",
114
114
  "test:playwright": "npm run build && NODE_PATH=\"$(npm root -g)\" playwright test --config tests/playwright/playwright.config.mjs",
115
115
  "clean": "node scripts/clean-dist.js",
116
116
  "build": "echo \"tsc is compiling ...\" && tsc && chmod +x dist/dexbot.js dist/bot.js dist/unlock.js dist/pm2.js dist/credential-daemon.js",
117
117
  "build:clean": "npm run clean && npm run build",
118
118
  "build:tests": "tsc -p tsconfig.tests.json && cp tests/package.json dist/tests/package.json && cp tests/helpers/esm_mock_hooks.mjs tests/helpers/esm_mock_loader.mjs dist/tests/helpers/",
119
119
  "typecheck": "tsc --noEmit",
120
+ "typecheck:analysis": "tsc -p analysis/tsconfig.json",
120
121
  "check:any": "npm run build && node dist/scripts/check_any.js",
121
122
  "check:any:update": "npm run build && node dist/scripts/check_any.js --update",
122
123
  "check:any:list": "npm run build && node dist/scripts/check_any.js --list",