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 🙏

© 2024 – Pkg Stats / Ryan Hefner

tradingview-ws

v0.0.3

Published

Tradingview websocket API

Downloads

68

Readme

Tradingview websockets integration

Unofficial library to interact with websockets on Tradingview.

Features

  • Realtime data from Tradingview
  • Authorization with session id from cookies
  • Fetching candlesticks for any symbol with any available timeframe

Example

import { connect, getCandles } from 'tradingview-ws'

(async function() {
  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])
}());

API

connect(options: ConnectionOptions = {}): Promise<TradingviewConnection>

Creates new connection to tradingview websockets. Returns TradingviewConnection.

Options:

  • sessionId?: string - authorize connection if present. Can be received from cookies.

getCandles({ connection, symbols, amount, timeframe = 60 }: GetCandlesParams)

Fetches all available candles for symbols. The maximum amount is around 13_000 candles for the hourly timeframe. Returns an array where each element is an array of candles for one symbol in the order it passed to the function.

Options:

  • connection: TradingviewConnection - connection object
  • symbols: string[] - array of symbols. Symbol name can be found on Symbol info modal(click three dots after symbol name on the top left corner of the chart).
  • timeframe?: number | '1D' | '1W' | '1M' - candlestick timeframe, default is 60
  • amount?: number - amount of candles to fetch. If not present, it will try to fetch as much as possible.

TradingviewConnection

Connection object. Can be used directly to receive and send data to websockets.

Methods:

  • subscribe: (handler: Subscriber) => Unsubscriber - subscribe to websockets events
  • send: (name: string, params: any[]) => void - send command to websockets
  • close: () => Promise<void> - close the connection