Skip to content

fix market orders using stale book prices or log page#1029

Open
mooncitydev wants to merge 1 commit into
CrocSwap:developfrom
mooncitydev:fix/market-order-safety
Open

fix market orders using stale book prices or log page#1029
mooncitydev wants to merge 1 commit into
CrocSwap:developfrom
mooncitydev:fix/market-order-safety

Conversation

@mooncitydev

Copy link
Copy Markdown
Contributor

hey team, mooncitydev here. looked through the trading path and found a few spots where market orders could go out with bad assumptions. not sure how often it bites in prod but the failure modes are rough when they hit.

first, market buys/sells and position closes fell back to mark price when the order book side was empty. mark and top of book can diverge a lot during reconnects or thin liquidity, so fill price on chain could be way off what the user expected. now we require a live bid/ask and reject if the book has not updated in the last 10s.

second, the orderbook websocket watchdog called forceReconnect after 5s of silence but also bumped lastMessageTimeRef without getting new data. that meant the UI kept showing a filled book while the feed was actually dead. removed that fake reset and surface a stale state while reconnecting.

third, market/limit/cancel txs used marketOrderLogPage from a 30s cache and never refreshed at submit time. if the on chain page moved, txs could fail intermittently. we now fetch the current page right before building the transaction.

added a small helper + tests for the book freshness checks. cheers

stop falling back to mark price when the book is empty, refresh the on-chain log page right before building txs, and fix the orderbook watchdog that reset its timer without new data
@netlify

netlify Bot commented May 19, 2026

Copy link
Copy Markdown

👷 Deploy request for ambi-perps pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 7896078

@netlify

netlify Bot commented May 19, 2026

Copy link
Copy Markdown

Deploy Preview for ambi-perps-us ready!

Name Link
🔨 Latest commit 7896078
🔍 Latest deploy log https://app.netlify.com/projects/ambi-perps-us/deploys/6a0c82c91b21e700086dfcf6
😎 Deploy Preview https://deploy-preview-1029--ambi-perps-us.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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.

1 participant