Setup Trading View Charting Library JS for crypto
Learn how to setup a Trading View candle chart with crypto real time price updates, and historical candle chart.
Mobula pair data API allows you to fetch real-time and historical price data for any on-chain pair. You can use this data to feed Trading View charting library.
What you’ll need
- Access to trading view codebase repo (need manual approval from Trading View)
- An API key from the Dashboard (only for production use, you can use the API without an API key in development mode)
- A react app (or any other framework) to display the chart
Walkthrough
Identify your asset
Pick your asset symbol, name or address. If it is a symbol/name, make sure to check case sensitivity and to respect the asset name as listed on Mobula curated token list (explorable here). If it is an address, make sure to check the blockchain supported (check here for the full list) and to respect the blockchain ID format.
You can also use pair address directly (if using asset, we will route to the largest liquidity pool for this asset).
Setup Chart Component
Let’s first setup the main chart component - you must host the trading view lib files inside the public folder of your app, in our example, we host them at static/charting_library.
Fetch Mobula Historical Data API
We can then implement the fetching logic to get the historical data from Mobula API. We will use the market/history/pair
endpoint to fetch the historical data for the last 300 datapoints of our resolution.
Fetch Mobula Real Time Data API
We can then implement the fetching logic to get the real time data from Mobula API. We will use the pair
WSS endpoint to fetch the real time updates & trades for our pair.
We also have to implement the getNextBarTime
function to get the next bar time for our resolution.
Need help?
Can’t find what you’re looking for? Reach out to us, response times < 1h.