[英]Get all exchange prices of a cryptocurrency from coinbase (PHP)
My project is to draw a line chart with chart.js from historical coinbase price data.
我的项目是从历史 coinbase 价格数据中使用 chart.js 绘制折线图。 The result should be similar to Googles crypto chart.
结果应该类似于谷歌的加密图表。 I allready have found a simple way to get the live prices of any cryptocurrency, but I don't know how to get the historical data.
我已经找到了一种简单的方法来获取任何加密货币的实时价格,但我不知道如何获取历史数据。 My project is written in PHP, you can see my live price grabber function below.
我的项目是用 PHP 编写的,您可以在下面看到我的实时价格抓取功能。
/**
* coinbase api call prices
*/
function api_call_price($from, $to) {
$from = (trim(strtoupper($from)));
$to = (trim(strtoupper($to)));
$url = 'curl -s -H "CB-VERSION: 2017-12-06" "https://api.coinbase.com/v2/prices/'.$from.'-'.$to.'/spot"';
$tmp = shell_exec($url);
$data = json_decode($tmp, true);
if ($data && $data['data'] && $data['data']['amount']) {
return (float)$data['data']['amount'];
}
return null;
}
// Usage: api_call_price("BTC", "EUR");
好的,我现在的解决方案是通过 cronjob 获取数据并将其存储为 JSON 字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.