Polymarket

Trade prediction markets on Polygon.

Market Order

Execute a buy or sell market order.

async marketOrder(request: PolymarketMarketOrderRequest): Promise<PolymarketMarketOrderResponse>

Request Parameters:

  • tokenId (string): Market token ID for the position

  • size (number): Order size (meaning differs by side)

  • side (string): "BUY" or "SELL"

Size Parameter:

  • BUY: size is the USD amount to spend (e.g., 10 = $10 worth of shares)

  • SELL: size is the number of shares to sell (e.g., 10 = 10 shares)

Response:

  • success (boolean): Whether the operation succeeded

  • data.orderInfo (object): Order information (on success)

    • orderId (string): Unique order identifier

    • side (string): "BUY" or "SELL"

    • size (string): Order size

    • priceUsd (string): Price per share in USD

    • totalPriceUsd (string): Total order value in USD

    • txHashes (string[]): Transaction hashes

  • error / error_message (string | null): Error message (on failure)

Example:

Redeem Positions

Redeem settled positions and claim winnings.

Request Parameters (optional):

  • tokenIds (string[], optional): Specific token IDs to redeem. Omit or pass empty array to redeem all redeemable positions.

Response:

  • success (boolean): Whether the operation succeeded

  • data (array): Array of redemption results

    • success (boolean): Whether this redemption succeeded

    • position (object | null): Position details (on success)

      • question (string): Market question text

      • outcome (string): Outcome name (e.g., "Yes", "No")

      • valueUsd (string): Position value in USD

      • pnlUsd (string): Profit/loss in USD

      • pnlPercent (string): Profit/loss percentage

      • isRedeemable (boolean): Whether position can be redeemed

      • Plus additional fields

    • transactionHash (string | null): Transaction hash (on success)

  • error / error_message (string | null): Error message (on failure)

Example:

Common Errors

Errors are returned from Polymarket's API in the error / error_message 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

Note: Additional error messages may be returned by Polymarket's API. Check the error / error_message field in the response for specific details.

Notes

  • Polymarket's API accepts different decimal precision for buys and sells. This can result in dust positions if selling a position before expiry. This can be cleaned up with the redeemPositions() method after expiry.

  • Position data is available via agent.currentPositions and agent.getCurrentPositions().

  • Polymarket positions include enriched metadata (question, outcome, PNL) when retrieved via getCurrentPositions().

Last updated