mod utils; use crypto_pair::{normalize_currency, normalize_pair}; use serde::{Deserialize, Serialize}; use serde_json::Value; use std::collections::HashMap; use utils::http_get; const EXCHANGE_NAME: &str = "deribit"; #[derive(Serialize, Deserialize)] #[allow(non_snake_case)] struct DeribitResponse { id: Option, jsonrpc: String, result: Vec, usIn: i64, usOut: i64, usDiff: i64, testnet: bool, #[serde(flatten)] extra: HashMap, } #[derive(Serialize, Deserialize)] struct Instrument { kind: String, quote_currency: String, instrument_name: String, base_currency: String, #[serde(flatten)] extra: HashMap, } /// Get active trading instruments. /// /// doc: /// /// `currency`, available values are `BTC` and `ETH`. /// /// `kind`, available values are `future` and `option`. /// /// Example: fn fetch_instruments(currency: &str, kind: &str) -> Vec { let url = format!( "https://www.deribit.com/api/v2/public/get_instruments?currency={currency}&kind={kind}" ); let txt = http_get(&url).unwrap(); let resp = serde_json::from_str::>(&txt).unwrap(); resp.result } #[test] fn verify_all_symbols() { let mut markets = fetch_instruments("BTC", "future"); let mut tmp_markets = fetch_instruments("ETH", "future"); markets.append(&mut tmp_markets); tmp_markets = fetch_instruments("BTC", "option"); markets.append(&mut tmp_markets); tmp_markets = fetch_instruments("ETH", "option"); markets.append(&mut tmp_markets); for market in markets.iter() { let pair = normalize_pair(&market.instrument_name, EXCHANGE_NAME).unwrap(); let pair_expected = format!( "{}/{}", normalize_currency(&market.base_currency, EXCHANGE_NAME), normalize_currency(&market.quote_currency, EXCHANGE_NAME) ); assert_eq!(pair.as_str(), pair_expected); } }