00000

$curl = curl_init();
$agent = ‘Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)’;

curl_setopt_array($curl, array(
CURLOPT_URL => “https://api.gdax.com/products”,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => “”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_USERAGENT => $agent,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => “GET”,
CURLOPT_HTTPHEADER => array(
“cache-control: no-cache”,
“postman-token: 86e8d4f7-802a-624d-f6e6-17e900f2b7b4”
),
));

$file = fopen(“contacts.csv”,”w”);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

$today = date(“Y-m-d”);
$twoDaysBefore = date(‘Y-m-d’, strtotime(‘-2 days’, strtotime($today)));

var_dump($today);
var_dump($twoDaysBefore);
//exit;

if ($err) {
echo “cURL Error #:” . $err;
} else {
$response = json_decode($response,true);
foreach ($response as $item){

echo (‘

‘.$item[‘id’].’

‘);
fputcsv($file,array($item[‘id’]));
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => “https://api.gdax.com/products/”.$item[‘id’].”/candles?start=”.$twoDaysBefore.”T00%3A00%3A00.00000Z&end=”.$today.”T23%3A59%3A00.00000Z&granularity=2000″,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => “”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_USERAGENT => $agent,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => “GET”,
CURLOPT_POSTFIELDS => “{\n\t\”granularity\”:60\n}”,
CURLOPT_HTTPHEADER => array(
“cache-control: no-cache”,
“content-type: application/json”,
“postman-token: f9a0b489-602b-58ed-6dbc-f49e8c3feeca”
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo “cURL Error #:” . $err;
} else {
// echo $response;
$response = json_decode($response,true);
foreach ($response as $item){
$row = $item[0].’,’.$item[1].’,’.$item[2].’,’.$item[3].’,’.$item[4].’,’.$item[5];
$item[0] = date(‘Y-m-d H:i:s’, $item[0]);
fputcsv($file,$item);
}
// exit;
// var_dump($response);
}
}