dexbot 1.6.13 → 1.6.15
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 +66 -4
- package/README.md +2 -2
- package/analysis/README.md +6 -6
- package/analysis/tradingview/README.md +2 -1
- package/claw/README.md +7 -7
- 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 +105 -31
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +36 -2
- package/dist/dexbot.js +23 -3
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +26 -11
- package/dist/modules/account_bots.d.ts +10 -6
- package/dist/modules/account_bots.js +13 -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/bitshares-native/subscriptions.js +1 -1
- package/dist/modules/bot_defaults.d.ts +29 -4
- package/dist/modules/bot_defaults.js +65 -10
- package/dist/modules/bot_settings.d.ts +4 -0
- package/dist/modules/bot_settings.js +58 -21
- package/dist/modules/config.js +6 -1
- package/dist/modules/constants.d.ts +13 -5
- package/dist/modules/constants.js +36 -5
- package/dist/modules/credit_runtime.d.ts +35 -5
- package/dist/modules/credit_runtime.js +219 -38
- package/dist/modules/dexbot_class.d.ts +23 -0
- package/dist/modules/dexbot_class.js +60 -17
- package/dist/modules/dexbot_cow_runtime.d.ts +62 -174
- package/dist/modules/dexbot_cow_runtime.js +350 -64
- 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 +2 -2
- package/dist/modules/dexbot_fill_runtime.js +16 -8
- package/dist/modules/dexbot_maintenance_runtime.d.ts +24 -81
- package/dist/modules/dexbot_maintenance_runtime.js +104 -70
- package/dist/modules/dexbot_startup_runtime.js +15 -2
- package/dist/modules/dexbot_state_recovery.js +17 -1
- 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 +4 -4
- 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 +141 -12
- package/dist/modules/order/grid.js +666 -92
- package/dist/modules/order/grid_reconcile.d.ts +1 -1
- package/dist/modules/order/grid_reconcile.js +9 -8
- package/dist/modules/order/grid_reconcile_internal.js +61 -58
- package/dist/modules/order/index.d.ts +37 -9
- package/dist/modules/order/logger.js +2 -2
- package/dist/modules/order/manager.d.ts +10 -2
- package/dist/modules/order/manager.js +56 -31
- package/dist/modules/order/strategy.d.ts +2 -2
- package/dist/modules/order/strategy.js +51 -21
- package/dist/modules/order/sync_engine.js +22 -9
- package/dist/modules/order/utils/math.d.ts +101 -29
- package/dist/modules/order/utils/math.js +215 -84
- package/dist/modules/order/utils/order.d.ts +58 -58
- package/dist/modules/order/utils/order.js +135 -106
- package/dist/modules/order/utils/system.d.ts +193 -6
- package/dist/modules/order/utils/system.js +394 -31
- package/dist/modules/order/utils/validate.d.ts +1 -1
- package/dist/modules/order/utils/validate.js +71 -59
- package/dist/modules/runtime_settings.d.ts +1 -1
- package/dist/modules/runtime_settings.js +3 -3
- package/dist/modules/types.d.ts +55 -4
- package/dist/scripts/analyze-credit.js +44 -27
- package/dist/scripts/analyze-orders.d.ts +1 -1
- package/dist/scripts/analyze-orders.js +4 -4
- package/dist/scripts/diagnose-pool-history.js +35 -30
- package/dist/scripts/divergence-calc.js +6 -6
- package/dist/scripts/pnl.js +1 -1
- package/dist/scripts/rich_list.d.ts +18 -0
- package/dist/scripts/rich_list.js +461 -0
- package/dist/scripts/run-tests.js +80 -4
- package/dist/scripts/validate_bots.d.ts +1 -1
- package/dist/scripts/validate_bots.js +3 -3
- package/dist/unlock.d.ts +2 -1
- package/dist/unlock.js +11 -5
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -2
- package/docs/COW_INVARIANTS.md +12 -6
- package/docs/DEXBOT_COMPARISON.md +7 -7
- package/docs/EVOLUTION.md +10 -8
- 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 +30 -1
- package/docs/MPA_CREDIT_USAGE.md +11 -6
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +170 -12
- package/docs/README.md +3 -3
- package/docs/WORKFLOW.md +1 -0
- package/docs/architecture.md +62 -8
- package/docs/developer_guide.md +12 -3
- package/market_adapter/README.md +4 -4
- package/modules/README.md +1 -1
- package/package.json +2 -1
- package/scripts/README.md +59 -32
- package/tests/README.md +12 -3
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
* - getOrderSize(order) - Extract order size with fallback
|
|
61
61
|
*
|
|
62
62
|
* SECTION 10: STRATEGY CALCULATIONS (7 functions)
|
|
63
|
-
* -
|
|
64
|
-
* -
|
|
65
|
-
* -
|
|
66
|
-
* -
|
|
67
|
-
* -
|
|
68
|
-
* -
|
|
69
|
-
* -
|
|
63
|
+
* - resolveEdgeCount(config, side) - Clamped per-side edge count (>=0 int, 0 disables)
|
|
64
|
+
* - resolveEdgeOrders(config) - Total edge orders buy+sell (fee/count totals)
|
|
65
|
+
* - resolveLiveEdgeAnchorPrice(manager, side) - Live-grid edge anchor (genesis ladder extreme; null when no usable ladder)
|
|
66
|
+
* - resolveEdgeAnchorPrice(config, side) - Config-bound anchor fallback (buy→minPrice, sell→maxPrice; null when unresolvable)
|
|
67
|
+
* - compareEdge(a, b, edge, anchorPrice) - Shared anchored edge comparator (single ordering source)
|
|
68
|
+
* - edgeOrderIdSet(allSlots, config, orderType, anchorPrice?, excludeIds?) - Edge order id set (config count; shares the picker ordering; excludeIds carries the window exclusion)
|
|
69
|
+
* - selectEdgeSlots(sortedAsc, count, excludeIds, edge, anchorPrice?) - Shared position picker (both edges anchor toward their bound)
|
|
70
70
|
*
|
|
71
71
|
* ===============================================================================
|
|
72
72
|
*/
|
|
@@ -79,7 +79,7 @@ import { getErrorMessage, getErrorCode, getErrorName } from '../../utils/errors.
|
|
|
79
79
|
import { hasGenesisLadder } from '../genesis_policy.js';
|
|
80
80
|
import { parseSlotIndex as parseSlotIndexShared } from './slot.js';
|
|
81
81
|
const { isValidNumber, toFiniteNumber } = Format;
|
|
82
|
-
const { blockchainToFloat, floatToBlockchainInt, quantizeFloat, priceSlotEqual } = MathUtils;
|
|
82
|
+
const { blockchainToFloat, floatToBlockchainInt, quantizeFloat, slotIndexForPrice, priceSlotEqual } = MathUtils;
|
|
83
83
|
const orderLogger = new Logger('Order');
|
|
84
84
|
const ORDER_GONE_ERROR_FRAGMENT = 'not found';
|
|
85
85
|
/**
|
|
@@ -398,7 +398,18 @@ function _validatePriceCorrectionEntry(manager, entry) {
|
|
|
398
398
|
if (!hasGenesisLadder(manager?._genesis)) {
|
|
399
399
|
return { valid: false, reason: `no price ladder (INV-GRID-004) — slot ${slotId} has no authoritative price` };
|
|
400
400
|
}
|
|
401
|
-
|
|
401
|
+
// Genesis is guaranteed here (guarded above), so compare ladder LEVELS --
|
|
402
|
+
// not priceSlotEqual at the asset amount precision, which collapses
|
|
403
|
+
// adjacent levels for a low-precision asset and would accept a stale entry.
|
|
404
|
+
let sameLevel;
|
|
405
|
+
try {
|
|
406
|
+
const genesis = manager._genesis;
|
|
407
|
+
sameLevel = slotIndexForPrice(slot.price, genesis) === slotIndexForPrice(Number(entry.expectedPrice), genesis);
|
|
408
|
+
}
|
|
409
|
+
catch {
|
|
410
|
+
sameLevel = priceSlotEqual(slot.price, Number(entry.expectedPrice), Number(precision));
|
|
411
|
+
}
|
|
412
|
+
if (!sameLevel) {
|
|
402
413
|
return { valid: false, reason: `slot ${slotId} now targets ${slot.price} (entry queued ${entry.expectedPrice})` };
|
|
403
414
|
}
|
|
404
415
|
// Size check: the broadcast sends amountToSell from the QUEUED snapshot.
|
|
@@ -1279,6 +1290,11 @@ function geometryTypeForSlotIndex(idx, boundaryIdx, gapSlots) {
|
|
|
1279
1290
|
return null;
|
|
1280
1291
|
if (boundaryIdx === null || boundaryIdx === undefined || boundaryIdx === '')
|
|
1281
1292
|
return null;
|
|
1293
|
+
// Unknown gap width must also fail closed: Number(null)/Number('') === 0
|
|
1294
|
+
// would collapse the gap band and misclassify an in-band slot as a rail
|
|
1295
|
+
// slot (the same trap guarded in detectGapEvacuationCandidates).
|
|
1296
|
+
if (gapSlots === null || gapSlots === undefined || gapSlots === '')
|
|
1297
|
+
return null;
|
|
1282
1298
|
const n = Number(idx);
|
|
1283
1299
|
const b = Number(boundaryIdx);
|
|
1284
1300
|
const g = Number(gapSlots);
|
|
@@ -1306,6 +1322,14 @@ function detectGapEvacuationCandidates(masterGrid, boundaryIdx, gapSlots) {
|
|
|
1306
1322
|
const out = [];
|
|
1307
1323
|
if (!masterGrid || typeof masterGrid.values !== 'function')
|
|
1308
1324
|
return out;
|
|
1325
|
+
// Explicit null/undefined/'' guard BEFORE Number(): Number(null) === 0 and
|
|
1326
|
+
// Number('') === 0 are finite and would read an unknown boundary as slot 0,
|
|
1327
|
+
// selecting a fake gap band around it (same trap guarded in
|
|
1328
|
+
// geometryTypeForSlotIndex / isSlotIndexInGapBand).
|
|
1329
|
+
if (boundaryIdx === null || boundaryIdx === undefined || boundaryIdx === '')
|
|
1330
|
+
return out;
|
|
1331
|
+
if (gapSlots === null || gapSlots === undefined || gapSlots === '')
|
|
1332
|
+
return out;
|
|
1309
1333
|
const b = Number(boundaryIdx);
|
|
1310
1334
|
const g = Number(gapSlots);
|
|
1311
1335
|
if (!Number.isFinite(b) || !Number.isFinite(g) || g < 0)
|
|
@@ -2400,7 +2424,7 @@ function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSl
|
|
|
2400
2424
|
referencePrice = centerPrice;
|
|
2401
2425
|
}
|
|
2402
2426
|
if (referencePrice === null) {
|
|
2403
|
-
const fallbackCap = Math.max(Math.floor((config?.
|
|
2427
|
+
const fallbackCap = Math.max(Math.floor((config?.coreOrders?.sell ?? 1) / 2), Math.floor((config?.coreOrders?.buy ?? 1) / 2), 1);
|
|
2404
2428
|
const effectiveBudget = crossChunkBudget ?? fallbackCap;
|
|
2405
2429
|
return { boundaryIdx: null, remainingBudget: effectiveBudget };
|
|
2406
2430
|
}
|
|
@@ -2409,22 +2433,22 @@ function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSl
|
|
|
2409
2433
|
// Empty slot list with a Tier 1-3 reference: no honest index
|
|
2410
2434
|
// exists (calculateIdealBoundary returns -1). Stay null rather
|
|
2411
2435
|
// than letting the clamp below fabricate a slot-0 boundary.
|
|
2412
|
-
const fallbackCap = Math.max(Math.floor((config?.
|
|
2436
|
+
const fallbackCap = Math.max(Math.floor((config?.coreOrders?.sell ?? 1) / 2), Math.floor((config?.coreOrders?.buy ?? 1) / 2), 1);
|
|
2413
2437
|
return { boundaryIdx: null, remainingBudget: crossChunkBudget ?? fallbackCap };
|
|
2414
2438
|
}
|
|
2415
2439
|
recovered = true;
|
|
2416
2440
|
}
|
|
2417
|
-
// Apply shift from fills with rate-limiting (
|
|
2441
|
+
// Apply shift from fills with rate-limiting (edge fills excluded: static insurance).
|
|
2418
2442
|
let netShift = 0;
|
|
2419
|
-
//
|
|
2443
|
+
// Edge ladder: fills from edge-pinned edge slots never crawl the
|
|
2420
2444
|
// boundary — they are static fat-finger insurance, not market movement.
|
|
2421
|
-
// `edgeAnchors` (
|
|
2445
|
+
// `edgeAnchors` (resolveLiveEdgeAnchorPrice) is the same anchor the
|
|
2422
2446
|
// placement sites use; without it the classification falls back to the
|
|
2423
2447
|
// config-bound anchor, which can disagree with the slots actually placed.
|
|
2424
2448
|
// The window exclusion is the same one every placement picker applies: a
|
|
2425
2449
|
// window that reaches the grid edge (e.g. a keep-low window sitting on
|
|
2426
2450
|
// the floor) must not let the edge pick land on window members — otherwise
|
|
2427
|
-
// a genuine window fill is treated as a static
|
|
2451
|
+
// a genuine window fill is treated as a static edge fill and never
|
|
2428
2452
|
// crawls, and the hole is refilled same-side. Unknown geometry
|
|
2429
2453
|
// (null boundary) fails open to the previous classification.
|
|
2430
2454
|
const windowBoundaryIdx = (currentBoundaryIdx === null || currentBoundaryIdx === undefined)
|
|
@@ -2432,28 +2456,28 @@ function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSl
|
|
|
2432
2456
|
: currentBoundaryIdx;
|
|
2433
2457
|
const windowBuyIds = windowIdSetFromSlots(allSlots, config, ORDER_TYPES.BUY, windowBoundaryIdx, gapSlots);
|
|
2434
2458
|
const windowSellIds = windowIdSetFromSlots(allSlots, config, ORDER_TYPES.SELL, windowBoundaryIdx, gapSlots);
|
|
2435
|
-
const
|
|
2436
|
-
const
|
|
2459
|
+
const edgeBuyIds = edgeOrderIdSet(allSlots, config, ORDER_TYPES.BUY, edgeAnchors?.buy ?? null, windowBuyIds);
|
|
2460
|
+
const edgeSellIds = edgeOrderIdSet(allSlots, config, ORDER_TYPES.SELL, edgeAnchors?.sell ?? null, windowSellIds);
|
|
2437
2461
|
// Pending crawls: fills recorded by earlier batches whose derivation
|
|
2438
2462
|
// never committed (refused broadcast, P4 abort, or pre-restart loss —
|
|
2439
2463
|
// the Sep-10 case: 4 fills consumed under a null boundary, crawl lost,
|
|
2440
2464
|
// restart refilled the holes same-side). Entries for slots in the
|
|
2441
2465
|
// CURRENT batch are excluded — those fills crawl below as usual;
|
|
2442
|
-
// anything older is still owed and shifts here.
|
|
2466
|
+
// anything older is still owed and shifts here. Edge-slot entries
|
|
2443
2467
|
// never crawl (static insurance), same as live fills.
|
|
2444
2468
|
const currentSlotIds = new Set((fills ?? []).map((f) => f?.id).filter((id) => typeof id === 'string' && id.length > 0));
|
|
2445
2469
|
const owedPending = (pendingCrawls ?? []).filter((e) => e
|
|
2446
2470
|
&& typeof e.slotId === 'string' && e.slotId.length > 0
|
|
2447
2471
|
&& !currentSlotIds.has(e.slotId)
|
|
2448
2472
|
&& (e.side === ORDER_TYPES.BUY || e.side === ORDER_TYPES.SELL)
|
|
2449
|
-
&& !(e.side === ORDER_TYPES.BUY &&
|
|
2450
|
-
&& !(e.side === ORDER_TYPES.SELL &&
|
|
2473
|
+
&& !(e.side === ORDER_TYPES.BUY && edgeBuyIds && edgeBuyIds.has(e.slotId))
|
|
2474
|
+
&& !(e.side === ORDER_TYPES.SELL && edgeSellIds && edgeSellIds.has(e.slotId)));
|
|
2451
2475
|
for (const fill of fills ?? []) {
|
|
2452
2476
|
if (!isShiftEligibleFill(fill))
|
|
2453
2477
|
continue;
|
|
2454
|
-
if (fill && fill.type === ORDER_TYPES.BUY &&
|
|
2478
|
+
if (fill && fill.type === ORDER_TYPES.BUY && edgeBuyIds && fill.id != null && edgeBuyIds.has(fill.id))
|
|
2455
2479
|
continue;
|
|
2456
|
-
if (fill && fill.type === ORDER_TYPES.SELL &&
|
|
2480
|
+
if (fill && fill.type === ORDER_TYPES.SELL && edgeSellIds && fill.id != null && edgeSellIds.has(fill.id))
|
|
2457
2481
|
continue;
|
|
2458
2482
|
if (fill.type === ORDER_TYPES.SELL)
|
|
2459
2483
|
netShift++;
|
|
@@ -2477,7 +2501,7 @@ function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSl
|
|
|
2477
2501
|
// consumes from the same pool so the total across all chunks
|
|
2478
2502
|
// never exceeds half the active window.
|
|
2479
2503
|
// Falls back to a per-call cap when no budget is set.
|
|
2480
|
-
const fallbackCap = Math.max(Math.floor((config?.
|
|
2504
|
+
const fallbackCap = Math.max(Math.floor((config?.coreOrders?.sell ?? 1) / 2), Math.floor((config?.coreOrders?.buy ?? 1) / 2), 1);
|
|
2481
2505
|
const effectiveBudget = crossChunkBudget ?? fallbackCap;
|
|
2482
2506
|
const cap = Math.min(Math.abs(effectiveBudget), fallbackCap);
|
|
2483
2507
|
if (recovered && anchoredFromFills) {
|
|
@@ -2544,9 +2568,10 @@ export function consumePendingFillCrawls(manager) {
|
|
|
2544
2568
|
catch { /* best-effort */ }
|
|
2545
2569
|
}
|
|
2546
2570
|
};
|
|
2547
|
-
// NB: Number(null) === 0 — check null/undefined
|
|
2571
|
+
// NB: Number(null) === 0 and Number('') === 0 — check null/undefined/''
|
|
2572
|
+
// explicitly (the '' case matches runPreBroadcastGuards), or a
|
|
2548
2573
|
// boundary-less manager would "apply" onto slot 0.
|
|
2549
|
-
if (manager?.boundaryIdx === null || manager?.boundaryIdx === undefined) {
|
|
2574
|
+
if (manager?.boundaryIdx === null || manager?.boundaryIdx === undefined || manager?.boundaryIdx === '') {
|
|
2550
2575
|
clear();
|
|
2551
2576
|
return { applied: false, reason: 'null-boundary' };
|
|
2552
2577
|
}
|
|
@@ -2559,15 +2584,15 @@ export function consumePendingFillCrawls(manager) {
|
|
|
2559
2584
|
const slots = Array.from(manager?.orders instanceof Map ? manager.orders.values() : []);
|
|
2560
2585
|
// Classify with the SAME live anchors the strategy derivation uses, or the
|
|
2561
2586
|
// two disagree: the config-bound fallback is null for mode-string/relative
|
|
2562
|
-
// bounds, so a restart would rank a stale below-rail slot as
|
|
2587
|
+
// bounds, so a restart would rank a stale below-rail slot as an edge order and
|
|
2563
2588
|
// silently drop a crawl the live run recorded as ordinary market movement.
|
|
2564
2589
|
// The window exclusion must match placement too (same source as the count
|
|
2565
|
-
// fix) — a window over the
|
|
2590
|
+
// fix) — a window over the edge must not be read as an edge order, or
|
|
2566
2591
|
// its owed crawl is dropped instead of applied.
|
|
2567
2592
|
const windowBuyIds = liveWindowIdSet(manager, ORDER_TYPES.BUY);
|
|
2568
2593
|
const windowSellIds = liveWindowIdSet(manager, ORDER_TYPES.SELL);
|
|
2569
|
-
const
|
|
2570
|
-
const
|
|
2594
|
+
const edgeBuyIds = edgeOrderIdSet(slots, config, ORDER_TYPES.BUY, resolveLiveEdgeAnchorPrice(manager, 'buy'), windowBuyIds);
|
|
2595
|
+
const edgeSellIds = edgeOrderIdSet(slots, config, ORDER_TYPES.SELL, resolveLiveEdgeAnchorPrice(manager, 'sell'), windowSellIds);
|
|
2571
2596
|
let netShift = 0;
|
|
2572
2597
|
let count = 0;
|
|
2573
2598
|
for (const e of pending) {
|
|
@@ -2575,9 +2600,9 @@ export function consumePendingFillCrawls(manager) {
|
|
|
2575
2600
|
continue;
|
|
2576
2601
|
if (e.side !== ORDER_TYPES.BUY && e.side !== ORDER_TYPES.SELL)
|
|
2577
2602
|
continue;
|
|
2578
|
-
if (e.side === ORDER_TYPES.BUY &&
|
|
2603
|
+
if (e.side === ORDER_TYPES.BUY && edgeBuyIds && edgeBuyIds.has(e.slotId))
|
|
2579
2604
|
continue;
|
|
2580
|
-
if (e.side === ORDER_TYPES.SELL &&
|
|
2605
|
+
if (e.side === ORDER_TYPES.SELL && edgeSellIds && edgeSellIds.has(e.slotId))
|
|
2581
2606
|
continue;
|
|
2582
2607
|
netShift += e.side === ORDER_TYPES.SELL ? 1 : -1;
|
|
2583
2608
|
count++;
|
|
@@ -2586,12 +2611,15 @@ export function consumePendingFillCrawls(manager) {
|
|
|
2586
2611
|
clear();
|
|
2587
2612
|
return { applied: false, reason: 'nothing-owed' };
|
|
2588
2613
|
}
|
|
2589
|
-
const
|
|
2590
|
-
const
|
|
2591
|
-
const fallbackCap = Math.max(Math.floor(Number(
|
|
2614
|
+
const coreOrdersCfg = config?.coreOrders;
|
|
2615
|
+
const coreOrdersObj = (coreOrdersCfg && typeof coreOrdersCfg === 'object') ? coreOrdersCfg : {};
|
|
2616
|
+
const fallbackCap = Math.max(Math.floor(Number(coreOrdersObj.sell ?? 1) / 2), Math.floor(Number(coreOrdersObj.buy ?? 1) / 2), 1);
|
|
2592
2617
|
if (Math.abs(netShift) > fallbackCap)
|
|
2593
2618
|
netShift = Math.sign(netShift) * fallbackCap;
|
|
2594
|
-
|
|
2619
|
+
// Absent-aware: Number(null) === 0 is finite, so a plain Number() would use
|
|
2620
|
+
// a collapsed (0) gap instead of the config-derived fallback and let the
|
|
2621
|
+
// ceiling + validatePersistedBoundary run on the wrong band.
|
|
2622
|
+
let gapSlots = Format.toKnownNumber(manager?._gapSlots);
|
|
2595
2623
|
if (!Number.isFinite(gapSlots)) {
|
|
2596
2624
|
try {
|
|
2597
2625
|
gapSlots = MathUtils.calculateGapSlots(config?.incrementPercent, config?.targetSpreadPercent, config?.gridLimits);
|
|
@@ -2627,89 +2655,89 @@ export function consumePendingFillCrawls(manager) {
|
|
|
2627
2655
|
return { applied: true, from: boundary, to: candidate, count };
|
|
2628
2656
|
}
|
|
2629
2657
|
/**
|
|
2630
|
-
* Per-side
|
|
2631
|
-
* Buy
|
|
2658
|
+
* Per-side edge count (edge-pinned fat-finger insurance orders).
|
|
2659
|
+
* Buy edges pin at the grid floor, sell edges at the grid ceiling.
|
|
2632
2660
|
* Non-finite/non-integer/negative values disable (0).
|
|
2633
2661
|
*
|
|
2634
|
-
* The legacy numeric form (`
|
|
2662
|
+
* The legacy numeric form (`edgeOrders: n`) is migrated here at read time
|
|
2635
2663
|
* to `{ buy: n, sell: 0 }`: the editor seeder rewrites the persisted JSON, but
|
|
2636
|
-
* a hand-edited bots.json that bypassed the editor must not have its
|
|
2664
|
+
* a hand-edited bots.json that bypassed the editor must not have its edge
|
|
2637
2665
|
* count silently read as 0.
|
|
2638
2666
|
*
|
|
2639
2667
|
* @param {Object} config - Bot configuration
|
|
2640
2668
|
* @param {string} side - 'buy' or 'sell'
|
|
2641
|
-
* @returns {number}
|
|
2669
|
+
* @returns {number} Edge count for the side (>= 0 integer)
|
|
2642
2670
|
*/
|
|
2643
|
-
function
|
|
2671
|
+
function resolveEdgeCount(config, side) {
|
|
2644
2672
|
const key = side === 'sell' ? 'sell' : 'buy';
|
|
2645
|
-
const
|
|
2646
|
-
if (typeof
|
|
2673
|
+
const rawEdge = config?.edgeOrders;
|
|
2674
|
+
if (typeof rawEdge === 'number') {
|
|
2647
2675
|
if (side === 'sell')
|
|
2648
2676
|
return 0;
|
|
2649
|
-
const n = Math.floor(
|
|
2677
|
+
const n = Math.floor(rawEdge);
|
|
2650
2678
|
return Number.isFinite(n) && n >= 0 ? n : 0;
|
|
2651
2679
|
}
|
|
2652
|
-
const raw = Number(
|
|
2680
|
+
const raw = Number(rawEdge?.[key] ?? 0);
|
|
2653
2681
|
if (!Number.isInteger(raw) || raw < 0)
|
|
2654
2682
|
return 0;
|
|
2655
2683
|
return raw;
|
|
2656
2684
|
}
|
|
2657
2685
|
/**
|
|
2658
|
-
* Total
|
|
2686
|
+
* Total edge count across both sides (fee/count totals).
|
|
2659
2687
|
*
|
|
2660
2688
|
* @param {Object} config - Bot configuration
|
|
2661
|
-
* @returns {number} Total
|
|
2689
|
+
* @returns {number} Total edges (buy + sell)
|
|
2662
2690
|
*/
|
|
2663
|
-
function
|
|
2664
|
-
return
|
|
2691
|
+
function resolveEdgeOrders(config) {
|
|
2692
|
+
return resolveEdgeCount(config, 'buy') + resolveEdgeCount(config, 'sell');
|
|
2665
2693
|
}
|
|
2666
2694
|
/**
|
|
2667
|
-
* Edge-pinned
|
|
2695
|
+
* Edge-pinned order id set for one side, or null when disabled.
|
|
2668
2696
|
* Type/price-filtered, then ordered by the SAME edge order the placement
|
|
2669
|
-
* pickers use (
|
|
2697
|
+
* pickers use (compareEdge via selectEdgeSlots) — single source
|
|
2670
2698
|
* of truth, so the no-crawl classification can never drift from placement.
|
|
2671
2699
|
* Anchor: explicit live-grid edge when supplied, otherwise the config-bound
|
|
2672
2700
|
* fallback (unresolved -> plain rank). Shelf/manual ids (non-slot-N, e.g.
|
|
2673
|
-
* fork-kept deep-* orders below the rail) are never
|
|
2701
|
+
* fork-kept deep-* orders below the rail) are never edge orders: they would
|
|
2674
2702
|
* otherwise win the cheapest-first rank and poison the deficit check while
|
|
2675
2703
|
* the shelf is live (issue #27 follow-up). No-op upstream (grids only mint
|
|
2676
2704
|
* slot-N).
|
|
2677
2705
|
*
|
|
2678
2706
|
* @param {Array<Object>} allSlots - All grid slots (need id/price/type)
|
|
2679
|
-
* @param {Object} config - Bot configuration (
|
|
2707
|
+
* @param {Object} config - Bot configuration (edge count source)
|
|
2680
2708
|
* @param {string} orderType - ORDER_TYPES.BUY (floor) or SELL (ceiling)
|
|
2681
2709
|
* @param {number|null} [anchorPrice] - Explicit edge anchor (live grid edge);
|
|
2682
2710
|
* callers that picked slots must pass the SAME anchor so no-crawl
|
|
2683
2711
|
* classification matches placement. NB: null/undefined falls back to the
|
|
2684
2712
|
* config-bound anchor (unresolved -> plain rank) — unlike
|
|
2685
|
-
*
|
|
2713
|
+
* selectEdgeSlots, where null alone means plain rank.
|
|
2686
2714
|
* @param {Set<string>|null} [excludeIds] - Windowed ids to skip (same set the
|
|
2687
2715
|
* placement pickers exclude). Window + edge are additive in every target
|
|
2688
2716
|
* (order counts, fees, hold-back), so a window that reaches the grid edge
|
|
2689
2717
|
* (e.g. a keep-low window sitting on the floor) must not let the edge pick
|
|
2690
2718
|
* land on window members — otherwise counting reads N/N with zero
|
|
2691
|
-
* dedicated
|
|
2719
|
+
* dedicated edge orders and the deficit never fires (issue #27 follow-up).
|
|
2692
2720
|
* @returns {Set<string>|null} Edge slot ids, or null when side disabled
|
|
2693
2721
|
*/
|
|
2694
|
-
function
|
|
2722
|
+
function edgeOrderIdSet(allSlots, config, orderType, anchorPrice = null, excludeIds = null) {
|
|
2695
2723
|
const isSell = orderType === ORDER_TYPES.SELL;
|
|
2696
2724
|
const side = isSell ? 'sell' : 'buy';
|
|
2697
2725
|
// Filter by the canonical side type, not the caller's token: the previous
|
|
2698
2726
|
// per-side resolvers did the same, so a non-canonical token keeps the
|
|
2699
2727
|
// floor behavior instead of silently matching nothing.
|
|
2700
2728
|
const type = isSell ? ORDER_TYPES.SELL : ORDER_TYPES.BUY;
|
|
2701
|
-
const n =
|
|
2729
|
+
const n = resolveEdgeCount(config, side);
|
|
2702
2730
|
if (n <= 0)
|
|
2703
2731
|
return null;
|
|
2704
2732
|
const ids = new Set();
|
|
2705
2733
|
if (!Array.isArray(allSlots))
|
|
2706
2734
|
return ids;
|
|
2707
2735
|
// NB: Number(null) === 0 is finite — null/undefined must mean "no anchor".
|
|
2708
|
-
const anchor = anchorPrice == null ?
|
|
2736
|
+
const anchor = anchorPrice == null ? resolveEdgeAnchorPrice(config, side) : Number(anchorPrice);
|
|
2709
2737
|
const ascending = allSlots
|
|
2710
2738
|
.filter((s) => s && s.id != null && s.price != null && s.type === type && parseSlotIndex(s.id) !== null)
|
|
2711
2739
|
.sort((a, b) => Number(a.price) - Number(b.price));
|
|
2712
|
-
for (const s of
|
|
2740
|
+
for (const s of selectEdgeSlots(ascending, n, excludeIds, isSell ? 'ceiling' : 'floor', anchor)) {
|
|
2713
2741
|
ids.add(String(s.id));
|
|
2714
2742
|
}
|
|
2715
2743
|
return ids;
|
|
@@ -2717,21 +2745,21 @@ function reserveEdgeIdSet(allSlots, config, orderType, anchorPrice = null, exclu
|
|
|
2717
2745
|
/**
|
|
2718
2746
|
* Window member ids for one side from an explicit slot list and geometry.
|
|
2719
2747
|
*
|
|
2720
|
-
* Mirror of the window every placement picker excludes from its
|
|
2748
|
+
* Mirror of the window every placement picker excludes from its edge
|
|
2721
2749
|
* pick: in-rail slots of the side (geometry via isSlotInRail), ordered
|
|
2722
2750
|
* closest to market first (buys: highest price first; sells: lowest first),
|
|
2723
|
-
* sliced to the configured
|
|
2751
|
+
* sliced to the configured coreOrders count. The slice runs over the FULL
|
|
2724
2752
|
* rail, not just live orders — window membership is geometric (a virtual
|
|
2725
|
-
* hole inside the window still blocks the
|
|
2726
|
-
* slices would misclassify live
|
|
2753
|
+
* hole inside the window still blocks the edge pick there), so live-only
|
|
2754
|
+
* slices would misclassify live edge orders as window members whenever the
|
|
2727
2755
|
* window itself is under-filled.
|
|
2728
2756
|
*
|
|
2729
2757
|
* Returns null when the boundary geometry is unknown (null boundary): the
|
|
2730
|
-
* pickers cannot place
|
|
2758
|
+
* pickers cannot place edge orders without it either, so callers fail open
|
|
2731
2759
|
* (no exclusion) and keep their previous classification instead of guessing.
|
|
2732
2760
|
*
|
|
2733
2761
|
* @param {Array<Object>} allSlots - Slots (master grid or clone)
|
|
2734
|
-
* @param {Object} config - Bot configuration (
|
|
2762
|
+
* @param {Object} config - Bot configuration (coreOrders count source)
|
|
2735
2763
|
* @param {string} orderType - ORDER_TYPES.BUY or SELL
|
|
2736
2764
|
* @param {number|null|undefined} boundaryIdx - Boundary the rail is derived from
|
|
2737
2765
|
* @param {number} gapSlots - Gap band size
|
|
@@ -2742,7 +2770,7 @@ function windowIdSetFromSlots(allSlots, config, orderType, boundaryIdx, gapSlots
|
|
|
2742
2770
|
const isSell = orderType === ORDER_TYPES.SELL;
|
|
2743
2771
|
const type = isSell ? ORDER_TYPES.SELL : ORDER_TYPES.BUY;
|
|
2744
2772
|
const side = isSell ? 'sell' : 'buy';
|
|
2745
|
-
const count = Math.max(0, Math.floor(Number(config?.
|
|
2773
|
+
const count = Math.max(0, Math.floor(Number(config?.coreOrders?.[side])) || 0);
|
|
2746
2774
|
if (!(count > 0))
|
|
2747
2775
|
return new Set();
|
|
2748
2776
|
if (!Array.isArray(allSlots))
|
|
@@ -2801,26 +2829,26 @@ function liveWindowIdSet(manager, orderType) {
|
|
|
2801
2829
|
*
|
|
2802
2830
|
* - CREATE ids of the plan (the slots a fold did not convert into an
|
|
2803
2831
|
* UPDATE), minus
|
|
2804
|
-
* -
|
|
2832
|
+
* - edge-ladder ids. Edge orders are static edge insurance; their fills
|
|
2805
2833
|
* never crawl (deriveTargetBoundary filters them), so a guard-skipped
|
|
2806
|
-
*
|
|
2834
|
+
* edge order must not pin geometry either. Without this exclusion an edge order
|
|
2807
2835
|
* CREATE skipped at the wrong moment (e.g. a floor BUY above the last-fill
|
|
2808
2836
|
* pivot while the market dumps below the grid) would hold the boundary for
|
|
2809
2837
|
* a cycle although nothing was stranded.
|
|
2810
2838
|
*
|
|
2811
|
-
* Absent/disabled
|
|
2812
|
-
* so callers that never configured
|
|
2839
|
+
* Absent/disabled edge orders or an empty action list yield the plain CREATE ids,
|
|
2840
|
+
* so callers that never configured edge orders keep the previous behavior.
|
|
2813
2841
|
*
|
|
2814
2842
|
* @param {Array<Object>} actions - Optimized COW actions
|
|
2815
2843
|
* @param {Object} [options]
|
|
2816
|
-
* @param {Object} [options.config] - Bot configuration (
|
|
2817
|
-
* @param {Iterable<Object>} [options.slots] - Master slots (
|
|
2844
|
+
* @param {Object} [options.config] - Bot configuration (edge count source)
|
|
2845
|
+
* @param {Iterable<Object>} [options.slots] - Master slots (edge classification)
|
|
2818
2846
|
* @param {{buy?: number|null, sell?: number|null}} [options.edgeAnchors] - Live
|
|
2819
|
-
* edge anchors (same pair the strategy classifies
|
|
2847
|
+
* edge anchors (same pair the strategy classifies edge fills against)
|
|
2820
2848
|
* @param {unknown} [options.manager] - OrderManager for the window exclusion (same
|
|
2821
2849
|
* set the placement pickers exclude); omit to fall back to the previous
|
|
2822
2850
|
* exclusion-free classification (fail-open)
|
|
2823
|
-
* @returns {string[]} Refill slot ids (CREATE ids minus
|
|
2851
|
+
* @returns {string[]} Refill slot ids (CREATE ids minus edge ids)
|
|
2824
2852
|
*/
|
|
2825
2853
|
function collectRefillSlotIds(actions, options = {}) {
|
|
2826
2854
|
const { config = null, slots = null, edgeAnchors = null, manager = null } = options;
|
|
@@ -2832,12 +2860,12 @@ function collectRefillSlotIds(actions, options = {}) {
|
|
|
2832
2860
|
.map((a) => a.id);
|
|
2833
2861
|
if (createIds.length === 0)
|
|
2834
2862
|
return out;
|
|
2835
|
-
let
|
|
2863
|
+
let edgeIds = null;
|
|
2836
2864
|
if (slots && config) {
|
|
2837
2865
|
try {
|
|
2838
2866
|
// Accept a Map (master grid), an array of slots, or any iterable of
|
|
2839
2867
|
// slot objects. Map entries are [id, slot] pairs, so `.values()` is
|
|
2840
|
-
// required — Array.from(map) would hand
|
|
2868
|
+
// required — Array.from(map) would hand edgeOrderIdSet pairs.
|
|
2841
2869
|
const allSlots = Array.isArray(slots)
|
|
2842
2870
|
? slots
|
|
2843
2871
|
: (slots && typeof slots.values === 'function'
|
|
@@ -2846,30 +2874,30 @@ function collectRefillSlotIds(actions, options = {}) {
|
|
|
2846
2874
|
// Window exclusion keeps classification in agreement with the
|
|
2847
2875
|
// placement pickers: a window reaching the grid edge must not have
|
|
2848
2876
|
// its window hole-CREATEs dropped from the wire as if they were
|
|
2849
|
-
//
|
|
2877
|
+
// edge orders, or a guard-skipped window refill would no longer pin
|
|
2850
2878
|
// the committed boundary (stranding the hole it failed to fill).
|
|
2851
2879
|
const windowBuyIds = manager ? liveWindowIdSet(manager, ORDER_TYPES.BUY) : null;
|
|
2852
2880
|
const windowSellIds = manager ? liveWindowIdSet(manager, ORDER_TYPES.SELL) : null;
|
|
2853
|
-
const buyIds =
|
|
2854
|
-
const sellIds =
|
|
2881
|
+
const buyIds = edgeOrderIdSet(allSlots, config, ORDER_TYPES.BUY, edgeAnchors?.buy ?? null, windowBuyIds);
|
|
2882
|
+
const sellIds = edgeOrderIdSet(allSlots, config, ORDER_TYPES.SELL, edgeAnchors?.sell ?? null, windowSellIds);
|
|
2855
2883
|
if (buyIds || sellIds)
|
|
2856
|
-
|
|
2884
|
+
edgeIds = new Set([...(buyIds ?? []), ...(sellIds ?? [])]);
|
|
2857
2885
|
}
|
|
2858
2886
|
catch {
|
|
2859
|
-
|
|
2887
|
+
edgeIds = null;
|
|
2860
2888
|
}
|
|
2861
2889
|
}
|
|
2862
2890
|
for (const id of createIds) {
|
|
2863
|
-
// Fail-open on classification errors: an id we cannot prove is
|
|
2891
|
+
// Fail-open on classification errors: an id we cannot prove is an edge order
|
|
2864
2892
|
// stays in the wire, so the hold keeps its previous (conservative) reach.
|
|
2865
|
-
if (
|
|
2893
|
+
if (edgeIds && edgeIds.has(id))
|
|
2866
2894
|
continue;
|
|
2867
2895
|
out.push(id);
|
|
2868
2896
|
}
|
|
2869
2897
|
return out;
|
|
2870
2898
|
}
|
|
2871
2899
|
/**
|
|
2872
|
-
* Resolved bound anchor for
|
|
2900
|
+
* Resolved bound anchor for edges from CONFIG alone.
|
|
2873
2901
|
* BUY floor anchors toward minPrice (dip-insurance end), SELL ceiling toward
|
|
2874
2902
|
* maxPrice (spike-insurance end). Resolves numeric and "Nx" relative forms
|
|
2875
2903
|
* via resolveConfiguredPriceBound (startPrice-referenced); falls back to the
|
|
@@ -2877,16 +2905,16 @@ function collectRefillSlotIds(actions, options = {}) {
|
|
|
2877
2905
|
*
|
|
2878
2906
|
* Known limit: this is the statically resolved config bound, not the
|
|
2879
2907
|
* gridPrice/AMA-referenced live rail bound. Placement call sites should use
|
|
2880
|
-
*
|
|
2908
|
+
* resolveLiveEdgeAnchorPrice(manager, side), which prefers the genesis
|
|
2881
2909
|
* ladder extreme and returns null when there is no usable ladder. Callers that
|
|
2882
|
-
* need a fallback (e.g.
|
|
2910
|
+
* need a fallback (e.g. edgeOrderIdSet) still resolve this config bound when
|
|
2883
2911
|
* the live anchor is null; the live resolver itself no longer computes it.
|
|
2884
2912
|
*
|
|
2885
2913
|
* @param {Object} config - Bot configuration
|
|
2886
2914
|
* @param {string} side - 'buy' or 'sell'
|
|
2887
2915
|
* @returns {number|null} Finite anchor price, or null
|
|
2888
2916
|
*/
|
|
2889
|
-
function
|
|
2917
|
+
function resolveEdgeAnchorPrice(config, side) {
|
|
2890
2918
|
const isSell = side === 'sell';
|
|
2891
2919
|
const bound = isSell ? config?.maxPrice : config?.minPrice;
|
|
2892
2920
|
const mode = isSell ? 'max' : 'min';
|
|
@@ -2900,7 +2928,7 @@ function resolveReserveEdgeAnchorPrice(config, side) {
|
|
|
2900
2928
|
return Number.isFinite(raw) ? raw : null;
|
|
2901
2929
|
}
|
|
2902
2930
|
/**
|
|
2903
|
-
* Live-grid
|
|
2931
|
+
* Live-grid edge anchor (single source for edge placement).
|
|
2904
2932
|
*
|
|
2905
2933
|
* The anchor must come from the geometry the bot is actually trading, never
|
|
2906
2934
|
* from a config value that can be a mode string ("pool"/"book"), a relative
|
|
@@ -2918,7 +2946,7 @@ function resolveReserveEdgeAnchorPrice(config, side) {
|
|
|
2918
2946
|
* paper over. The former tiers — the live in-rail slot extreme and the resolved
|
|
2919
2947
|
* config bound — are gone with the legacy matcher they only existed to cover;
|
|
2920
2948
|
* any config-bound fallback is now resolved by the individual consumer that
|
|
2921
|
-
* wants one (see
|
|
2949
|
+
* wants one (see edgeOrderIdSet), not by this live-edge resolver. The fault
|
|
2922
2950
|
* itself is reported
|
|
2923
2951
|
* once per grid generation by the sync-entry gate; this resolver stays silent
|
|
2924
2952
|
* because it is called from per-fill and per-placement paths.
|
|
@@ -2927,7 +2955,7 @@ function resolveReserveEdgeAnchorPrice(config, side) {
|
|
|
2927
2955
|
* @param {string} side - 'buy' or 'sell'
|
|
2928
2956
|
* @returns {number|null} Finite anchor price, or null
|
|
2929
2957
|
*/
|
|
2930
|
-
function
|
|
2958
|
+
function resolveLiveEdgeAnchorPrice(manager, side) {
|
|
2931
2959
|
const isSell = side === 'sell';
|
|
2932
2960
|
const levels = manager?._genesis?.priceLevels;
|
|
2933
2961
|
if (Array.isArray(levels) && levels.length > 0) {
|
|
@@ -2938,7 +2966,7 @@ function resolveLiveReserveEdgeAnchorPrice(manager, side) {
|
|
|
2938
2966
|
return null;
|
|
2939
2967
|
}
|
|
2940
2968
|
/**
|
|
2941
|
-
* Shared anchored edge comparator for
|
|
2969
|
+
* Shared anchored edge comparator for edge selection (single source).
|
|
2942
2970
|
* With a finite anchor: in-bound slots first, nearest the anchor first
|
|
2943
2971
|
* (floor ascending, ceiling descending); stale out-of-bound slots last,
|
|
2944
2972
|
* still nearest the anchor first. Without one: plain rank fallback
|
|
@@ -2950,7 +2978,7 @@ function resolveLiveReserveEdgeAnchorPrice(manager, side) {
|
|
|
2950
2978
|
* @param {number|null} anchorPrice - Resolved bound anchor (null = rank fallback)
|
|
2951
2979
|
* @returns {number} Comparator result for Array.prototype.sort
|
|
2952
2980
|
*/
|
|
2953
|
-
function
|
|
2981
|
+
function compareEdge(a, b, edge, anchorPrice) {
|
|
2954
2982
|
const ceil = edge === 'ceiling';
|
|
2955
2983
|
// NB: Number(null) === 0 is finite — null/undefined must mean "no anchor".
|
|
2956
2984
|
const anchor = anchorPrice == null ? Number.NaN : Number(anchorPrice);
|
|
@@ -2968,25 +2996,25 @@ function compareReserveEdge(a, b, edge, anchorPrice) {
|
|
|
2968
2996
|
return ceil ? pa - pb : pb - pa;
|
|
2969
2997
|
}
|
|
2970
2998
|
/**
|
|
2971
|
-
* Central edge selector: take
|
|
2999
|
+
* Central edge selector: take edge slots from a price-ascending list,
|
|
2972
3000
|
* skipping already-windowed ids. Both edges anchor at the live grid's own
|
|
2973
|
-
* edge (
|
|
3001
|
+
* edge (resolveLiveEdgeAnchorPrice) when finite — floor: nearest
|
|
2974
3002
|
* at/above the live floor first, slots below it rank last; ceiling: nearest
|
|
2975
3003
|
* at/below the live ceiling first, slots above it rank last. Anchoring to the
|
|
2976
|
-
* live edge keeps the
|
|
3004
|
+
* live edge keeps the edge order on genuine live-rail slots when the grid still
|
|
2977
3005
|
* carries leftovers from an older bound or the configured bound disagrees
|
|
2978
3006
|
* with the geometry being traded. Callers pre-filter rail/type and apply
|
|
2979
3007
|
* their own size gates; this only picks positions. A null anchor degrades to
|
|
2980
3008
|
* plain rank (floor: lowest first; ceiling: highest first).
|
|
2981
3009
|
*
|
|
2982
3010
|
* @param {Array<Object>} sortedAsc - Slots sorted by price ascending
|
|
2983
|
-
* @param {number} count -
|
|
3011
|
+
* @param {number} count - Edge count
|
|
2984
3012
|
* @param {Set<string>|null} excludeIds - Windowed ids to skip
|
|
2985
3013
|
* @param {string} edge - 'floor' or 'ceiling'
|
|
2986
3014
|
* @param {number|null} [anchorPrice] - Live edge anchor for the side (null = rank-based)
|
|
2987
|
-
* @returns {Array<Object>}
|
|
3015
|
+
* @returns {Array<Object>} Edge slots (ascending for floor, descending for ceiling)
|
|
2988
3016
|
*/
|
|
2989
|
-
function
|
|
3017
|
+
function selectEdgeSlots(sortedAsc, count, excludeIds, edge, anchorPrice = null) {
|
|
2990
3018
|
const n = Math.max(0, Math.floor(Number(count) || 0));
|
|
2991
3019
|
if (n <= 0 || !Array.isArray(sortedAsc))
|
|
2992
3020
|
return [];
|
|
@@ -3001,21 +3029,22 @@ function selectReserveEdgeSlots(sortedAsc, count, excludeIds, edge, anchorPrice
|
|
|
3001
3029
|
// Anchored: shared comparator — in-bound slots nearest the bound first,
|
|
3002
3030
|
// stale out-of-bound slots last.
|
|
3003
3031
|
return avail
|
|
3004
|
-
.sort((x, y) =>
|
|
3032
|
+
.sort((x, y) => compareEdge(x, y, edge, anchor))
|
|
3005
3033
|
.slice(0, n);
|
|
3006
3034
|
}
|
|
3007
3035
|
/**
|
|
3008
3036
|
* Total target order count across both sides (used for BTS fee calculation).
|
|
3009
3037
|
* Single source of truth so every budget derivation sizes identically.
|
|
3010
|
-
* Includes per-side
|
|
3038
|
+
* Includes per-side edge orders: they rest live on-chain and pay creation fees.
|
|
3011
3039
|
*
|
|
3012
3040
|
* @param {Object} config - Bot configuration
|
|
3013
3041
|
* @returns {number} Total target order count
|
|
3014
3042
|
*/
|
|
3015
|
-
function
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3043
|
+
function getCoreOrdersTotal(config) {
|
|
3044
|
+
const coreOrders = config?.coreOrders;
|
|
3045
|
+
return Math.max(0, coreOrders?.buy ?? 1) +
|
|
3046
|
+
Math.max(0, coreOrders?.sell ?? 1) +
|
|
3047
|
+
resolveEdgeOrders(config);
|
|
3019
3048
|
}
|
|
3020
3049
|
/**
|
|
3021
3050
|
* Calculate side budget after BTS fee deduction.
|
|
@@ -3268,6 +3297,6 @@ function collectKnownOnChainOrderIds(mgr, placedResults, placedContexts, extraCr
|
|
|
3268
3297
|
const all = new Set([...masterIds, ...createIds]);
|
|
3269
3298
|
return { masterIds: [...masterIds], createIds: [...createIds], all: [...all] };
|
|
3270
3299
|
}
|
|
3271
|
-
export { parseChainOrder, applyChainSizeToGridOrder, buildFillKey, correctOrderPriceOnChain, correctAllPriceMismatches, _validatePriceCorrectionEntry, _stampCorrectionProvenance, findLiveOrderOwnerByChainId, buildCreateOrderArgs, getOrderTypeFromUpdatedFlags, resolveConfiguredPriceBound, virtualizeOrder, convertToSpreadPlaceholder, toRailHolePlaceholder, geometryTypeForSlotIndex, detectGapEvacuationCandidates, updateGapEvacuationStreaks, resolveSpreadOrderSide, chainOrderMatchesSlot, chainOrderMatchesSlotWithTolerance, crossingCandidateChainId, isCrossingCheckCandidate, buildCrossingCheckCandidates, parseSlotIndex, filterOrdersByType, buildOutsideInPairGroups, extractBatchOperationResults, formatUnmatchedChainOrder, isNonBlockingUnmatchedOrder, isStrandedHoldOrder, isOrderOnChain, isOrderVirtual, hasOnChainId, isOrderPlaced, isPhantomOrder, isSlotAvailable, isEmptyGridSlot, isOrderHealthy, checkSizeThreshold, checkSizesBeforeMinimum, calculateIdealBoundary, assignGridRoles, resolveOnChainRetypeType, shouldFlagOutOfSpread, buildIndexes, validateIndexes, ordersEqual, buildDelta, deriveTargetBoundary, isShiftEligibleFill,
|
|
3272
|
-
export {
|
|
3300
|
+
export { parseChainOrder, applyChainSizeToGridOrder, buildFillKey, correctOrderPriceOnChain, correctAllPriceMismatches, _validatePriceCorrectionEntry, _stampCorrectionProvenance, findLiveOrderOwnerByChainId, buildCreateOrderArgs, getOrderTypeFromUpdatedFlags, resolveConfiguredPriceBound, virtualizeOrder, convertToSpreadPlaceholder, toRailHolePlaceholder, geometryTypeForSlotIndex, detectGapEvacuationCandidates, updateGapEvacuationStreaks, resolveSpreadOrderSide, chainOrderMatchesSlot, chainOrderMatchesSlotWithTolerance, crossingCandidateChainId, isCrossingCheckCandidate, buildCrossingCheckCandidates, parseSlotIndex, filterOrdersByType, buildOutsideInPairGroups, extractBatchOperationResults, formatUnmatchedChainOrder, isNonBlockingUnmatchedOrder, isStrandedHoldOrder, isOrderOnChain, isOrderVirtual, hasOnChainId, isOrderPlaced, isPhantomOrder, isSlotAvailable, isEmptyGridSlot, isOrderHealthy, checkSizeThreshold, checkSizesBeforeMinimum, calculateIdealBoundary, assignGridRoles, resolveOnChainRetypeType, shouldFlagOutOfSpread, buildIndexes, validateIndexes, ordersEqual, buildDelta, deriveTargetBoundary, isShiftEligibleFill, resolveEdgeCount, resolveEdgeOrders, selectEdgeSlots, getCoreOrdersTotal, getSideBudget, calculateBudgetedSizes, buildCreateOpFingerprint, isOrderGoneErrorMessage, recordDuplicateOrphanDetection, clearDuplicateOrphanDetection, duplicateOrphanLogInfo, chainOrderUnchangedFromCache, detectCrossedBookPlan, collectKnownOnChainOrderIds, edgeOrderIdSet, liveWindowIdSet, checkGridPriceInvariant, reportGridPriceInvariant };
|
|
3301
|
+
export { resolveEdgeAnchorPrice, resolveLiveEdgeAnchorPrice, compareEdge, collectRefillSlotIds, recordOrderPlacement, isFreshlyPlacedOrder, _filterUnmatchedChainOrders };
|
|
3273
3302
|
//# sourceMappingURL=order.js.map
|