crypto_rest_client/exchanges/mexc/
mexc_swap.rs

1use super::super::utils::http_get;
2use crate::error::Result;
3use std::collections::BTreeMap;
4
5const BASE_URL: &str = "https://contract.mexc.com";
6
7/// MEXC Swap market.
8///
9/// * REST API doc: <https://mxcdevelop.github.io/APIDoc/>
10/// * Trading at: <https://contract.mexc.com/exchange>
11pub struct MexcSwapRestClient {
12    _api_key: Option<String>,
13    _api_secret: Option<String>,
14}
15
16impl MexcSwapRestClient {
17    pub fn new(api_key: Option<String>, api_secret: Option<String>) -> Self {
18        MexcSwapRestClient { _api_key: api_key, _api_secret: api_secret }
19    }
20
21    /// Get most recent trades.
22    ///
23    /// For example: <https://contract.mexc.com/api/v1/contract/deals/BTC_USDT>
24    pub fn fetch_trades(symbol: &str) -> Result<String> {
25        gen_api!(format!("/api/v1/contract/deals/{symbol}"))
26    }
27
28    /// Get the latest Level2 snapshot of orderbook.
29    ///
30    /// Top 2000 bids and asks will be returned.
31    ///
32    /// For example: <https://contract.mexc.com/api/v1/contract/depth/BTC_USDT?limit=2000>
33    ///
34    /// Rate limit: 20 times /2 seconds
35    pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
36        gen_api!(format!("/api/v1/contract/depth/{symbol}?limit=2000"))
37    }
38}