Add pendingmatch flag to orderbook query response #714
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.
Description
Prevent cross order
Meanwhile, need merge https://github.com/binance-chain/http-ap/pull/85 and bnb-chain/go-sdk#110 with this change
Rationale
Here is an example of crossed price levels in websocket depth:
After BeginBlock of height 101, the round order (sell, price=3,quantity=5) was inserted into order book. Websocket queried node depth API and the response included this order. and then an order (buy price=3,quantity=9) was also inserted into order book. After matching, in the endblock the remaining price level (buy, price=3,quantity=4) was published to websocket as delta. However, the price level (sell, price=3,quantity=5) still stayed in websocket depth cache, hence the crossed order (buy, 3,5) and (sell, 3,4) received by websocket subscriber. The price level (buy, 3,5) actually doesn’t exist in the real order book.
Solution:
Add a boolean flag “pending_match” in node depth API response to indicate the case of unmatched round orders in order book.
If len(roundOrders[symbol])>0, “pending_match” = true. The drawback is for mini-tokens, the roundOrders will be kept for several blocks until match, and hence the client has a lower chance to get order book with pending_match=false.
The client (websocket-ap) will discard this query result when pendingMatch is true.
Example
RUN TestGetDepth
{"Height":2644,"Levels":[{"buyQty":"0.00000000","buyPrice":"0.00000000","sellQty":"0.00000000","sellPrice":"0.00000000"},{"buyQty":"0.00000000","buyPrice":"0.00000000","sellQty":"0.00000000","sellPrice":"0.00000000"}],"PendingMatch":true}
Changes
Notable changes:
Preflight checks
make build
)make test
)make integration_test
)Already reviewed by
...
Related issues