-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlist_markets.rs
More file actions
56 lines (49 loc) · 1.61 KB
/
Copy pathlist_markets.rs
File metadata and controls
56 lines (49 loc) · 1.61 KB
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
55
56
//! Connect with `MoonClient` and print the market catalog from the latest snapshot.
//!
//! Run:
//! cargo run --example list_markets --release -- "<key_base64>" [host:port] [limit]
use std::env;
mod common;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("Usage: list_markets <key_base64> [host:port] [limit]");
std::process::exit(1);
}
let limit: usize = args.get(3).and_then(|s| s.parse().ok()).unwrap_or(20);
let client = match common::connect(&args[1], args.get(2), common::init_config()) {
Ok(client) => client,
Err(err) => {
eprintln!("[connect/init] failed: {err}");
std::process::exit(2);
}
};
let Some(snapshot) = client.snapshot() else {
eprintln!("[markets] no snapshot published");
std::process::exit(3);
};
let markets = snapshot.markets();
println!(
"[markets] count={} corr={}",
markets.market_count(),
markets.corr_count()
);
if markets.market_count() == 0 {
eprintln!("[markets] empty market list");
std::process::exit(4);
}
for market in markets.iter().take(limit) {
market.with(|market| {
println!(
"[market] {} base={} status={} trading={} max_lev={} tick={} step={}",
market.symbol(),
market.base_currency,
market.exchange_status(),
market.status_trading,
market.max_leverage,
market.tick_size(),
market.step_size()
);
});
}
}