crypto_rest_client/exchanges/bitget/
bitget_swap.rs

1use super::super::utils::http_get;
2use crate::error::Result;
3use std::collections::BTreeMap;
4
5const BASE_URL: &str = "https://api.bitget.com";
6
7/// The RESTful client for Bitget swap markets.
8///
9/// * RESTful API doc: <https://bitgetlimited.github.io/apidoc/en/mix/#restapi>
10/// * Trading at: <https://www.bitget.com/mix/>
11pub struct BitgetSwapRestClient {
12    _api_key: Option<String>,
13    _api_secret: Option<String>,
14}
15
16impl BitgetSwapRestClient {
17    pub fn new(api_key: Option<String>, api_secret: Option<String>) -> Self {
18        BitgetSwapRestClient { _api_key: api_key, _api_secret: api_secret }
19    }
20
21    /// Get the latest Level2 snapshot of orderbook.
22    ///
23    /// For example: <https://api.bitget.com/api/mix/v1/market/depth?symbol=BTCUSDT_UMCBL&limit=100>
24    ///
25    /// Rate Limit:20 requests per 2 seconds
26    pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
27        gen_api!(format!("/api/mix/v1/market/depth?symbol={symbol}&limit=100"))
28    }
29
30    /// Get open interest.
31    ///
32    /// For example:
33    ///
34    /// - <https://api.bitget.com/api/mix/v1/market/open-interest?symbol=BTCUSDT_UMCBL>
35    pub fn fetch_open_interest(symbol: &str) -> Result<String> {
36        gen_api!(format!("/api/mix/v1/market/open-interest?symbol={symbol}"))
37    }
38}