pub struct BitgetWs { /* private fields */ }Expand description
Bitget WebSocket client.
Provides real-time data streaming for Bitget exchange.
Implementations§
Source§impl BitgetWs
impl BitgetWs
Sourcepub async fn disconnect(&self) -> Result<()>
pub async fn disconnect(&self) -> Result<()>
Disconnects from the WebSocket server.
Sourcepub fn state(&self) -> WsConnectionState
pub fn state(&self) -> WsConnectionState
Returns the current connection state.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Checks if the WebSocket is connected.
Sourcepub async fn subscribe_ticker(&self, symbol: &str) -> Result<()>
pub async fn subscribe_ticker(&self, symbol: &str) -> Result<()>
Sourcepub async fn subscribe_orderbook(&self, symbol: &str, depth: u32) -> Result<()>
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)
Sourcepub async fn subscribe_trades(&self, symbol: &str) -> Result<()>
pub async fn subscribe_trades(&self, symbol: &str) -> Result<()>
Sourcepub async fn subscribe_kline(&self, symbol: &str, interval: &str) -> Result<()>
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”)
Sourcepub async fn unsubscribe(&self, stream_name: String) -> Result<()>
pub async fn unsubscribe(&self, stream_name: String) -> Result<()>
Sourcepub async fn subscriptions(&self) -> Vec<String>
pub async fn subscriptions(&self) -> Vec<String>
Returns the list of active subscriptions.
Sourcepub async fn watch_ticker(
&self,
symbol: &str,
market: Option<Market>,
) -> Result<MessageStream<Ticker>>
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),
}
}Sourcepub async fn watch_order_book(
&self,
symbol: &str,
limit: Option<u32>,
) -> Result<MessageStream<OrderBook>>
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),
}
}Sourcepub async fn watch_trades(
&self,
symbol: &str,
market: Option<Market>,
) -> Result<MessageStream<Vec<Trade>>>
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),
}
}