Skip to content

feat(dex): add fill probability estimator for limit orders - #1134

Merged
Nanle-code merged 1 commit into
Nanle-code:masterfrom
elgifts12:feat/fill-probability-estimator
Oct 5, 2026
Merged

Nanle-code merged 1 commit into
Nanle-code:masterfrom
elgifts12:feat/fill-probability-estimator

Conversation

@elgifts12

Copy link
Copy Markdown

Estimate the likelihood a proposed limit order fills using two signals from current order book depth and recent trade cadence:

  • Depth score: walks book levels from best price toward the limit; aggressive prices (inside spread) score ~1, deep passive limits ~0. Formula: exp(-3 * depthFraction)
  • Cadence score: trades-per-minute at-or-better-than limit price in a 5-min window. Formula: 1 - exp(-0.5 * tpm)

Both combine via weighted geometric mean (depth 60%, cadence 40%) into a [0,1] probability with tier labels (very_high/high/medium/low/very_low).

New files:
src/lib/fillProbability.ts - pure estimation engine, no React deps
src/hooks/useFillProbability.ts - useMemo reactive wrapper, returns null
when book data is absent
src/lib/tests/fillProbability.test.ts - 12 tests covering primary flow,
boundary cases, and failure paths

Modified files:
src/components/dashboard/SlippageTradePanel.tsx - add optional trades prop,
expand metrics grid 4->5 cols with color-coded Fill Probability stat
src/components/dashboard/DEXExplorer.tsx - thread fetched trades into
SlippageTradePanel

Invalid inputs (bad side, non-positive price/qty, NaN) return probability 0 without throwing. Existing SlippageTradePanel tests are unaffected since the trades prop is optional.

Summary

Closes #860

How was this tested?

Merge requirements

A PR is merged only when every box below is true. See
Merge requirements for the full policy.

  • All required CI checks pass on the latest commit (not just an earlier push).
  • No required checks are failing, pending, or skipped — re-run or fix them; do not ask for a merge while any are outstanding.
  • The branch has no merge conflicts with the target branch (rebase or merge master if GitHub shows "This branch has conflicts").
  • Tests were added or updated for the change (primary flow, a boundary case, and a failure case).
  • Docs were updated where behaviour, configuration, or security posture changed.

Security-sensitive changes

  • This PR touches a path covered by .github/CODEOWNERS (wallet, auth, cryptography, CI) and a code owner has been requested for review.
  • I described any change to key handling, signing, session lifetime, or trusted endpoints above.

Estimate the likelihood a proposed limit order fills using two signals
from current order book depth and recent trade cadence:

- Depth score: walks book levels from best price toward the limit;
  aggressive prices (inside spread) score ~1, deep passive limits ~0.
  Formula: exp(-3 * depthFraction)
- Cadence score: trades-per-minute at-or-better-than limit price in a
  5-min window. Formula: 1 - exp(-0.5 * tpm)

Both combine via weighted geometric mean (depth 60%, cadence 40%) into
a [0,1] probability with tier labels (very_high/high/medium/low/very_low).

New files:
  src/lib/fillProbability.ts         - pure estimation engine, no React deps
  src/hooks/useFillProbability.ts    - useMemo reactive wrapper, returns null
                                       when book data is absent
  src/lib/tests/fillProbability.test.ts - 12 tests covering primary flow,
                                          boundary cases, and failure paths

Modified files:
  src/components/dashboard/SlippageTradePanel.tsx - add optional trades prop,
    expand metrics grid 4->5 cols with color-coded Fill Probability stat
  src/components/dashboard/DEXExplorer.tsx - thread fetched trades into
    SlippageTradePanel

Invalid inputs (bad side, non-positive price/qty, NaN) return probability 0
without throwing. Existing SlippageTradePanel tests are unaffected since
the trades prop is optional.
@vercel

vercel Bot commented Oct 4, 2026

Copy link
Copy Markdown

@Manuelshub is attempting to deploy a commit to the nanle-code's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Nanle-code
Nanle-code merged commit 752c97f into Nanle-code:master Oct 5, 2026
1 check failed
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.

[2026 DEX] Implement limit-order fill probability estimates

3 participants