仅获取 Yahoo Historical 上 30 天的数据 API

Only Getting 30 Days of Data on Yahoo Historical API

我正在尝试访问 Yahoo api 的历史数据(使用 PHP/Mysql 实现),以 url 为例:

$url = http://ichart.finance.yahoo.com/table.csv?s=INTC&c=2014&f=2015&a=0&d=0&b=1&e=1&g=d&ignore=.csv

这是我用来访问它的代码:

$filesize = 2000;
$handle = fopen($url, "r");
$raw_quote_data = fread($handle, $filesize);
echo $raw_quote_data;
fclose($handle);

echo 语句用于错误检查,以确保我在将所有数据存储到数据库之前获取了所有数据。但是,被 returned 的 $raw_quote_data 只有输入时间范围内最后 30 天的数据。因为我输入的日期范围是2014年1月1日到2015年1月1日,所以应该是return365天的数据。那我做错了什么?其余数据去了哪里?

当然,我尝试的第一件事是更改文件大小,这对输出的影响为零。

您正在请求一个 15kb 的文件,但只读取了 2000 字节。 另请注意,当您手动从缓冲区读取时,所有数据可能尚未到达。这就是为什么 "it made no difference."

试试这个:

set_time_limit(0);
$file = @fopen($file_path,"rb");
while(!feof($file))
{
    print(@fread($file, 1024*8));
    ob_flush();
    flush();
}

有关详细信息,请参阅 this article

或者 file_get_contents 可能是更简单的方法。

改用file_get_contents()

$raw_quote_data =  file_get_contents($url);