我正在尝试使用AlphaVantage API获取一些数据,并且我想将某只股票支付的所有股息存储在一个数组中。我现在只尝试保存股息,但将来我希望能将股息与特定日期关联起来。
用于检索数据的函数:
async function fetchTimeSeriesDailyAdjusted (ticker) { //Fetch function to get the daily close and the dividends
const apiTimeSeriesDailyAdjusted = `https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=${symbol}&apikey=${apiKey}`; //Lik of the API - update the symbol
try {
const response = await fetch(apiTimeSeriesDailyAdjusted);
const data = await response.json();
const historicalDividend = []; //Array of the dividends
for (let date in data['Time Series (Daily)']) { //This for should make the code go through all the JSON
historicalDividend = entry ['7. dividend amount']; //This should store the dividend while the for loop "goes"
}
console.log(historicalDividend); //Console log to see the dividend
return historicalDividend; //Value that the function must return
} catch (error) {
console.error('Error fetching apiTimeSeriesDailyAdjusted'); //Log of the error
}
}
这是我创建的函数,但正如我所看到的,可能你也看到了,它不起作用。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号