Skip to main content

Module ws

Module ws 

Source
Expand description

Predict.fun WebSocket client for real-time market data (BNB Chain).

Connects to wss://ws.predict.fun/ws and provides:

  • Orderbook snapshots (predictOrderbook/{marketId})
  • Asset price updates (assetPriceUpdate/{feedId})
  • Cross-venue chance data (polymarketChance/{marketId}, kalshiChance/{marketId})
  • Wallet event notifications (predictWalletEvents/{jwt})

§Protocol

Custom JSON RPC over WebSocket (not graphql-ws):

→ {"requestId": 0, "method": "subscribe", "params": ["predictOrderbook/123"]}
← {"type": "R", "requestId": 0, "success": true}
← {"type": "M", "topic": "predictOrderbook/123", "data": {...}}

§Example

use predict_fun_sdk::ws::{PredictWsClient, PredictWsMessage, Topic};

let (client, mut rx) = PredictWsClient::connect_mainnet().await?;

client.subscribe(Topic::Orderbook { market_id: 45532 }).await?;
client.subscribe(Topic::AssetPrice { feed_id: 1 }).await?;

while let Some(msg) = rx.recv().await {
    match msg {
        PredictWsMessage::Orderbook(ob) => {
            println!("OB market={}: {} bids, {} asks",
                ob.market_id, ob.bids.len(), ob.asks.len());
        }
        PredictWsMessage::AssetPrice(p) => {
            println!("Price feed {}: ${:.2}", p.feed_id, p.price);
        }
        _ => {}
    }
}

Modules§

feeds
Known asset price feed IDs for Topic::AssetPrice.

Structs§

AssetPriceUpdate
Oracle price update.
CrossVenueChance
Cross-venue chance data (Polymarket or Kalshi).
LastOrderSettled
Last settled order info.
OrderbookSnapshot
Full orderbook snapshot pushed on every change.
PredictWsClient
Handle for interacting with the WebSocket connection.
PredictWsConfig
WebSocket connection config.
WalletEvent
Wallet event notification (fills, settlements).

Enums§

CrossVenueSource
PredictWsMessage
Parsed WebSocket message.
Topic
Subscription topic for the predict.fun WebSocket feed.

Constants§

PREDICT_GQL_MAINNET
GraphQL endpoints (for reference / future use).
PREDICT_GQL_TESTNET
PREDICT_WS_MAINNET
WebSocket endpoints.
PREDICT_WS_TESTNET

Type Aliases§

Level
Orderbook level: (price, size).