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_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);
}
}