crypto_rest_client/exchanges/huobi/
huobi_inverse_swap.rs

1use super::super::utils::http_get;
2use crate::error::Result;
3use std::collections::BTreeMap;
4
5const BASE_URL: &str = "https://api.hbdm.com";
6
7/// Huobi Inverse Swap market.
8///
9/// Inverse Swap market uses coins like BTC as collateral.
10///
11/// * REST API doc: <https://huobiapi.github.io/docs/coin_margined_swap/v1/en/>
12/// * Trading at: <https://futures.huobi.com/en-us/swap/exchange/>
13/// * Rate Limits: <https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#api-rate-limit-illustration>
14///  * For restful interfaces:all products(futures, coin margined swap, usdt
15///    margined swap) 800 times/second for one IP at most
16pub struct HuobiInverseSwapRestClient {
17    _api_key: Option<String>,
18    _api_secret: Option<String>,
19}
20
21impl_contract!(HuobiInverseSwapRestClient);
22
23impl HuobiInverseSwapRestClient {
24    /// Get the latest Level2 orderbook snapshot.
25    ///
26    /// Top 150 bids and asks (aggregated) are returned.
27    ///
28    /// For example: <https://api.hbdm.com/swap-ex/market/depth?contract_code=BTC-USD&type=step0>
29    pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
30        gen_api!(format!("/swap-ex/market/depth?contract_code={symbol}&type=step0"))
31    }
32
33    /// Get open interest.
34    ///
35    /// For example: <https://api.hbdm.com/swap-api/v1/swap_open_interest?contract_code=BTC-USD>
36    pub fn fetch_open_interest(symbol: Option<&str>) -> Result<String> {
37        if let Some(symbol) = symbol {
38            gen_api!(format!("/swap-api/v1/swap_open_interest?contract_code={symbol}"))
39        } else {
40            gen_api!("/swap-api/v1/swap_open_interest")
41        }
42    }
43}