Expand description
§bitget_rs
Bitget V2 Futures SDK crate used by crypto_exc_all.
Current coverage:
- Public common/notice:
GET /api/v2/public/timeGET /api/v2/public/annoucements
- Futures market:
GET /api/v2/mix/market/tickerGET /api/v2/mix/market/tickersGET /api/v2/mix/market/contractsGET /api/v2/mix/market/orderbookGET /api/v2/mix/market/merge-depthGET /api/v2/mix/market/candlesGET /api/v2/mix/market/history-candlesGET /api/v2/mix/market/symbol-priceGET /api/v2/mix/market/current-fund-rateGET /api/v2/mix/market/history-fund-rateGET /api/v2/mix/market/open-interestGET /api/v2/mix/market/oi-limitGET /api/v2/mix/market/query-position-leverGET /api/v2/mix/market/vip-fee-rateGET /api/v2/mix/market/long-shortGET /api/v2/mix/market/account-long-shortGET /api/v2/mix/market/taker-buy-sellGET /api/v2/mix/market/exchange-rate
- Futures account/position:
GET /api/v2/mix/account/accountsGET /api/v2/mix/account/accountGET /api/v2/mix/account/billGET /api/v2/mix/account/sub-account-assetsGET /api/v2/mix/position/all-positionGET /api/v2/mix/position/history-positionPOST /api/v2/mix/account/set-leveragePOST /api/v2/mix/account/set-margin-modePOST /api/v2/mix/account/set-position-modePOST /api/v2/mix/account/set-marginPOST /api/v2/mix/account/set-asset-modeGET /api/v2/common/trade-rate
- Futures trade:
POST /api/v2/mix/order/place-orderPOST /api/v2/mix/order/batch-place-orderPOST /api/v2/mix/order/cancel-orderPOST /api/v2/mix/order/cancel-batch-ordersPOST /api/v2/mix/order/cancel-all-ordersPOST /api/v2/mix/order/modify-orderPOST /api/v2/mix/order/close-positionsPOST /api/v2/mix/order/place-plan-orderPOST /api/v2/mix/order/place-tpsl-orderPOST /api/v2/mix/order/place-pos-tpslPOST /api/v2/mix/order/modify-plan-orderPOST /api/v2/mix/order/modify-tpsl-orderPOST /api/v2/mix/order/cancel-plan-orderGET /api/v2/mix/order/detailGET /api/v2/mix/order/orders-pendingGET /api/v2/mix/order/orders-historyGET /api/v2/mix/order/orders-plan-pendingGET /api/v2/mix/order/orders-plan-historyGET /api/v2/mix/order/plan-sub-orderGET /api/v2/mix/order/fills
- Spot wallet/asset:
GET /api/v2/spot/public/coinsGET /api/v2/spot/wallet/deposit-addressGET /api/v2/spot/wallet/deposit-recordsGET /api/v2/spot/wallet/withdrawal-recordsGET /api/v2/spot/wallet/transfer-coin-infoPOST /api/v2/spot/wallet/transferPOST /api/v2/spot/wallet/withdrawal
- WebSocket:
- V2 public/private URL config
- login signing with
timestamp + GET + /user/verify - string
ping/pong - subscribe / unsubscribe payload builders
place-order/cancel-ordertrade payload builders and trade ack parser- base typed event parser with raw fallback
- typed DTOs for
ticker,orders,account,positions,books*,trade,candle*,fill,orders-algo,adl-noti, andpositions-historypushes - WebSocket session with SOCKS5/SOCKS5h proxy support
- reconnect manager with public/private client split, unified message forwarding, pending/active subscription registry, runtime subscribe/unsubscribe, timed ping, private login replay with ack gate, inbound stall timeout, connected-session failure limits, granular connection states, metrics, and subscription replay
- HMAC-SHA256 + Base64 request signing
- SOCKS/HTTP proxy configuration
- Mocked request, signature header, and response mapping tests
§Environment
BITGET_API_KEY=...
BITGET_API_SECRET=...
BITGET_PASSPHRASE=...
BITGET_API_URL=https://api.bitget.com
BITGET_API_TIMEOUT_MS=5000
BITGET_PROXY_URL=socks5h://127.0.0.1:7897
BITGET_WS_PUBLIC_URL=wss://ws.bitget.com/v2/ws/public
BITGET_WS_PRIVATE_URL=wss://ws.bitget.com/v2/ws/privateLowercase key names are also accepted for compatibility with existing .env files:
bitget_api_key=...
bitget_api_secret=...
bitget_passphrase=...
bitget_PASSPHRASE=...§Example
use bitget_rs::api::market::{BitgetMarket, TickerRequest};
#[tokio::main]
async fn main() -> Result<(), bitget_rs::Error> {
let market = BitgetMarket::new_public()?;
let tickers = market
.get_ticker(TickerRequest::new("BTCUSDT", "USDT-FUTURES"))
.await?;
println!("{} {}", tickers[0].symbol, tickers[0].last_price);
Ok(())
}§WebSocket Example
use bitget_rs::api::websocket::{BitgetWebsocket, BitgetWebsocketChannel};
use bitget_rs::config::Config;
#[tokio::main]
async fn main() -> Result<(), bitget_rs::Error> {
let websocket = BitgetWebsocket::new_public(Config::from_env());
let mut session = websocket.connect_public().await?;
let ticker = BitgetWebsocketChannel::new("USDT-FUTURES", "ticker")
.with_inst_id("BTCUSDT");
session.subscribe(&[ticker]).await?;
while let Some(event) = session.recv_event().await {
println!("{event:?}");
}
Ok(())
}Public and private smoke examples are also available:
cargo run -p bitget_rs --example websocket_public_smoke
cargo run -p bitget_rs --example websocket_private_smokewebsocket_public_smoke subscribes to public ticker and books5 and waits for one market data push. websocket_private_smoke logs in with BITGET_API_KEY / BITGET_API_SECRET / BITGET_PASSPHRASE, subscribes to account and orders, and does not place orders.
Re-exports§
pub use api::account::BitgetAccount;pub use api::announcements::BitgetAnnouncements;pub use api::asset::BitgetAsset;pub use api::market::BitgetMarket;pub use api::trade::BitgetTrade;pub use api::websocket::BitgetWebsocket;pub use client::BitgetClient;pub use error::Error;