pub struct Bitget { /* private fields */ }Expand description
Bitget exchange structure.
Implementations§
Source§impl Bitget
impl Bitget
Sourcepub fn get_auth(&self) -> Result<BitgetAuth, Error>
pub fn get_auth(&self) -> Result<BitgetAuth, Error>
Get the authentication instance if credentials are configured.
Sourcepub fn check_required_credentials(&self) -> Result<(), Error>
pub fn check_required_credentials(&self) -> Result<(), Error>
Check that required credentials are configured.
Sourcepub async fn fetch_markets(
&self,
) -> Result<Arc<HashMap<String, Arc<Market>>>, Error>
pub async fn fetch_markets( &self, ) -> Result<Arc<HashMap<String, Arc<Market>>>, Error>
Fetch all trading markets.
§Returns
Returns a vector of Market structures containing market information.
§Errors
Returns an error if the API request fails or response parsing fails.
§Example
let bitget = Bitget::builder().build()?;
let markets = bitget.fetch_markets().await?;
println!("Found {} markets", markets.len());Sourcepub async fn load_markets(
&self,
reload: bool,
) -> Result<Arc<HashMap<String, Arc<Market>>>, Error>
pub async fn load_markets( &self, reload: bool, ) -> Result<Arc<HashMap<String, Arc<Market>>>, Error>
Load and cache market data.
If markets are already loaded and reload is false, returns cached data.
§Arguments
reload- Whether to force reload market data from the API.
§Returns
Returns a HashMap containing all market data, keyed by symbol (e.g., “BTC/USDT”).
§Errors
Returns an error if the API request fails or response parsing fails.
§Example
let bitget = Bitget::builder().build()?;
// Load markets for the first time
let markets = bitget.load_markets(false).await?;
println!("Loaded {} markets", markets.len());
// Subsequent calls use cache (no API request)
let markets = bitget.load_markets(false).await?;
// Force reload
let markets = bitget.load_markets(true).await?;Sourcepub async fn fetch_ticker(&self, symbol: &str) -> Result<Ticker, Error>
pub async fn fetch_ticker(&self, symbol: &str) -> Result<Ticker, Error>
Fetch ticker for a single trading pair.
§Arguments
symbol- Trading pair symbol (e.g., “BTC/USDT”).
§Returns
Returns Ticker data for the specified symbol.
§Errors
Returns an error if the market is not found or the API request fails.
§Example
let bitget = Bitget::builder().build()?;
bitget.load_markets(false).await?;
let ticker = bitget.fetch_ticker("BTC/USDT").await?;
println!("BTC/USDT last price: {:?}", ticker.last);Sourcepub async fn fetch_tickers(
&self,
symbols: Option<Vec<String>>,
) -> Result<Vec<Ticker>, Error>
pub async fn fetch_tickers( &self, symbols: Option<Vec<String>>, ) -> Result<Vec<Ticker>, Error>
Fetch tickers for multiple trading pairs.
§Arguments
symbols- Optional list of trading pair symbols; fetches all ifNone.
§Returns
Returns a vector of Ticker structures.
§Errors
Returns an error if markets are not loaded or the API request fails.
§Example
let bitget = Bitget::builder().build()?;
bitget.load_markets(false).await?;
// Fetch all tickers
let all_tickers = bitget.fetch_tickers(None).await?;
// Fetch specific tickers
let tickers = bitget.fetch_tickers(Some(vec!["BTC/USDT".to_string(), "ETH/USDT".to_string()])).await?;Sourcepub async fn fetch_order_book(
&self,
symbol: &str,
limit: Option<u32>,
) -> Result<OrderBook, Error>
pub async fn fetch_order_book( &self, symbol: &str, limit: Option<u32>, ) -> Result<OrderBook, Error>
Fetch order book for a trading pair.
§Arguments
symbol- Trading pair symbol.limit- Optional depth limit (valid values: 1, 5, 15, 50, 100; default: 100).
§Returns
Returns OrderBook data containing bids and asks.
§Errors
Returns an error if the market is not found or the API request fails.
§Example
let bitget = Bitget::builder().build()?;
bitget.load_markets(false).await?;
let orderbook = bitget.fetch_order_book("BTC/USDT", Some(50)).await?;
println!("Best bid: {:?}", orderbook.bids.first());
println!("Best ask: {:?}", orderbook.asks.first());Sourcepub async fn fetch_trades(
&self,
symbol: &str,
limit: Option<u32>,
) -> Result<Vec<Trade>, Error>
pub async fn fetch_trades( &self, symbol: &str, limit: Option<u32>, ) -> Result<Vec<Trade>, Error>
Fetch recent public trades.
§Arguments
symbol- Trading pair symbol.limit- Optional limit on number of trades (maximum: 500).
§Returns
Returns a vector of Trade structures, sorted by timestamp in descending order.
§Errors
Returns an error if the market is not found or the API request fails.
§Example
let bitget = Bitget::builder().build()?;
bitget.load_markets(false).await?;
let trades = bitget.fetch_trades("BTC/USDT", Some(100)).await?;
for trade in trades.iter().take(5) {
println!("Trade: {:?} @ {:?}", trade.amount, trade.price);
}Sourcepub async fn fetch_ohlcv_v2(
&self,
request: OhlcvRequest,
) -> Result<Vec<OHLCV>, Error>
pub async fn fetch_ohlcv_v2( &self, request: OhlcvRequest, ) -> Result<Vec<OHLCV>, Error>
Fetch OHLCV (candlestick) data.
§Arguments
symbol- Trading pair symbol.timeframe- Candlestick timeframe (e.g., “1m”, “5m”, “1h”, “1d”).since- Optional start timestamp in milliseconds.limit- Optional limit on number of candles (maximum: 1000).
§Returns
Returns a vector of OHLCV structures.
§Errors
Returns an error if the market is not found or the API request fails.
§Example
let bitget = Bitget::builder().build()?;
bitget.load_markets(false).await?;
let ohlcv = bitget.fetch_ohlcv("BTC/USDT", "1h", None, Some(100)).await?;
for candle in ohlcv.iter().take(5) {
println!("Open: {}, Close: {}", candle.open, candle.close);
}Requirements: 2.3, 2.6
Sourcepub async fn fetch_ohlcv(
&self,
symbol: &str,
timeframe: &str,
since: Option<i64>,
limit: Option<u32>,
) -> Result<Vec<OHLCV>, Error>
👎Deprecated since 0.2.0: Use fetch_ohlcv_v2 with OhlcvRequest::builder() instead
pub async fn fetch_ohlcv( &self, symbol: &str, timeframe: &str, since: Option<i64>, limit: Option<u32>, ) -> Result<Vec<OHLCV>, Error>
Fetch OHLCV (candlestick) data (deprecated).
§Deprecated
This method is deprecated. Use fetch_ohlcv_v2 with
OhlcvRequest::builder() instead for a more ergonomic API.
§Arguments
symbol- Trading pair symbol.timeframe- Candlestick timeframe (e.g., “1m”, “5m”, “1h”, “1d”).since- Optional start timestamp in milliseconds.limit- Optional limit on number of candles (maximum: 1000).
§Returns
Returns a vector of OHLCV structures.
§Example
let bitget = Bitget::builder().build()?;
bitget.load_markets(false).await?;
let ohlcv = bitget.fetch_ohlcv("BTC/USDT", "1h", None, Some(100)).await?;
for candle in ohlcv.iter().take(5) {
println!("Open: {}, Close: {}", candle.open, candle.close);
}Sourcepub async fn fetch_balance(&self) -> Result<Balance, Error>
pub async fn fetch_balance(&self) -> Result<Balance, Error>
Fetch account balances.
§Returns
Returns a Balance structure with all currency balances.
§Errors
Returns an error if authentication fails or the API request fails.
§Example
let bitget = Bitget::builder()
.api_key("your-api-key")
.secret("your-secret")
.passphrase("your-passphrase")
.build()?;
let balance = bitget.fetch_balance().await?;
if let Some(btc) = balance.get("BTC") {
println!("BTC balance: free={}, used={}, total={}", btc.free, btc.used, btc.total);
}Sourcepub async fn fetch_my_trades(
&self,
symbol: &str,
since: Option<i64>,
limit: Option<u32>,
) -> Result<Vec<Trade>, Error>
pub async fn fetch_my_trades( &self, symbol: &str, since: Option<i64>, limit: Option<u32>, ) -> Result<Vec<Trade>, Error>
Fetch user’s trade history.
§Arguments
symbol- Trading pair symbol.since- Optional start timestamp in milliseconds.limit- Optional limit on number of trades (maximum: 500).
§Returns
Returns a vector of Trade structures representing user’s trade history.
§Errors
Returns an error if authentication fails or the API request fails.
§Example
let bitget = Bitget::builder()
.api_key("your-api-key")
.secret("your-secret")
.passphrase("your-passphrase")
.build()?;
bitget.load_markets(false).await?;
let my_trades = bitget.fetch_my_trades("BTC/USDT", None, Some(50)).await?;Sourcepub async fn create_order_v2(
&self,
request: OrderRequest,
) -> Result<Order, Error>
pub async fn create_order_v2( &self, request: OrderRequest, ) -> Result<Order, Error>
Create a new order.
§Arguments
symbol- Trading pair symbol.order_type- Order type (Market, Limit).side- Order side (Buy or Sell).amount- Order quantity asAmounttype.price- Optional price asPricetype (required for limit orders).
§Returns
Returns the created Order structure with order details.
§Errors
Returns an error if authentication fails, market is not found, or the API request fails.
§Example
let bitget = Bitget::builder()
.api_key("your-api-key")
.secret("your-secret")
.passphrase("your-passphrase")
.build()?;
bitget.load_markets(false).await?;
// Create a limit buy order
let order = bitget.create_order(
"BTC/USDT",
OrderType::Limit,
OrderSide::Buy,
Amount::new(dec!(0.001)),
Some(Price::new(dec!(50000.0))),
).await?;
println!("Order created: {}", order.id);Requirements: 2.2, 2.6
Sourcepub async fn create_order(
&self,
symbol: &str,
order_type: OrderType,
side: OrderSide,
amount: Amount,
price: Option<Price>,
) -> Result<Order, Error>
👎Deprecated since 0.2.0: Use create_order_v2 with OrderRequest::builder() instead
pub async fn create_order( &self, symbol: &str, order_type: OrderType, side: OrderSide, amount: Amount, price: Option<Price>, ) -> Result<Order, Error>
Create a new order (deprecated).
§Deprecated
This method is deprecated. Use create_order_v2 with
OrderRequest::builder() instead for a more ergonomic API.
§Arguments
symbol- Trading pair symbol.order_type- Order type (Market, Limit).side- Order side (Buy or Sell).amount- Order quantity asAmounttype.price- Optional price asPricetype (required for limit orders).
§Returns
Returns the created Order structure with order details.
§Errors
Returns an error if authentication fails or the API request fails.
§Example
let bitget = Bitget::builder()
.api_key("your-api-key")
.secret("your-secret")
.passphrase("your-passphrase")
.build()?;
bitget.load_markets(false).await?;
// Create a limit buy order
let order = bitget.create_order(
"BTC/USDT",
OrderType::Limit,
OrderSide::Buy,
Amount::new(dec!(0.001)),
Some(Price::new(dec!(50000.0))),
).await?;
println!("Order created: {}", order.id);Sourcepub async fn cancel_order(&self, id: &str, symbol: &str) -> Result<Order, Error>
pub async fn cancel_order(&self, id: &str, symbol: &str) -> Result<Order, Error>
Cancel an existing order.
§Arguments
id- Order ID to cancel.symbol- Trading pair symbol.
§Returns
Returns the canceled Order structure.
§Errors
Returns an error if authentication fails or the API request fails.
§Example
let bitget = Bitget::builder()
.api_key("your-api-key")
.secret("your-secret")
.passphrase("your-passphrase")
.build()?;
bitget.load_markets(false).await?;
let order = bitget.cancel_order("123456789", "BTC/USDT").await?;Sourcepub async fn fetch_order(&self, id: &str, symbol: &str) -> Result<Order, Error>
pub async fn fetch_order(&self, id: &str, symbol: &str) -> Result<Order, Error>
Fetch a single order by ID.
§Arguments
id- Order ID to fetch.symbol- Trading pair symbol.
§Returns
Returns the Order structure with current status.
§Errors
Returns an error if authentication fails or the API request fails.
§Example
let bitget = Bitget::builder()
.api_key("your-api-key")
.secret("your-secret")
.passphrase("your-passphrase")
.build()?;
bitget.load_markets(false).await?;
let order = bitget.fetch_order("123456789", "BTC/USDT").await?;
println!("Order status: {:?}", order.status);Sourcepub async fn fetch_open_orders(
&self,
symbol: Option<&str>,
since: Option<i64>,
limit: Option<u32>,
) -> Result<Vec<Order>, Error>
pub async fn fetch_open_orders( &self, symbol: Option<&str>, since: Option<i64>, limit: Option<u32>, ) -> Result<Vec<Order>, Error>
Fetch open orders.
§Arguments
symbol- Optional trading pair symbol. If None, fetches all open orders.since- Optional start timestamp in milliseconds.limit- Optional limit on number of orders (maximum: 500).
§Returns
Returns a vector of open Order structures.
§Errors
Returns an error if authentication fails or the API request fails.
§Example
let bitget = Bitget::builder()
.api_key("your-api-key")
.secret("your-secret")
.passphrase("your-passphrase")
.build()?;
bitget.load_markets(false).await?;
// Fetch all open orders
let all_open = bitget.fetch_open_orders(None, None, None).await?;
// Fetch open orders for specific symbol
let btc_open = bitget.fetch_open_orders(Some("BTC/USDT"), None, Some(50)).await?;Sourcepub async fn fetch_closed_orders(
&self,
symbol: Option<&str>,
since: Option<i64>,
limit: Option<u32>,
) -> Result<Vec<Order>, Error>
pub async fn fetch_closed_orders( &self, symbol: Option<&str>, since: Option<i64>, limit: Option<u32>, ) -> Result<Vec<Order>, Error>
Fetch closed orders.
§Arguments
symbol- Optional trading pair symbol. If None, fetches all closed orders.since- Optional start timestamp in milliseconds.limit- Optional limit on number of orders (maximum: 500).
§Returns
Returns a vector of closed Order structures.
§Errors
Returns an error if authentication fails or the API request fails.
§Example
let bitget = Bitget::builder()
.api_key("your-api-key")
.secret("your-secret")
.passphrase("your-passphrase")
.build()?;
bitget.load_markets(false).await?;
// Fetch closed orders for specific symbol
let closed = bitget.fetch_closed_orders(Some("BTC/USDT"), None, Some(50)).await?;Source§impl Bitget
impl Bitget
Sourcepub fn builder() -> BitgetBuilder
pub fn builder() -> BitgetBuilder
Creates a new Bitget instance using the builder pattern.
This is the recommended way to create a Bitget instance.
§Example
use ccxt_exchanges::bitget::Bitget;
let bitget = Bitget::builder()
.api_key("your-api-key")
.secret("your-secret")
.passphrase("your-passphrase")
.sandbox(true)
.build()
.unwrap();Sourcepub fn new_with_options(
config: ExchangeConfig,
options: BitgetOptions,
) -> Result<Bitget, Error>
pub fn new_with_options( config: ExchangeConfig, options: BitgetOptions, ) -> Result<Bitget, Error>
Creates a new Bitget instance with custom options.
This is used internally by the builder pattern.
§Arguments
config- Exchange configuration.options- Bitget-specific options.
Sourcepub fn base(&self) -> &BaseExchange
pub fn base(&self) -> &BaseExchange
Returns a reference to the base exchange.
Sourcepub fn base_mut(&mut self) -> &mut BaseExchange
pub fn base_mut(&mut self) -> &mut BaseExchange
Returns a mutable reference to the base exchange.
Sourcepub fn options(&self) -> &BitgetOptions
pub fn options(&self) -> &BitgetOptions
Returns the Bitget options.
Sourcepub fn set_options(&mut self, options: BitgetOptions)
pub fn set_options(&mut self, options: BitgetOptions)
Sets the Bitget options.
Sourcepub fn rate_limit(&self) -> u32
pub fn rate_limit(&self) -> u32
Returns the rate limit in requests per second.
Sourcepub fn is_sandbox(&self) -> bool
pub fn is_sandbox(&self) -> bool
Returns true if sandbox/testnet mode is enabled.
Sandbox mode is enabled when either:
config.sandboxis set totrueoptions.testnetis set totrue
§Returns
true if sandbox mode is enabled, false otherwise.
§Example
use ccxt_exchanges::bitget::Bitget;
use ccxt_core::ExchangeConfig;
let config = ExchangeConfig {
sandbox: true,
..Default::default()
};
let bitget = Bitget::new(config).unwrap();
assert!(bitget.is_sandbox());Sourcepub fn timeframes(&self) -> HashMap<String, String>
pub fn timeframes(&self) -> HashMap<String, String>
Returns the supported timeframes.
Sourcepub fn urls(&self) -> BitgetUrls
pub fn urls(&self) -> BitgetUrls
Returns the API URLs.
Returns testnet URLs when sandbox mode is enabled (via config.sandbox or options.testnet),
otherwise returns production URLs.
§Returns
BitgetUrls::testnet()when sandbox mode is enabledBitgetUrls::production()when sandbox mode is disabled
Sourcepub fn signed_request(
&self,
endpoint: impl Into<String>,
) -> BitgetSignedRequestBuilder<'_>
pub fn signed_request( &self, endpoint: impl Into<String>, ) -> BitgetSignedRequestBuilder<'_>
Creates a signed request builder for authenticated API requests.
§Arguments
endpoint- API endpoint path (e.g., “/api/v2/spot/account/assets”)
§Returns
Returns a BitgetSignedRequestBuilder for fluent API construction.
§Example
use ccxt_exchanges::bitget::Bitget;
use ccxt_exchanges::bitget::signed_request::HttpMethod;
use ccxt_core::ExchangeConfig;
let bitget = Bitget::new(ExchangeConfig::default())?;
let data = bitget.signed_request("/api/v2/spot/account/assets")
.execute()
.await?;