Skip to content

fix: use round_down for market order price#325

Open
skyc1e wants to merge 1 commit intoPolymarket:mainfrom
skyc1e:fix/market-order-round-down
Open

fix: use round_down for market order price#325
skyc1e wants to merge 1 commit intoPolymarket:mainfrom
skyc1e:fix/market-order-round-down

Conversation

@skyc1e
Copy link
Copy Markdown

@skyc1e skyc1e commented Apr 8, 2026

get_market_order_amounts uses round_normal for price, but the TypeScript client uses roundDown in the equivalent getMarketOrderRawAmounts (helpers.ts:200).

round_normal can round up (e.g. 0.5550.56 with 2 decimal precision), producing a worse effective price for BUY market orders — fewer shares per dollar.

This changes line 88 of builder.py from round_normal to round_down for market orders only. Limit orders (get_order_amounts) are unchanged and correctly use round_normal in both clients.

Includes a regression test using a price that diverges between the two rounding methods.

Closes #323


Note

Medium Risk
Changes market order price rounding, which directly affects computed maker/taker amounts and effective execution price. Risk is contained to market orders but could impact downstream order validation and user outcomes if rounding assumptions differ.

Overview
Market order construction now rounds the input price down (via round_down) in get_market_order_amounts instead of using round_normal, preventing cases where mid-tick prices round up and produce a worse effective price (notably for BUY market orders).

Adds a regression test (test_market_order_uses_round_down_for_price) that exercises a price (0.555 with tick_size="0.01") where round_normal and round_down diverge, ensuring the builder matches the expected (TypeScript-aligned) rounding behavior.

Reviewed by Cursor Bugbot for commit ac9827a. Bugbot is set up for automated code reviews on this repo. Configure here.

Market orders should not round price in the unfavorable direction.
round_normal can round up (e.g. 0.555 -> 0.56), giving BUY orders
fewer shares per dollar. round_down (0.555 -> 0.55) matches the
TypeScript client's roundDown behavior for market orders.

Limit orders (get_order_amounts) correctly use round_normal and
are not changed.

Closes Polymarket#323
@skyc1e skyc1e requested a review from a team as a code owner April 8, 2026 00:16
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ac9827a. Configure here.

side, maker, taker = builder.get_market_order_amounts(
SELL, 100.0, 0.555, config
)
self.assertEqual(side, UtilsSell)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SELL regression test missing price rounding assertions

Low Severity

The SELL half of test_market_order_uses_round_down_for_price only asserts that side == UtilsSell, without verifying that round_down was actually used for the price — unlike the BUY half, which explicitly checks effective_price against both round_down and round_normal results. This means a future regression that changes SELL price rounding back to round_normal would not be caught by this test, defeating the stated purpose of a regression test for issue #323.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ac9827a. Configure here.

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.

bug: market order price uses round_normal instead of round_down (inconsistent with TS client)

1 participant