fix(predict): refresh balance/allowance before Polymarket order submission#26954
Conversation
…ssion Polymarket CLOB infrastructure intermittently returns 400 'not enough balance / allowance' errors at high request rates. As a temporary workaround, call GET /balance-allowance/update before each order to refresh the balance/allowance state on their end. - Add refreshBalanceAllowance() utility with L2 HMAC auth - Call it in placeOrder() before submitClobOrder (best-effort) - BUY orders refresh COLLATERAL, SELL orders refresh CONDITIONAL - Failure does not block order submission
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection: Key changes:
Tag selection rationale:
The risk is medium because while the changes are isolated and the workaround is best-effort (non-blocking on failure), it does modify the order placement flow which is a critical user action in the predictions feature. Performance Test Selection: |
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, have a team admin enable autofix in the Cursor dashboard.
The committed fixture schema is out of date. To update, comment: |
|



Description
Polymarket's CLOB infrastructure is intermittently returning 400 errors with "not enough balance / allowance" when placing orders at high request rates. As a temporary workaround communicated by the Polymarket team, we now call
GET /balance-allowance/updatebefore each order to refresh the balance/allowance state on their end.Changes:
utils.ts: AddrefreshBalanceAllowance()utility that calls the CLOB balance-allowance/update endpoint with L2 HMAC auth headersasset_type=COLLATERAL(USDC)asset_type=CONDITIONALwith the order'stoken_idPolymarketProvider.ts: CallrefreshBalanceAllowance()inplaceOrder()right beforesubmitClobOrder(), wrapped in try/catch so failures don't block order submissionutils.test.ts: 5 new tests covering BUY/SELL paths, auth headers, error resilience, and custom signature typesPolymarketProvider.test.ts: 4 new integration tests verifying call ordering, parameter passing for both sides, and graceful degradation on refresh failureChangelog
CHANGELOG entry: null
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/PRED-726
Manual testing steps
Screenshots/Recordings
N/A — no UI changes
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Adds a new preflight network call in the order placement path; while failures are best-effort and don’t block orders, it changes timing/behavior in a core trading flow and could affect reliability or rate limits.
Overview
Adds a temporary workaround for intermittent Polymarket CLOB
not enough balance / allowanceerrors by introducingrefreshBalanceAllowance()(callsGET /balance-allowance/updatewith L2 HMAC headers) and invoking it inPolymarketProvider.placeOrder()immediately beforesubmitClobOrder().The refresh is best-effort (wrapped in
try/catchwith logging) and varies request params by side: BUY refreshesasset_type=COLLATERAL, SELL refreshesasset_type=CONDITIONALwithtoken_id. Updates unit/integration tests to cover parameter selection, call ordering, header usage, and non-blocking behavior on refresh failure.Written by Cursor Bugbot for commit 8a46817. This will update automatically on new commits. Configure here.