Registry / devops / tradingview-ws

tradingview-ws

JSON →
library0.0.3jsnpmunverified

An unofficial Node.js library for interacting with TradingView's WebSocket API. Current version 0.0.3 provides real-time data, authorization via session ID, and candlestick fetching for any symbol and timeframe. Supports up to ~13,000 candles per request for hourly timeframes. Features TypeScript definitions and ESM-only exports. Key differentiators: lightweight, promise-based, and direct WebSocket access without browser emulation. Release cadence is irregular; use with caution for production.

npm install tradingview-ws
INSTALL
IMPORT
SIG · TRADINGVIEW-WS
T
tradingview-ws
devopsjavascriptv0.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

connect
import { connect } from 'tradingview-ws'
const connect = require('tradingview-ws').connect
ESM-only package; CommonJS require may break. Use dynamic import if needed.
getCandles
import { getCandles } from 'tradingview-ws'
import getCandles from 'tradingview-ws'
getCandles is a named export, not default.
TradingviewConnection
import type { TradingviewConnection } from 'tradingview-ws'
import { TradingviewConnection } from 'tradingview-ws'
TradingviewConnection is a type-only export when using TypeScript; use import type.

Initializes a WebSocket connection, fetches 10,000 hourly candlesticks for two FX pairs, then closes the connection.

import { connect, getCandles } from 'tradingview-ws' async function fetchCandles() { const connection = await connect() const candles = await getCandles({ connection, symbols: ['FX:AUDCAD', 'FX:AUDCHF'], amount: 10_000, timeframe: 60 }) await connection.close() console.log('Candles for AUDCAD:', candles[0]) console.log('Candles for AUDCHF:', candles[1]) } fetchCandles().catch(console.error)
Debug
Known issues
breakingESM-only package: require() will throw 'ERR_REQUIRE_ESM' in Node.js
fix
Use import syntax or dynamic import() in CommonJS modules. Set 'type': 'module' in package.json if using ESM.
affects: >=0.0.3
gotchaSession ID from cookies is optional but without it data may be limited or incomplete
fix
Pass a valid sessionId in connect options to get full data access.
affects: >=0.0.3
gotchaMaximum amount of candles per request is ~13,000; requesting more will silently cap
fix
Do not request more than 13,000 candles per call; split requests if needed.
affects: >=0.0.3
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Using CommonJS require() to import an ESM-only package
fix
Replace require with import: `import { connect, getCandles } from 'tradingview-ws'`
TypeError: ws_1.default is not a constructor
Misimporting the WebSocket dependency due to wrong import style
fix
Ensure correct import: `import WebSocket from 'ws'` if using CommonJS in a ESM project, but prefer the library's own interface.
Candles array is empty even after successful connection
No data returned because symbol names are invalid or session expired
fix
Verify symbol names from TradingView's symbol info modal and provide a valid sessionId.
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies
wsrequiredWebSocket client for Node.js
Agent activity
4 hits · last 30 days
node
4
Resources
tradingview-ws — npm install tradingview-ws · libregistry