BitgetWs

Struct BitgetWs 

Source
pub struct BitgetWs { /* private fields */ }
Expand description

Bitget WebSocket client.

Provides real-time data streaming for Bitget exchange.

Implementations§

Source§

impl BitgetWs

Source

pub fn new(url: String) -> Self

Creates a new Bitget WebSocket client.

§Arguments
  • url - WebSocket server URL
Source

pub async fn connect(&self) -> Result<()>

Connects to the WebSocket server.

Source

pub async fn disconnect(&self) -> Result<()>

Disconnects from the WebSocket server.

Source

pub async fn state(&self) -> WsConnectionState

Returns the current connection state.

Source

pub async fn is_connected(&self) -> bool

Checks if the WebSocket is connected.

Source

pub async fn receive(&self) -> Option<Value>

Receives the next message from the WebSocket.

Source

pub async fn subscribe_ticker(&self, symbol: &str) -> Result<()>

Subscribes to a ticker stream.

§Arguments
  • symbol - Trading pair symbol (e.g., “BTCUSDT”)
Source

pub async fn subscribe_orderbook(&self, symbol: &str, depth: u32) -> Result<()>

Subscribes to an orderbook stream.

§Arguments
  • symbol - Trading pair symbol (e.g., “BTCUSDT”)
  • depth - Orderbook depth (5, 15, or default)
Source

pub async fn subscribe_trades(&self, symbol: &str) -> Result<()>

Subscribes to a trades stream.

§Arguments
  • symbol - Trading pair symbol (e.g., “BTCUSDT”)
Source

pub async fn subscribe_kline(&self, symbol: &str, interval: &str) -> Result<()>

Subscribes to a kline/candlestick stream.

§Arguments
  • symbol - Trading pair symbol (e.g., “BTCUSDT”)
  • interval - Kline interval (e.g., “1m”, “5m”, “1H”)
Source

pub async fn unsubscribe(&self, stream_name: String) -> Result<()>

Unsubscribes from a stream.

§Arguments
  • stream_name - Stream identifier to unsubscribe from
Source

pub async fn subscriptions(&self) -> Vec<String>

Returns the list of active subscriptions.

Source

pub async fn watch_ticker( &self, symbol: &str, market: Option<Market>, ) -> Result<MessageStream<Ticker>>

Watches ticker updates for a symbol.

Returns a stream of Ticker updates for the specified symbol.

§Arguments
  • symbol - Trading pair symbol (e.g., “BTCUSDT”)
  • market - Optional market information for symbol resolution
§Returns

A MessageStream<Ticker> that yields ticker updates.

§Example
use ccxt_exchanges::bitget::ws::BitgetWs;
use futures::StreamExt;

let ws = BitgetWs::new("wss://ws.bitget.com/v2/ws/public".to_string());
ws.connect().await?;
let mut stream = ws.watch_ticker("BTCUSDT", None).await?;
while let Some(result) = stream.next().await {
    match result {
        Ok(ticker) => println!("Ticker: {:?}", ticker.last),
        Err(e) => eprintln!("Error: {}", e),
    }
}
Source

pub async fn watch_order_book( &self, symbol: &str, limit: Option<u32>, ) -> Result<MessageStream<OrderBook>>

Watches order book updates for a symbol.

Returns a stream of OrderBook updates for the specified symbol.

§Arguments
  • symbol - Trading pair symbol (e.g., “BTCUSDT”)
  • limit - Optional depth limit (5, 15, or full depth)
§Returns

A MessageStream<OrderBook> that yields order book updates.

§Example
use ccxt_exchanges::bitget::ws::BitgetWs;
use futures::StreamExt;

let ws = BitgetWs::new("wss://ws.bitget.com/v2/ws/public".to_string());
ws.connect().await?;
let mut stream = ws.watch_order_book("BTCUSDT", Some(5)).await?;
while let Some(result) = stream.next().await {
    match result {
        Ok(orderbook) => println!("Best bid: {:?}", orderbook.bids.first()),
        Err(e) => eprintln!("Error: {}", e),
    }
}
Source

pub async fn watch_trades( &self, symbol: &str, market: Option<Market>, ) -> Result<MessageStream<Vec<Trade>>>

Watches trade updates for a symbol.

Returns a stream of Trade updates for the specified symbol.

§Arguments
  • symbol - Trading pair symbol (e.g., “BTCUSDT”)
  • market - Optional market information for symbol resolution
§Returns

A MessageStream<Vec<Trade>> that yields trade updates.

§Example
use ccxt_exchanges::bitget::ws::BitgetWs;
use futures::StreamExt;

let ws = BitgetWs::new("wss://ws.bitget.com/v2/ws/public".to_string());
ws.connect().await?;
let mut stream = ws.watch_trades("BTCUSDT", None).await?;
while let Some(result) = stream.next().await {
    match result {
        Ok(trades) => {
            for trade in trades {
                println!("Trade: {:?} @ {:?}", trade.amount, trade.price);
            }
        }
        Err(e) => eprintln!("Error: {}", e),
    }
}

Auto Trait Implementations§

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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