Skip to content

fix(validation): warn when activeOrders exceeds grid capacity (Range/Incr) - #21

Closed
Impulssi wants to merge 2 commits into
froooze:mainfrom
Impulssi:fix/validate-grid-capacity
Closed

fix(validation): warn when activeOrders exceeds grid capacity (Range/Incr)#21
Impulssi wants to merge 2 commits into
froooze:mainfrom
Impulssi:fix/validate-grid-capacity

Conversation

@Impulssi

Copy link
Copy Markdown
Contributor

Problem (issue #19)

With Range [1.15x - 1.5x] and Incr 1.5% the grid cannot hold activeOrders S:27. dexbot order showed:

Spread: 6.17% (4.60%) | Incr.: 1.65% (1.50%)
Active: 6/6  buy      | 22/27 sell
Slots: 10 buy 3 spread 23 sell

createOrderGrid (modules/order/grid.ts:444-460) generates ln(1.15*1.5)/ln(1.015) ~ 36 levels, so the sell side fits only ~23 orders. Target 27 is never reachable — the surplus silently stays unfilled. The startup log confirmed:

Startup reconcile complete: target(sell=27, buy=6), chain(sell=27, buy=6), gridActive(sell=22, buy=6)

There was no warning at dexbot bot time. The operator naturally assumes funds are missing (virtualReservation) when it is actually grid geometry.

Fix

Add a per-side capacity check in collectValidationIssues (modules/bot_settings.ts). The estimate mirrors createOrderGrid geometry: each side grows geometrically from the center; gap slots split around the boundary.

buyCapacity  = floor(log(minFactor)/log(step)) - floor(gapSlots/2) - 1
sellCapacity = floor(log(maxFactor)/log(step)) - ceil(gapSlots/2)  - 1

Now the issue case warns at startup:

Bot[0] 'testo': activeOrders sell:27 exceeds grid capacity — Range [1.15x-1.5x]
with Incr 1.5% fits ~24 sell orders. After reset the surplus silently stays
unfilled (e.g. S:27 showed Active 22/27, Slots 23 sell). Widen maxPrice,
lower Incr, or reduce activeOrders.sell.

The same check covers the buy side, numeric (absolute price) bounds, and skips safely when types are mixed or fields are missing.

Testing

8 cases verified against the compiled output:

  • [1.15x-1.5x] 1.5% S:27 → warns fits ~24 sell (observed 23)
  • [1.15x-2.0x] 1.5% S:27 → no warning (the documented workaround)
  • old config 0.65%/3% [1.15x-1.5x] B6/S27 → no warning
  • inactive bot → no warning
  • B:15 on 1.15x → warns buy fits ~7
  • mixed x-factor/numeric bounds → skipped safely
  • missing incrementPercent → skipped s

Fixes #19


Note: I'm new to this codebase and worked through this change with an AI
coding assistant (opencode). The bug was hit on my own live instance and
all measurements / reproduction steps are mine — but please flag anything
in the code that looks off and I'll dig in and follow up.

With Range [1.15x-1.5x] and Incr 1.5% the grid holds ~34 order slots
(S:23 max). Target S:27 (33 total) silently becomes 22/27 with no
warning (operator assumes funds missing). Add capacity check in
collectValidationIssues: estimate levels from Range/Incr/Spread and
warn when required > available - buffer.
…rning

Estimate buy and sell capacity separately (mirrors createOrderGrid
geometry: each side grows geometrically from the center, gap slots
split around the boundary). Issue case now reports 'fits ~24 sell
orders' vs observed 23. Warning text rewritten to state the symptom
(Active 22/27, Slots 23 sell) and the remedies per side.
@froooze

froooze commented Sep 1, 2026

Copy link
Copy Markdown
Owner

I see the need to educate the user about a proper DEXBot2 range. Give the user a hint afterwards is not beneficial nor should the active order count play a role about a proper range.

User sees now range legend, with color highlight.
489531a

@froooze froooze closed this Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

activeOrders S:27 does not fit Range [1.15x-1.5x] with Incr 1.5% - no validation warning

2 participants