A Python client for TradingView WebSocket API. Lightweight, real-time data for stocks, crypto, indices, etc.
Project description
pytradingview
A lightweight, open-source Python client for connecting to TradingView's WebSocket API.
Features
- WebSocket connection management
- Easy to extend for custom signals and data
- Download data
- Search for symbols
Dependencies
websocket-client
requests
Installation
pip install pytradingview
Usage
# example.py
from pytradingview import TVclient
# Create the client and chart
client = TVclient()
chart = client.chart
# Set up the chart
chart.set_up_chart()
# Set the market
chart.set_market("BINANCE:BTCUSD", {
"timeframe": "1", # 1-minute chart
"currency": "USD",
})
# Event: When the symbol data is loaded
chart.on_symbol_loaded(lambda _: print("✅ Market loaded:", chart.get_infos['description']))
# Event: When price data is updated
def handle_update(_):
if chart.get_periods:
print(f"🟢 New Price: {chart.get_periods['close']}")
chart.on_update(handle_update)
# Start the WebSocket connection
client.create_connection()
Authentication
Guest mode (default):
from pytradingview import TVclient
client = TVclient() # uses TradingView unauthorized_user_token
Auth token mode:
from pytradingview import TVclient
client = TVclient(auth_token="YOUR_TRADINGVIEW_AUTH_TOKEN")
Username/password mode (fetches token via TradingView signin endpoint):
from pytradingview import TVclient
client = TVclient(username="you@example.com", password="your-password")
Command line (CLI)
python -m pytradingview -d -s '2025-04-24 00:00' -e '2025-04-25 00:00' -p 'FX:EURUSD'
python -m pytradingview -d -s '2025-04-24 00:00' -e 'now' -p 'FX:EURUSD'
python -m pytradingview --search EURUSD --max 50
python -m pytradingview -d -p 'CME_MINI:ES1!' -t '1' -s '-1d' -e 'now' --username 'you@example.com' --password 'your-password'
export PYTRADINGVIEW_AUTH_TOKEN='YOUR_TRADINGVIEW_AUTH_TOKEN'
python -m pytradingview -d -p 'CME_MINI:ES1!' -t '1' --start=-2h --end=now -o /tmp/es_1m.csv
Contributing
Contributions are welcome! Please open issues or PRs to collaborate.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytradingview-0.5.0.tar.gz.
File metadata
- Download URL: pytradingview-0.5.0.tar.gz
- Upload date:
- Size: 25.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a79519b94f4415f3a7b1a474856abdeebdc950fb206da08f1834018aedf48527
|
|
| MD5 |
52d97e2ffb455d0f10cc723339fe5f67
|
|
| BLAKE2b-256 |
cd6738c6c4ea665c56959b451aa5bc900c7a4fc516af1291aabf32afd7131d48
|
Provenance
The following attestation bundles were made for pytradingview-0.5.0.tar.gz:
Publisher:
python-publish.yml on kwesy/pytradingview
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytradingview-0.5.0.tar.gz -
Subject digest:
a79519b94f4415f3a7b1a474856abdeebdc950fb206da08f1834018aedf48527 - Sigstore transparency entry: 941350985
- Sigstore integration time:
-
Permalink:
kwesy/pytradingview@2a1c4b2004eb45ccd9b5d910cd3540339c29c309 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/kwesy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@2a1c4b2004eb45ccd9b5d910cd3540339c29c309 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pytradingview-0.5.0-py3-none-any.whl.
File metadata
- Download URL: pytradingview-0.5.0-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3306b492524b746e839d6312337b1f52c3ef90166f75d3f3f100e8a436122b49
|
|
| MD5 |
4360a5a143985c70438968f8641cd746
|
|
| BLAKE2b-256 |
3458a1b3d1ee11f1e13c2d272d45a379d18e63928f7c74495644f53f6eb96cd6
|
Provenance
The following attestation bundles were made for pytradingview-0.5.0-py3-none-any.whl:
Publisher:
python-publish.yml on kwesy/pytradingview
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytradingview-0.5.0-py3-none-any.whl -
Subject digest:
3306b492524b746e839d6312337b1f52c3ef90166f75d3f3f100e8a436122b49 - Sigstore transparency entry: 941351019
- Sigstore integration time:
-
Permalink:
kwesy/pytradingview@2a1c4b2004eb45ccd9b5d910cd3540339c29c309 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/kwesy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@2a1c4b2004eb45ccd9b5d910cd3540339c29c309 -
Trigger Event:
push
-
Statement type: