| Crates.io | tradingview-rs |
| lib.rs | tradingview-rs |
| version | 0.1.0 |
| created_at | 2024-01-11 06:34:07.200786+00 |
| updated_at | 2025-07-09 10:00:02.862226+00 |
| description | Tradingview datafeed api `tradingview-rs` project. |
| homepage | |
| repository | https://github.com/bitbytelabio/tradingview-rs |
| max_upload_size | |
| id | 1095928 |
| size | 2,044,734 |
This is a data source library for algorithmic trading written in Rust inspired by TradingView-API. It provides programmatic access to TradingView's data and features through a robust, async-first API.
⚠️ Alpha Stage: This library is currently in alpha stage and not ready for production use. Breaking changes may occur between versions.
Add this to your Cargo.toml:
[dependencies]
tradingview-rs = { git = "https://github.com/bitbytelabio/tradingview-rs.git", branch = "main" }
use tradingview::{
Interval, OHLCV,
chart::{ChartOptions, fetch_chart_data},
socket::DataServer,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Get this token from `get_quote_token(cookies)` function
let auth_token = std::env::var("TV_AUTH_TOKEN").expect("TV_AUTH_TOKEN is not set");
let option =ChartOptions::builder()
.symbol("AAPL")
.exchange("NASDAQ")
.interval(Interval::OneDay);
let data = fetch_chart_data(&auth_token, option, None).await?;
Ok(())
}
use tradingview::UserCookies;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let user = UserCookies::default()
.login("username", "password", Some("totp_secret"))
.await?;
// Use authenticated user for premium features
Ok(())
}
use tradingview::{
Interval, QuoteValue,
callback::EventCallback,
chart::ChartOptions,
pine_indicator::ScriptType,
socket::DataServer,
websocket::{WebSocket, WebSocketClient},
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let auth_token = env::var("TV_AUTH_TOKEN").expect("TV_AUTH_TOKEN is not set");
let quote_callback = |data: QuoteValue| {
println!("{:#?}", data);
};
let callbacks: EventCallback = EventCallback::default().on_quote_data(quote_callback);
let client = WebSocketClient::default().set_callbacks(callbacks);
let websocket = WebSocket::new()
.server(DataServer::ProData)
.auth_token(&auth_token)
.client(client)
.build()
.await
.unwrap();
websocket
.create_quote_session()
.await?
.set_fields()
.await?
.add_symbols(vec![
"SP:SPX",
"BINANCE:BTCUSDT",
"BINANCE:ETHUSDT",
"BITSTAMP:ETHUSD",
"NASDAQ:TSLA",
])
.await?;
websocket.subscribe().await
Ok(())
}
The examples/ directory contains comprehensive examples:
historical_data.rs - Fetch historical OHLCV datafetch_historical_data_batch.rs - Batch historical data operationsuser.rs - User authentication and session managementindicator.rs - Working with Pine Script indicatorsmisc.rs - Miscellaneous utility functionsRun an example:
cargo run --example historical_data
For examples requiring authentication, create a .env file:
TV_USERNAME=your_username
TV_PASSWORD=your_password
TV_TOTP_SECRET=your_2fa_secret # Optional, for 2FA
Since this library is in alpha stage, documentation is actively being developed.
Contributions are welcome! Please read our Code of Conduct first.
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)If you discover a security vulnerability, please see our Security Policy for reporting instructions.
This project is licensed under the MIT License - see the LICENSE file for details.
This library is not affiliated with TradingView. Use at your own risk and ensure compliance with TradingView's Terms of Service.