Skip to main content

zcash_client_backend/tor/http/cryptex/
xt.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 XT exchange.
8pub struct Xt {
9    _private: (),
10}
11
12impl Xt {
13    /// Prepares for unauthenticated connections to XT.
14    pub fn unauthenticated() -> Self {
15        Self { _private: () }
16    }
17}
18
19#[derive(Debug, Deserialize)]
20#[allow(dead_code)]
21struct XtData {
22    s: String,
23    t: u64,
24    ap: Decimal,
25    aq: Decimal,
26    bp: Decimal,
27    bq: Decimal,
28}
29
30#[derive(Debug, Deserialize)]
31#[allow(dead_code)]
32struct XtResponse {
33    rc: u32,
34    mc: String,
35    ma: Vec<String>,
36    result: (XtData,),
37}
38
39impl Exchange for Xt {
40    async fn query_zec_to_usd(&self, client: &Client) -> Result<ExchangeData, Error> {
41        // API documentation:
42        // https://doc.xt.com/docs/spot/Market/GetBestPendingOrderTicker
43        let res = client
44            .http_get_json::<XtResponse>(
45                "https://sapi.xt.com/v4/public/ticker/book?symbol=zec_usdt"
46                    .parse()
47                    .unwrap(),
48                |b| b,
49                RETRY_LIMIT,
50                retry_filter,
51            )
52            .await?;
53        let data = res.into_body().result.0;
54        Ok(ExchangeData {
55            bid: data.bp,
56            ask: data.ap,
57        })
58    }
59}