-
Notifications
You must be signed in to change notification settings - Fork 2
/
fetch_instruments.rs
62 lines (51 loc) · 1.61 KB
/
fetch_instruments.rs
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
57
58
59
60
61
62
use std::io;
use futures::StreamExt;
use tradingview::{ClientOptions, Currency, TickerSymbol, TradingView};
fn on_two_factor() -> String {
println!("Enter two factor code: ");
let mut code = String::new();
io::stdin().read_line(&mut code).unwrap();
code.trim().to_string()
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
env_logger::init();
let client_options = ClientOptions::builder().build();
let trading_view = TradingView::new(client_options);
trading_view
.login(
"username",
"password",
true,
Some(tradingview::Either::Right(on_two_factor)),
)
.await?;
let tickers = &[
TickerSymbol::builder()
.symbol("OMXSTO:SAND".to_string())
.currency(Currency::Sek)
.build(),
TickerSymbol::builder()
.symbol("OMXSTO:ERIC_B".to_string())
.currency(Currency::Sek)
.build(),
TickerSymbol::builder()
.symbol("NASDAQ:AAPL".to_string())
.currency(Currency::Usd)
.build(),
TickerSymbol::builder()
.symbol("COINBASE:BTCUSD".to_string())
.currency(Currency::Usd)
.build(),
TickerSymbol::builder()
.symbol("EUREX:FDAX1!".to_string())
.currency(Currency::Eur)
.build(),
];
let mut instruments = trading_view.fetch_instruments(tickers).await?;
while let Some(instrument) = instruments.next().await {
let instrument = instrument.unwrap();
println!("{:?}", instrument);
}
Ok(())
}