TradingView Python Bindings (tradingview)
High-performance Python bindings for the tradingview-rs asynchronous TradingView data provider, implemented in Rust via PyO3 0.29 and Maturin.
Features institutional-grade historical OHLCV data retrieval, real-time quote and candlestick streaming via WebSocket, corporate fundamental financial metrics, and global economic calendar events with direct Polars DataFrame integration.
Features
- Direct Polars Integration: Fetch historical candles, batch series, fundamentals, and economic calendar events directly as Polars DataFrames (
as_dataframe=True). - Zero GIL Contention: Long-running network requests, batch iterations, and deserialization execute asynchronously on a background Tokio runtime while releasing the Python Global Interpreter Lock (GIL).
- Dual-Mode Streaming: Subscribe to live quotes and in-flight candlesticks using native async iterators (
async for) or synchronous callbacks (add_callback) dispatched on the asyncio event loop with exception isolation (sys.unraisablehook). - Strict Protocol Parity: Inherits
tradingview-rs's exact UTF-16 code-unit packet framing, 1:1 heartbeat echoing, and session management. - Typed & Tested: 100% type annotated with
.pyitype stubs, PEP 561py.typedmarker, and comprehensive automated test suite.
Installation
pip install tradingview-rs
To enable Polars and Pandas support:
pip install "tradingview-rs[polars,pandas]"
Quick Start
1. Historical Candlesticks Directly to Polars
import asyncio
from tradingview import TradingViewClient, Interval
async def main():
client = TradingViewClient()
# Fetch 100 daily bars directly as a Polars DataFrame
df = await client.get_historical("AAPL", "NASDAQ", Interval.OneDay, n_bars=100, as_dataframe=True)
print(df)
# Or retrieve structured HistoricalSeries with .to_polars() and .to_pandas()
series = await client.get_historical("BTCUSDT", "BINANCE", Interval.OneHour, n_bars=50)
polars_df = series.to_polars()
latest = series[-1]
print(f"Latest Bar: Close={latest.close}, Vol={latest.volume}")
# Concurrent batch retrieval as a dictionary of DataFrames
batch = await client.get_historical_batch(
[("AAPL", "NASDAQ"), ("MSFT", "NASDAQ")],
interval=Interval.OneDay,
n_bars=30,
as_dataframe=True,
)
print("AAPL rows:", batch["NASDAQ:AAPL"].height)
await client.close()
asyncio.run(main())
2. Real-Time Quotes & Candlestick Streaming
import asyncio
from tradingview import TradingViewClient, Interval, QuoteTick, CandleUpdate
def on_quote(tick: QuoteTick):
print(f"[Callback] {tick.symbol} Price={tick.price} Bid={tick.bid} Ask={tick.ask}")
def on_candle(candle: CandleUpdate):
print(f"[Callback] {candle.symbol} Close={candle.close} High={candle.high} Low={candle.low}")
async def main():
client = TradingViewClient()
# 1. Quote streaming with callback & async iterator
quote_sub = await client.subscribe_quotes(["BINANCE:BTCUSDT"], callback=on_quote)
async for tick in quote_sub:
print(f"[Iterator] Tick: {tick.symbol} @ {tick.price}")
break
await quote_sub.stop()
# 2. Live in-flight 1-minute candle streaming
candle_sub = await client.subscribe_bars(["BINANCE:ETHUSDT"], interval=Interval.OneMinute, callback=on_candle)
async for candle in candle_sub:
print(f"[Iterator] Live Candle: {candle.symbol} Close={candle.close} Vol={candle.volume}")
break
await candle_sub.stop()
await client.close()
asyncio.run(main())
3. Corporate Fundamentals & Economic Calendar
import asyncio
from tradingview import TradingViewClient, FinancialPeriod, EconomicImportance
async def main():
client = TradingViewClient()
# Query corporate revenue history as a Polars DataFrame
fund_df = await client.get_fundamental(
"AAPL", "NASDAQ", "total_revenue", FinancialPeriod.FiscalYear, n_bars=5, as_dataframe=True
)
print(fund_df)
# Query macroeconomic releases
events_df = await client.get_economic_calendar(
countries=["US"], min_importance=EconomicImportance.High, as_dataframe=True
)
print(events_df.select(["date", "country", "title", "indicator", "actual", "forecast"]))
await client.close()
asyncio.run(main())
License
MIT License.
Release files for tradingview-rs 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tradingview_rs-0.4.0.tar.gz | 597.4 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tradingview_rs-0.4.0-cp310-abi3-manylinux_2_38_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.38+ x86-64 | Details |
| tradingview_rs-0.4.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 9.0 MB
Release files / tradingview_rs-0.4.0.tar.gz
| Download URL | tradingview_rs-0.4.0.tar.gz |
|---|---|
| Size | 597.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
00a61538c5eb31fc6cf2b38fa9f2364882fe57677989fdf3c4d8e9c677ef9f47
|
|
BLAKE2b-256 checksum How to use checksums |
2f8a3578387862be6459e6904eab515bd1f29c2d70c420f212e507a430ba88cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / tradingview_rs-0.4.0-cp310-abi3-manylinux_2_38_x86_64.whl
| Download URL | tradingview_rs-0.4.0-cp310-abi3-manylinux_2_38_x86_64.whl |
|---|---|
| Size | 4.4 MB |
| Tags | CPython 3.10 Linux glibc 2.38+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
9bba5efdaf876ecd21116df4a631bff096706f4efd629ae7769bc8114d452bd5
|
|
BLAKE2b-256 checksum How to use checksums |
a0b92cd1475344ccf28812433fe4ace625f1d4d040d90ba70ee75e001fffeed2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / tradingview_rs-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | tradingview_rs-0.4.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b93d9bfa8fbba2dc9c2ecc84d0833d0ea36abe6323a111dddbc33ecca17047bb
|
|
BLAKE2b-256 checksum How to use checksums |
165b9d6485d193d3e54c960b8036db15adfc7bc8ab6a2fd20d36799baf041243
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|