Polymarket
Trade prediction markets on Polygon.
Market Order
Execute a buy or sell market order.
async marketOrder(request: PolymarketMarketOrderRequest): Promise<PolymarketMarketOrderResponse>def market_order(request: PolymarketMarketOrderRequest | dict) -> PolymarketMarketOrderResponseRequest Parameters:
tokenId(string): Market token ID for the positionsize(number): Order size (meaning differs by side)side(string): "BUY" or "SELL"
Size Parameter:
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)
Response:
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/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 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 redeemedPlus 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:
"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.currentPositionsandagent.getCurrentPositions().Polymarket positions include enriched metadata (question, outcome, PNL) when retrieved via
getCurrentPositions().
Last updated