npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tradingview-api-adapter

v2.0.0

Published

Real-time market data from TradingView via WebSocket: quotes, candles, symbol info, streaming, groups.

Readme

tradingview-api-adapter

📊 Real-time market data from TradingView via WebSocket — typed, composable, and ergonomic.

import { tv } from 'tradingview-api-adapter'

const client = tv()
const btc = client.symbol('BINANCE:BTCUSDT')

console.log(await btc.price()) // → 72183.99

btc.stream().on('price', ({ price }) => {
  console.log('BTC:', price)
})

await client.disconnect()

Features

  • Real-time quotes — typed lp, bid, ask, ch, chp, volume, and 50+ other fields
  • Historical candles — OHLCV bars at any TradingView timeframe (1m → 1M)
  • Symbol metadata — full SymbolInfo (description, exchange, session hours, …) via one .info() call
  • Multi-symbol streamsPortfolio for ad-hoc collections, Group for named, mutable ones
  • Auto-reconnect — exponential backoff + jitter, automatic session replay
  • Full TypeScript typesQuoteSnapshot<['lp', 'bid']> gives you { lp?: number | null; bid?: number | null }
  • Async iteratorfor await (const tick of stream) { ... }
  • Explicit resource managementusing client = tv() auto-disconnects
  • Node + Browser — dynamic ws import so browser bundles don't carry Node-only code
  • Proxy + auth — HTTP/SOCKS proxy agent, sessionid/authToken for premium access
  • Battle-tested — 227+ unit tests, integration against a mock WebSocket server, live e2e

Installation

npm install tradingview-api-adapter

Requires Node.js ≥ 20. See browser guide for client-side usage.

Quick start

Get a price

import { tv } from 'tradingview-api-adapter'

const client = tv()
const btc = client.symbol('BINANCE:BTCUSDT')

const price = await btc.price()
console.log(`BTC: $${price}`)

await client.disconnect()

Stream live updates

const stream = btc.stream(['lp', 'bid', 'ask', 'ch', 'chp'] as const)

stream.on('price', ({ price }) => console.log(price))
stream.on('change', ({ value, percent }) => console.log(`${value} (${percent}%)`))

// Or use async iteration:
for await (const { data } of stream) {
  console.log(data.lp, data.bid, data.ask)
  if (someCondition) break // ← automatically closes the stream
}

Fetch historical candles

const candles = await btc.candles({ timeframe: '1h', count: 100 })
// → Candle[] with { time, open, high, low, close, volume }

Multi-symbol portfolio

const portfolio = client.symbols([
  'BINANCE:BTCUSDT',
  'BINANCE:ETHUSDT',
  'NASDAQ:AAPL',
])

const prices = await portfolio.prices()
// → { 'BINANCE:BTCUSDT': 72183, 'BINANCE:ETHUSDT': 2200, 'NASDAQ:AAPL': 260 }

portfolio.stream().on('price', ({ symbol, price }) => {
  console.log(`${symbol}: $${price}`)
})

Named groups with live mutation

const crypto = client.createGroup('crypto', ['BINANCE:BTCUSDT', 'BINANCE:ETHUSDT'])

const stream = crypto.stream()
stream.on('price', ({ symbol, price }) => console.log(symbol, price))

// Add a pair — active streams pick it up automatically
crypto.add('BINANCE:SOLUSDT')

// Remove a pair — active streams stop emitting for it
crypto.remove('BINANCE:ETHUSDT')

// List all registered groups on the client
console.log(client.groups.list) // → ['crypto']

Symbol metadata

const info = await btc.info()
console.log(info.description) // → 'Bitcoin / TetherUS'
console.log(info.exchange) // → 'Binance'
console.log(info.currencyCode) // → 'USDT'
console.log(info.isTradable) // → true

Documentation

Examples

The examples/ directory contains 12 runnable demos:

| # | File | What it shows | |---|---|---| | 01 | 01-single-price.ts | Minimal one-shot price fetch | | 02 | 02-streaming.ts | Single-symbol stream with price, change events | | 03 | 03-multi-symbol.ts | Ad-hoc Portfolio | | 04 | 04-groups.ts | Named Group with live add/remove | | 05 | 05-candles-history.ts | Historical OHLCV bars | | 06 | 06-candles-streaming.ts | Live bar ticks (via internal ChartSession) | | 07 | 07-symbol-info.ts | Full symbol metadata | | 08 | 08-async-iterator.ts | for await over a stream | | 09 | 09-reconnect-resilience.ts | Automatic reconnect with backoff | | 10 | 10-browser.html | Vanilla HTML page via esm.sh CDN | | 11 | 11-proxy-node.ts | HTTP/SOCKS proxy through an agent | | 12 | 12-auth-session.ts | Authenticated access with TradingView cookies |

Run any of them with npx tsx examples/NN-*.ts. Enable verbose logging via DEBUG=tradingview-adapter:* npx tsx examples/NN-*.ts.

Design principles

This library is a full rewrite of 1.x. The redesign prioritised:

  1. Typed over stringly-typed. QuoteSnapshot<['lp', 'bid']> is { lp?: number | null; bid?: number | null }, not Record<string, any>.
  2. Composable over monolithic. TransportProtocolSessionManager ↔ public API are independently testable and swappable.
  3. One socket, many sessions. A single WebSocket connection multiplexes every quote and chart subscription through a shared SessionManager.
  4. Pooled symbols. client.symbol('BTC') always returns the same instance, so overlapping groups dedupe automatically.
  5. No hidden state. Every resource (symbol, stream, group) has an explicit lifecycle.
  6. Browser-safe by construction. ws is loaded through dynamic import() so browser bundlers can drop it.

License

MIT © Gerasimenko Oleg