Python implementation for anonymous access to TradingView market data via WebSocket and symbol search
Project description
TradingView Python API
A Python client for the TradingView WebSocket API, providing real-time market data and symbol search functionality.
Features
- 🔍 Symbol Search: Search for trading symbols across exchanges
- 🔌 WebSocket Connection: Real-time connection to TradingView
- 📊 Chart Sessions: Subscribe to live market data for specific symbols
- 🔄 Ping/Pong: Automatic connection keep-alive
- 📈 Multiple Symbols: Subscribe to multiple symbols simultaneously
Support
If you like this project, consider buying me a coffee 😊
Installation
pip install tradingview-api
Quick Start
Symbol Search
from TradingView import SymbolSearch
# Create search client
search = SymbolSearch()
# Search for symbols
results = search.search_symbol("AAPL")
for result in results:
print(f"{result['symbol']}: {result['description']}")
WebSocket Connection
from TradingView import TradingViewClient
# Create client
client = TradingViewClient()
# Set up event handlers
def on_connect():
print("Connected!")
def on_login():
print("Logged in!")
client.on_connect = on_connect
client.on_login = on_login
# Connect
client.connect()
Chart Session
from TradingView import TradingViewClient, ChartSession
# Create client and connect
client = TradingViewClient()
client.connect()
# Create chart session
session = ChartSession(client, "NASDAQ:AAPL")
# Subscribe to market data
session.subscribe()
# Handle updates
def on_update(data):
print(f"Market data: {data}")
session.on_update = on_update
Examples
The package includes comprehensive examples in the examples/ folder:
Individual Examples
# Run specific examples
python examples/example1_symbol_search.py
python examples/example2_basic_client.py
python examples/example3_websocket_with_ping.py
python examples/example4_chart_session.py
python examples/example5_multiple_symbols.py
python examples/example6_chart_types.py
Example Descriptions
- Symbol Search (
example1_symbol_search.py): Demonstrates symbol search functionality - Basic Client (
example2_basic_client.py): Basic WebSocket connection and authentication - WebSocket with Ping (
example3_websocket_with_ping.py): Connection with automatic ping/pong - Chart Session (
example4_chart_session.py): Real-time market data subscription - Multiple Symbols (
example5_multiple_symbols.py): Subscribe to multiple symbols simultaneously
API Reference
SymbolSearch
search_symbol(query: str) -> List[Dict]
Search for trading symbols.
Parameters:
query(str): Search query (e.g., "AAPL", "BTC")
Returns:
- List of dictionaries containing symbol information:
symbol: Symbol identifierdescription: Symbol descriptionexchange: Exchange nametype: Symbol typecurrency: Currency code
TradingViewClient
connect()
Connect to TradingView WebSocket.
disconnect()
Disconnect from TradingView WebSocket.
is_connected() -> bool
Check if connected to TradingView.
Event Handlers
on_connect: Called when connectedon_login: Called when logged inon_data: Called when data is receivedon_error: Called when an error occurson_close: Called when connection closes
ChartSession
__init__(client: TradingViewClient, symbol: str)
Create a new chart session.
Parameters:
client: TradingViewClient instancesymbol: Symbol to subscribe to (e.g., "NASDAQ:AAPL")
subscribe()
Subscribe to market data for the symbol.
unsubscribe()
Unsubscribe from market data.
Event Handlers
on_update: Called when market data is receivedon_error: Called when an error occurs
Development
Setup
git clone https://github.com/kaash04/TradingView-API-Python.git
cd TradingView-Python
pip install -e .
Running Examples
# Run individual examples
python examples/example1_symbol_search.py
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
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 tradingview_api-1.0.1.tar.gz.
File metadata
- Download URL: tradingview_api-1.0.1.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a99ad0a2baf183ac7bd4b1946f627d9bb4deb3194757f5e973598277340adced
|
|
| MD5 |
317fa3aa7289ac0fb68506fa5f35ac53
|
|
| BLAKE2b-256 |
05eed8bc0f0845dc1724b4383e3fc3f39b1e169f7a5b75f3f4e29c8f1248e3bf
|
File details
Details for the file tradingview_api-1.0.1-py3-none-any.whl.
File metadata
- Download URL: tradingview_api-1.0.1-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0af1c3b7345f854f6b9d42a7d65b7a9af7bc01cc6dbdd3a7df25bd83c6cf264
|
|
| MD5 |
23c038bce92919990bf18b7a6f6e950d
|
|
| BLAKE2b-256 |
1e3bb8e8ca9d4d899a5f716b22dfa906d621236c6c245e00405d4d6a7568589d
|