Skip to main content

zcash_client_backend/tor/http/cryptex/
mexc.rs

1use rust_decimal::Decimal;
2use serde::Deserialize;
3
4use super::{Exchange, ExchangeData, RETRY_LIMIT, retry_filter};
5use crate::tor::{Client, Error};
6
7/// Querier for the MEXC exchange.
8pub struct Mexc {
9    _private: (),
10}
11
12impl Mexc {
13    /// Prepares for unauthenticated connections to MEXC.
14    pub fn unauthenticated() -> Self {
15        Self { _private: () }
16    }
17}
18
19#[derive(Debug, Deserialize)]
20#[allow(dead_code)]
21#[allow(non_snake_case)]
22struct MexcData {
23    symbol: String,
24    priceChange: Decimal,
25    priceChangePercent: Decimal,
26    prevClosePrice: Decimal,
27    lastPrice: Decimal,
28    bidPrice: Decimal,
29    bidQty: Decimal,
30    askPrice: Decimal,
31    askQty: Decimal,
32    openPrice: Decimal,
33    highPrice: Decimal,
34    lowPrice: Decimal,
35    volume: Decimal,
36    quoteVolume: Decimal,
37    openTime: u64,
38    closeTime: u64,
39}
40
41impl Exchange for Mexc {
42    async fn query_zec_to_usd(&self, client: &Client) -> Result<ExchangeData, Error> {
43        // API documentation:
44        // https://mexcdevelop.github.io/apidocs/spot_v3_en/#24hr-ticker-price-change-statistics
45        let res = client
46            .http_get_json::<MexcData>(
47                "https://api.mexc.com/api/v3/ticker/24hr?symbol=ZECUSDT"
48                    .parse()
49                    .unwrap(),
50                |b| b,
51                RETRY_LIMIT,
52                retry_filter,
53            )
54            .await?;
55        let data = res.into_body();
56        Ok(ExchangeData {
57            bid: data.bidPrice,
58            ask: data.askPrice,
59        })
60    }
61}