Code Monkey home page Code Monkey logo

tradingview-ws's Introduction

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

tradingview-ws's People

Contributors

endenwer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.