Skip to main content

Module websocket

Module websocket 

Source
Expand description

WebSocket module for Predict.fun real-time data

This module provides WebSocket connectivity for receiving real-time orderbook updates and other market data from Predict.fun.

§Example

use predict_sdk::websocket::{PredictWebSocket, WsMessage};

let ws = PredictWebSocket::new("wss://ws.predict.fun/ws".to_string());
let mut stream = ws.connect().await?;

// Subscribe to a market's orderbook
ws.subscribe_orderbook(5614).await?;

// Process incoming messages
while let Some(msg) = stream.next().await {
    match msg? {
        WsMessage::PushMessage(push) if push.is_orderbook() => {
            let orderbook = parse_orderbook_update(&push)?;
            println!("Orderbook update: {:?}", orderbook);
        }
        _ => {}
    }
}

Structs§

AssetPriceData
Asset price update data from assetPriceUpdate topic
OrderbookData
Orderbook update data from predictOrderbook topic
PredictWebSocket
WebSocket client for Predict.fun
PredictWsStream
WebSocket message stream that yields parsed messages
PriceLevel
A price level in the orderbook
PushMessage
Server-initiated push message
RawWsMessage
Raw WebSocket message from server (before parsing)
RequestResponse
Response to a client request
WsError
WebSocket error from server
WsRequest
WebSocket request sent by the client

Enums§

WsMessage
Parsed WebSocket message

Functions§

parse_asset_price_update
Parse asset price data from a push message
parse_orderbook_update
Parse orderbook data from a push message
parse_wallet_event
Parse wallet event data from a push message