我对 Alpha Vantage API 进行了这个非常简单的 PHP 调用,以用 NASDAQ 股票价格填充表格(或列表):
<?php
function get_price($commodity = "")
{
$url = 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=' . $commodity . '&outputsize=full&apikey=myKey';
$obj = json_decode(file_get_contents($url), true);
$date = $obj['Meta Data']['3. Last Refreshed'];
$result = $obj['Time Series (Daily)']['2018-03-23']['4. close'];
$rd_result = round($result, 2);
echo $result;
}
?>
<?php get_price("XOM");
get_price("AAPL");
get_price("MSFT");
get_price("CVX");
get_price("CAT");
get_price("BA");
?>
它有效,但速度太慢了。它可能需要超过 30 秒。在 Alpha Vantage 的 json 文件在几分之一秒内加载时加载。
有谁知道我哪里错了?