Skip to main content

zcash_client_backend/tor/http/cryptex/
digi_finex.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 DigiFinex exchange.
8pub struct DigiFinex {
9    _private: (),
10}
11
12impl DigiFinex {
13    /// Prepares for unauthenticated connections to DigiFinex.
14    pub fn unauthenticated() -> Self {
15        Self { _private: () }
16    }
17}
18
19#[derive(Debug, Deserialize)]
20#[allow(dead_code)]
21struct DigiFinexData {
22    vol: Decimal,
23    change: Decimal,
24    base_vol: Decimal,
25    sell: Decimal,
26    last: Decimal,
27    symbol: String,
28    low: Decimal,
29    buy: Decimal,
30    high: Decimal,
31}
32
33#[derive(Debug, Deserialize)]
34#[allow(dead_code)]
35struct DigiFinexResponse {
36    date: u64,
37    code: u32,
38    ticker: (DigiFinexData,),
39}
40
41impl Exchange for DigiFinex {
42    async fn query_zec_to_usd(&self, client: &Client) -> Result<ExchangeData, Error> {
43        // API documentation:
44        // https://docs.digifinex.com/en-ww/spot/v3/rest.html#ticker-price
45        let res = client
46            .http_get_json::<DigiFinexResponse>(
47                "https://openapi.digifinex.com/v3/ticker?symbol=zec_usdt"
48                    .parse()
49                    .unwrap(),
50                |b| b,
51                RETRY_LIMIT,
52                retry_filter,
53            )
54            .await?;
55        let data = res.into_body().ticker.0;
56        Ok(ExchangeData {
57            bid: data.buy,
58            ask: data.sell,
59        })
60    }
61}