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§
- Asset
Price Update - Oracle price update.
- Cross
Venue Chance - Cross-venue chance data (Polymarket or Kalshi).
- Last
Order Settled - Last settled order info.
- Orderbook
Snapshot - Full orderbook snapshot pushed on every change.
- Predict
WsClient - Handle for interacting with the WebSocket connection.
- Predict
WsConfig - WebSocket connection config.
- Wallet
Event - Wallet event notification (fills, settlements).
Enums§
- Cross
Venue Source - Predict
WsMessage - 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).