Struct Stream

Source
pub struct Stream {
    pub client: Client,
}

Fields§

§client: Client

Implementations§

Source§

impl Stream

Source

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,

  • private is set to true if the request is for a private endpoint or a BybitError if an error occurs.
Source

pub async fn ws_priv_subscribe<'b, F>( &self, req: Subscription<'_>, handler: F, ) -> Result<(), BybitError>
where F: FnMut(WebsocketEvents) -> Result<(), BybitError> + 'static + Send,

Source

pub async fn ws_subscribe<'b, F>( &self, req: Subscription<'_>, category: Category, handler: F, ) -> Result<(), BybitError>
where F: FnMut(WebsocketEvents) -> Result<(), BybitError> + 'static + Send,

Source

pub fn build_subscription(action: Subscription<'_>) -> String

Source

pub fn build_trade_subscription( orders: RequestType<'_>, recv_window: Option<u64>, ) -> String

Source

pub async fn ws_orderbook( &self, subs: Vec<(i32, &str)>, category: Category, sender: UnboundedSender<OrderBookUpdate>, ) -> Result<(), BybitError>

Subscribes to the specified order book updates and handles the order book events

§Arguments
  • subs - A vector of tuples containing the order book ID and symbol
  • category - The category of the order book
§Example
use your_crate_name::Category;
let subs = vec![(1, "BTC"), (2, "ETH")];
Source

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 subscriptions
  • category - The category of the trades
§Example
use your_crate_name::Category;
let subs = vec!["BTCUSD", "ETHUSD"];
let category = Category::Linear;
ws_trades(subs, category);
Source

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);
Source

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);
Source

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

pub async fn ws_liquidations( &self, subs: Vec<&str>, category: Category, sender: UnboundedSender<LiquidationData>, ) -> Result<(), BybitError>

Source

pub async fn ws_klines( &self, subs: Vec<(&str, &str)>, category: Category, sender: UnboundedSender<WsKline>, ) -> Result<(), BybitError>

Source

pub async fn ws_position( &self, cat: Option<Category>, sender: UnboundedSender<PositionData>, ) -> Result<(), BybitError>

Source

pub async fn ws_executions( &self, cat: Option<Category>, sender: UnboundedSender<ExecutionData>, ) -> Result<(), BybitError>

Source

pub async fn ws_fast_exec( &self, sender: UnboundedSender<FastExecData>, ) -> Result<(), BybitError>

Source

pub async fn ws_orders( &self, cat: Option<Category>, sender: UnboundedSender<OrderData>, ) -> Result<(), BybitError>

Source

pub async fn ws_wallet( &self, sender: UnboundedSender<WalletData>, ) -> Result<(), BybitError>

Source

pub async fn ws_trade_stream<'a, F>( &self, req: UnboundedReceiver<RequestType<'a>>, handler: F, ) -> Result<(), BybitError>
where F: FnMut(WebsocketEvents) -> Result<(), BybitError> + 'static + Send, 'a: 'static,

Source

pub async fn event_loop<'a, H>( stream: WebSocketStream<MaybeTlsStream<TcpStream>>, handler: H, order_sender: Option<UnboundedReceiver<RequestType<'_>>>, ) -> Result<(), BybitError>

Trait Implementations§

Source§

impl Bybit for Stream

Source§

fn new(api_key: Option<String>, secret_key: Option<String>) -> Stream

Creates a new instance of the module with default configuration. Read more
Source§

fn new_with_config( config: &Config, api_key: Option<String>, secret_key: Option<String>, ) -> Stream

Creates a new instance of the module with custom configuration. Read more
Source§

impl Clone for Stream

Source§

fn clone(&self) -> Stream

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Stream

§

impl !RefUnwindSafe for Stream

§

impl Send for Stream

§

impl Sync for Stream

§

impl Unpin for Stream

§

impl !UnwindSafe for Stream

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more