-
Feb 28th, 2022, 11:50 AM
#1
Thread Starter
Junior Member
How to convert Time in investing.com site
I am trying to figure out to get 1min data from the below link through web scraping but would like to know what is the root URL for the JSON object for 1min or 5min data. https://in.investing.com/indices/india-vix-chart or https://www.investing.com/indices/india-vix
, I can see candles data and multiple links -- in Network session --> XHR candle Datalink: https://sbcharts.investing.com/chart...0ebc_1day.json but here the data is completely different. I am using excel - power query to fetch the JSON directly.
Honestly - been asked in another forum, but hardly getting any leads. All I would like to know the json url of 1 min or 5min data.Any guidance is highly appreciated.
-
Mar 2nd, 2022, 11:35 PM
#2
Re: How to convert Time in investing.com site
It looks like when you visit the website, there is a GUID for the particular index you're searching for. In the case of india-vix, it is 8ac61a4e-91f8-bfe8-35d2-ddad727ce62c. What it then does is submit a GET request to https://sbcharts.investing.com/charts_xml/{{guid no spaces}}_1day.json, e.g. https://sbcharts.investing.com/chart...e62c_1day.json. From there, it provides you with the candle data as an array of arrays where the first item in the inner array is the timestamp in UTC and the second item is the price in India rupee (aka INR).
In fact, if I use a REST client like insomnia and make the same GET request, the response is returned (so there's not even a need for authentication).
I'm not sure about from Excel, but here is an example of getting the data using JavaScript:
Code:
window.addEventListener('load', () => {
// submit a GET request and get the JSON
fetch('https://sbcharts.investing.com/charts_xml/8ac61a4e91f8bfe835d2ddad727ce62c_1day.json')
.then(results => results.json())
.then(json => {
// get the candles
const candles = json.candles;
// get the <table> and <tbody>
const table = document.getElementById('india-vix');
const tableBody = table.querySelector('tbody');
// loop over the candles
for (let i = 0; i < candles.length; i++) {
// create a <tr> for each candle with a <td> for the date and value
const candle = candles[i];
const candleTr = document.createElement('tr');
const candleDate = new Date(candle[0]);
const candleIndexTd = document.createElement('td');
const candleDateTd = document.createElement('td');
const candleValueTd = document.createElement('td');
candleIndexTd.innerHTML = (i + 1);
candleDateTd.innerHTML = candleDate.toLocaleString();
candleValueTd.innerHTML = candle[1];
candleTr.append(candleIndexTd);
candleTr.append(candleDateTd);
candleTr.append(candleValueTd);
tableBody.append(candleTr);
}
})
.catch(() => alert('Something went wrong making the request.'));
}, false);
Fiddle: https://jsfiddle.net/0f8gL4tn/
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|