-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65f6290
commit c8c7157
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use std::env; | ||
|
||
use tracing::info; | ||
use tradingview_rs::{ | ||
chart::{ | ||
session::{ChartCallbackFn, WebSocket}, | ||
ChartOptions, ChartSeries, | ||
}, | ||
models::Interval, | ||
socket::DataServer, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
tracing_subscriber::fmt::init(); | ||
let auth_token = env::var("TV_AUTH_TOKEN").unwrap(); | ||
|
||
let handlers = ChartCallbackFn { | ||
on_chart_data: Box::new(|data| Box::pin(on_chart_data(data))), | ||
on_symbol_resolved: Box::new(|data| Box::pin(on_symbol_resolved(data))), | ||
on_series_completed: Box::new(|data| Box::pin(on_series_completed(data))), | ||
}; | ||
|
||
let mut socket = WebSocket::build() | ||
.server(DataServer::ProData) | ||
.auth_token(auth_token) | ||
.connect(handlers) | ||
.await | ||
.unwrap(); | ||
|
||
socket | ||
.set_market( | ||
"BINANCE:BTCUSDT", | ||
ChartOptions { | ||
resolution: Interval::OneMinute, | ||
bar_count: 50_000, | ||
..Default::default() | ||
}, | ||
) | ||
.await | ||
.unwrap(); | ||
socket.subscribe().await; | ||
} | ||
|
||
async fn on_chart_data(data: ChartSeries) -> Result<(), tradingview_rs::error::Error> { | ||
let end = data.data.first().unwrap().timestamp; | ||
info!("on_chart_data: {:?} - {:?}", data.data.len(), end); | ||
Ok(()) | ||
} | ||
|
||
async fn on_symbol_resolved( | ||
data: tradingview_rs::chart::SymbolInfo, | ||
) -> Result<(), tradingview_rs::error::Error> { | ||
info!("on_symbol_resolved: {:?}", data); | ||
Ok(()) | ||
} | ||
|
||
async fn on_series_completed( | ||
data: tradingview_rs::chart::SeriesCompletedMessage, | ||
) -> Result<(), tradingview_rs::error::Error> { | ||
info!("on_series_completed: {:?}", data); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters