TradingView Data Source
Introduction
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.
The library exposes two usage tiers:
- High-level — An event-driven
DataLoaderthat connects a source to multiple sinks with backpressure and graceful shutdown. - Low-level — Direct access to HTTP clients, WebSocket sessions, and raw message parsing for full control.
⚠️ Alpha Stage: This library is currently in alpha stage and not ready for production use. Breaking changes may occur between versions.
Features
- Async Support — Built with Tokio for high-performance async operations
- Event-Driven Pipeline —
DataSource→ fan-out →EventSinkarchitecture with bounded channels, cancellation tokens, and error recovery - Multiple Sinks — Built-in channel, callback, and Kafka (RedPanda) sinks; implement your own via the
EventSinktrait - Real-time Data — WebSocket-based live market data with automatic reconnection and circuit breaker
- Historical Data — Fetch OHLCV data for single symbols and concurrent batch operations
- Session Management — Shared sessions between threads to respect TradingView's rate limits
- Custom Indicators — Work with Pine Script indicators via study configurations
- Chart Drawings — Retrieve your chart drawings and annotations
- Replay Mode — Historical market replay functionality
- Symbol Search — Search and filter symbols by market, country, and type
- News Integration — Access TradingView news and headlines
- User Authentication — Login with username/password + TOTP 2FA support
- Premium Features — Access TradingView Pro/Premium/Expert data tiers
- Fundamental data
- Technical analysis signals
- Invite-only indicators support
- Public chat interactions
- Screener integration
- Economic calendar
- Vectorized data conversion
Installation
Add this to your Cargo.toml:
[]
# From crates.io (recommended):
= "0.1"
# Or from the Git repository:
= { = "https://github.com/bitbytelabio/tradingview-rs.git", = "main" }
Feature Flags
| Feature | Default | Description |
|---|---|---|
rustls-tls |
✅ | TLS via rustls (recommended) |
native-tls |
— | TLS via platform-native libraries |
user |
✅ | User authentication (login, 2FA, session cookies) |
Example with optional features:
[]
= { = "0.1", = false, = ["native-tls", "user"] }
Quick Start
Historical Data (Single Symbol)
use ;
async
Historical Data (Batch)
use ;
async
Symbol Search
use ;
async
User Authentication
use UserCookies;
async
Real-time Data
use dotenv;
use ;
use ;
use ;
async
Working with Indicators
use ;
async
Examples
The examples/ directory contains runnable examples for every major feature:
| Example | Description |
|---|---|
historical_data_fetch.rs |
Fetch historical OHLCV for a single symbol |
batch_historical_fetch.rs |
Concurrent batch historical data |
live_quote.rs |
Real-time quote streaming via WebSocket |
channel_consumer.rs |
Event-driven loader with a channel sink |
callback_consumer.rs |
Event-driven loader with an inline callback sink |
user.rs |
User authentication and session management |
search.rs |
Symbol search and filtering |
misc.rs |
Miscellaneous utility functions |
Run an example:
Prerequisites
- Rust 1.85+ (edition 2024) — This library uses modern Rust features
- TradingView Account — Required for authenticated features (free tier works for most)
- Network Access — Connects to TradingView's servers
Environment Variables
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
TV_AUTH_TOKEN=your_auth_token # Get from user authentication
Architecture
┌──────────────────────────────────────────────────┐
│ tradingview-rs │
├──────────────────────────────────────────────────┤
│ High-Level API (event-driven) │
│ ┌──────────┐ ┌───────────┐ ┌────────────┐ │
│ │ Source │───▶│ DataLoader │───▶│ EventSink │ │
│ │ (TV feed) │ │ (fan-out) │ │ (channel, │ │
│ │ │ │ │ │ callback, │ │
│ │ │ │ │ │ kafka) │ │
│ └──────────┘ └───────────┘ └────────────┘ │
├──────────────────────────────────────────────────┤
│ Low-Level API (direct access) │
│ ┌──────────────┐ ┌──────────────┐ ┌───────────┐ │
│ │ historical │ │ live │ │ client │ │
│ │ (WebSocket) │ │ (WebSocket) │ │ (REST) │ │
│ └──────────────┘ └──────────────┘ └───────────┘ │
├──────────────────────────────────────────────────┤
│ Shared: models, chart, quote, error, utils │
└──────────────────────────────────────────────────┘
| Module | Purpose |
|---|---|
historical |
Single + batch OHLCV retrieval via WebSocket |
live |
Real-time WebSocket streaming (quotes, charts, studies) |
client |
REST HTTP client (search, news, financial calendar) |
loader |
Event-driven orchestrator (source → fan-out → sinks) |
source |
DataSource trait + TradingView WebSocket adapter |
sink |
EventSink trait + channel, callback, Kafka sinks |
events |
Normalized MarketEvent types (Candle, Quote, News, etc.) |
chart |
Chart session config + Pine Script studies |
quote |
Real-time quote data model + field definitions |
Use Cases
- VNQuant Datafeed — Event-driven data engine with RedPanda (Kafka)
- Algorithmic Trading Bots — Real-time market data for trading strategies
- Market Research — Historical data analysis and backtesting
- Portfolio Management — Track and analyze investment performance
- Technical Analysis — Custom indicators and studies
Documentation
Full API documentation is published on docs.rs. All public types, traits, and modules are documented with examples.
Quick links to key types:
DataLoader— event-driven orchestratorHistoricalClient— historical dataWebSocketClient— real-time streamingSymbol— instrument representationInterval— time granularity
For the project roadmap, see ROADMAP.md.
Before Opening an Issue
- Check existing issues - Your problem might already be reported
- Update to latest version - Bug fixes are released regularly
- Review examples - Make sure you're using the API correctly
- Provide minimal reproduction - Include code that demonstrates the issue
- Include error messages - Full error output helps with debugging
Known Issues & Limitations
- Rate Limiting — TradingView enforces rate limits; respect them to avoid bans
- Session Expiry — User sessions expire periodically and need renewal
- Alpha Quality — Breaking changes may occur between minor versions
- Premium Features — Some features require TradingView Pro/Premium/Expert subscription
- Study Series Loading — Some Pine Script study data series need fixes (see
TODOin indicator code) - Parse Round-Trip —
SocketMessagedeserialization has known round-trip mismatches with the serdeuntaggedenum (7 tests currently skipped)
Roadmap
See ROADMAP.md for planned features, milestones, and version timeline.
Contributing
Contributions are welcome! Please read our Code of Conduct first.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Security
If you discover a security vulnerability, please see our Security Policy for reporting instructions.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Disclaimer
This library is not affiliated with TradingView. Use at your own risk and ensure compliance with TradingView's Terms of Service.