Market Order
Execute a buy or sell market order.tokenId(string): Market token ID for the positionsize(number): Order size (meaning differs by side)side(string): “BUY” or “SELL”expiresAt(string | null, optional): ISO 8601 timestamp. In manual mode, the suggestion expires at this time. If omitted, no time-based expiry is set (suggestions are auto-cleared at eachrunstart).waitForConfirmation(boolean, optional): Iftrue(default), the SDK polls for transaction receipts after the order executes and returnssuccess: falseif any transaction reverted onchain. Set tofalseto skip receipt polling.
- BUY:
sizeis the USD amount to spend (e.g.,10= $10 worth of shares) - SELL:
sizeis the number of shares to sell (e.g.,10= 10 shares)
success(boolean): Whether the operation succeededdata.orderInfo(object): Order information (on success)orderId(string): Unique order identifierside(string): “BUY” or “SELL”size(string): Order sizepriceUsd(string): Price per share in USDtotalPriceUsd(string): Total order value in USDtxHashes(string[]): Transaction hashes
error(string | null): Error message (on failure)
Redeem Positions
Redeem settled positions and claim winnings.tokenIds(string[], optional): Specific token IDs to redeem. Omit or pass empty array to redeem all redeemable positions.waitForConfirmation(boolean, optional): Iftrue(default), the SDK polls for transaction receipts after redemption and returnssuccess: falseif any transaction reverted onchain. Set tofalseto skip receipt polling.
success(boolean): Whether the operation succeededdata(array): Array of redemption resultssuccess(boolean): Whether this redemption succeededposition(object | null): Position details (on success)question(string): Market question textoutcome(string): Outcome name (e.g., “Yes”, “No”)valueUsd(string): Position value in USDpnlUsd(string): Profit/loss in USDpnlPercent(string): Profit/loss percentageisRedeemable(boolean): Whether position can be redeemedcontractAddress(string): Token contract addresstokenId(string | null): Token IDdecimals(number): Token decimalsconditionId(string): Market condition IDformattedShares(string): Human-readable share countshares(string): Raw share countaveragePriceUsd(string): Average entry priceinitialValue(string): Original position valuepnlRealizedUsd(string): Realized PnL in USDpnlRealizedPercent(string): Realized PnL percentageisNegativeRisk(boolean): Whether this is a negative risk marketimageUrl(string): Market image URLendDate(string): Market end date
transactionHash(string | null): Transaction hash (on success)
error(string | null): Error message (on failure)
Common Errors
Errors are returned from Polymarket’s API in theerror field. Common errors include:
| Error | Cause | Solution |
|---|---|---|
| ”Insufficient balance” | Not enough USDC for BUY order | Check currentPositions for USDC balance |
| ”No orderbook exists for the requested token id” | Invalid tokenId or market doesn’t exist | Verify tokenId from Polymarket API |
error field in the response for specific details.
Getting Token IDs
ThetokenId identifies a specific outcome (e.g., “Yes” or “No”) in a Polymarket market. You can find token IDs through:
- Polymarket’s CLOB API:
GET https://clob.polymarket.com/marketsreturns all markets with theirtokensarray, each containing atoken_idandoutcome. - From positions: If you already hold shares,
getCurrentPositions()returns Polymarket positions with token IDs in the position data.
Notes
- Polymarket’s API accepts different decimal precision for buys and sells. This can result in dust positions if selling a position before expiry. Clean up dust with
redeemPositions()after market expiry. - Negative risk markets: Some markets use an inverted pricing model. The SDK handles this transparently, but be aware that position values may display differently.
- Position data is available via
agent.currentPositionsandagent.getCurrentPositions(). - Polymarket positions include enriched metadata (question, outcome, PNL) when retrieved via
getCurrentPositions().
See Also
- Polymarket Agent Example — Full working prediction market agent
- Positions — Polymarket positions include enriched metadata via
getCurrentPositions() - Error Handling — Polymarket-specific error codes