crypto_rest_client/exchanges/huobi/
huobi_linear_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 Linear Swap market.
8///
9/// Linear Swap market uses USDT as collateral.
10///
11/// * REST API doc: <https://huobiapi.github.io/docs/usdt_swap/v1/en/>
12/// * Trading at: <https://futures.huobi.com/en-us/linear_swap/exchange/>
13/// * Rate Limits: <https://huobiapi.github.io/docs/usdt_swap/v1/en/#api-rate-limit-illustration>
14///   * For restful interfaces, products, (future, coin margined swap, usdt
15///     margined swap)800 times/second for one IP at most
16pub struct HuobiLinearSwapRestClient {
17    _api_key: Option<String>,
18    _api_secret: Option<String>,
19}
20
21impl_contract!(HuobiLinearSwapRestClient);
22
23impl HuobiLinearSwapRestClient {
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/linear-swap-ex/market/depth?contract_code=BTC-USDT&type=step0>
29    pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
30        gen_api!(format!("/linear-swap-ex/market/depth?contract_code={symbol}&type=step0"))
31    }
32
33    /// Get open interest.
34    ///
35    /// For example: <https://api.hbdm.com/linear-swap-api/v1/swap_open_interest?contract_code=BTC-USDT>
36    pub fn fetch_open_interest(symbol: Option<&str>) -> Result<String> {
37        if let Some(symbol) = symbol {
38            gen_api!(format!("/linear-swap-api/v1/swap_open_interest?contract_code={symbol}"))
39        } else {
40            gen_api!("/linear-swap-api/v1/swap_open_interest")
41        }
42    }
43}