0

enter image description here My project is to draw a line chart with chart.js from historical coinbase price data. 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.

/**
 * 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");
Game Unity
  • 125
  • 10
  • What values do you put in `$from` and `$to`? I am trying to get historic minutely values , but can only get the price for a day. – TenG May 06 '21 at 10:41

1 Answers1

0

OK, my solution is now to grab the data via cronjob and store it as a JSON string.

Game Unity
  • 125
  • 10