pub struct Stream {
pub client: Client,
}Expand description
Manages WebSocket streaming connections to the Limitless Exchange.
Connects to wss://ws.limitless.exchange/socket.io/?EIO=4&transport=websocket
and handles the Socket.IO protocol (Engine.IO v4 + Socket.IO) over the
raw WebSocket transport.
§Event Reference
| Client → Server (emit) | Auth | Description |
|---|---|---|
subscribe_market_prices | No | AMM prices + CLOB orderbook |
subscribe_positions | Yes | Portfolio position updates |
subscribe_order_events | Yes | OME + settlement lifecycle |
subscribe_market_lifecycle | No | Market creation / resolution |
| Server → Client (on) | Auth | Description |
|---|---|---|
newPriceData | No | AMM price update |
orderbookUpdate | No | CLOB orderbook snapshot |
positions | Yes | Position balance change |
orderEvent | Yes | OME state or settlement result |
marketCreated | No | New market funded and visible |
marketResolved | No | Market resolved with winning outcome |
system | — | System notifications |
authenticated | Yes | Auth confirmation |
exception | — | Error notifications |
Fields§
§client: ClientImplementations§
Source§impl Stream
impl Stream
Sourcepub async fn ws_ping(&self) -> Result<(), LimitlessError>
pub async fn ws_ping(&self) -> Result<(), LimitlessError>
Tests connectivity by performing the full Socket.IO handshake.
Connects, reads the Engine.IO open packet, sends namespace connect, and verifies the server acknowledges it.
Sourcepub async fn ws_subscribe<F>(&self, handler: F) -> Result<(), LimitlessError>
pub async fn ws_subscribe<F>(&self, handler: F) -> Result<(), LimitlessError>
Subscribe to a public data stream with an event handler callback.
The handler receives a Value that is an array [event_name, payload]
for Socket.IO events, or the raw parsed JSON for other messages.
§Example
use limitless::prelude::*;
#[tokio::main]
async fn main() {
let stream: Stream = Limitless::new(None, None);
stream
.ws_subscribe(|event| {
println!("Received: {:?}", event);
Ok(())
})
.await
.unwrap();
}Sourcepub async fn ws_subscribe_with_commands<F>(
&self,
cmd_receiver: UnboundedReceiver<String>,
handler: F,
) -> Result<(), LimitlessError>
pub async fn ws_subscribe_with_commands<F>( &self, cmd_receiver: UnboundedReceiver<String>, handler: F, ) -> Result<(), LimitlessError>
Subscribe to a stream with dynamic command support.
Allows emitting subscription commands (subscribe/unsubscribe) after
the connection is established. Commands should be complete Socket.IO
frames (e.g., 42/markets,["subscribe_market_prices",{...}]).
Use frame_socketio_event to build properly framed commands.
Sourcepub async fn ws_subscribe_market<F>(
&self,
market_slug: &str,
handler: F,
) -> Result<(), LimitlessError>
pub async fn ws_subscribe_market<F>( &self, market_slug: &str, handler: F, ) -> Result<(), LimitlessError>
Subscribe to market updates for a specific slug.
Handles the full lifecycle: connect, handshake, subscribe, and
event dispatch. The handler receives [event_name, payload] arrays.
§Example
use limitless::prelude::*;
#[tokio::main]
async fn main() {
let ws: Stream = Limitless::new(None, None);
ws.ws_subscribe_market("btc-above-100k", |event_name, payload| {
println!("{event_name}: {payload}");
Ok(())
}).await.unwrap();
}Sourcepub async fn ws_subscribe_events<F>(
&self,
handler: F,
) -> Result<(), LimitlessError>
pub async fn ws_subscribe_events<F>( &self, handler: F, ) -> Result<(), LimitlessError>
Subscribe to the WebSocket event stream and receive typed WsEventKind events.
Connects, performs the Socket.IO handshake, then enters an event
loop that parses every incoming server event through
deserialize_event before passing the resulting WsEventKind
to handler.
§Example
use limitless::prelude::*;
#[tokio::main]
async fn main() {
let ws: Stream = Limitless::new(None, None);
ws.ws_subscribe_events(|event| {
match event {
WsEventKind::NewPriceData(p) => println!("AMM prices for {}", p.market_address),
WsEventKind::TradeEvent(t) => println!("Trade: {} @ {}", t.size, t.price),
WsEventKind::Unknown(payload) => println!("Unknown: {payload:?}"),
other => println!("Event: {other:?}"),
}
Ok(())
}).await.unwrap();
}