crypto_rest_client/exchanges/mexc/
mexc_spot.rs

1use super::super::utils::http_get;
2use crate::error::Result;
3use std::collections::BTreeMap;
4
5const BASE_URL: &str = "https://www.mexc.com";
6
7/// MEXC Spot market.
8///
9/// * REST API doc: <https://mxcdevelop.github.io/APIDoc/>
10/// * Trading at: <https://www.mexc.com/exchange/BTC_USDT>
11/// * Rate Limits: <https://mxcdevelop.github.io/APIDoc/open.api.v2.en.html#rate-limit>
12///   * The default rate limiting rule for an endpoint is 20 times per second.
13pub struct MexcSpotRestClient {
14    _access_key: String,
15    _secret_key: Option<String>,
16}
17
18impl MexcSpotRestClient {
19    pub fn new(access_key: String, secret_key: Option<String>) -> Self {
20        MexcSpotRestClient { _access_key: access_key, _secret_key: secret_key }
21    }
22
23    /// Get latest trades.
24    ///
25    /// 1000 trades are returned.
26    ///
27    /// For example: <https://www.mexc.com/open/api/v2/market/deals?symbol=BTC_USDT&limit=1000>
28    #[allow(non_snake_case)]
29    pub fn fetch_trades(symbol: &str) -> Result<String> {
30        gen_api!(format!("/open/api/v2/market/deals?symbol={symbol}&limit=1000"))
31    }
32
33    /// Get latest Level2 snapshot of orderbook.
34    ///
35    /// Top 2000 bids and asks will be returned.
36    ///
37    /// For example: <https://www.mexc.com/open/api/v2/market/depth?symbol=BTC_USDT&depth=2000>
38    pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
39        gen_api!(format!("/open/api/v2/market/depth?symbol={symbol}&depth=2000"))
40    }
41}