Skip to content

fix(client): round protected BUY market orders down to preserve max_price (#292) - #1

Open
FluxNimbusAi wants to merge 1 commit into
mainfrom
fix/292-protected-buy-rounding
Open

fix(client): round protected BUY market orders down to preserve max_price (#292)#1
FluxNimbusAi wants to merge 1 commit into
mainfrom
fix/292-protected-buy-rounding

Conversation

@FluxNimbusAi

Copy link
Copy Markdown
Owner

Summary

Protected BUY market orders with max_price can become unfillable at the target ask level due to aggressive rounding of the taker amount.

Bug

When prepare_market_order_draft encounters a protected BUY (where max_price is set), _compute_market_order_amounts() uses round_up for the final taker-amount step after verifying the implied price would exceed max_price. Since implied price = maker / taker, inflating taker drives the implied price below max_price, making the order unfillable at the target ask level.

Example

  • Amount: 1 USD, Price: $0.07/share
  • Current behavior: round_up(0.07 * 1e6, ...) → 14,285,714 shares
  • Implied price: $1,000,000 / 14,285,714 = $0.06999… (below target)
  • Fixed behavior: round_down → 14,285,714 shares (implied ≥ $0.07)

Fix

Remove the protect_price parameter from _compute_market_order_amounts(). Use round_down uniformly in both branches — this is consistent with:

  • The unprotected path (already used round_down)
  • The TypeScript reference implementation
  • The fix applied to py-clob-client v0.34.6 via PR #323 (round_normalround_down)

Tests

Added comprehensive test suite covering all problematic prices in 2dp and 3dp markets where rounding errors would break the max_price guarantee.

Related: issue Polymarket#292, py-clob-client #323

…rice (Polymarket#292)

When prepare_market_order_draft encounters a protected BUY (max_price set),
_compute_market_order_amounts used round_up for the final taker-amount step.
Since implied price = maker / taker, inflating taker drives the implied price
below max_price, making the order unfillable at the target ask level.

Fix: remove the protect_price parameter and use round_down uniformly. This is
consistent with:
- The unprotected path (already used round_down)
- TypeScript reference implementation
- py-clob-client v0.34.6 after #323 fix

Bug report: issue Polymarket#292 (same root cause as pollymarket/py-clob-client #323).

Tests: 14 cases covering all problematic prices in 2dp and 3dp markets.
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.

1 participant