Skip to main content

zcash_client_backend/tor/http/cryptex/
gemini.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 Gemini exchange.
8pub struct Gemini {
9    _private: (),
10}
11
12impl Gemini {
13    /// Prepares for unauthenticated connections to Gemini.
14    pub fn unauthenticated() -> Self {
15        Self { _private: () }
16    }
17}
18
19#[derive(Debug, Deserialize)]
20#[allow(dead_code)]
21struct GeminiData {
22    symbol: String,
23    open: Decimal,
24    high: Decimal,
25    low: Decimal,
26    close: Decimal,
27    changes: Vec<Decimal>,
28    bid: Decimal,
29    ask: Decimal,
30}
31
32impl Exchange for Gemini {
33    async fn query_zec_to_usd(&self, client: &Client) -> Result<ExchangeData, Error> {
34        // API documentation:
35        // https://docs.gemini.com/rest-api/#ticker-v2
36        let res = client
37            .http_get_json::<GeminiData>(
38                "https://api.gemini.com/v2/ticker/zecusd".parse().unwrap(),
39                |b| b,
40                RETRY_LIMIT,
41                retry_filter,
42            )
43            .await?;
44        let data = res.into_body();
45        Ok(ExchangeData {
46            bid: data.bid,
47            ask: data.ask,
48        })
49    }
50}