pub struct Stream {
pub client: Client,
}Fields§
§client: ClientImplementations§
Source§impl Stream
impl Stream
Sourcepub async fn ws_ping(&self, private: bool) -> Result<(), BybitError>
pub async fn ws_ping(&self, private: bool) -> Result<(), BybitError>
Tests for connectivity by sending a ping request to the Bybit server.
§Returns
Returns a Result containing a String with the response message if successful,
privateis set totrueif the request is for a private endpoint or aBybitErrorif an error occurs.
pub async fn ws_priv_subscribe<'b, F>( &self, req: Subscription<'_>, handler: F, ) -> Result<(), BybitError>
pub async fn ws_subscribe<'b, F>( &self, req: Subscription<'_>, category: Category, handler: F, ) -> Result<(), BybitError>
pub fn build_subscription(action: Subscription<'_>) -> String
pub fn build_trade_subscription( orders: RequestType<'_>, recv_window: Option<u64>, ) -> String
Sourcepub async fn ws_orderbook(
&self,
subs: Vec<(i32, &str)>,
category: Category,
sender: UnboundedSender<OrderBookUpdate>,
) -> Result<(), BybitError>
pub async fn ws_orderbook( &self, subs: Vec<(i32, &str)>, category: Category, sender: UnboundedSender<OrderBookUpdate>, ) -> Result<(), BybitError>
Sourcepub async fn ws_rpi_orderbook(
&self,
subs: Vec<&str>,
category: Category,
sender: UnboundedSender<RPIOrderbookUpdate>,
) -> Result<(), BybitError>
pub async fn ws_rpi_orderbook( &self, subs: Vec<&str>, category: Category, sender: UnboundedSender<RPIOrderbookUpdate>, ) -> Result<(), BybitError>
Subscribes to RPI (Real-time Price Improvement) orderbook stream.
RPI orderbooks show both regular orders and RPI orders, which can provide price improvement for takers.
Push frequency: 100ms for Spot, Perpetual & Futures (level 50 data).
Topic format: orderbook.rpi.{symbol}
§Arguments
subs- Vector of symbol strings to subscribe to (e.g.,vec!["BTCUSDT", "ETHUSDT"])category- Product category (Linear, Inverse, or Spot)sender- Channel sender for RPI orderbook updates
§Returns
Returns Ok(()) if subscription succeeds, otherwise returns a BybitError.
§Example
use rs_bybit::prelude::*;
use tokio::sync::mpsc;
let client = Client::new("api_key", "api_secret", None, None)?;
let stream = Stream { client };
let (tx, mut rx) = mpsc::unbounded_channel();
stream.ws_rpi_orderbook(vec!["BTCUSDT"], Category::Linear, tx).await?;
while let Some(update) = rx.recv().await {
println!("RPI Orderbook update: {:?}", update);
}Sourcepub async fn ws_trades(
&self,
subs: Vec<&str>,
category: Category,
sender: UnboundedSender<WsTrade>,
) -> Result<(), BybitError>
pub async fn ws_trades( &self, subs: Vec<&str>, category: Category, sender: UnboundedSender<WsTrade>, ) -> Result<(), BybitError>
This function subscribes to the specified trades and handles the trade events.
§Arguments
subs- A vector of trade subscriptionscategory- The category of the trades
§Example
use your_crate_name::Category;
let subs = vec!["BTCUSD", "ETHUSD"];
let category = Category::Linear;
ws_trades(subs, category);Sourcepub async fn ws_tickers(
&self,
subs: Vec<&str>,
category: Category,
sender: UnboundedSender<Ticker>,
) -> Result<(), BybitError>
pub async fn ws_tickers( &self, subs: Vec<&str>, category: Category, sender: UnboundedSender<Ticker>, ) -> Result<(), BybitError>
Subscribes to ticker events for the specified symbols and category.
§Arguments
subs- A vector of symbols for which ticker events are subscribed.category- The category for which ticker events are subscribed.
§Examples
use your_crate_name::Category;
let subs = vec!["BTCUSD", "ETHUSD"];
let category = Category::Linear;
let sender = UnboundedSender<Ticker>;
ws_tickers(subs, category, sender);Sourcepub async fn ws_timed_tickers(
&self,
subs: Vec<&str>,
category: Category,
sender: UnboundedSender<Timed<Ticker>>,
) -> Result<(), BybitError>
pub async fn ws_timed_tickers( &self, subs: Vec<&str>, category: Category, sender: UnboundedSender<Timed<Ticker>>, ) -> Result<(), BybitError>
Subscribes to ticker events with timestamp for the specified symbols and category.
§Arguments
subs- A vector of symbols for which ticker events are subscribed.category- The category for which ticker events are subscribed.
§Examples
use your_crate_name::Category;
let subs = vec!["BTCUSD", "ETHUSD"];
let category = Category::Linear;
let sender = UnboundedSender<Ticker>;
ws_timed_tickers(subs, category, sender);Sourcepub async fn ws_timed_linear_tickers(
self: Arc<Self>,
subs: Vec<String>,
sender: UnboundedSender<Timed<LinearTickerDataSnapshot>>,
) -> Result<(), BybitError>
pub async fn ws_timed_linear_tickers( self: Arc<Self>, subs: Vec<String>, sender: UnboundedSender<Timed<LinearTickerDataSnapshot>>, ) -> Result<(), BybitError>
A high abstraction level stream of timed linear snapshots, which you can
subscribe to using the receiver of the sender. Internally this method
consumes the linear ticker API but instead of returning a stream of deltas
we update the initial snapshot with all subsequent streams, and thanks
to internally using .scan we you get Timed<LinearTickerDataSnapshot>,
instead of Timed<LinearTickerDataDelta>.
If you provide multiple symbols, the LinearTickerDataSnapshot values
will be interleaved.
§Usage
use bybit::prelude::*;
use tokio::sync::mpsc;
use std::sync::Arc;
#[tokio::main]
async fn main() {
let ws: Arc<Stream> = Arc::new(Bybit::new(None, None));
let (tx, mut rx) = mpsc::unbounded_channel::<Timed<LinearTickerDataSnapshot>>();
tokio::spawn(async move {
ws.ws_timed_linear_tickers(vec!["BTCUSDT".to_owned(), "ETHUSDT".to_owned()], tx)
.await
.unwrap();
});
while let Some(ticker_snapshot) = rx.recv().await {
println!("{:#?}", ticker_snapshot);
}
}pub async fn ws_liquidations( &self, subs: Vec<&str>, category: Category, sender: UnboundedSender<LiquidationData>, ) -> Result<(), BybitError>
pub async fn ws_klines( &self, subs: Vec<(&str, &str)>, category: Category, sender: UnboundedSender<WsKline>, ) -> Result<(), BybitError>
pub async fn ws_position( &self, cat: Option<Category>, sender: UnboundedSender<PositionData>, ) -> Result<(), BybitError>
pub async fn ws_executions( &self, cat: Option<Category>, sender: UnboundedSender<ExecutionData>, ) -> Result<(), BybitError>
pub async fn ws_fast_exec( &self, sender: UnboundedSender<FastExecData>, ) -> Result<(), BybitError>
pub async fn ws_orders( &self, cat: Option<Category>, sender: UnboundedSender<OrderData>, ) -> Result<(), BybitError>
pub async fn ws_wallet( &self, sender: UnboundedSender<WalletData>, ) -> Result<(), BybitError>
Sourcepub async fn ws_system_status(
&self,
sender: UnboundedSender<SystemStatusUpdate>,
) -> Result<(), BybitError>
pub async fn ws_system_status( &self, sender: UnboundedSender<SystemStatusUpdate>, ) -> Result<(), BybitError>
Subscribes to system status updates via WebSocket.
System status updates provide real-time information about platform maintenance or service incidents. This is useful for monitoring exchange health and planning trading activities around maintenance windows.
§Arguments
sender- Channel sender for system status updates
§Returns
Returns Ok(()) if subscription succeeds, otherwise returns a BybitError.
§Example
use rs_bybit::prelude::*;
use tokio::sync::mpsc;
let client = Client::new("api_key", "api_secret", None, None)?;
let stream = Stream { client };
let (tx, mut rx) = mpsc::unbounded_channel();
stream.ws_system_status(tx).await?;
while let Some(update) = rx.recv().await {
println!("System status update: {:?}", update);
}