Sports Channel
This WebSocket streams score changes, period transitions, and game status updates for active matches. Subscribe by game ID to follow specific contests. No authentication is needed.
Endpoint
Section titled “Endpoint”wss://api.openfish.fun/ws/sportsProtocol
Section titled “Protocol”Subscribe
Section titled “Subscribe”After opening the connection, send a JSON message with the game IDs you want to track:
{ "channel": "live-score", "games": ["game-123", "game-456"]}| Field | Type | Description |
|---|---|---|
channel | string | Must be "live-score" for score subscriptions |
games | string[] | List of game ID strings to subscribe to |
Subscription Acknowledgment
Section titled “Subscription Acknowledgment”The server confirms which games you are now following:
{ "type": "subscribed", "games": ["game-123", "game-456"]}Adding More Games
Section titled “Adding More Games”Additional subscription messages extend your existing set rather than replacing it:
{ "channel": "live-score", "games": ["game-789"]}Response:
{ "type": "subscribed", "games": ["game-123", "game-456", "game-789"]}Score Update Format
Section titled “Score Update Format”Whenever the state of a tracked game changes, the server delivers an update:
{ "gameId": "game-123", "homeScore": 2, "awayScore": 1, "clock": "65:00", "period": "2H", "status": "LIVE", "timestamp": 1700000000}| Field | Type | Description |
|---|---|---|
gameId | string | Unique game identifier |
homeScore | number | Current home team score |
awayScore | number | Current away team score |
clock | string | Game clock or elapsed time |
period | string | Current period (e.g., 1H, 2H, Q3, FT) |
status | string | Game status (see table below) |
timestamp | number | Unix timestamp in seconds |
Game Statuses
Section titled “Game Statuses”| Status | Description |
|---|---|
PRE | Game has not started yet |
LIVE | Game currently in progress |
HALF | Halftime or intermission break |
FINAL | Game completed |
Period Values
Section titled “Period Values”| Period | Description |
|---|---|
1H, 2H | First half, second half |
Q1, Q2, Q3, Q4 | Quarters (basketball, American football) |
HT | Halftime |
FT | Full time (match ended in regulation) |
OT | Overtime |
Heartbeat
Section titled “Heartbeat”The server sends WebSocket PING frames every 10 seconds. Your client must respond with PONG to keep the connection alive.
Rust SDK Example
Section titled “Rust SDK Example”use openfish_client_sdk::ws::SportsSocket;use futures_util::StreamExt;
#[tokio::main]async fn main() -> anyhow::Result<()> { let mut ws = SportsSocket::connect("wss://api.openfish.fun/ws/sports").await?;
// Subscribe to specific games ws.subscribe_games(&["game-123", "game-456"]).await?;
while let Some(update) = ws.next().await { println!( "[{}] {} vs {} : {}-{} ({} {})", update.game_id, "Home", "Away", update.home_score, update.away_score, update.period, update.status, );
if update.status == "FINAL" { println!("Game {} has ended.", update.game_id); } }
Ok(())}Integration with Market Data
Section titled “Integration with Market Data”Score updates from this channel pair naturally with prediction market data, enabling automated strategies that react to in-game developments:
- Use the Gamma API to find sports-related events and extract game IDs.
- Subscribe to the sports WebSocket for live score updates.
- Subscribe to the market WebSocket for the corresponding token’s order book.
- React to score changes by placing or adjusting orders.
use openfish_client_sdk::ws::{SportsSocket, MarketSocket};use futures_util::StreamExt;
#[tokio::main]async fn main() -> anyhow::Result<()> { let mut sports = SportsSocket::connect("wss://api.openfish.fun/ws/sports").await?; let mut market = MarketSocket::connect( "wss://api.openfish.fun/ws/market?asset_id=71321045..." ).await?;
sports.subscribe_games(&["game-123"]).await?;
tokio::select! { Some(score) = sports.next() => { println!("Score update: {}-{}", score.home_score, score.away_score); // Adjust trading strategy based on score... } Some(book) = market.next() => { println!("Book update received"); // Update local order book... } }
Ok(())}Next Steps
Section titled “Next Steps”- RTDS — Real-time crypto price feeds.
- Market Channel — Order book events.
- WebSocket Overview — All available channels.