fix market orders using stale book prices or log page#1029
Open
mooncitydev wants to merge 1 commit into
Open
Conversation
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
👷 Deploy request for ambi-perps pending review.Visit the deploys page to approve it
|
✅ Deploy Preview for ambi-perps-us ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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