Skip to content

Repository files navigation

TradingView CLI

Control a running TradingView Desktop session from your terminal through Chrome DevTools Protocol (CDP). The tv command emits JSON, so it works well in shell scripts and jq pipelines.

This is an unofficial local automation tool. It is not affiliated with or endorsed by TradingView Inc.

Prerequisites

  • Node.js 20 or newer
  • TradingView Desktop installed and signed in
  • A TradingView plan that supports the features you use
  • TradingView launched with a local CDP port (the default is 9222)

Install

Clone the repository and install its single runtime dependency:

git clone https://github.com/tradesdontlie/tradingview-cli.git
cd tradingview-cli
npm install
npm link

npm link makes the tv command available globally. Without linking, run commands as npm run tv -- <command>.

Launch TradingView with CDP

The simplest option is:

tv launch
tv status

tv launch finds TradingView on macOS, Windows, or Linux and restarts it with --remote-debugging-port=9222. Pass --no-kill to avoid closing an existing instance, or --port 9333 to choose another port.

Platform launch scripts are also included:

# Windows
.\scripts\launch_tv_debug.bat
# macOS
./scripts/launch_tv_debug_mac.sh

# Linux
./scripts/launch_tv_debug_linux.sh

To launch manually, fully quit TradingView first and start its executable with:

--remote-debugging-port=9222

Quick Start

# Inspect the current chart
tv status
tv state
tv quote
tv ohlcv --count 20 --summary

# Change the chart
tv symbol NASDAQ:AAPL
tv timeframe 15
tv type Candles

# Read indicator and Pine drawing data
tv values
tv data lines --filter "My Indicator"
tv data labels --filter "My Indicator"

# Work with Pine Script
tv pine analyze --file indicator.pine
tv pine set --file indicator.pine
tv pine compile

# Practice with bar replay
tv replay start --date 2025-03-01
tv replay step
tv replay trade buy
tv replay status

# Stream newline-delimited JSON
tv stream quote --interval 500 | jq .close

Run tv --help, tv <command> --help, or tv <command> <subcommand> --help for the current options.

Commands

Area Commands
Connection status, launch, update, discover, ui-state
Chart state, symbol, timeframe, type, info, search, range, scroll
Market data quote, ohlcv, values
Advanced data data lines, labels, tables, boxes, strategy, trades, equity, depth, indicator
Pine Script pine get, set, compile, raw-compile, analyze, check, save, new, open, list, errors, console
Screenshots screenshot
Replay replay start, step, stop, status, autoplay, trade
Drawings draw shape, list, get, remove, clear
Alerts alert list, create, delete
Watchlists watchlist get, add, add-bulk, remove
Layouts and indicators layout list, layout switch, indicator add, remove, toggle, set, get
UI automation ui click, keyboard, hover, scroll, find, eval, type, panel, fullscreen, mouse
Panes and tabs pane list, layout, focus, symbol; tab list, new, close, switch
Streaming stream ohlcv, quote, bars, values, lines, labels, tables, all

Most commands operate on the currently active TradingView chart. Entity IDs returned by tv state, tv draw list, or related commands are session-specific.

JSON Output and Exit Codes

Successful commands write formatted JSON to stdout:

{
  "success": true,
  "symbol": "NASDAQ:AAPL",
  "resolution": "15"
}

Errors are JSON on stderr. Exit codes are:

  • 0: success
  • 1: invalid command, invalid input, or operation failure
  • 2: CDP connection failure or TradingView not running

Streaming commands emit JSON Lines (one JSON object per line) until interrupted with Ctrl+C.

Multi-feed OHLCV Streaming

Stream different symbols and timeframes from separate chart panes, including panes in other TradingView tabs:

tv stream ohlcv CME_MINI:ES1!@1 CME_MINI:NQ1!@5 NASDAQ:AAPL@15 --interval 250

The final @ separates each symbol from its timeframe. Existing matching panes are reused. When necessary, the CLI expands a chart layout or opens another tab, configures one pane per feed, and leaves those panes and tabs open after the stream stops.

Each changed feed emits one JSON object containing symbol, timeframe, bar_time, open, high, low, close, volume, bar_index, observed_at, tab_id, and pane_index. Stdout contains JSONL events only; startup notices and recoverable errors go to stderr.

Python can pipe those events directly into arrays or backend calculations:

import json
import subprocess

command = [
    "tv", "stream", "ohlcv",
    "CME_MINI:ES1!@1",
    "CME_MINI:NQ1!@5",
    "NASDAQ:AAPL@15",
    "--interval", "250",
]

process = subprocess.Popen(command, stdout=subprocess.PIPE, text=True)
try:
    for line in process.stdout:
        bar = json.loads(line)
        # Append bar fields to NumPy arrays, queues, databases, or calculations here.
        print(bar["symbol"], bar["timeframe"], bar["close"])
finally:
    process.terminate()
    process.wait()

This polls the latest forming bar from each local chart pane; it is not a raw exchange-tick feed. A value is emitted when that pane's latest OHLCV record changes, so updates that occur between polls can be missed. The default polling interval is 250 ms and the minimum is 100 ms.

Updating

From a clean Git checkout on main:

tv update

The command fetches and fast-forwards origin/main. If package-lock.json changed, it also runs npm ci. Restart the tv command after an update.

Testing

npm ci
npm run lint
npm test

The offline suite covers routing, Pine analysis and compile checks, input sanitization, replay behavior, launch detection, chart history, indicator inputs, self-update guards, and the repository boundary.

With TradingView Desktop running on port 9222, run the live integration suite:

npm run test:e2e

Architecture

tv command -> command adapter -> core operation -> CDP on localhost:9222 -> TradingView Desktop
  • src/cli/ parses commands and serializes results.
  • src/core/ implements chart, data, Pine, replay, drawing, UI, and launch behavior.
  • src/connection.js owns the CDP connection and safe page evaluation helpers.
  • src/wait.js centralizes chart readiness and render waits.

Security and Limitations

  • CDP can control the TradingView Desktop page. Keep it bound to localhost and never expose port 9222 to an untrusted network.
  • The CLI automates your local desktop session; it does not bypass TradingView authentication, subscriptions, permissions, or product limits.
  • TradingView's internal page APIs can change without notice and may require compatibility updates here.
  • Review commands before using them in unattended scripts, especially UI automation, alert deletion, drawing removal, and replay trades.

Use this project subject to the TradingView Terms of Use.

Contributing

Bug reports and pull requests are welcome. See CONTRIBUTING.md for development commands and scope.

Attribution and Disclaimer

TradingView is a trademark of TradingView Inc. This independent project is not affiliated with, endorsed by, sponsored by, or associated with TradingView Inc. It does not include or modify TradingView software. Users are responsible for complying with TradingView's terms and all applicable laws.

License

The source code is available under the MIT License. See LICENSE for the full license and trademark notice.

About

Standalone CLI for controlling TradingView Desktop via Chrome DevTools Protocol

Resources

Contributing

Security policy

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages