TradingView Snapshot with REST API v1

CHART-IMG
6 min readMar 12, 2023

--

In this tutorial, I will show you how to use CHART-IMG REST API version 1 to capture TradingView charts with examples using CURL and URL with a query string to make the process easy to understand and follow.

For more detailed documentation, visit doc.chart-img.com.

Authentication

Although the API is free for anyone to use, you must include your personal access key in every request. To obtain your key, log in to chart-img.com using your Google account and generate it.

There are two ways to authenticate your access key. One is by including in the request header Authorization with the prefix Bearer followed by your key. The second method is including the key in the URL.

I recommend using the first method for production because it offers better security. However, if you prefer simplicity, you can include the key in the URL, which allows you to test it directly in your browser.

Header Authorization:

## for Linux based
curl -G https://api.chart-img.com/v1/tradingview/advanced-chart \
-H "Authorization: Bearer {YOUR_API_KEY}" \
-o chart-img-01.png

## for Windows, you have to merge all lines into one by removing the backslashes
curl -G https://api.chart-img.com/v1/tradingview/advanced-chart -H "Authorization: Bearer {YOUR_API_KEY}" -o chart-img-01.png

This should download an image with the file name chart-img-01.png.

URL Query String:

https://api.chart-img.com/v1/tradingview/advanced-chart?key={YOUR_API_KEY}

You can test this URL by directly entering it into your browser, but don’t forget to replace {YOUR_API_KEY} with your key.

TradingView Symbols

You can check the list of TradingView exchange symbols supported by visiting doc.chart-img.com. Please note that the availability of real-time, delayed, and daily-only data will vary depending on the specific exchange.

If you require a real-time chart for an unsupported exchange and have a data subscription plan, please refer to version 2 of the API.

TradingView Mini Chart

This Mini Chart allows you to view the price and change percentages of the exchange symbol, along with a simplified area chart.

To customize the chart, specify the parameters in the query string with symbol, interval, theme, width, height, and format. If the default values are the same, you don’t need to include them. Refer to the documentation for more detailed information.

Let’s try a specific image size with the interval 3M.

## for Linux based
curl -G https://api.chart-img.com/v1/tradingview/mini-chart \
-H "Authorization: Bearer {YOUR_API_KEY}" \
-d "symbol=BINANCE:ETHUSDT" \
-d "width=600" \
-d "height=400" \
-d "interval=3M" \
-d "theme=light" \
-o chart-img-02.png

## for Windows, you have to merge all lines into one by removing the backslashes
curl -G https://api.chart-img.com/v1/tradingview/mini-chart -H "Authorization: Bearer {YOUR_API_KEY}" -d "symbol=BINANCE:ETHUSDT" -d "width=600" -d "height=400" -d "interval=3M" -d "theme=light" -o chart-img-02.png
https://api.chart-img.com/v1/tradingview/mini-chart?key={YOUR_API_KEY}&symbol=BINANCE:ETHUSDT&width=600&height=400&interval=3M&theme=light
CHART-IMG-02.PNG

TradingView Advanced Chart

The Advanced Chart offers market prices, ranges, and multiple technical indicators.

You can customize the chart using several query string parameters such as symbol, interval, theme, studies, timezone, width, height, format, style, and range. You can also include multiple indicator studies with various input values, allowing you to tailor the chart to your preferences. Refer to the documentation for more detailed information.

Let’s make a simple chart with default values.

## for Linux based
curl -G https://api.chart-img.com/v1/tradingview/advanced-chart \
-H "Authorization: Bearer {YOUR_API_KEY}" \
-d "theme=light" \
-o chart-img-03.png

## for Windows, you have to merge all lines into one by removing the backslashes
curl -G https://api.chart-img.com/v1/tradingview/advanced-chart -H "Authorization: Bearer {YOUR_API_KEY}" -d "theme=light" -o chart-img-03.png
https://api.chart-img.com/v1/tradingview/advanced-chart?key={YOUR_API_KEY}&theme=light
CHART-IMG-03.PNG

The volume will be displayed in the main chart by default if the chart supports volume. If you prefer, you can choose to display it separately in the indicator pane, as shown in the following example.

Let’s customize the chart with indicators with separate volumes. Refer to the documentation for supported studies with default values.

## for Linux based
curl -G https://api.chart-img.com/v1/tradingview/advanced-chart \
-H "Authorization: Bearer {YOUR_API_KEY}" \
-d "symbol=BINANCE:BNBUSDT" \
-d "interval=4h" \
-d "studies=RSI" \
-d "theme=light" \
-o chart-img-04.png

