How to run the library
This tutorial describes how to run the library on your machine. You can also watch the video below that demonstrates running the library step-by-step.
Prepare the Projectβ
Download the the library ZIP file from the Advanced Charts π (restricted access) / Trading Terminal π (restricted access) repository.
Create a new folder (
examplein this tutorial). Copy thecharting_libraryanddatafeedfolders from the archive toexample.Create the following
index.htmlfile in theexamplefolder:/example/index.html<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset = "UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
</body>
</html>Add two script references into the
<head>section:<script src="charting_library/charting_library.standalone.js"></script>
<script src="datafeeds/udf/dist/bundle.js"></script>charting_library/charting_library.standalone.jscontains the code that creates the chart widget.datafeeds/udf/dist/bundle.jscontains a sample datafeed implementation that loads data to the chart.
Define the container for the chart in the
<body>section:<div id="chartContainer"></div>To create a chart, you should initialize the Widget Constructor in
<body>. To do this, configure some basic Widget Constructor parameters:<script>
new TradingView.widget({
container: 'chartContainer',
locale: 'en',
library_path: 'charting_library/',
datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo-feed-data.tradingview.com"),
symbol: 'AAPL',
interval: '1D',
fullscreen: true,
debug: true
});
</script>containeris set to the container ID from the previous step.library_pathspecifies a path to additional HTML, JavaScript, and CSS files that allow you to render the chart. In this tutorial, thecharting_libraryfolder stores these files.datafeedis set to theUDFCompatibleDatafeedsample that TradingView provides.
Run the Libraryβ
Execute the following command in the
examplefolder to run the library locally.python -m http.server 9090noteIn this tutorial, the Python
http.servermodule is used. You can use any server/port that you prefer.Open
http://localhost:9090/in your web browser to see the result.
Complete Codeβ
<!DOCTYPE HTML>
<html lang="en">
    <head>
        <meta charset = "UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>TradingView - Advanced Charts</title>
        <script src="charting_library/charting_library.standalone.js"></script>
        <script src="datafeeds/udf/dist/bundle.js"></script>
    </head>
    <body>
        <div id="chartContainer"></div>
        <script>
            new TradingView.widget({
                container: 'chartContainer',
                locale: 'en',
                library_path: 'charting_library/',
                datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo-feed-data.tradingview.com"),
                symbol: 'AAPL',
                interval: '1D',
                fullscreen: true,
                debug: true,
            });
        </script>
    </body>
</html>
What's next?β
In this tutorial, you have set up Widget Constructor and a static chart. You can follow the How to connect data via Datafeed API tutorial to learn more about implementing real-time data streaming.