fix: use round_down for market order price#325
fix: use round_down for market order price#325skyc1e wants to merge 1 commit intoPolymarket:mainfrom
Conversation
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
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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) |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit ac9827a. Configure here.


get_market_order_amountsusesround_normalfor price, but the TypeScript client usesroundDownin the equivalentgetMarketOrderRawAmounts(helpers.ts:200).round_normalcan round up (e.g.0.555→0.56with 2 decimal precision), producing a worse effective price for BUY market orders — fewer shares per dollar.This changes line 88 of
builder.pyfromround_normaltoround_downfor market orders only. Limit orders (get_order_amounts) are unchanged and correctly useround_normalin 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
pricedown (viaround_down) inget_market_order_amountsinstead of usinground_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.555withtick_size="0.01") whereround_normalandround_downdiverge, 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.