pub struct PredictWebSocket { /* private fields */ }Expand description
WebSocket client for Predict.fun
Implementations§
Source§impl PredictWebSocket
impl PredictWebSocket
Sourcepub async fn connect(&self) -> Result<PredictWsStream>
pub async fn connect(&self) -> Result<PredictWsStream>
Connect to the WebSocket and return a message stream
The returned stream yields parsed WsMessage items. Heartbeat messages are handled automatically.
Sourcepub async fn subscribe_orderbook(&self, market_id: u64) -> Result<()>
pub async fn subscribe_orderbook(&self, market_id: u64) -> Result<()>
Subscribe to orderbook updates for a market
Sourcepub async fn unsubscribe_orderbook(&self, market_id: u64) -> Result<()>
pub async fn unsubscribe_orderbook(&self, market_id: u64) -> Result<()>
Unsubscribe from orderbook updates for a market
Sourcepub async fn subscribe_asset_price(&self, price_feed_id: &str) -> Result<()>
pub async fn subscribe_asset_price(&self, price_feed_id: &str) -> Result<()>
Subscribe to asset price updates for a price feed
The price_feed_id is typically a Pyth price feed ID (hex string). Common feeds:
- BTC/USD: 0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43
- ETH/USD: 0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace
Sourcepub async fn unsubscribe_asset_price(&self, price_feed_id: &str) -> Result<()>
pub async fn unsubscribe_asset_price(&self, price_feed_id: &str) -> Result<()>
Unsubscribe from asset price updates for a price feed
Sourcepub async fn subscribe_polymarket_chance(&self, market_id: u64) -> Result<()>
pub async fn subscribe_polymarket_chance(&self, market_id: u64) -> Result<()>
Subscribe to Polymarket chance updates for a market
Receives chance/price data from Polymarket for cross-platform comparison.
Sourcepub async fn subscribe_kalshi_chance(&self, market_id: u64) -> Result<()>
pub async fn subscribe_kalshi_chance(&self, market_id: u64) -> Result<()>
Subscribe to Kalshi chance updates for a market
Receives chance/price data from Kalshi for cross-platform comparison.
Sourcepub async fn subscribe_wallet_events(&self, jwt: &str) -> Result<()>
pub async fn subscribe_wallet_events(&self, jwt: &str) -> Result<()>
Subscribe to wallet events (order fills, cancellations, etc.)
Requires a JWT token obtained from PredictClient::authenticate().
Topic: predictWalletEvents/{jwt}
Events include:
- orderAccepted: Order placed in orderbook
- orderTransactionSuccess: Order filled on-chain
- orderCancelled: Order cancelled
- orderTransactionFailed: On-chain transaction failed
Sourcepub async fn unsubscribe_wallet_events(&self, jwt: &str) -> Result<()>
pub async fn unsubscribe_wallet_events(&self, jwt: &str) -> Result<()>
Unsubscribe from wallet events
Sourcepub async fn send_heartbeat(&self, timestamp: u64) -> Result<()>
pub async fn send_heartbeat(&self, timestamp: u64) -> Result<()>
Send a heartbeat response with the given timestamp
Sourcepub async fn reconnect(&self) -> Result<PredictWsStream>
pub async fn reconnect(&self) -> Result<PredictWsStream>
Reconnect to the WebSocket server
Clears the old writer and establishes a fresh connection. Subscriptions must be re-sent after reconnecting.
Sourcepub fn config(&self) -> &WsConnectionConfig
pub fn config(&self) -> &WsConnectionConfig
Get the connection config (for backoff settings)
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Check if connected
Sourcepub fn subscribed_markets(&self) -> Vec<u64>
pub fn subscribed_markets(&self) -> Vec<u64>
Get list of subscribed market IDs
Auto Trait Implementations§
impl !Freeze for PredictWebSocket
impl !RefUnwindSafe for PredictWebSocket
impl Send for PredictWebSocket
impl Sync for PredictWebSocket
impl Unpin for PredictWebSocket
impl !UnwindSafe for PredictWebSocket
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more