<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ahmad Ghorbani on Medium]]></title>
        <description><![CDATA[Stories by Ahmad Ghorbani on Medium]]></description>
        <link>https://medium.com/@amadghorbani?source=rss-6cb06a7cde4c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fC7kzZPn72hBBr_-ouHe1A.jpeg</url>
            <title>Stories by Ahmad Ghorbani on Medium</title>
            <link>https://medium.com/@amadghorbani?source=rss-6cb06a7cde4c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 20:23:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amadghorbani/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Integrating TradingView Charting Library with React.js]]></title>
            <link>https://medium.com/@amadghorbani/integrating-tradingview-charting-library-with-react-js-e499d8343425?source=rss-6cb06a7cde4c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e499d8343425</guid>
            <category><![CDATA[tradingview]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[charting-library]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Ahmad Ghorbani]]></dc:creator>
            <pubDate>Thu, 10 Nov 2022 20:55:25 GMT</pubDate>
            <atom:updated>2022-11-11T08:03:56.739Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*Ua8mbt1QsE7hUSGKMZgEpg.png" /></figure><p>Charting Library is a powerful solution for displaying financial charts. It can be connected to your own API to be used in your website or app.</p><p>TradingView company has implemented the charting library in plain JavaScript which is available in this repositiory: <a href="https://github.com/tradingview/charting-library-tutorial">https://github.com/tradingview/charting-library-tutorial</a>.</p><p>You can read the documentation and run the chart to see the results.</p><p>However, integrating charting library with React.js may be confusing and is not well documented.</p><blockquote>Before you begin, note that the Charting Library is free, but its code is in a private repository on GitHub. Make sure that you have access to this repository: <a href="https://github.com/tradingview/charting_library/">https://github.com/tradingview/charting_library/</a>. You can’t implement the chart without having the Charting Library.</blockquote><p>If you see 404 error page, then you need to request access to this repository at <a href="https://tradingview.com/HTML5-stock-forex-bitcoin-charting-library/?feature=technical-analysis-charts">https://tradingview.com/HTML5-stock-forex-bitcoin-charting-library/?feature=technical-analysis-charts</a> and click on the “Get Library” button.</p><p>In order to implement it in react, we need to copy the Charting Library folder in two paths in our react project: src and public. It seems redundant to have this folder in two places but this is how react and webpack work. When working inside src path in react, we do not have access to the files that are outside of src path. On the other hand, if we want to load a JavaScript file using a script tag in index.html file in react, the file must be in the public path.</p><p>Another thing also needs to be changed. inside main.js, we see that TradingView is called without being imported. This class is declared in charting_library/ charting_library.standalone.js with “var” keyword, which declares a variable globally. Since react is modular, this class can not be accessed globally. We can declare this class using “const” keyword and then export it. Then we can import it wherever it is needed.</p><p>After fixing these issues, we see two script tags in index.html file.</p><p>The first one is:</p><pre>&lt;script type=&quot;text/javascript&quot; src=&quot;/charting_library/charting_library.js&quot;&gt;&lt;/script&gt;</pre><p>And the last one is:</p><pre>&lt;script type=&quot;module&quot; src=&quot;src/main.js&quot;&gt;&lt;/script&gt;</pre><p>These two scripts can be run inside a react component like this:</p><pre>import React, { useEffect } from &quot;react&quot;;<br>import Datafeed from &quot;../trading-view/datafeed&quot;;<br>import TradingView from &quot;../charting_library/charting_library.standalone&quot;;<br><br>const TradingViewChart = () =&gt; {<br><br>useEffect(() =&gt; {<br>const script = document.createElement(&quot;script&quot;);<br>script.type = &quot;text/jsx&quot;;<br>script.src = &quot;/public/charting_library/charting_library.js&quot;;<br><br>document.head.appendChild(script);<br>window.tvWidget = new TradingView.widget({<br>symbol: &quot;Bitfinex:BTC/USD&quot;, // default symbol<br>interval: &quot;1D&quot;, // default interval<br>fullscreen: true, // displays the chart in the fullscreen mode<br>container: &quot;tv_chart_container&quot;,<br>datafeed: Datafeed,<br>library_path: &quot;/charting_library/&quot;,<br>});<br><br>return () =&gt; script.remove();<br>}, []); <br><br>return &lt;div id=&quot;tv_chart_container&quot;&gt;&lt;/div&gt;;<br>};<br><br>export default TradingViewChart;</pre><p>The first script is now created inside our component. Note that we do not need to create the second script. In fact, the second script was used to run a module (it runs the code that exists in src/main.js); but here we have copied the code that exists in “src/main.js” and it is run when our component is mounted.</p><p>You can find the complete implementation in my GitHub repo: <a href="https://github.com/Ahmad-Ghorbani/trading-view-react">https://github.com/Ahmad-Ghorbani/trading-view-react</a>.</p><p><a href="https://github.com/Ahmad-Ghorbani/trading-view-react">GitHub - Ahmad-Ghorbani/trading-view-react</a></p><p>I have not implemented the web socket connection here (but implemented it for our website). I assume that it is not so difficult to work with that.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e499d8343425" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>