Skip to main content
Version: latest

How to connect data via datafeed API

This tutorial explains how to implement real-time data streaming to Advanced Charts / Trading Platform step-by-step. As an example, the tutorial describes connection via free CryptoCompare API that provides data from several crypto exchanges.

After completing this tutorial, you will learn how to implement datafeed using Datafeed API, display historical data using ordinary HTTP requests, and stream real-time data via WebSocket.

The tutorial is divided into three parts:

  1. Widget Constructor set-up
  2. Datafeed implementation
  3. Streaming implementation
Tips
  • You can find the final code for this tutorial on the GitHub 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 Getting 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 CryptoCompare API, which has a wide range of market data.

caution

We cannot guarantee that CryptoCompare works in your region. If you see the ERR_CONNECTION_REFUSED error when running the tutorial, try to use a proxy or VPN.

See results on the fly

If you want to see the results of this tutorial right away, take the following steps:

  1. Clone the tutorial repository. Note that for the real project, it is better to use this repository as a submodule in yours.

    git clone https://github.com/tradingview/charting-library-tutorial.git
  2. Go to the repository folder and initialize the Git submodule with the library:

    git submodule update --init --recursive

    Alternatively, you can download the the library repository from a ZIP file or clone it using Git.

  3. Run the following command to serve static files:

    npx serve