crypto_rest_client/exchanges/gate/
gate_future.rs

1use super::super::utils::http_get;
2use crate::error::Result;
3use std::collections::BTreeMap;
4
5const BASE_URL: &str = "https://api.gateio.ws/api/v4";
6
7/// The RESTful client for Gate Future markets.
8///
9/// * RESTful API doc: <https://www.gate.io/docs/apiv4/en/index.html#delivery>
10/// * Trading at: <https://www.gateio.pro/cn/futures-delivery/usdt>
11pub struct GateFutureRestClient {
12    _api_key: Option<String>,
13    _api_secret: Option<String>,
14}
15
16impl GateFutureRestClient {
17    pub fn new(api_key: Option<String>, api_secret: Option<String>) -> Self {
18        GateFutureRestClient { _api_key: api_key, _api_secret: api_secret }
19    }
20
21    /// Get the latest Level2 snapshot of orderbook.
22    ///
23    /// Top 50 asks and bids are returned.
24    ///
25    /// For example:
26    ///
27    /// - <https://api.gateio.ws/api/v4/delivery/usdt/order_book?contract=BTC_USDT_20220624&limit=50>
28    /// - <https://api.gateio.ws/api/v4/delivery/btc/order_book?contract=BTC_USD_20220624&limit=50>
29    pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
30        let without_date = &symbol[..(symbol.len() - 8)];
31        let settle = if without_date.ends_with("_USD_") {
32            "btc"
33        } else if without_date.ends_with("_USDT_") {
34            "usdt"
35        } else {
36            panic!("Unknown symbol {symbol}");
37        };
38        gen_api!(format!("/delivery/{settle}/order_book?contract={symbol}&limit=50"))
39    }
40}