Skip to content

Repository files navigation

TradingView-API

Build with market data, from your first chart to a running watcher. Fetch candles and quotes, run indicators and strategies, and turn ideas into working tools. An independent community project, not an official TradingView API.

Get started · Explore examples · Read the data API guide

Language: English · Français · Español · Português

Tests npm Stars

Mathieu2301/TradingView-API | #1 Repo Of The Day on Trendshift

Recorded demonstration: a candle request returns 40 daily BTC/USDT candles, visualized as a line chart

An actual candle request, recorded on 2 October 2026 with the development preview (fetchCandles, called getCandles in version 4) and visualized for this demo. Prices are not live.

One request, real data

V4 release candidate is available on npm under next. Install with npm install @mathieuc/tradingview@next. The default latest tag is still v3 and does not export getCandles.

import { getCandles } from '@mathieuc/tradingview/data';

const candles = await getCandles({ symbol: 'BINANCE:BTCUSDT', timeframe: 'D', count: 40 });
console.log(candles.at(-1)); // { time, open, high, low, close, volume }

Prefer to start without code? The setup paths below work too.

Version 4 is a breaking rewrite in TypeScript, with a new API and no compatibility layer. Coming from v3? Read the migration guide. Every v3 feature is still available: see the coverage matrix and reliability evidence. The RC preparation report tracks current checks and remaining release gates. npm versions 3.x keep the previous Client API; check the npm page for the version you install.

Get started

Interactive quick-start

The interactive launcher is included starting with 4.0.0-rc.1:

npx @mathieuc/tradingview@next

Run it from your project directory with Node.js 20+. Choose a path:

  1. Autonomous agent (recommended) — opens the TradingView-API market watcher on Molted Studio. No local project setup.
  2. Claude Code CLI — starts your installed claude CLI here with a ready-to-use project prompt.
  3. Codex CLI — starts your installed codex CLI here with the same prompt.
  4. Another local coding agent — prints the prompt to paste into your agent.
  5. Install the library only — runs npm install @mathieuc/tradingview@next here, without generating files or starting an agent.

Claude Code and Codex must already be installed and authenticated. Their normal permission prompts remain enabled. If launch fails, the prompt is printed for manual use. If no browser is available, the hosted link remains visible.

Use --choice 4 to print the prompt directly, or --help for usage. Non-interactive callers must pass --choice. To try the launcher from this checkout:

npm ci && npm run build
node bin/tradingview.mjs

Install manually

npm install @mathieuc/tradingview@next
# Or: bun add @mathieuc/tradingview@next

next installs the V4 release candidate; the default latest tag still installs V3. Do not mix the V4 imports with a V3 installation.

The V4 package is ESM with TypeScript declarations. CommonJS projects can require() it on Node 20.19+ or 22.12+, or use await import().

Want to contribute?

Open an issue to discuss a feature or report a bug, or send a pull request. Questions and early ideas are welcome; you do not need a perfect reproduction to start a conversation. npm run check runs the type check, lint, tests, build and package smoke test.

Data API

The data API handles connections, sessions, timeouts and cleanup for you. It suits any application: scripts, servers, dashboards, bots or agents.

import {
  getCandles, watchCandles, getQuote, getIndicatorData, searchMarkets,
} from '@mathieuc/tradingview/data';

// One-shot: resolves with complete data, then releases everything.
const hourly = await getCandles({ symbol: 'BINANCE:BTCUSDT', timeframe: '60', count: 500 });
const lastWeek = await getCandles({ symbol: 'NASDAQ:AAPL', timeframe: '15', from: new Date(Date.now() - 7 * 86_400_000) });
const quote = await getQuote('BINANCE:BTCUSDT');
const [market] = await searchMarkets('ethereum', { type: 'crypto' });

// Watcher: keeps streaming until stopped.
const watcher = await watchCandles({ symbol: 'BINANCE:BTCUSDT', timeframe: '1' }, {
  onData: (candles) => console.log(candles.at(-1)?.close),
  onError: (error) => console.error(error.code, error.message),
});
await watcher.stop();

// Indicators and strategies (Pine scripts need an account).
const { values } = await getIndicatorData({
  symbol: 'BINANCE:BTCUSDT', indicator: 'STD;RSI', credentials: { session, signature },
});
Need Function
Candles: latest bars, deep history, date ranges, Heikin Ashi/Renko/... getCandles, watchCandles
Quotes: last price, change, bid/ask, volume... getQuote, getQuotes, watchQuotes
Indicator values, drawings and strategy reports getIndicatorData, watchIndicator
Symbol metadata getSymbolInfo
Stock/crypto screening and ranked lists getScreener, getHotlist
Account watchlists (read-only) getWatchlists
Search and ratings searchMarkets, searchIndicators, getTechnicalAnalysis

Websocket data functions accept timeoutMs, an AbortSignal, account credentials, and an optional shared client. HTTP lookups accept an AbortSignal through their options. Errors are TradingViewErrors with a code such as SYMBOL_ERROR, TIMEOUT or STUDY_ERROR. Read the data API guide for every option.

Low-level API

For full control (several charts and studies on one connection, replay mode, raw packets), use the client and sessions directly:

import { TradingViewClient, getIndicator } from '@mathieuc/tradingview';

const client = new TradingViewClient({ credentials: { session, signature } }); // Credentials are optional
const chart = client.createChart();

chart.on('update', () => console.log(chart.lastCandle?.close));
chart.on('error', (error) => console.error(error.message));
chart.setMarket('BINANCE:BTCUSDT', { timeframe: '60', count: 300 });

const supertrend = chart.createStudy(await getIndicator('STD;Supertrend'));
supertrend.on('update', () => console.log(supertrend.values.at(-1)));

// When your application is finished:
await client.close();

The low-level API reference covers charts, replay, studies, quotes, account and layout functions, Pine permissions, custom transports and protocol helpers. The examples show each feature.

Accounts and limits

Without an account, TradingView serves limited data: shorter intraday history, no Pine studies, and possibly delayed or substitute feeds. With your sessionid and sessionid_sign cookies (credentials), you get what your account can access. Keep them in environment variables or a secret store; never put them in source files, issues or prompts.

Project links

TradingView is a trademark of its respective owner. This project is not affiliated with or endorsed by TradingView. Check your data provider's terms and applicable market-data permissions for your use case.