Skip to content

WebSocket Overview

Openfish exposes five WebSocket endpoints spread across two servers. These connections push real-time updates for order books, trades, price feeds, live sports scores, and community discussion.

ChannelEndpointServerAuth
Marketwss://api.openfish.fun/ws/marketCLOB (3002)No
Userwss://api.openfish.fun/ws/userCLOB (3002)Yes
RTDSwss://api.openfish.fun/ws/rtdsCLOB (3002)No
Sportswss://api.openfish.fun/ws/sportsCLOB (3002)No
Commentswss://gamma.openfish.fun/ws/commentsGammaNo

Live order book and trade data. Subscribe by token asset ID or market condition ID.

Event TypeDescriptionRequires Custom Feature
bookFull order book snapshotNo
price_changePrice level added/removed/updatedNo
last_trade_priceTrade executionNo
best_bid_askBest prices changedYes
tick_size_changeTick size updatedNo
new_marketNew market createdYes
market_resolvedMarket outcome determinedYes

Private stream of order and trade updates scoped to a specific API key.

Event TypeDescription
orderOrder placement, partial fill, cancellation
tradeTrade lifecycle (MATCHED, MINED, CONFIRMED, FAILED)

Streaming price feeds for crypto assets. Subscribe by asset symbol.

Event TypeDescription
subscribedSubscription acknowledgment
Price tickAsset price update

Live game scores and status updates. Subscribe by game ID.

Event TypeDescription
subscribedSubscription acknowledgment
Score updateGame score, period, status

Real-time comment feed for events and markets. Subscribe by entity type and ID.

Event TypeDescription
subscribedSubscription acknowledgment
CommentNew comment posted

All five WebSocket endpoints share the same lifecycle pattern:

  1. Connect — Open a WebSocket connection to the endpoint.
  2. Subscribe — Send a JSON subscription message with your channel and filter criteria.
  3. Receive — The server pushes events that match your subscription.
  4. Heartbeat — Reply to periodic keep-alive messages to hold the connection open.
  5. Disconnect — Close the connection when finished.

Every Openfish WebSocket endpoint uses a text-based PING/PONG protocol with a 10-second interval. The server sends a text message "PING" and expects the client to reply with a text message "PONG".

Note: These are text messages, not WebSocket-level ping/pong frames. Your client must explicitly send "PONG" when it receives a "PING" text message.

If no PONG arrives within the timeout window, the server terminates the connection.

use openfish_client_sdk::ws::{MarketSocket, UserSocket, RtdsSocket, SportsSocket, CommentSocket};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Market channel -- no auth
let mut market_ws = MarketSocket::connect("wss://api.openfish.fun/ws/market").await?;
market_ws.subscribe(&["71321045679252212594626385532706912750332728571942532289631379312455583992563"]).await?;
// User channel -- requires API key as query param
let mut user_ws = UserSocket::connect(
"wss://api.openfish.fun/ws/user?token=your-api-key"
).await?;
// RTDS channel
let mut rtds_ws = RtdsSocket::connect("wss://api.openfish.fun/ws/rtds").await?;
rtds_ws.subscribe_assets(&["BTC", "ETH"]).await?;
// Sports channel
let mut sports_ws = SportsSocket::connect("wss://api.openfish.fun/ws/sports").await?;
sports_ws.subscribe_games(&["game-123"]).await?;
// Comments channel (gamma server)
let mut comment_ws = CommentSocket::connect("wss://gamma.openfish.fun/ws/comments").await?;
comment_ws.subscribe("market", "abc123").await?;
// Process events from any channel...
while let Some(event) = market_ws.next().await {
println!("{:?}", event);
}
Ok(())
}
SymptomCauseFix
Connection closes immediatelyNo subscription message sent after connectingSend a valid subscription message right away
Connection drops after ~10 secondsMissing heartbeat responsesEnsure PONG frames are sent
No messages receivedInvalid token IDs or inactive marketsVerify IDs and check market status
{"error": "invalid token"} on user WSInvalid API keyCheck your API key UUID