Predict API (Beta)
  1. WebSocket
Predict API (Beta)
  • FAQs
  • Deployed Contracts
  • Guides
    • Understanding the Orderbook
    • [TS] How to authenticate your API requests
    • [PY] How to authenticate your API requests
    • How to create or cancel orders
  • Authorization
    • Get auth message
      GET
    • Get JWT with valid signature
      POST
  • Accounts
    • Get connected account
      GET
    • Get account activity
      GET
    • Set a referral
      POST
  • Orders
    • Get order by hash
      GET
    • Get orders
      GET
    • Get order match events
      GET
    • Create an order
      POST
    • Remove orders from the orderbook
      POST
  • Categories
    • Get categories
      GET
    • Get category by slug
      GET
  • Markets
    • Get markets
    • Get market by ID
    • Get market statistics
    • Get market last sale information
    • Get the orderbook for a market
  • Positions
    • Get positions
  • OAuth
    • Finalize a OAuth connection
    • Get the orders for a OAuth connection
    • Create an order for a OAuth connection
    • Cancel the orders for a OAuth connection
    • Get the positions for a OAuth connection
  • WebSocket
    • General Information
    • Request Format
    • Response Format
    • Subscription Topics
    • Heartbeats
    • Client Example
  1. WebSocket

Request Format

Request Format#

Message Protocol#

The API uses a JSON-based protocol with specific message structures for client requests and server responses.

Base Message Structure (Client to Server)#

All client requests must follow this format:
{
  "method": "subscribe" | "unsubscribe" | "heartbeat",
  "requestId": number,
  "params": string[],
  "data": any
}
FieldTypeRequiredDescription
methodstringYesThe action to perform: subscribe, unsubscribe, or heartbeat.
requestIdnumberConditionalA unique, non-negative integer to track request responses. Required for subscribe and unsubscribe.
paramsstring[]ConditionalAn array containing the topic string(s). Required for subscribe and unsubscribe.
dataanyConditionalPayload for the method. Required for heartbeat (must be the timestamp received from server).

Heartbeat Mechanism#

To maintain an active connection, the server implements a heartbeat mechanism.
1.
Server Probe: Every 15 seconds, the server sends:
{ "type": "M", "topic": "heartbeat", "data": 1736696400000 }
2.
Client Response: The client must respond within the next 15 seconds with:
{ "method": "heartbeat", "data": 1736696400000 }
Note: The data value must match the timestamp received from the server.
Failure to respond to the heartbeat will result in the server terminating the connection.

Subscription Topics#

Topics are formatted as topicName/parameter.

1. Predict Orderbook#

Live updates for a specific market's orderbook.
Topic: predictOrderbook/{marketId}
Payload: Orderbook data (JSON).

2. Polymarket Chance#

Percentage chance updates for a market from Polymarket.
Topic: polymarketChance/{marketId}
Payload:
{
  "percentage": number,
  "timestamp": number
}

3. Kalshi Chance#

Percentage chance updates for a market from Kalshi.
Topic: kalshiChance/{marketId}
Payload:
{
  "percentage": number,
  "timestamp": number
}

4. Asset Price Update#

Real-time price updates for a specific price feed.
Topic: assetPriceUpdate/{priceFeedId}
Payload:
{
  "price": number,
  "publishTime": number,
  "timestamp": number
}

5. Predict Wallet Events (Authenticated)#

Live events specific to a user's wallet. Requires a valid JWT.
Topic: predictWalletEvents/{jwt}
Payload: One of several wallet event types.
Event Types:
orderAccepted: Order successfully placed in orderbook.
orderNotAccepted: Order rejected (e.g., duplicate).
orderExpired: Order reached its end time.
orderCancelled: User cancelled the order.
orderTransactionSubmitted: Order matched, transaction sent to blockchain.
orderTransactionSuccess: On-chain transaction succeeded.
orderTransactionFailed: On-chain transaction failed.

Error Codes#

CodeDescription
invalid_jsonThe message sent by the client is not valid JSON.
invalid_topicThe requested topic is malformed or unknown.
invalid_credentials(Wallet events) The provided JWT is invalid or expired.
internal_server_errorAn unexpected error occurred on the server.
unsupported_contractThe requested market/contract is not supported.
Modified at 2026-01-12 15:28:03
Previous
General Information
Next
Response Format
Built with