fix(clob book): show best bid/ask at the top of the orderbook#81
Open
Nexory wants to merge 2 commits into
Open
fix(clob book): show best bid/ask at the top of the orderbook#81Nexory wants to merge 2 commits into
Nexory wants to merge 2 commits into
Conversation
…rket#75) The display iterated bids and asks in storage order — best prices ended up at the bottom of the table. Reverse the iteration order so the maker side stays at the top, matching how every other CLOB UI presents the book. Closes Polymarket#75.
The previous tests defined their own `.iter().rev()` chain via `rendered_bid_prices` / `rendered_ask_prices` instead of exercising the production iterator, so removing `.rev()` from `print_order_book` would still leave the tests green — a tautology. This commit extracts the ordering into two thin functions, `bids_in_display_order` and `asks_in_display_order`, both used by `print_order_book`. Tests now call these helpers directly. Removing `.rev()` from either helper makes the corresponding test fail with a verbatim wrong-order assertion, which is the property we want pinned. Empirical verification: - HEAD (with .rev()): 3 passed; 0 failed - bids helper without .rev(): 2 passed; 1 failed (bids test) - asks helper without .rev(): 2 passed; 1 failed (asks test) - cargo fmt --check: exit 0 - cargo clippy --all-targets -- -D warnings: exit 0 An empty-input case is added so the helpers are also pinned against panics on empty bids/asks.
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.
The change
Two
.rev()calls — one on the bids iterator, one on asks — insrc/output/clob/books.rs. The Polymarket CLOB API returns bids in ascending-price order (worst bid first) and asks in descending-price order (worst ask first), so iterating straight intotabled::Tableburies the best prices at the bottom of each section. The ordering is now extracted into two smallsuper-visible helpers (bids_in_display_order,asks_in_display_order) used byprint_order_book, so the tests can exercise the production ordering directly without re-implementing it inline. JSON output, the type definitions, and every other display path are untouched.Empirical verification (local, Windows + stable rustc 1.96.0)
Three unit tests are added to
src/output/clob/books.rs. Each calls a production helper directly — there is no.iter().rev()chain in the test body, so the assertion fails if the helper stops reversing.Running the full books module tests on the branch as it stands (both helpers reverse):
Then deleting
.rev()only frombids_in_display_order(asks helper kept reversing) and re-running:And, symmetric, with
.rev()removed only fromasks_in_display_order(bids helper kept reversing):That is the property each test actually pins.
Compliance
cargo fmt --check— exit 0cargo clippy --all-targets -- -D warnings— exit 0cargo test— full suite: 84 passed | 1 failed; the one failure (commands::upgrade::tests::detect_target_returns_valid_triplewithUnsupported platform: windows/x86_64) reproduces unchanged onmainand is unrelated to this PR (detect_targetfor Windows insrc/commands/upgrade.rs).Reproduction in the wild
Reproduced against the BTC
$150k by June 30market and 2 other high-volume markets — API ordering is consistent (bids ascending, asks descending), and the table layout buries the best prices at the bottom in every case. The non-obvious ordering is also documented in Polymarket/rs-clob-client#330 for the V1 Rust SDK.JSON output (
OutputFormat::Json) keeps the API order so programmatic consumers stay backward-compatible — this is purely the human-facing table.Closes #75.