## for Windows, you have to merge all lines into one by removing the backslashes
curl -G https://api.chart-img.com/v1/tradingview/advanced-chart -H "Authorization: Bearer {YOUR_API_KEY}" -d "symbol=BINANCE:BNBUSDT" -d "interval=4h" -d "studies=RSI" -d "theme=light" -o chart-img-04.png
https://api.chart-img.com/v1/tradingview/advanced-chart?key={YOUR_API_KEY}&symbol=BINANCE:BNBUSDT&interval=4h&studies=RSI&theme=light
CHART-IMG-04.PNG

Let’s make indicators with custom input values. If you require more extensive customization, including specific colors and drawings, please refer to API version 2.

## for Linux based
curl -G https://api.chart-img.com/v1/tradingview/advanced-chart \
-H "Authorization: Bearer {YOUR_API_KEY}" \
-d "symbol=CAPITALCOM:GOLD" \
-d "interval=1w" \
-d "studies=EMA:12" \
-d "studies=EMA:26" \
-d "studies=EMA:50" \
-d "studies=EMA:100" \
-d "theme=light" \
-o chart-img-05.png

## for Windows, you have to merge all lines into one by removing the backslashes
curl -G https://api.chart-img.com/v1/tradingview/advanced-chart -H "Authorization: Bearer {YOUR_API_KEY}" -d "symbol=CAPITALCOM:GOLD" -d "interval=1w" -d "studies=EMA:12" -d "studies=EMA:26" -d "studies=EMA:50" -d "studies=EMA:100" -d "theme=light" -o chart-img-05.png
https://api.chart-img.com/v1/tradingview/advanced-chart?key={YOUR_API_KEY}&symbol=CAPITALCOM:GOLD&interval=1w&studies=EMA:12&studies=EMA:26&studies=EMA:50&studies=EMA:100&theme=light
CHART-IMG-05.PNG

Public Storage

You can request the API to save the rendered chart image to storage and return the public URL in JSON format. To use this feature, add /storage to your endpoint URL. This feature applies to both mini and advanced charts.

## for Linux based
curl -G https://api.chart-img.com/v1/tradingview/advanced-chart/storage \
-H "Authorization: Bearer {YOUR_API_KEY}" \
-d "symbol=BINANCE:ETHUSDT" \
-d "studies=MACD" \
-d "studies=CCI:10,close" \
-d "interval=4h" \
-d "theme=light" \
-o chart-img-06.json

## for Windows, you have to merge all lines into one by removing the backslashes
curl -G https://api.chart-img.com/v1/tradingview/advanced-chart/storage -H "Authorization: Bearer {YOUR_API_KEY}" -d "symbol=BINANCE:ETHUSDT" -d "studies=MACD" -d "studies=CCI:10,close" -d "interval=4h" -d "theme=light" -o chart-img-06.json
https://api.chart-img.com/v1/tradingview/advanced-chart/storage?key={YOUR_API_KEY}&symbol=BINANCE:ETHUSDT&studies=MACD&studies=CCI:10,close&interval=4h&theme=light
{
"url": "https://api.chart-img.com/v1/storage/pub/9c3e8b95-263d-4a5c-9711-070f2ded1b68.png",
"size": 63173,
"cors": null,
"etag": "177e59d441a3794b99d0d4cc9d670188",
"expireAt": "2023-03-26T15:25:53.489Z",
"createdAt": "2023-03-12T15:25:53.714Z"
}

For more detailed information on the storage limit, refer to the documentation.

Error Handle

The API uses standard HTTP status codes to indicate success, failure, and error. Consider these status codes as you develop your application to ensure smooth functionality.

Unprocessable Content (422):

This response indicates that the request entity is valid, but the server cannot process it due to unsupported or invalid key values such as symbol, interval, width, or height. To avoid exceeding your maximum resolution, check the response header for your usage plan type.

Too Many Requests (429):

Your plan determines your maximum request limit and quota. To ensure you do not exceed these limits, adjust the frequency and amount of your requests accordingly.

Server Error (5xx):

If a server error occurs with any 5xx status code, wait a few seconds and try the request again. The API is based on Serverless architecture and should rarely go offline for any reason.

To address the issue of incomplete responses due to server timeouts, a new status code (504) has been added. This status code will return in cases where the server cannot process the request within the time limit.

Conclusion

I will continue to support version 1 alongside the new release for as long as possible and add minor features if necessary.

If you have any questions or feedback, please don’t hesitate to share them in the comments section below.

Happy Charting!

CHART-IMG

--

--

No responses yet