-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrealtime.rs
61 lines (52 loc) · 1.58 KB
/
realtime.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
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<()> {
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 mut stream = trading_view
.subscribe_to_symbols(&[
TickerSymbol::builder()
.symbol("CME_MINI:ES1!".to_string())
.currency(Currency::Usd)
.build(),
TickerSymbol::builder()
.symbol("OMXSTO:OMXS30".to_string())
.currency(Currency::Sek)
.build(),
TickerSymbol::builder()
.symbol("COINBASE:BTCUSD".to_string())
.currency(Currency::Usd)
.build(),
])
.await?;
while let Some(data) = stream.next().await {
println!(
"{}",
format!(
"{} {} ({} | {}%) Volume: {}",
data.get_symbol(),
data.get_price(),
data.get_change(),
data.get_change_percent().unwrap_or_default(),
data.get_volume()
)
);
}
Ok(())
}