Skip to main content

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

pytradingview-0.5.0.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytradingview-0.5.0-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

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

Hashes for pytradingview-0.5.0.tar.gz
Algorithm Hash digest
SHA256 a79519b94f4415f3a7b1a474856abdeebdc950fb206da08f1834018aedf48527
MD5 52d97e2ffb455d0f10cc723339fe5f67
BLAKE2b-256 cd6738c6c4ea665c56959b451aa5bc900c7a4fc516af1291aabf32afd7131d48

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytradingview-0.5.0.tar.gz:

Publisher: python-publish.yml on kwesy/pytradingview

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pytradingview-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3306b492524b746e839d6312337b1f52c3ef90166f75d3f3f100e8a436122b49
MD5 4360a5a143985c70438968f8641cd746
BLAKE2b-256 3458a1b3d1ee11f1e13c2d272d45a379d18e63928f7c74495644f53f6eb96cd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytradingview-0.5.0-py3-none-any.whl:

Publisher: python-publish.yml on kwesy/pytradingview

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page