fix(client): round protected BUY market orders down to preserve max_price (#292) - #1
Open
FluxNimbusAi wants to merge 1 commit into
Open
fix(client): round protected BUY market orders down to preserve max_price (#292)#1FluxNimbusAi wants to merge 1 commit into
FluxNimbusAi wants to merge 1 commit into
Conversation
…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.
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.
Summary
Protected BUY market orders with
max_pricecan become unfillable at the target ask level due to aggressive rounding of the taker amount.Bug
When
prepare_market_order_draftencounters a protected BUY (wheremax_priceis set),_compute_market_order_amounts()usesround_upfor the final taker-amount step after verifying the implied price would exceedmax_price. Since implied price = maker / taker, inflating taker drives the implied price belowmax_price, making the order unfillable at the target ask level.Example
round_up(0.07 * 1e6, ...)→ 14,285,714 sharesround_down→ 14,285,714 shares (implied ≥ $0.07)Fix
Remove the
protect_priceparameter from_compute_market_order_amounts(). Useround_downuniformly in both branches — this is consistent with:round_down)round_normal→round_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