Thanks in advance for the help I am just learning for fun.
I have the following code i have written:
async function fetchRSI(date, tickr) {
try {
//console.log("trying....");
const response = await fetch('https://api.polygon.io/v1/indicators/rsi/' + tickr + '?timestamp=' + date + '×pan=day&adjusted=true&window=14&series_type=close&order=desc&apiKey=3t1MkRpyjZYfpTl6Yd1x7LXQIFX9iKqr', {
method: 'GET',
credentials: 'same-origin'
});
const exam = await response.json();
//console.log(exam);
return exam
} catch (error) {
console.error(error);
}
}
called via
RSI = await fetchRSI(formattedDate, tickr);
console.log(RSI);
This gives me an output
{
results: {
underlying: {
url: 'https://api.polygon.io/v2/aggs/ticker/AAPL/range/1/day/1640926800000/1647388800000?limit=75&sort=desc'
},
values: [ [Object] ]
},
status: 'OK',
request_id: 'c799a17224ada3de6036840068ffdbe0'
}
if called via
RSI = await fetchRSI(formattedDate, tickr);
console.log(RSI.results.values);
the output is
[ { timestamp: 1645074000000, value: 46.44735154180954 } ]
i am trying to access the value in this output however when i run:
RSI = await fetchRSI(formattedDate, tickr);
console.log(RSI.results.values.value);
or
RSI = await fetchRSI(formattedDate, tickr);
console.log(RSI.results.values[1]);
or
RSI = await fetchRSI(formattedDate, tickr);
console.log(RSI.results.values['value']);
all return undefined
I have tried many more methods of accessing all return undefined. preferably i would like to save the value to a variable.
there has to be something Im missing?
Thanks,