Skip to content

Instantly share code, notes, and snippets.

@bigprof
Created April 16, 2014 10:29
Show Gist options
  • Save bigprof/10849285 to your computer and use it in GitHub Desktop.
Save bigprof/10849285 to your computer and use it in GitHub Desktop.
<?php
/* use this code as a guide for how to fetch bitcoin historical trade data from bitcoincharts, based on Bitstamp.net */
/* historical interval in hours */
define('AVERAGE_INTERVAL', 6);
$hist = file("http://api.bitcoincharts.com/v1/trades.csv?symbol=bitstampUSD&start=" . (time() - AVERAGE_INTERVAL * 3600));
if(!is_array($hist)) die("Unable to fetch data .. Try again later!");
$trades = array();
foreach($hist as $entry){
$trades[] = explode(',', trim($entry));
}
?><pre dir="ltr"><? print_r($trades); ?></pre><?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment