1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::collections::HashMap;
use super::super::utils::http_get;
use crate::error::Result;
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Serialize, Deserialize)]
struct FutureMarket {
instrument_id: String,
underlying: String,
base_currency: String,
quote_currency: String,
settlement_currency: String,
contract_val: String,
listing: String,
delivery: String,
tick_size: String,
trade_increment: String,
alias: String,
is_inverse: String,
contract_val_currency: String,
category: String,
underlying_index: String,
#[serde(flatten)]
extra: HashMap<String, Value>,
}
fn fetch_future_markets_raw() -> Result<Vec<FutureMarket>> {
let txt = http_get("https://www.okex.com/api/futures/v3/instruments", None)?;
let markets = serde_json::from_str::<Vec<FutureMarket>>(&txt)?;
Ok(markets)
}
pub(super) fn fetch_linear_future_symbols() -> Result<Vec<String>> {
let symbols = fetch_future_markets_raw()?
.into_iter()
.filter(|x| x.is_inverse == "false")
.map(|m| m.instrument_id)
.collect::<Vec<String>>();
Ok(symbols)
}
pub(super) fn fetch_inverse_future_symbols() -> Result<Vec<String>> {
let symbols = fetch_future_markets_raw()?
.into_iter()
.filter(|x| x.is_inverse == "true")
.map(|m| m.instrument_id)
.collect::<Vec<String>>();
Ok(symbols)
}