Skip to content

WebSocket Overview

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

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

Live order book deltas and trade data. Subscribe by token asset ID or market condition ID; request initial_dump=true with level 3 when you need a one-time full book snapshot before processing deltas.

Event TypeDescription
bookOne-time full order book snapshot on initial dump
price_changePrice level added/removed/updated
last_trade_priceTrade execution
best_bid_askBest prices changed
tick_size_changeTick size updated
new_marketNew market created
market_resolvedMarket outcome determined

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.me/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.me/ws/user?token=your-api-key"
).await?;
// RTDS channel
let mut rtds_ws = RtdsSocket::connect("wss://api.openfish.me/ws/rtds").await?;
rtds_ws.subscribe_assets(&["BTC", "ETH"]).await?;
// Sports channel
let mut sports_ws = SportsSocket::connect("wss://api.openfish.me/ws/sports").await?;
sports_ws.subscribe_games(&["game-123"]).await?;
// Comments channel (gamma server)
let mut comment_ws = CommentSocket::connect("wss://gamma.openfish.me/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