dexbot 1.6.13 → 1.6.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +2 -2
- package/claw/docs/AI_BOT_LIBRARY_API.md +1 -1
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -4
- package/claw/modules/claw_catalog.ts +8 -4
- package/claw/modules/dexbot_profiles.ts +59 -15
- package/claw/modules/types.ts +2 -1
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/claw/skills/margin-trading/SKILL.md +1 -1
- package/claw/skills/margin-trading/references/position-management.md +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +25 -25
- package/dist/modules/account_bots.d.ts +7 -6
- package/dist/modules/account_bots.js +10 -10
- package/dist/modules/account_orders.d.ts +36 -4
- package/dist/modules/account_orders.js +76 -5
- package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +1 -2
- package/dist/modules/bitshares-native/crypto/ecc_core.js +1 -1
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts +1 -2
- package/dist/modules/bitshares-native/serial/chain_constants.js +1 -2
- package/dist/modules/bot_defaults.d.ts +16 -2
- package/dist/modules/bot_defaults.js +34 -8
- package/dist/modules/bot_settings.d.ts +4 -0
- package/dist/modules/bot_settings.js +55 -21
- package/dist/modules/config.js +6 -1
- package/dist/modules/constants.d.ts +7 -5
- package/dist/modules/constants.js +12 -5
- package/dist/modules/dexbot_class.d.ts +5 -0
- package/dist/modules/dexbot_class.js +8 -3
- package/dist/modules/dexbot_cow_runtime.d.ts +62 -174
- package/dist/modules/dexbot_cow_runtime.js +331 -46
- package/dist/modules/dexbot_credential_client.d.ts +1 -16
- package/dist/modules/dexbot_credential_client.js +1 -1
- package/dist/modules/dexbot_fill_runtime.d.ts +1 -1
- package/dist/modules/dexbot_fill_runtime.js +12 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts +18 -80
- package/dist/modules/dexbot_maintenance_runtime.js +57 -68
- package/dist/modules/dexbot_startup_runtime.js +12 -0
- package/dist/modules/dexbot_state_recovery.js +16 -0
- package/dist/modules/key_store.d.ts +0 -5
- package/dist/modules/key_store.js +1 -1
- package/dist/modules/order/accounting.js +11 -11
- package/dist/modules/order/export.js +2 -2
- package/dist/modules/order/format.d.ts +15 -1
- package/dist/modules/order/format.js +19 -1
- package/dist/modules/order/genesis_policy.d.ts +1 -1
- package/dist/modules/order/genesis_policy.js +1 -1
- package/dist/modules/order/grid.d.ts +23 -11
- package/dist/modules/order/grid.js +383 -51
- package/dist/modules/order/grid_reconcile.d.ts +1 -1
- package/dist/modules/order/grid_reconcile.js +5 -5
- package/dist/modules/order/grid_reconcile_internal.js +48 -40
- package/dist/modules/order/index.d.ts +34 -8
- package/dist/modules/order/logger.js +2 -2
- package/dist/modules/order/manager.d.ts +9 -2
- package/dist/modules/order/manager.js +58 -24
- package/dist/modules/order/strategy.d.ts +2 -2
- package/dist/modules/order/strategy.js +51 -21
- package/dist/modules/order/sync_engine.js +4 -0
- package/dist/modules/order/utils/math.d.ts +3 -3
- package/dist/modules/order/utils/math.js +38 -27
- package/dist/modules/order/utils/order.d.ts +58 -58
- package/dist/modules/order/utils/order.js +119 -102
- package/dist/modules/order/utils/system.d.ts +193 -6
- package/dist/modules/order/utils/system.js +392 -29
- package/dist/modules/order/utils/validate.js +26 -4
- package/dist/modules/runtime_settings.d.ts +1 -1
- package/dist/modules/runtime_settings.js +3 -3
- package/dist/modules/types.d.ts +48 -4
- package/dist/scripts/analyze-orders.d.ts +1 -1
- package/dist/scripts/analyze-orders.js +4 -4
- package/dist/scripts/divergence-calc.js +6 -6
- package/dist/scripts/validate_bots.d.ts +1 -1
- package/dist/scripts/validate_bots.js +3 -3
- package/dist/unlock.js +7 -2
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -2
- package/docs/COW_INVARIANTS.md +6 -6
- package/docs/DEXBOT_COMPARISON.md +5 -5
- package/docs/EVOLUTION.md +8 -7
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +8 -6
- package/docs/GRID_PRICE_INVARIANT.md +3 -3
- package/docs/GRID_RECALCULATION.md +4 -1
- package/docs/GRID_RECONCILE.md +4 -4
- package/docs/LIFECYCLE.md +11 -11
- package/docs/LOGGING.md +14 -0
- package/docs/MPA_CREDIT_USAGE.md +1 -1
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +12 -4
- package/docs/README.md +3 -3
- package/docs/architecture.md +6 -6
- package/docs/developer_guide.md +7 -2
- package/package.json +1 -1
- package/tests/README.md +1 -1
|
@@ -315,16 +315,186 @@ export declare function persistGridSnapshot(manager: OrderManagerLike, accountOr
|
|
|
315
315
|
* @returns {number} Number of streak entries restored
|
|
316
316
|
*/
|
|
317
317
|
export declare function restoreGapEvacStreaks(manager: OrderManagerLike, persisted: unknown): number;
|
|
318
|
+
/** Why spread correction is degraded or refused for a cycle. */
|
|
319
|
+
export type SpreadCorrectionRefusalReason = 'cold-book' | 'stale-snapshot' | 'unmatched-orders';
|
|
320
|
+
export interface SpreadCorrectionReadiness {
|
|
321
|
+
/** False => hard refusal (cold book): the planner must not act this cycle. */
|
|
322
|
+
ok: boolean;
|
|
323
|
+
/** Degraded cause ('stale-snapshot'/'unmatched-orders') or hard cause ('cold-book'). */
|
|
324
|
+
reason: SpreadCorrectionRefusalReason | null;
|
|
325
|
+
/**
|
|
326
|
+
* Crossing floor for the planner's filter: the freshest live market read
|
|
327
|
+
* when available, else the fill-derived reference. null => no floor
|
|
328
|
+
* (fail-open). Not a refusal premise.
|
|
329
|
+
*/
|
|
330
|
+
marketRef: number | null;
|
|
331
|
+
/** Fill-derived reference only (live pivot or persisted row); gates the COW bypass. */
|
|
332
|
+
fillMarketRef: number | null;
|
|
333
|
+
/** False => the local snapshot cannot license the LAST-FILL-GUARD bypass. */
|
|
334
|
+
snapshotTrusted: boolean;
|
|
335
|
+
/** Known-unmatched chain orders from the last sync (price-level collision filter input). */
|
|
336
|
+
unmatched: UnmatchedChainOrderLike[];
|
|
337
|
+
}
|
|
338
|
+
/** Narrowed read-only view of an unmatched chain order used by the readiness gate. */
|
|
339
|
+
export interface UnmatchedChainOrderLike extends Record<string, unknown> {
|
|
340
|
+
price?: number;
|
|
341
|
+
orderId?: string;
|
|
342
|
+
chainOrderId?: string;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* The single freshness window shared by the spread-correction trust decisions
|
|
346
|
+
* that are time-based: snapshot staleness (and therefore the COW bypass) and
|
|
347
|
+
* the live-market-price refresh pacing. Resolved once so a per-bot
|
|
348
|
+
* `config.timing` override cannot make one check trust what another rejects.
|
|
349
|
+
* The crossing floor itself does NOT use a time window — it picks the newer
|
|
350
|
+
* of the live read and the fill.
|
|
351
|
+
*
|
|
352
|
+
* 0 (constant unset) => no time bound: staleness never triggers and the
|
|
353
|
+
* live-price refresh is never forced, so the crossing floor stays on the fill
|
|
354
|
+
* anchor. Fail-open, matching the never-synced first-tick behavior.
|
|
355
|
+
*
|
|
356
|
+
* @param {Object} manager - OrderManager instance
|
|
357
|
+
* @returns {number} Freshness window in ms (0 => no bound => fail-open)
|
|
358
|
+
*/
|
|
359
|
+
export declare function resolveSpreadFreshnessMs(manager: OrderManagerLike): number;
|
|
360
|
+
/**
|
|
361
|
+
* Resolve the crossing floor spread correction must not trade through.
|
|
362
|
+
*
|
|
363
|
+
* Two pieces of real market evidence can supply the floor: an externally
|
|
364
|
+
* observed live price (order book/ticker) and the fill-derived reference
|
|
365
|
+
* (last account trade). Neither is judged by a threshold — the NEWER one wins.
|
|
366
|
+
* A live read older than the last fill loses to the fill (an executed trade is
|
|
367
|
+
* fresher market truth); a live read at least as new wins; with no live read
|
|
368
|
+
* at all the fill is used; with neither the floor is null (fail-open).
|
|
369
|
+
*
|
|
370
|
+
* This is what lets us drop the arbitrary "how far is too far" distance cap:
|
|
371
|
+
* we keep the floor fresh and compare evidence by recency, rather than guessing
|
|
372
|
+
* when an old floor went stale.
|
|
373
|
+
*
|
|
374
|
+
* @param {Object} manager - OrderManager instance
|
|
375
|
+
* @returns {number|null} Crossing floor or null (fail-open)
|
|
376
|
+
*/
|
|
377
|
+
export declare function resolveSpreadCrossingFloor(manager: OrderManagerLike): number | null;
|
|
378
|
+
/**
|
|
379
|
+
* Refresh the cached live market price from the order book/ticker.
|
|
380
|
+
* Best-effort; caches only a finite positive price. Returns the new price or
|
|
381
|
+
* null. Call through maybeRefreshLiveMarketPrice to respect the pacing bound.
|
|
382
|
+
*
|
|
383
|
+
* @param {Object} manager - OrderManager instance
|
|
384
|
+
* @param {unknown} BitShares - BitShares client
|
|
385
|
+
* @returns {Promise<number|null>} New price or null
|
|
386
|
+
*/
|
|
387
|
+
export declare function refreshLiveMarketPrice(manager: OrderManagerLike, BitShares: unknown): Promise<number | null>;
|
|
388
|
+
/**
|
|
389
|
+
* Refresh the live market price if none is fresh, pacing attempts to one per
|
|
390
|
+
* freshness window so a chain that keeps failing cannot turn the spread check
|
|
391
|
+
* into an RPC loop. The spread path stays RPC-free while the cache is fresh.
|
|
392
|
+
*
|
|
393
|
+
* @param {Object} manager - OrderManager instance
|
|
394
|
+
* @param {unknown} BitShares - BitShares client
|
|
395
|
+
* @param {Object} [options]
|
|
396
|
+
* @param {number} [options.now] - Injectable clock (tests)
|
|
397
|
+
* @returns {Promise<number|null>} Cached/new price or null
|
|
398
|
+
*/
|
|
399
|
+
export declare function maybeRefreshLiveMarketPrice(manager: OrderManagerLike, BitShares: unknown, options?: {
|
|
400
|
+
now?: number;
|
|
401
|
+
}): Promise<number | null>;
|
|
402
|
+
/**
|
|
403
|
+
* Evaluate whether spread correction may act on the current local snapshot,
|
|
404
|
+
* in ONE place. Pure: reads manager state, returns a verdict, no side effects;
|
|
405
|
+
* the caller maps the reason to a stall and the existing wiring arms the
|
|
406
|
+
* targeted sync.
|
|
407
|
+
*
|
|
408
|
+
* Premises:
|
|
409
|
+
* - P-A cold book (no live order on either side): `ok=false` — hard refusal,
|
|
410
|
+
* there is no realized spread to repair and only the reconcile path owns
|
|
411
|
+
* the first window. Requires `options.onChainOrders`; skipped otherwise.
|
|
412
|
+
* - P-B stale snapshot (a completed sync is older than the freshness window):
|
|
413
|
+
* degraded-ok — the planner may still act, but `snapshotTrusted=false` so
|
|
414
|
+
* the LAST-FILL-GUARD bypass is withheld. Never-synced is treated as fresh
|
|
415
|
+
* (historical fail-open for the first tick).
|
|
416
|
+
* - P-C known-unmatched chain orders: degraded-ok — plan, but the collision
|
|
417
|
+
* filter drops their price levels and `snapshotTrusted=false`.
|
|
418
|
+
*
|
|
419
|
+
* The market anchor is deliberately NOT a refusal premise — it is returned for
|
|
420
|
+
* the crossing filter, and a real fill denies the bypass via `fillMarketRef`.
|
|
421
|
+
*
|
|
422
|
+
* @param {Object} manager - OrderManager instance
|
|
423
|
+
* @param {Object} [options]
|
|
424
|
+
* @param {number} [options.now] - Injectable clock (tests)
|
|
425
|
+
* @param {Object|null} [options.onChainOrders] - Live local window view; enables P-A
|
|
426
|
+
* @returns {SpreadCorrectionReadiness} Readiness verdict
|
|
427
|
+
*/
|
|
428
|
+
export declare function evaluateSpreadCorrectionReadiness(manager: OrderManagerLike, options?: {
|
|
429
|
+
now?: number;
|
|
430
|
+
onChainOrders?: {
|
|
431
|
+
buys: unknown[];
|
|
432
|
+
sells: unknown[];
|
|
433
|
+
} | null;
|
|
434
|
+
}): SpreadCorrectionReadiness;
|
|
435
|
+
/**
|
|
436
|
+
* Resolve the last real FILL price — the fill-derived market reference.
|
|
437
|
+
* Returns null (fail-open) when no real fill is known.
|
|
438
|
+
*
|
|
439
|
+
* The bot's grid anchor (AMA/startPrice) and its own book mid are NOT market
|
|
440
|
+
* references — they are grid geometry or the bot's own quotes — so they are
|
|
441
|
+
* deliberately not used here. Only a real fill price qualifies: the live
|
|
442
|
+
* LAST-FILL-GUARD pivot when it is fill-provenanced, else the bot-scoped
|
|
443
|
+
* persisted reference that survives grid regeneration.
|
|
444
|
+
*
|
|
445
|
+
* Feeds the COW bypass gate (via the readiness verdict's `fillMarketRef`) and
|
|
446
|
+
* is the fallback crossing floor when no fresh live market read exists.
|
|
447
|
+
*
|
|
448
|
+
* @param {Object} manager - OrderManager instance
|
|
449
|
+
* @returns {number|null} Reference price or null
|
|
450
|
+
*/
|
|
451
|
+
export declare function resolveSpreadMarketReference(manager: OrderManagerLike): number | null;
|
|
452
|
+
/**
|
|
453
|
+
* Resolve the reference the generic LAST-FILL-GUARD judges against.
|
|
454
|
+
*
|
|
455
|
+
* Prefers the live armed pivot. When that is cold (a grid regeneration
|
|
456
|
+
* cleared it, or a rejected-snapshot reset ran) it falls back to the
|
|
457
|
+
* bot-scoped last-market-fill row — the same market truth spread correction
|
|
458
|
+
* already uses. This is what stops a rebuild from silently un-arming the
|
|
459
|
+
* guard until the next fill: the price the account last traded at is known,
|
|
460
|
+
* so a CREATE/rotation must still not cross it.
|
|
461
|
+
*
|
|
462
|
+
* Read-time fallback only: it does NOT mutate the pivot or persist an
|
|
463
|
+
* old-generation value, so the genesis-bound pivot/persist contract is
|
|
464
|
+
* unchanged. The guard still validates the value onto the CURRENT ladder via
|
|
465
|
+
* resolveOnGridPivot at the call site (off-ladder → raw value + warn), so a
|
|
466
|
+
* regenerated geometry stays the authority on which placements are off-grid.
|
|
467
|
+
*
|
|
468
|
+
* @param {Object} manager - OrderManager instance
|
|
469
|
+
* @returns {{price: number|null, type: string|null}} Effective pivot (both null when cold)
|
|
470
|
+
*/
|
|
471
|
+
export declare function resolveLastFillGuardReference(manager: OrderManagerLike): {
|
|
472
|
+
price: number | null;
|
|
473
|
+
type: string | null;
|
|
474
|
+
};
|
|
475
|
+
/**
|
|
476
|
+
* Restore the persisted bot-scoped last-market-fill reference into the
|
|
477
|
+
* manager. Deliberately independent of the boundary and the genesis: this is
|
|
478
|
+
* the anchor spread correction uses to avoid trading through the last real
|
|
479
|
+
* fill price, and it must survive a grid regeneration (the genesis-bound
|
|
480
|
+
* LAST-FILL-GUARD pivot does not). TTL-expired rows are erased from disk,
|
|
481
|
+
* mirroring restoreLastFillPivot's dead-row hygiene.
|
|
482
|
+
*
|
|
483
|
+
* @param {Object} manager - OrderManager instance
|
|
484
|
+
* @param {unknown} persisted - {price, type, fillsAt} from loadLastMarketFill
|
|
485
|
+
* @param {Object} [options]
|
|
486
|
+
* @param {number} [options.now] - Injectable clock (tests)
|
|
487
|
+
* @returns {boolean} True when the reference was restored
|
|
488
|
+
*/
|
|
489
|
+
export declare function restoreLastMarketFill(manager: OrderManagerLike, persisted: unknown, options?: {
|
|
490
|
+
now?: number;
|
|
491
|
+
}): boolean;
|
|
318
492
|
/**
|
|
319
493
|
* Normalize a persisted LAST-FILL-GUARD pivot row (shared by the
|
|
320
494
|
* AccountOrders sanitizer/loader and the payload builder's row contract).
|
|
321
495
|
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
* - finite price > 0
|
|
325
|
-
* - type is ORDER_TYPES.BUY or ORDER_TYPES.SELL
|
|
326
|
-
* - finite fillsAt > 0
|
|
327
|
-
* - non-empty string genesisHash
|
|
496
|
+
* The shared normalizeFillRow gate plus a non-empty string genesisHash (the
|
|
497
|
+
* pivot is bound to the grid generation; the market row deliberately is not).
|
|
328
498
|
*
|
|
329
499
|
* @param {unknown} row - Raw candidate row
|
|
330
500
|
* @returns {Object|null} Normalized row or null
|
|
@@ -335,6 +505,23 @@ export declare function normalizeLastFillPivot(row: unknown): {
|
|
|
335
505
|
fillsAt: number;
|
|
336
506
|
genesisHash: string;
|
|
337
507
|
} | null;
|
|
508
|
+
/**
|
|
509
|
+
* Normalize a persisted bot-scoped last-market-fill row.
|
|
510
|
+
*
|
|
511
|
+
* Same normalizeFillRow contract as normalizeLastFillPivot but deliberately
|
|
512
|
+
* WITHOUT the genesisHash binding: this row is market truth about the account
|
|
513
|
+
* (the last price it traded at), not grid geometry, so it must survive a grid
|
|
514
|
+
* regeneration/rejection. It is used only as a market reference by spread
|
|
515
|
+
* correction, never as the COW LAST-FILL-GUARD pivot.
|
|
516
|
+
*
|
|
517
|
+
* @param {unknown} row - Raw candidate row
|
|
518
|
+
* @returns {{price:number,type:string,fillsAt:number}|null} Normalized row or null
|
|
519
|
+
*/
|
|
520
|
+
export declare function normalizeLastMarketFill(row: unknown): {
|
|
521
|
+
price: number;
|
|
522
|
+
type: string;
|
|
523
|
+
fillsAt: number;
|
|
524
|
+
} | null;
|
|
338
525
|
/**
|
|
339
526
|
* Write the LAST-FILL-GUARD pivot scalar family in one place (free
|
|
340
527
|
* implementation shared by the manager method, cow_runtime's queued-fill
|