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
|
@@ -4,7 +4,7 @@ import { _countActiveOnGrid, _cancelChainOrder, _recoverStartupSyncFailure, _ref
|
|
|
4
4
|
import { ORDER_TYPES, ORDER_STATES, TIMING } from '../constants.js';
|
|
5
5
|
import { readOpenOrdersGuarded } from '../chain_orders.js';
|
|
6
6
|
import { getAssetFeesSafe, priceSlotEqual } from './utils/math.js';
|
|
7
|
-
import { isOrderPlaced, parseChainOrder, isOrderOnChain, findLiveOrderOwnerByChainId, chainOrderMatchesSlotWithTolerance, duplicateOrphanLogInfo,
|
|
7
|
+
import { isOrderPlaced, parseChainOrder, isOrderOnChain, findLiveOrderOwnerByChainId, chainOrderMatchesSlotWithTolerance, duplicateOrphanLogInfo, resolveEdgeCount, } from './utils/order.js';
|
|
8
8
|
import * as Format from './format.js';
|
|
9
9
|
import { getErrorMessage } from '../utils/errors.js';
|
|
10
10
|
function _startupChainSnapshotSignature(orders, manager) {
|
|
@@ -142,7 +142,7 @@ export async function decideStartupGridAction({ persistedGrid, chainOpenOrders,
|
|
|
142
142
|
* - Then create missing orders if chain has fewer than target.
|
|
143
143
|
* - Then cancel excess orders if chain has more than target.
|
|
144
144
|
*
|
|
145
|
-
* Targets are derived from config.
|
|
145
|
+
* Targets are derived from config.coreOrders.{buy,sell} and chain counts are computed
|
|
146
146
|
* from current on-chain open orders.
|
|
147
147
|
* @param {Object} params - Destructured parameters
|
|
148
148
|
* @param {Object} params.manager - OrderManager instance
|
|
@@ -180,11 +180,11 @@ export async function reconcileGridOrders({ manager, config, account, privateKey
|
|
|
180
180
|
const parsedChain = (chainOpenOrders || [])
|
|
181
181
|
.map((co) => ({ chain: co, parsed: parseChainOrder(co, manager.assets) }))
|
|
182
182
|
.filter((x) => x.parsed !== null);
|
|
183
|
-
const activeCfg = (config && config.
|
|
183
|
+
const activeCfg = (config && config.coreOrders) ? config.coreOrders : {};
|
|
184
184
|
let targetBuy = Math.max(0, Number.isFinite(Number(activeCfg.buy)) ? Number(activeCfg.buy) : 1)
|
|
185
|
-
+
|
|
185
|
+
+ resolveEdgeCount(config, 'buy');
|
|
186
186
|
let targetSell = Math.max(0, Number.isFinite(Number(activeCfg.sell)) ? Number(activeCfg.sell) : 1)
|
|
187
|
-
+
|
|
187
|
+
+ resolveEdgeCount(config, 'sell');
|
|
188
188
|
const chainBuys = parsedChain.filter((x) => x.parsed.type === ORDER_TYPES.BUY).map((x) => x.chain);
|
|
189
189
|
const chainSells = parsedChain.filter((x) => x.parsed.type === ORDER_TYPES.SELL).map((x) => x.chain);
|
|
190
190
|
// PHASE 1: In-memory reconciliation under lock — pure planning, no blockchain I/O.
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { ORDER_TYPES, ORDER_STATES, TIMING, BTS_PRECISION } from '../constants.js';
|
|
8
8
|
import { readOpenOrdersGuarded } from '../chain_orders.js';
|
|
9
9
|
import { getMinOrderSize, getAssetFees, getAssetFeesSafe, blockchainToFloat, findCrossedOrder, resolveGapBand, isSlotInRail, priceSlotEqual } from './utils/math.js';
|
|
10
|
-
import { isOrderPlaced, parseChainOrder, buildCreateOrderArgs, buildOutsideInPairGroups, extractBatchOperationResults, chainOrderMatchesSlotWithTolerance, buildCrossingCheckCandidates, isCrossingCheckCandidate, getSideBudget, calculateBudgetedSizes,
|
|
10
|
+
import { isOrderPlaced, parseChainOrder, buildCreateOrderArgs, buildOutsideInPairGroups, extractBatchOperationResults, chainOrderMatchesSlotWithTolerance, buildCrossingCheckCandidates, isCrossingCheckCandidate, getSideBudget, calculateBudgetedSizes, getCoreOrdersTotal, convertToSpreadPlaceholder, isOrderGoneErrorMessage, clearDuplicateOrphanDetection, resolveEdgeCount, resolveLiveEdgeAnchorPrice, edgeOrderIdSet, compareEdge, parseSlotIndex, reportGridPriceInvariant, liveWindowIdSet } from './utils/order.js';
|
|
11
11
|
import { resolveAccountRef } from './utils/system.js';
|
|
12
12
|
import * as Format from './format.js';
|
|
13
13
|
import { getErrorMessage, getErrorCode, getErrorName } from '../utils/errors.js';
|
|
@@ -58,7 +58,7 @@ function computePlacementCrossing(manager, gridOrder, excludeChainOrderId = null
|
|
|
58
58
|
*/
|
|
59
59
|
function _countActiveOnGrid(manager, type) {
|
|
60
60
|
// Slot-N gated: fork-kept shelf/manual orders (non-slot-N ids, e.g.
|
|
61
|
-
// deep-*) sit outside window accounting — same gate as
|
|
61
|
+
// deep-*) sit outside window accounting — same gate as edge
|
|
62
62
|
// classification and matched-excess candidates (issue #27 follow-up).
|
|
63
63
|
// Without this, a live shelf inflates matchedOnGrid, suppresses
|
|
64
64
|
// neededSlots/creates, and its chain-count surplus cancels real window
|
|
@@ -107,7 +107,7 @@ function _deriveBudgetedSideSizes(manager, type) {
|
|
|
107
107
|
if (!funds)
|
|
108
108
|
return derived;
|
|
109
109
|
const side = type === ORDER_TYPES.BUY ? 'buy' : 'sell';
|
|
110
|
-
const totalTarget =
|
|
110
|
+
const totalTarget = getCoreOrdersTotal(manager.config);
|
|
111
111
|
const budget = getSideBudget(side, funds, manager.config, totalTarget);
|
|
112
112
|
if (!(budget > 0))
|
|
113
113
|
return derived;
|
|
@@ -182,7 +182,7 @@ function _pickVirtualSlotsToActivate(manager, type, count) {
|
|
|
182
182
|
.filter(typeFilter)
|
|
183
183
|
.filter(inRail)
|
|
184
184
|
// Slot-N gated: fork-kept shelf/manual slots (non-slot-N ids, e.g.
|
|
185
|
-
// deep-*) must never activate as window orders — same gate as
|
|
185
|
+
// deep-*) must never activate as window orders — same gate as edge
|
|
186
186
|
// classification and startup cancel candidates (issue #27 follow-up).
|
|
187
187
|
// A VIRTUAL shelf passes the type + fail-open geometry filters above;
|
|
188
188
|
// without this it would consume window activation budget at an
|
|
@@ -235,10 +235,10 @@ function _pickVirtualSlotsToActivate(manager, type, count) {
|
|
|
235
235
|
return valid;
|
|
236
236
|
}
|
|
237
237
|
/**
|
|
238
|
-
* Pick edge-pinned
|
|
238
|
+
* Pick edge-pinned edge slots (floor for BUY, ceiling for SELL).
|
|
239
239
|
* Same rail membership gate as _pickVirtualSlotsToActivate, opposite end:
|
|
240
|
-
* the
|
|
241
|
-
* Size gate is STRICTER than that picker's —
|
|
240
|
+
* the edge ladder rests at the grid edge instead of the market window.
|
|
241
|
+
* Size gate is STRICTER than that picker's — edge orders activate only with
|
|
242
242
|
* their own stored size (>= min order size), never a locally derived one,
|
|
243
243
|
* so an unsized edge slot waits for the target-grid sizing pipeline.
|
|
244
244
|
* @param {Object} manager - OrderManager instance.
|
|
@@ -248,7 +248,7 @@ function _pickVirtualSlotsToActivate(manager, type, count) {
|
|
|
248
248
|
* @returns {Array<Object>} Array of picked edge slots (edge first).
|
|
249
249
|
* @private
|
|
250
250
|
*/
|
|
251
|
-
function
|
|
251
|
+
function _pickEdgeSlots(manager, orderType, count, excludeIds = null) {
|
|
252
252
|
if (count <= 0)
|
|
253
253
|
return [];
|
|
254
254
|
const type = orderType;
|
|
@@ -259,20 +259,20 @@ function _pickEdgeReserveSlots(manager, orderType, count, excludeIds = null) {
|
|
|
259
259
|
const typeFilter = boundaryKnown
|
|
260
260
|
? (slot) => slot && (slot.type === type || slot.type === ORDER_TYPES.SPREAD)
|
|
261
261
|
: (slot) => slot && slot.type === type;
|
|
262
|
-
//
|
|
262
|
+
// Edge classification (edgeOrderIdSet / countLiveEdgeOrders) is
|
|
263
263
|
// slot-N gated; keep placement in agreement so a kept virtual non-grid
|
|
264
|
-
// shelf is never activated as
|
|
264
|
+
// shelf is never activated as an edge order it would then never be counted
|
|
265
265
|
// as (issue #27 follow-up). No-op upstream (grids only mint slot-N).
|
|
266
266
|
const gridSlot = (slot) => parseSlotIndex(slot?.id) !== null;
|
|
267
267
|
// Both edges anchor at the live grid's own edge (ladder/rail extreme):
|
|
268
268
|
// floor — nearest at/above the live floor first; ceiling — nearest
|
|
269
269
|
// at/below the live ceiling first. Stale out-of-grid slots sort last.
|
|
270
|
-
const edgeAnchor =
|
|
270
|
+
const edgeAnchor = resolveLiveEdgeAnchorPrice(manager, edgeDesc ? 'sell' : 'buy');
|
|
271
271
|
const edgeFirst = Array.from(manager.orders.values())
|
|
272
272
|
.filter(typeFilter)
|
|
273
273
|
.filter(gridSlot)
|
|
274
274
|
.filter(inRail)
|
|
275
|
-
.sort((a, b) =>
|
|
275
|
+
.sort((a, b) => compareEdge(a, b, edgeDesc ? 'ceiling' : 'floor', edgeAnchor));
|
|
276
276
|
let effectiveMin = 0;
|
|
277
277
|
try {
|
|
278
278
|
effectiveMin = getMinOrderSize(type, manager.assets);
|
|
@@ -287,10 +287,10 @@ function _pickEdgeReserveSlots(manager, orderType, count, excludeIds = null) {
|
|
|
287
287
|
if (excludeIds && excludeIds.has(slot.id))
|
|
288
288
|
continue;
|
|
289
289
|
if (!slot.orderId && slot.state === ORDER_STATES.VIRTUAL) {
|
|
290
|
-
// Exact sizes only:
|
|
290
|
+
// Exact sizes only: an edge order is activated solely with the size the
|
|
291
291
|
// grid already carries (written by the target-grid sizing pipeline
|
|
292
292
|
// and persisted with the slot). No local re-derivation — a second
|
|
293
|
-
// sizing rule here could place the
|
|
293
|
+
// sizing rule here could place the edge with a size the target
|
|
294
294
|
// grid then has to correct on the next cycle. An unsized slot
|
|
295
295
|
// simply waits for the sizing pipeline instead of being guessed.
|
|
296
296
|
const storedSize = Number(slot.size) || 0;
|
|
@@ -1401,32 +1401,32 @@ async function _reconcileStartupSide({ orderType, targetCount, chainSideOrders,
|
|
|
1401
1401
|
const matchedOnGrid = _countActiveOnGrid(manager, orderType);
|
|
1402
1402
|
const neededSlots = Math.max(0, targetCount - matchedOnGrid);
|
|
1403
1403
|
let desiredSlots = _pickVirtualSlotsToActivate(manager, orderType, neededSlots);
|
|
1404
|
-
//
|
|
1404
|
+
// Edge ladder: the closest-first picker above backfills the middle. Swap
|
|
1405
1405
|
// its farthest tail for edge-pinned slots (floor for BUY, ceiling for SELL)
|
|
1406
1406
|
// so startup converges to window + edge instead of one contiguous block.
|
|
1407
|
-
let
|
|
1408
|
-
const
|
|
1409
|
-
const
|
|
1410
|
-
if (
|
|
1407
|
+
let edgeOrderIds = null;
|
|
1408
|
+
const edgeSide = orderType === ORDER_TYPES.SELL ? 'sell' : 'buy';
|
|
1409
|
+
const edgeCount = resolveEdgeCount(manager.config, edgeSide);
|
|
1410
|
+
if (edgeCount > 0) {
|
|
1411
1411
|
const pickedIds = new Set(desiredSlots.map((s) => s?.id).filter(Boolean));
|
|
1412
|
-
const freshEdge =
|
|
1413
|
-
const
|
|
1414
|
-
|
|
1415
|
-
// Window first, then the ready edge
|
|
1416
|
-
// still MISSING on-chain is held back for the edge (a live
|
|
1412
|
+
const freshEdge = _pickEdgeSlots(manager, orderType, edgeCount, pickedIds);
|
|
1413
|
+
const edgeAnchor = resolveLiveEdgeAnchorPrice(manager, edgeSide);
|
|
1414
|
+
edgeOrderIds = edgeOrderIdSet(Array.from(manager.orders.values()), manager.config, orderType, edgeAnchor, liveWindowIdSet(manager, orderType));
|
|
1415
|
+
// Window first, then the ready edge orders. Only the edge share
|
|
1416
|
+
// still MISSING on-chain is held back for the edge (a live edge order is
|
|
1417
1417
|
// already part of matchedOnGrid and must not shrink the window plan), so
|
|
1418
1418
|
// an edge pick that is not activatable yet (exact-size rule) leaves its
|
|
1419
1419
|
// slot unplanned: the target-grid pipeline then creates it at the edge
|
|
1420
1420
|
// with its own sizes, instead of the plan filling it with a middle
|
|
1421
1421
|
// window slot that the next cycle would have to rotate out.
|
|
1422
|
-
// Note: if the window picker itself took an edge/
|
|
1422
|
+
// Note: if the window picker itself took an edge/edge slot (only
|
|
1423
1423
|
// when the rail is too short to fill the window closer to market),
|
|
1424
|
-
// that slot is not a placed
|
|
1424
|
+
// that slot is not a placed edge order, so the plan comes out one short
|
|
1425
1425
|
// here and the target grid settles it on the next cycle.
|
|
1426
|
-
const
|
|
1427
|
-
? [...
|
|
1426
|
+
const liveEdges = edgeOrderIds
|
|
1427
|
+
? [...edgeOrderIds].filter((id) => isOrderPlaced(manager.orders.get(id))).length
|
|
1428
1428
|
: 0;
|
|
1429
|
-
const missingReserves = Math.max(0,
|
|
1429
|
+
const missingReserves = Math.max(0, edgeCount - liveEdges);
|
|
1430
1430
|
const keepCount = Math.max(0, neededSlots - missingReserves);
|
|
1431
1431
|
desiredSlots = [...desiredSlots.slice(0, keepCount), ...freshEdge];
|
|
1432
1432
|
}
|
|
@@ -1449,6 +1449,14 @@ async function _reconcileStartupSide({ orderType, targetCount, chainSideOrders,
|
|
|
1449
1449
|
const planVacatedRailRefill = (chainOrder, parsedChain) => {
|
|
1450
1450
|
const boundary = manager.boundaryIdx;
|
|
1451
1451
|
const gapSlots = manager._gapSlots;
|
|
1452
|
+
// Explicit null/undefined/'' guard BEFORE Number(): Number(null) === 0
|
|
1453
|
+
// is finite and would defeat this bail-out, running the refill scan on
|
|
1454
|
+
// a bogus boundary 0 (and a null gapSlots would default to 0 through
|
|
1455
|
+
// getSellStartIdx).
|
|
1456
|
+
if (boundary === null || boundary === undefined || boundary === '')
|
|
1457
|
+
return;
|
|
1458
|
+
if (gapSlots === null || gapSlots === undefined || gapSlots === '')
|
|
1459
|
+
return;
|
|
1452
1460
|
if (!Number.isFinite(Number(boundary)) || !Number.isFinite(Number(gapSlots)))
|
|
1453
1461
|
return;
|
|
1454
1462
|
const chainPrice = parsedChain?.price;
|
|
@@ -1627,14 +1635,14 @@ async function _reconcileStartupSide({ orderType, targetCount, chainSideOrders,
|
|
|
1627
1635
|
.map((co) => ({ chain: co, parsed: parseChainOrder(co, manager.assets) }))
|
|
1628
1636
|
.filter((x) => x.parsed !== null)
|
|
1629
1637
|
.sort(sortExcessCancelComparator);
|
|
1630
|
-
//
|
|
1631
|
-
// candidates at
|
|
1632
|
-
if (
|
|
1638
|
+
// Edge ladder: edge-priced orphans cancel last (they are adoption
|
|
1639
|
+
// candidates at edge prices, not first-to-cut).
|
|
1640
|
+
if (edgeOrderIds && edgeOrderIds.size > 0) {
|
|
1633
1641
|
const sidePrecision = orderType === ORDER_TYPES.SELL
|
|
1634
1642
|
? manager.assets?.assetA?.precision
|
|
1635
1643
|
: manager.assets?.assetB?.precision;
|
|
1636
1644
|
const edgePrices = [];
|
|
1637
|
-
for (const eid of
|
|
1645
|
+
for (const eid of edgeOrderIds) {
|
|
1638
1646
|
const slot = manager.orders.get(eid);
|
|
1639
1647
|
if (slot && Number.isFinite(Number(slot.price)))
|
|
1640
1648
|
edgePrices.push(Number(slot.price));
|
|
@@ -1666,9 +1674,9 @@ async function _reconcileStartupSide({ orderType, targetCount, chainSideOrders,
|
|
|
1666
1674
|
// matched (grid-known) slots. Computed once and shared by both the
|
|
1667
1675
|
// planOnly and execute branches so planning can never drift from
|
|
1668
1676
|
// execution: unmatched orphans cancel first, matched surplus after,
|
|
1669
|
-
//
|
|
1677
|
+
// edge order slots last (static insurance). Slot-N gated: fork-kept
|
|
1670
1678
|
// shelf/manual orders (non-slot-N ids, e.g. deep-*) are never excess
|
|
1671
|
-
// candidates —
|
|
1679
|
+
// candidates — edgeOrderIdSet already excludes them, so without this
|
|
1672
1680
|
// gate a live shelf heads the cheapest-first sort and is wiped on the
|
|
1673
1681
|
// next boot (issue #27 follow-up). No-op upstream (grids only mint
|
|
1674
1682
|
// slot-N).
|
|
@@ -1676,11 +1684,11 @@ async function _reconcileStartupSide({ orderType, targetCount, chainSideOrders,
|
|
|
1676
1684
|
.filter((o) => o && o.orderId)
|
|
1677
1685
|
.filter((o) => parseSlotIndex(o?.id) !== null)
|
|
1678
1686
|
.sort(sortMatchedCancelComparator);
|
|
1679
|
-
//
|
|
1680
|
-
if (
|
|
1687
|
+
// Edge ladder: matched edge slots cancel last (static insurance).
|
|
1688
|
+
if (edgeOrderIds && edgeOrderIds.size > 0) {
|
|
1681
1689
|
matchedExcess.sort((a, b) => {
|
|
1682
|
-
const fa =
|
|
1683
|
-
const fb =
|
|
1690
|
+
const fa = edgeOrderIds.has(a.id) ? 1 : 0;
|
|
1691
|
+
const fb = edgeOrderIds.has(b.id) ? 1 : 0;
|
|
1684
1692
|
return fa - fb;
|
|
1685
1693
|
});
|
|
1686
1694
|
}
|
|
@@ -1712,7 +1720,7 @@ async function _reconcileStartupSide({ orderType, targetCount, chainSideOrders,
|
|
|
1712
1720
|
// could never converge to its additive window+edge target (live
|
|
1713
1721
|
// 12 vs target 8 sat static across every restart). Same priority
|
|
1714
1722
|
// as the execute branch: unmatched first (above), matched after,
|
|
1715
|
-
//
|
|
1723
|
+
// edge order last (matchedExcess ordering).
|
|
1716
1724
|
for (const o of matchedExcess) {
|
|
1717
1725
|
if (cancelCount <= 0)
|
|
1718
1726
|
break;
|
|
@@ -72,12 +72,38 @@ declare const utils: {
|
|
|
72
72
|
accountTotals: import("../types.js").AccountTotals | null;
|
|
73
73
|
}): Promise<boolean>;
|
|
74
74
|
restoreGapEvacStreaks(manager: import("../types.js").OrderManagerLike, persisted: unknown): number;
|
|
75
|
+
resolveSpreadFreshnessMs(manager: import("../types.js").OrderManagerLike): number;
|
|
76
|
+
resolveSpreadCrossingFloor(manager: import("../types.js").OrderManagerLike): number | null;
|
|
77
|
+
refreshLiveMarketPrice(manager: import("../types.js").OrderManagerLike, BitShares: unknown): Promise<number | null>;
|
|
78
|
+
maybeRefreshLiveMarketPrice(manager: import("../types.js").OrderManagerLike, BitShares: unknown, options?: {
|
|
79
|
+
now?: number;
|
|
80
|
+
}): Promise<number | null>;
|
|
81
|
+
evaluateSpreadCorrectionReadiness(manager: import("../types.js").OrderManagerLike, options?: {
|
|
82
|
+
now?: number;
|
|
83
|
+
onChainOrders?: {
|
|
84
|
+
buys: unknown[];
|
|
85
|
+
sells: unknown[];
|
|
86
|
+
} | null;
|
|
87
|
+
}): system.SpreadCorrectionReadiness;
|
|
88
|
+
resolveSpreadMarketReference(manager: import("../types.js").OrderManagerLike): number | null;
|
|
89
|
+
resolveLastFillGuardReference(manager: import("../types.js").OrderManagerLike): {
|
|
90
|
+
price: number | null;
|
|
91
|
+
type: string | null;
|
|
92
|
+
};
|
|
93
|
+
restoreLastMarketFill(manager: import("../types.js").OrderManagerLike, persisted: unknown, options?: {
|
|
94
|
+
now?: number;
|
|
95
|
+
}): boolean;
|
|
75
96
|
normalizeLastFillPivot(row: unknown): {
|
|
76
97
|
price: number;
|
|
77
98
|
type: string;
|
|
78
99
|
fillsAt: number;
|
|
79
100
|
genesisHash: string;
|
|
80
101
|
} | null;
|
|
102
|
+
normalizeLastMarketFill(row: unknown): {
|
|
103
|
+
price: number;
|
|
104
|
+
type: string;
|
|
105
|
+
fillsAt: number;
|
|
106
|
+
} | null;
|
|
81
107
|
setLastFillPivot(manager: import("../types.js").OrderManagerLike, type: string, price: unknown, provenance: "fill" | "book", atMs?: number): boolean;
|
|
82
108
|
resetLastFillPivot(manager: import("../types.js").OrderManagerLike, reason?: string): boolean;
|
|
83
109
|
restoreLastFillPivot(manager: import("../types.js").OrderManagerLike, persisted: unknown, options?: {
|
|
@@ -200,10 +226,10 @@ declare const utils: {
|
|
|
200
226
|
buildDelta: typeof order.buildDelta;
|
|
201
227
|
deriveTargetBoundary: typeof order.deriveTargetBoundary;
|
|
202
228
|
isShiftEligibleFill: typeof order.isShiftEligibleFill;
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
229
|
+
resolveEdgeCount: typeof order.resolveEdgeCount;
|
|
230
|
+
resolveEdgeOrders: typeof order.resolveEdgeOrders;
|
|
231
|
+
selectEdgeSlots: typeof order.selectEdgeSlots;
|
|
232
|
+
getCoreOrdersTotal: typeof order.getCoreOrdersTotal;
|
|
207
233
|
getSideBudget: typeof order.getSideBudget;
|
|
208
234
|
calculateBudgetedSizes: typeof order.calculateBudgetedSizes;
|
|
209
235
|
buildCreateOpFingerprint: typeof order.buildCreateOpFingerprint;
|
|
@@ -214,13 +240,13 @@ declare const utils: {
|
|
|
214
240
|
chainOrderUnchangedFromCache: typeof order.chainOrderUnchangedFromCache;
|
|
215
241
|
detectCrossedBookPlan: typeof order.detectCrossedBookPlan;
|
|
216
242
|
collectKnownOnChainOrderIds: typeof order.collectKnownOnChainOrderIds;
|
|
217
|
-
|
|
243
|
+
edgeOrderIdSet: typeof order.edgeOrderIdSet;
|
|
218
244
|
liveWindowIdSet: typeof order.liveWindowIdSet;
|
|
219
245
|
checkGridPriceInvariant: typeof order.checkGridPriceInvariant;
|
|
220
246
|
reportGridPriceInvariant: typeof order.reportGridPriceInvariant;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
247
|
+
resolveEdgeAnchorPrice: typeof order.resolveEdgeAnchorPrice;
|
|
248
|
+
resolveLiveEdgeAnchorPrice: typeof order.resolveLiveEdgeAnchorPrice;
|
|
249
|
+
compareEdge: typeof order.compareEdge;
|
|
224
250
|
collectRefillSlotIds: typeof order.collectRefillSlotIds;
|
|
225
251
|
recordOrderPlacement: typeof order.recordOrderPlacement;
|
|
226
252
|
isFreshlyPlacedOrder: typeof order.isFreshlyPlacedOrder;
|
|
@@ -544,7 +544,7 @@ class Logger {
|
|
|
544
544
|
if (!this.config.display?.statusSummary?.enabled && !forceOutput)
|
|
545
545
|
return;
|
|
546
546
|
const market = manager.marketName || manager.config?.market || 'unknown';
|
|
547
|
-
const
|
|
547
|
+
const liveOrders = manager.getOrdersByTypeAndState?.(null, ORDER_STATES.ACTIVE) || [];
|
|
548
548
|
const partialOrders = manager.getOrdersByTypeAndState?.(null, ORDER_STATES.PARTIAL) || [];
|
|
549
549
|
const virtualOrders = manager.getOrdersByTypeAndState?.(null, ORDER_STATES.VIRTUAL) || [];
|
|
550
550
|
const buyName = manager.config?.assetB?.symbol || manager.config?.assetB || 'quote';
|
|
@@ -570,7 +570,7 @@ class Logger {
|
|
|
570
570
|
`virtual.grid: ${buy}Buy ${Format.formatAmountByPrecision(virtualBuy, buyPrecision)}${reset} ${buyName} | ${sell}Sell ${Format.formatAmountByPrecision(virtualSell, sellPrecision)}${reset} ${sellName}`,
|
|
571
571
|
`committed.grid: ${buy}Buy ${Format.formatAmountByPrecision(committedGridBuy, buyPrecision)}${reset} ${buyName} | ${sell}Sell ${Format.formatAmountByPrecision(committedGridSell, sellPrecision)}${reset} ${sellName}`,
|
|
572
572
|
`committed.chain: ${buy}Buy ${Format.formatAmountByPrecision(committedChainBuy, buyPrecision)}${reset} ${buyName} | ${sell}Sell ${Format.formatAmountByPrecision(committedChainSell, sellPrecision)}${reset} ${sellName}`,
|
|
573
|
-
`Orders: Virtual ${virtualOrders.length} | Active ${
|
|
573
|
+
`Orders: Virtual ${virtualOrders.length} | Active ${liveOrders.length} | Partial ${partialOrders.length}`,
|
|
574
574
|
`Spreads: ${manager.initialSpreadCount > 0 ? `${manager.currentSpreadCount}/${manager.initialSpreadCount} (gap)` : 'n/a (gap)'}`,
|
|
575
575
|
];
|
|
576
576
|
if (typeof manager.calculateCurrentSpread === 'function') {
|
|
@@ -77,7 +77,7 @@ interface COWExecuteParams {
|
|
|
77
77
|
excludeIds?: Set<string>;
|
|
78
78
|
gapSlots?: number | null;
|
|
79
79
|
evacStreaks?: Map<string, number> | null;
|
|
80
|
-
|
|
80
|
+
edgeAnchors?: {
|
|
81
81
|
buy?: number | null;
|
|
82
82
|
sell?: number | null;
|
|
83
83
|
} | null;
|
|
@@ -93,7 +93,7 @@ declare class COWRebalanceEngine {
|
|
|
93
93
|
assets: AssetPair | null;
|
|
94
94
|
config: GridConfig;
|
|
95
95
|
});
|
|
96
|
-
execute({ masterGrid, gridVersion, boundaryIdx, funds, manager, fills, excludeIds, gapSlots, evacStreaks,
|
|
96
|
+
execute({ masterGrid, gridVersion, boundaryIdx, funds, manager, fills, excludeIds, gapSlots, evacStreaks, edgeAnchors }: COWExecuteParams): Promise<RebalanceResult>;
|
|
97
97
|
}
|
|
98
98
|
declare class OrderManager implements OrderManagerLike {
|
|
99
99
|
config: GridConfig;
|
|
@@ -220,6 +220,13 @@ declare class OrderManager implements OrderManagerLike {
|
|
|
220
220
|
_lastFilledType: string | null;
|
|
221
221
|
_lastFilledAt: number;
|
|
222
222
|
lastFillPivotSource: 'fill' | 'book' | null;
|
|
223
|
+
_lastMarketFillPrice: number | null;
|
|
224
|
+
_lastMarketFillType: string | null;
|
|
225
|
+
_lastMarketFillAt: number;
|
|
226
|
+
_liveMarketPrice: number | null;
|
|
227
|
+
_liveMarketPriceAt: number;
|
|
228
|
+
_liveMarketPriceAttemptedAt: number;
|
|
229
|
+
_lastSyncAt: number;
|
|
223
230
|
_deferredRebalanceAt: number;
|
|
224
231
|
_lastHeldPlanSignature: {
|
|
225
232
|
boundaryIdx: number | null;
|
|
@@ -30,7 +30,7 @@ import { ORDER_TYPES, ORDER_STATES, REBALANCE_STATES, TIMING, LOG_LEVEL, PIPELIN
|
|
|
30
30
|
import { seedBotRuntimeConfig } from '../bot_defaults.js';
|
|
31
31
|
import { getMinOrderSize, computeChainFundTotals, hasValidAccountTotals, resolveConfigValueWithRegistry, isExplicitZeroAllocation, floatToBlockchainInt, validateBoundaryCommit, resolveGapSlots, resolveGapBand, isSlotInRail } from './utils/math.js';
|
|
32
32
|
import { validateOrder, validateGridForPersistence, validateWorkingGridFunds, checkFundDrift, reconcileGrid, optimizeRebalanceActions, projectTargetToWorkingGrid, buildStateUpdates, buildAbortedResult, buildSuccessResult, evaluateCommit } from './utils/validate.js';
|
|
33
|
-
import { resolveSpreadOrderSide, parseSlotIndex, parseChainOrder, geometryTypeForSlotIndex, isOrderOnChain,
|
|
33
|
+
import { resolveSpreadOrderSide, parseSlotIndex, parseChainOrder, geometryTypeForSlotIndex, isOrderOnChain, resolveEdgeCount, resolveLiveEdgeAnchorPrice, compareEdge, collectRefillSlotIds, recordOrderPlacement, isFreshlyPlacedOrder } from './utils/order.js';
|
|
34
34
|
import { getErrorMessage, getErrorCode } from '../utils/errors.js';
|
|
35
35
|
const { toFiniteNumber } = Format;
|
|
36
36
|
function stalePlacementDropReason(action, planBoundary) {
|
|
@@ -99,7 +99,7 @@ class COWRebalanceEngine {
|
|
|
99
99
|
this.assets = deps.assets;
|
|
100
100
|
this.config = deps.config;
|
|
101
101
|
}
|
|
102
|
-
async execute({ masterGrid, gridVersion, boundaryIdx, funds, manager = null, fills = [], excludeIds = new Set(), gapSlots = null, evacStreaks = null,
|
|
102
|
+
async execute({ masterGrid, gridVersion, boundaryIdx, funds, manager = null, fills = [], excludeIds = new Set(), gapSlots = null, evacStreaks = null, edgeAnchors = null }) {
|
|
103
103
|
const startTime = Date.now();
|
|
104
104
|
const workingGrid = new WorkingGrid(masterGrid, { baseVersion: gridVersion });
|
|
105
105
|
const strategyParams = {
|
|
@@ -219,6 +219,10 @@ class COWRebalanceEngine {
|
|
|
219
219
|
// boundary-hold still judge the plan; no geometry is refused here.
|
|
220
220
|
{
|
|
221
221
|
const railSize = targetGrid?.size ?? 0;
|
|
222
|
+
// Null boundary is DELIBERATELY compared against numeric 0 here:
|
|
223
|
+
// the recovery plan's window is measured from rail start, and an
|
|
224
|
+
// off-rail truncation is exactly the telemetry this warn surfaces
|
|
225
|
+
// (see ANCHOR-007). It never gates the plan.
|
|
222
226
|
const gap = Number(gapSlots) || 0;
|
|
223
227
|
const sellStart = Number(targetBoundary) + gap + 1;
|
|
224
228
|
if (Number.isFinite(sellStart) && railSize > 0 && sellStart >= railSize) {
|
|
@@ -230,13 +234,13 @@ class COWRebalanceEngine {
|
|
|
230
234
|
// stamped UPDATEs above; stale-dropped placements are excluded — a
|
|
231
235
|
// deferred placement justifies nothing). The executor holds the
|
|
232
236
|
// committed boundary when a listed refill is guard-skipped.
|
|
233
|
-
//
|
|
237
|
+
// Edge-ladder CREATEs are excluded (collectRefillSlotIds): edge orders
|
|
234
238
|
// are static edge insurance and their fills never crawl, so a skipped
|
|
235
|
-
//
|
|
239
|
+
// edge order must not pin geometry either.
|
|
236
240
|
const refillSlotIds = collectRefillSlotIds(optimizedActions, {
|
|
237
241
|
config: this.config,
|
|
238
242
|
slots: masterGrid,
|
|
239
|
-
edgeAnchors:
|
|
243
|
+
edgeAnchors: edgeAnchors,
|
|
240
244
|
manager: this
|
|
241
245
|
});
|
|
242
246
|
projectTargetToWorkingGrid(workingGrid, targetGrid, { actions: optimizedActions });
|
|
@@ -430,6 +434,24 @@ class OrderManager {
|
|
|
430
434
|
_lastFilledType;
|
|
431
435
|
_lastFilledAt;
|
|
432
436
|
lastFillPivotSource;
|
|
437
|
+
// Bot-scoped "last market fill" reference. Unlike the genesis-bound
|
|
438
|
+
// LAST-FILL-GUARD pivot (reset with the grid generation), this survives a
|
|
439
|
+
// grid regeneration/rejection and is used ONLY as a market anchor by
|
|
440
|
+
// spread correction (a real fill price must not be traded through).
|
|
441
|
+
// Written by setLastFillPivot on 'fill' provenance; restored at startup
|
|
442
|
+
// from the bot-scoped persisted row under a TTL.
|
|
443
|
+
_lastMarketFillPrice;
|
|
444
|
+
_lastMarketFillType;
|
|
445
|
+
_lastMarketFillAt;
|
|
446
|
+
// Externally-observed live market price (B/A), refreshed from the order
|
|
447
|
+
// book/ticker at a bounded cadence. The spread-correction crossing floor is
|
|
448
|
+
// the NEWER of this read and the fill anchor (an executed trade can be
|
|
449
|
+
// fresher market truth), so the floor tracks current market instead of a
|
|
450
|
+
// possibly days-old fill.
|
|
451
|
+
_liveMarketPrice;
|
|
452
|
+
_liveMarketPriceAt;
|
|
453
|
+
_liveMarketPriceAttemptedAt;
|
|
454
|
+
_lastSyncAt;
|
|
433
455
|
_deferredRebalanceAt;
|
|
434
456
|
_lastHeldPlanSignature;
|
|
435
457
|
_heldPlanSuppressionCount;
|
|
@@ -563,6 +585,13 @@ class OrderManager {
|
|
|
563
585
|
// 'fill' = armed by a real fill (persist-eligible), 'book' = armed by
|
|
564
586
|
// the startup book seed (heuristic, in-memory only), null = unarmed.
|
|
565
587
|
this.lastFillPivotSource = null;
|
|
588
|
+
this._lastMarketFillPrice = null;
|
|
589
|
+
this._lastMarketFillType = null;
|
|
590
|
+
this._lastMarketFillAt = 0;
|
|
591
|
+
this._liveMarketPrice = null;
|
|
592
|
+
this._liveMarketPriceAt = 0;
|
|
593
|
+
this._liveMarketPriceAttemptedAt = 0;
|
|
594
|
+
this._lastSyncAt = 0;
|
|
566
595
|
this._deferredRebalanceAt = 0;
|
|
567
596
|
this._lastHeldPlanSignature = null;
|
|
568
597
|
this._heldPlanSuppressionCount = 0;
|
|
@@ -582,7 +611,12 @@ class OrderManager {
|
|
|
582
611
|
gridLockContention: 0,
|
|
583
612
|
spreadRoleConversionBlocked: 0,
|
|
584
613
|
lastSyncDurationMs: 0,
|
|
585
|
-
metricsStartTime: Date.now()
|
|
614
|
+
metricsStartTime: Date.now(),
|
|
615
|
+
refusedCommitCount: 0,
|
|
616
|
+
orphanFillCreditedCount: 0,
|
|
617
|
+
restampBuyAboveAnchorCount: 0,
|
|
618
|
+
boundaryDriftExceedsWindowCount: 0,
|
|
619
|
+
gapBandPlacementShadowCount: 0
|
|
586
620
|
};
|
|
587
621
|
this._bootstrapping = 1;
|
|
588
622
|
this.logger?.log('[BOOTSTRAP] Started', 'debug');
|
|
@@ -1530,9 +1564,9 @@ class OrderManager {
|
|
|
1530
1564
|
* @returns {Array<import('./types').Order>}
|
|
1531
1565
|
*/
|
|
1532
1566
|
getInitialOrdersToActivate() {
|
|
1533
|
-
// Apply
|
|
1534
|
-
const sellCount = Math.max(0, toFiniteNumber(this.config.
|
|
1535
|
-
const buyCount = Math.max(0, toFiniteNumber(this.config.
|
|
1567
|
+
// Apply coreOrders limit from config
|
|
1568
|
+
const sellCount = Math.max(0, toFiniteNumber(this.config.coreOrders?.sell, 1));
|
|
1569
|
+
const buyCount = Math.max(0, toFiniteNumber(this.config.coreOrders?.buy, 1));
|
|
1536
1570
|
// Get minimum sizes for validation
|
|
1537
1571
|
const minOrderSizeFactor = this.config?.gridLimits?.MIN_ORDER_SIZE_FACTOR;
|
|
1538
1572
|
const minSellSize = getMinOrderSize(ORDER_TYPES.SELL, this.assets, minOrderSizeFactor);
|
|
@@ -1543,7 +1577,7 @@ class OrderManager {
|
|
|
1543
1577
|
const minSellSizeInt = floatToBlockchainInt(minSellSize, sellPrecision);
|
|
1544
1578
|
const minBuySizeInt = floatToBlockchainInt(minBuySize, buyPrecision);
|
|
1545
1579
|
// Rail membership by geometry (shared isSlotInRail), mirroring the
|
|
1546
|
-
// reconcile pickers (_pickVirtualSlotsToActivate /
|
|
1580
|
+
// reconcile pickers (_pickVirtualSlotsToActivate / _pickEdgeSlots).
|
|
1547
1581
|
// A freshly generated grid's roles never need this, but the gate keeps
|
|
1548
1582
|
// the startup placement path and the runtime activation path from
|
|
1549
1583
|
// diverging: a slot whose stored type is stale relative to the current
|
|
@@ -1584,21 +1618,21 @@ class OrderManager {
|
|
|
1584
1618
|
}
|
|
1585
1619
|
// Reverse for placement order (lowest first)
|
|
1586
1620
|
validBuys.sort((a, b) => a.price - b.price);
|
|
1587
|
-
//
|
|
1621
|
+
// Edge ladder: edge-pinned orders activate alongside the window
|
|
1588
1622
|
// without consuming its budget. Buys pin at the floor (lowest first),
|
|
1589
1623
|
// sells at the ceiling (highest first). Same min-size gate as the window.
|
|
1590
|
-
const
|
|
1624
|
+
const pickEdgeSlots = (orderType, count, windowed, precision, minSizeInt, ascending) => {
|
|
1591
1625
|
const picked = [];
|
|
1592
1626
|
if (count <= 0)
|
|
1593
1627
|
return picked;
|
|
1594
1628
|
const windowedIds = new Set(windowed.map((o) => o.id));
|
|
1595
1629
|
// Both edges anchor at the live grid's own edge (ladder/rail extreme).
|
|
1596
|
-
const edgeAnchor =
|
|
1630
|
+
const edgeAnchor = resolveLiveEdgeAnchorPrice(this, ascending ? 'buy' : 'sell');
|
|
1597
1631
|
const edge = ascending ? 'floor' : 'ceiling';
|
|
1598
1632
|
const edgeFirst = this.getOrdersByTypeAndState(orderType, ORDER_STATES.VIRTUAL)
|
|
1599
1633
|
.filter((o) => inRailFor(orderType, o))
|
|
1600
1634
|
.filter((o) => parseSlotIndex(o.id) !== null)
|
|
1601
|
-
.sort((a, b) =>
|
|
1635
|
+
.sort((a, b) => compareEdge(a, b, edge, edgeAnchor));
|
|
1602
1636
|
for (const o of edgeFirst) {
|
|
1603
1637
|
if (picked.length >= count)
|
|
1604
1638
|
break;
|
|
@@ -1612,9 +1646,9 @@ class OrderManager {
|
|
|
1612
1646
|
picked.sort((a, b) => ascending ? a.price - b.price : b.price - a.price);
|
|
1613
1647
|
return picked;
|
|
1614
1648
|
};
|
|
1615
|
-
const
|
|
1616
|
-
const
|
|
1617
|
-
return [...validSells, ...
|
|
1649
|
+
const edgeBuys = pickEdgeSlots(ORDER_TYPES.BUY, resolveEdgeCount(this.config, 'buy'), validBuys, buyPrecision, minBuySizeInt, true);
|
|
1650
|
+
const edgeSells = pickEdgeSlots(ORDER_TYPES.SELL, resolveEdgeCount(this.config, 'sell'), validSells, sellPrecision, minSellSizeInt, false);
|
|
1651
|
+
return [...validSells, ...edgeSells, ...validBuys, ...edgeBuys];
|
|
1618
1652
|
}
|
|
1619
1653
|
/**
|
|
1620
1654
|
* Get orders matching the specified type and state.
|
|
@@ -2243,12 +2277,12 @@ class OrderManager {
|
|
|
2243
2277
|
this._gapEvacStreaks = new Map();
|
|
2244
2278
|
if (!(this._gapEvacCancelQueued instanceof Set))
|
|
2245
2279
|
this._gapEvacCancelQueued = new Set();
|
|
2246
|
-
// Live
|
|
2247
|
-
// refill wire so
|
|
2248
|
-
// hole refill (which would let a skipped
|
|
2249
|
-
const
|
|
2250
|
-
buy:
|
|
2251
|
-
sell:
|
|
2280
|
+
// Live edge order anchors, resolved once and shared with the engine's
|
|
2281
|
+
// refill wire so an edge-ladder CREATE can never be classified as a
|
|
2282
|
+
// hole refill (which would let a skipped edge order pin the boundary).
|
|
2283
|
+
const edgeAnchors = {
|
|
2284
|
+
buy: resolveLiveEdgeAnchorPrice(this, 'buy'),
|
|
2285
|
+
sell: resolveLiveEdgeAnchorPrice(this, 'sell')
|
|
2252
2286
|
};
|
|
2253
2287
|
const result = await cowEngine.execute({
|
|
2254
2288
|
masterGrid: this.orders,
|
|
@@ -2260,7 +2294,7 @@ class OrderManager {
|
|
|
2260
2294
|
excludeIds,
|
|
2261
2295
|
gapSlots: this._gapSlots,
|
|
2262
2296
|
evacStreaks: this._gapEvacStreaks,
|
|
2263
|
-
|
|
2297
|
+
edgeAnchors
|
|
2264
2298
|
});
|
|
2265
2299
|
// Phase 3 safety net: act on stuck in-band orders regardless of the
|
|
2266
2300
|
// plan outcome — a plan that aborted for unrelated reasons must not
|
|
@@ -110,7 +110,7 @@ declare class StrategyEngine {
|
|
|
110
110
|
* 1. Derive new boundary index based on fills (boundary crawl)
|
|
111
111
|
* 2. Assign grid roles (BUY/SELL/SPREAD) based on boundary position
|
|
112
112
|
* 3. Calculate budget allocation for each side
|
|
113
|
-
* 4. Apply window discipline (
|
|
113
|
+
* 4. Apply window discipline (coreOrders count limits)
|
|
114
114
|
* 5. Calculate ideal order sizes based on budgets and weights
|
|
115
115
|
* 6. Build target grid map representing desired state
|
|
116
116
|
*
|
|
@@ -129,7 +129,7 @@ declare class StrategyEngine {
|
|
|
129
129
|
* @param {Object} params.config - Bot configuration
|
|
130
130
|
* - targetSpreadPercent {number}: Width of spread zone
|
|
131
131
|
* - incrementPercent {number}: Price step between orders
|
|
132
|
-
* -
|
|
132
|
+
* - coreOrders {Object}: Target active order counts
|
|
133
133
|
* - weightDistribution {Object}: Size weighting for each side
|
|
134
134
|
* @param {Object} params.accountAssets - Asset metadata (precision, IDs)
|
|
135
135
|
* @param {Object} params.funds - Current fund state
|