Connect data via datafeed API
Overview
This tutorial explains how to implement real-time data streaming in Advanced Charts / Trading Platform step-by-step. As an example, the tutorial connects the chart to the free, public Binance Spot REST and WebSocket APIs, which require no API key.
After completing this tutorial, you will learn how to implement a datafeed using the Datafeed API, load historical data with ordinary HTTP requests, stream real-time data over a shared WebSocket connection, and rebuild custom resolutions that the data source does not provide directly.
The tutorial is divided into three parts:
Once your datafeed works in Advanced Charts, you can reuse it in Trading Platform and add trading features such as order placement and depth of market. See the Extend to Trading Platform sub-tutorial.
- You can find the final code for this tutorial in the tutorial repository.
- At the end of each section, you will find the complete code blocks related to a specific step.
- Before proceeding with the tutorial, we recommend checking the Prerequisites section.
Prerequisites
Get repository access
The Advanced Charts repository is private. Refer to the Get access section for more information.
Use external data source
The library is used to display financial data, but it does not contain or provide any data. You need to implement your own data source to display data in the library. It can be a web API, a database, or a CSV file.
This tutorial uses the public Binance Spot APIs, which provide a wide range of crypto market data:
- The REST API (
https://api.binance.com/) supplies the symbol catalog, historical OHLCV bars, and quote snapshots. - The WebSocket API (
wss://stream.binance.com:9443/ws) streams realtime trades, tickers, and order-book depth.
No API key is required for the public spot endpoints used here.
See results on the fly
If you want to see the results of this tutorial right away, take the following steps:
-
Clone the tutorial repository.
git clone https://github.com/tradingview/charting-library-tutorial.gitcd charting-library-tutorial -
Install the project dependencies:
npm install -
Download the Advanced Charts runtime. If you have GitHub SSH access to TradingView's repositories, the install helper downloads the package and copies it into
vendor/tradingview/advanced_charts:npm run tv:install:ac -- 31.2.0Alternatively, place a
charting_library-master/folder in the project root manually and runnpm run tv:syncto copy it intovendor/tradingview/. -
Start the local server and open the chart:
npm run starthttp://127.0.0.1:3000
npx serve?The Trading Platform page proxies the CoinDesk news feed through a small same-origin route in server.mjs, so the project ships its own server (npm run start).
A static fallback is still available via npm run start:static, but the news feed will not load there.