Skip to content

fix: Cap market order taker amount at 4 decimals to match API limit (#87) - #88

Open
lushan888 wants to merge 1 commit into
Polymarket:mainfrom
lushan888:main
Open

fix: Cap market order taker amount at 4 decimals to match API limit (#87)#88
lushan888 wants to merge 1 commit into
Polymarket:mainfrom
lushan888:main

Conversation

@lushan888

@lushan888 lushan888 commented Jul 10, 2026

Copy link
Copy Markdown

Fix for #87 — Market orders rejected due to taker amount precision

Problem

getMarketOrderRawAmounts rounds the taker amount using ROUNDING_CONFIG.amount (5-6 decimals for 0.001/0.0001 tick markets), but the CLOB API accepts at most 4 decimals for the taker amount. Result: orders are rejected server-side.

Fix

After the existing tick-size rounding logic, cap rawTakerAmt at 4 decimals using roundDown for both BUY and SELL branches. This is a 4-line change with a named constant.

Verification

Scenario Before After
BUY $5 at 0.998 (0.001-tick) takerAmount = 5010020 (5 decimals) takerAmount = 5010000 (4 decimals) ✓
SELL 7.77 shares at 0.998 (0.001-tick) takerAmount = 7754460 (5 decimals) takerAmount = 7754000 (4 decimals) ✓

Impact

  • Minimal: existing rounding logic is preserved, only capped to 4 decimals when it exceeds
  • No API changes — same function signature, same types

Wallet (Base): 0xaa9e4971e0973065513b18dEF9eC06Eb1F39D7A2


Note

Low Risk
Localized rounding change in market order amount calculation with no API or signature changes; slight downward bias on taker size only when capping applies.

Overview
Fixes CLOB rejections when market orders compute a taker amount with more than four decimal places (common on 0.001/0.0001 tick markets where roundConfig.amount allows 5–6 decimals).

getMarketOrderRawAmounts now defines MAX_TAKER_DECIMALS = 4 and, after the existing tick-size rounding on both BUY and SELL, applies roundDown on rawTakerAmt when precision exceeds that cap. Maker-side rounding and the function signature are unchanged; only the final taker value sent through buildMarketOrderCreationArgs is adjusted to match the API limit.

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

…olymarket#87)

The Polymarket CLOB API accepts market-order taker amounts with at most 4
decimal places, but getMarketOrderRawAmounts uses the tick-size rounding
config (amount: 5 for 0.001-tick, amount: 6 for 0.0001-tick), which can
produce amounts with 5-6 decimals.

Fix: after the existing tick-size rounding logic, cap rawTakerAmt at 4
decimals (roundDown) for both BUY and SELL branches. This ensures the
parsed takerAmount never exceeds the API's limit.

Fixes Polymarket#87
@lushan888
lushan888 requested a review from a team as a code owner July 10, 2026 10:18
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