Current path: home/webdevt/cryptoimpot.fr/module/Application/src/Service/
?? Go up: /home/webdevt/cryptoimpot.fr/module/Application/src
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace Application\Service;
/**
* Description of CMCService
*
* @author jimmy
*/
class CryptocompareService {
public function getPriceByCode($code, $datetime) {
/*
tryConversion If set to false, it will try to get only direct trading values [ Default - true]
fsym REQUIRED The cryptocurrency symbol of interest [ Min length - 1] [ Max length - 10]
tsyms REQUIRED Comma separated cryptocurrency symbols list to convert into [ Min length - 1] [ Max length - 30]
ts The unix timestamp of interest
e The exchange to obtain data from (our aggregated average - CCCAGG - by default) [ Min length - 2] [ Max length - 30] [ Default - CCCAGG]
extraParams The name of your application (we recommend you send it) [ Min length - 1] [ Max length - 2000] [ Default - NotAvailable]
calculationType Type of average to calculate (Close - a Close of the day close price, MidHighLow - the average between the 24 H high and low, VolFVolT - the total volume to / the total volume from) [ Min length - 2] [ Max length - 30] [ Default - Close]
sign */
//$date = new DateTime($currentTime);
//$datestr = $date->format('Y-m-d');
//var_dump($currentTime);
$urlApi = 'https://min-api.cryptocompare.com/data/pricehistorical?';
// asset fsym
$urlApi .= 'fsym=' . $code;
$urlApi .= '&tsyms=EUR';
$urlApi .= '&ts=' . $dateTime->format('U');
$urlApi .= '&api_key=fd3aea02118639009c4a4de12b5f8a0f4619b08a814e04e9fa0aafc678127ea2';
// fetch data
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $urlApi);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$rawData = curl_exec($curl);
curl_close($curl);
// decode to array
$data = json_decode($rawData, true);
if (isset($data[$code])) {
return $data[$asset]['EUR'];
// //throw new Exception('Market value not found');
// echo $dateTime->format('Y-m-d');
// $price = 0;
}
// else {
// $price = $data[$asset]['EUR'];
// }
//
// return $price;
}
}