├── .gitignore ├── README.md ├── composer.json ├── src ├── CryptocompareApi.php ├── Historical.php ├── InvalidRequest.php ├── Market.php ├── News.php ├── Other.php ├── Price.php ├── Social.php ├── Streaming.php └── Toplists.php ├── test.php └── tests └── coinTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | .idea/* 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cryptocompare-api-php-wrapper 2 | 3 | 4 | # 0.) untested 5 | I just started rewriting it to match the documentation that can be found on 6 | 7 | https://min-api.cryptocompare.com/documentation 8 | 9 | 10 | There are some new endpoints available, some will get deprecated soon. I cleaned this up. Did not test yet. 11 | Added base for phpunit based unit tests. 12 | 13 | # 1.) Installation 14 | the easiest way to get started is to use composer to retrieve the files. 15 | 16 | ### prepare composer inside your project folder 17 | The following commands will download the pre compiled composer.phar, which will download the project for us. 18 | ```bash 19 | cd ~/Projectfolder 20 | wget https://getcomposer.org/composer.phar 21 | ``` 22 | 23 | ### create composer.json or add to your existing composer.json 24 | #### minimal composer.json 25 | ```composer 26 | { 27 | "require": { 28 | "loeken/cryptocompare-api-php-wrapper": "dev-master" 29 | } 30 | } 31 | ``` 32 | #### single line to add composer.json 33 | ```composer 34 | "loeken/cryptocompare-api-php-wrapper": "dev-master", 35 | ``` 36 | ### make composer update from github/packagist 37 | ```bash 38 | php composer.phar update 39 | ``` 40 | 41 | ### short explanation of composer 42 | composer retrieves the last version of the code from github and downloads it to the vendor/* folder inside your project. It will also generate a autoload.php which you can then load inside your php code, this will then load all classes included in this project. This is also usefull if you want to update our api wrapper to the last version, simply run the composer update command again. 43 | 44 | ### including our classes in your files 45 | if your .php script file is in the same folder as the vendor folder, use the following line, else adjust the path. 46 | ``` 47 | getSingleSymbolPriceEndpoint("true","BTC","USD","CCCAGG","false"); 60 | print_r($example1); 61 | 62 | ?> 63 | ``` 64 | 65 | 66 | ### apiKey 67 | thanks to a user submission we now have support for apiKeys you can simply set your apiKey after creating your object 68 | ```php 69 | setApiKey("yourapikeyhere"); 75 | $example1 = $cryptocomparePrice->getSingleSymbolPriceEndpoint("true","BTC","USD","CCCAGG","false"); 76 | print_r($example1); 77 | 78 | ?> 79 | ``` 80 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "loeken/cryptocompare-api-php-wrapper", 3 | "description": "Php wrapper class based on guzzle to query the cryptocompare.com api", 4 | "type": "library", 5 | "require": { 6 | "guzzlehttp/guzzle": "6.3" 7 | }, 8 | "require-dev": { 9 | "phpunit/phpunit": "^7" 10 | }, 11 | "license": "BSD-3-Clause", 12 | "authors": [{ 13 | "name": "Lukas Wenning", 14 | "email": "lwenning@cryptocompare.com" 15 | }], 16 | "minimum-stability": "dev", 17 | "autoload": { 18 | "psr-4": { 19 | "Cryptocompare\\": "src/" 20 | }, 21 | "classmap": [ 22 | "src/" 23 | ] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CryptocompareApi.php: -------------------------------------------------------------------------------- 1 | not recommended in production enviroment 32 | */ 33 | public $debug = false; 34 | 35 | 36 | // do not edit bellow unless you know what you are doing 37 | 38 | /** 39 | * @var string apiKey for your application from https://min-api.cryptocompare.com 40 | */ 41 | private $apiKey; 42 | 43 | /** 44 | * @var 45 | */ 46 | protected $httpClient; 47 | 48 | /** 49 | * CryptocompareApi constructor. 50 | * 51 | * @param string $apiKey 52 | * @param bool $debug 53 | */ 54 | function __construct($apiKey,$debug = false) 55 | { 56 | $this->setApiKey($apiKey); 57 | $this->setDebug($debug); 58 | 59 | $this->httpClient = new Client(['verify' => false]); 60 | } 61 | 62 | /** 63 | * @param string $type 64 | * @param string $action 65 | * @param array $options 66 | * 67 | * @return mixed 68 | * @throws GuzzleExceptionAlias 69 | * @throws InvalidRequest 70 | */ 71 | public function getRequest($type, $action, $options = []) 72 | { 73 | $apiEndpoint = $this->getApiEndpoint($type, $action); 74 | 75 | if ($apiEndpoint === null) { 76 | throw new \Exception('Invalid type'); 77 | } 78 | 79 | $result = $this->httpClient->request('GET', $apiEndpoint, [ 80 | "query" => $options, 81 | 'headers' => [ 82 | 'authorization' => 'Apikey ' . $this->getApiKey() 83 | ] 84 | ]); 85 | 86 | $statusCode = $result->getStatusCode(); 87 | 88 | if ($statusCode !== 200) { 89 | throw new InvalidRequest('Request is invalid', $statusCode); 90 | } 91 | 92 | $body = $result->getBody()->getContents(); 93 | return json_decode($body); 94 | } 95 | 96 | /** 97 | * @param array $input - an array of strings ( currencies ) 98 | * @return string - "EUR,USD,BTC" 99 | */ 100 | public function arrayToCommaSeperatedString ($input = array() ) { 101 | $output = implode(",", $input); 102 | return $output; 103 | } 104 | 105 | /** 106 | * @return string 107 | */ 108 | public function getApiKey() { 109 | return $this->apiKey; 110 | } 111 | 112 | /** 113 | * @param string $apiKey 114 | */ 115 | public function setApiKey($apiKey) { 116 | $this->apiKey = $apiKey; 117 | } 118 | 119 | /** 120 | * @param $debug 121 | */ 122 | public function setDebug($debug) { 123 | $this->debug = $debug; 124 | } 125 | 126 | /** 127 | * Generates the endpoint uri 128 | * 129 | * @param string $type 130 | * @param string $action 131 | * 132 | * @return string|null 133 | */ 134 | protected function getApiEndpoint($type, $action) 135 | { 136 | if ($type === self::PUB) { 137 | return self::PUBLIC_ENDPOINT . $action; 138 | } else if ($type === self::PRIV) { 139 | return self::PRIVATE_ENDPOINT . $action; 140 | } 141 | 142 | return null; 143 | } 144 | 145 | /** 146 | * logs the message if debug is enabled 147 | * 148 | * @param string $message 149 | */ 150 | protected function log($message) 151 | { 152 | if ($this->debug === true ) { 153 | echo $message; 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/Historical.php: -------------------------------------------------------------------------------- 1 | appplicationName; 32 | 33 | $params = array( 34 | "tryConversion" => $tryConversion, 35 | "fsym" => $fsym, 36 | "tsym" => $tsym, 37 | "e" => $e, 38 | "extraParams" => $extraParams, 39 | "sign" => $sign, 40 | "aggregate" => $aggregate, 41 | "limit" => $limit, 42 | "toTs" => $toTs, 43 | ); 44 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/histoday", $params); 45 | return $r; 46 | } 47 | 48 | /** 49 | * @param string $tryConversion 50 | * @param string $fsym 51 | * @param string $tsym 52 | * @param string $e 53 | * @param string $sign 54 | * @param int $aggregate 55 | * @param int $limit 56 | * @param null $toTs 57 | * @return mixed 58 | * @throws InvalidRequest 59 | * @throws \GuzzleHttp\Exception\GuzzleException 60 | */ 61 | public function getDataHistohour($tryConversion = "true", $fsym = "BTC", $tsym = "EUR", $e = "CCCAGG", $sign = "false", $aggregate = 1, $limit = 1440, $toTs = NULL) { 62 | $extraParams = $this->appplicationName; 63 | 64 | $params = array( 65 | "tryConversion" => $tryConversion, 66 | "fsym" => $fsym, 67 | "tsym" => $tsym, 68 | "e" => $e, 69 | "extraParams" => $extraParams, 70 | "sign" => $sign, 71 | "aggregate" => $aggregate, 72 | "limit" => $limit, 73 | "toTs" => $toTs, 74 | ); 75 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/histohour", $params); 76 | return $r; 77 | } 78 | 79 | /** 80 | * @param string $tryConversion 81 | * @param string $fsym 82 | * @param string $tsym 83 | * @param string $e 84 | * @param string $sign 85 | * @param int $aggregate 86 | * @param int $limit 87 | * @param null $toTs 88 | * @return mixed 89 | * @throws InvalidRequest 90 | * @throws \GuzzleHttp\Exception\GuzzleException 91 | */ 92 | public function getHistoMinute($tryConversion = "true", $fsym = "BTC", $tsym = "EUR", $e = "CCCAGG", $sign = "false", $aggregate = 1, $limit = 1440, $toTs = NULL) { 93 | $extraParams = $this->appplicationName; 94 | 95 | $params = array( 96 | "tryConversion" => $tryConversion, 97 | "fsym" => $fsym, 98 | "tsym" => $tsym, 99 | "e" => $e, 100 | "extraParams" => $extraParams, 101 | "sign" => $sign, 102 | "aggregate" => $aggregate, 103 | "limit" => $limit, 104 | "toTs" => $toTs, 105 | ); 106 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/histominute", $params); 107 | return $r; 108 | } 109 | 110 | /** 111 | * @param string $tryConversion 112 | * @param string $fsym 113 | * @param array $tsyms 114 | * @param string $ts 115 | * @param string $e 116 | * @param string $sign 117 | * @return mixed 118 | * @throws InvalidRequest 119 | * @throws \GuzzleHttp\Exception\GuzzleException 120 | */ 121 | public function getDataPriceHistorical($tryConversion = "true", $fsym = "BTC", $tsyms = array("USD","EUR"), $ts = "1507469305", $e = "CCCAGG", $sign = "false") { 122 | $_tsyms = ""; 123 | $extraParams = $this->appplicationName; 124 | foreach ($tsyms as $i => $tsym ) { 125 | if ($i == 0 ) { 126 | $_tsyms = $tsym; 127 | } else { 128 | $_tsyms = $_tsyms . "," . $tsym; 129 | } 130 | } 131 | $params = array( 132 | "tryConversion" => $tryConversion, 133 | "fsym" => $fsym, 134 | "tsyms" => $_tsyms, 135 | "e" => $e, 136 | "extraParams" => $extraParams, 137 | "sign" => $sign, 138 | "ts" => $ts, 139 | ); 140 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/pricehistorical", $params); 141 | return $r; 142 | } 143 | 144 | /** 145 | * @param string $tryConversion 146 | * @param string $fsym 147 | * @param string $tsym 148 | * @param string $e 149 | * @param string $avgType 150 | * @param int $UTCHourDiff 151 | * @param string $toTs 152 | * @param string $sign 153 | * @return mixed 154 | * @throws InvalidRequest 155 | * @throws \GuzzleHttp\Exception\GuzzleException 156 | */ 157 | public function getDataPriceHistoricalDayAvg($tryConversion = "true", $fsym = "BTC", $tsym = "EUR", $e = "CCCAGG", $avgType = "HourVWAP", $UTCHourDiff = 0, $toTs = "1487116800", $sign = "false") { 158 | 159 | $extraParams = $this->appplicationName;; 160 | 161 | $params = array( 162 | "tryConversion" => $tryConversion, 163 | "avgType" => $avgType, 164 | "UTCHourDiff" => $UTCHourDiff, 165 | "toTs" => $toTs, 166 | "fsym" => $fsym, 167 | "tsym" => $tsym, 168 | "e" => $e, 169 | "extraParams" => $extraParams, 170 | "sign" => $sign 171 | ); 172 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/dayAvg", $params); 173 | return $r; 174 | } 175 | 176 | /** 177 | * @param string $tsym 178 | * @param string $e 179 | * @param string $aggregate 180 | * @param string $aggregatePredictableTimePeriods 181 | * @param string $sign 182 | * @param int $limit 183 | * @param null $toTs 184 | * @return mixed 185 | * @throws InvalidRequest 186 | * @throws \GuzzleHttp\Exception\GuzzleException 187 | */ 188 | public function getDataExchangeHistoday($tsym = "EUR", $e = "CCCAGG", $aggregate = "1", $aggregatePredictableTimePeriods = "true", $sign = "false", $limit = 1440, $toTs = NULL) { 189 | $extraParams = $this->appplicationName; 190 | 191 | $params = array( 192 | "aggregatePredictableTimePeriods" => $aggregatePredictableTimePeriods, 193 | "tsym" => $tsym, 194 | "e" => $e, 195 | "extraParams" => $extraParams, 196 | "sign" => $sign, 197 | "aggregate" => $aggregate, 198 | "limit" => $limit, 199 | "toTs" => $toTs, 200 | ); 201 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/exchange/histoday", $params); 202 | return $r; 203 | } 204 | 205 | /** 206 | * @param string $tsym 207 | * @param string $e 208 | * @param int $aggregate 209 | * @param string $aggregatePredictableTimePeriods 210 | * @param string $sign 211 | * @param int $limit 212 | * @param null $toTs 213 | * @return mixed 214 | * @throws InvalidRequest 215 | * @throws \GuzzleHttp\Exception\GuzzleException 216 | */ 217 | public function getDataExchangeHistohour($tsym = "EUR", $e = "CCCAGG", $aggregate = 1, $aggregatePredictableTimePeriods = "true", $sign = "false", $limit = 1440, $toTs = NULL) { 218 | $extraParams = $this->appplicationName; 219 | 220 | $params = array( 221 | "aggregatePredictableTimePeriods" => $aggregatePredictableTimePeriods, 222 | "tsym" => $tsym, 223 | "e" => $e, 224 | "extraParams" => $extraParams, 225 | "sign" => $sign, 226 | "aggregate" => $aggregate, 227 | "limit" => $limit, 228 | "toTs" => $toTs, 229 | ); 230 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/exchange/histohour", $params); 231 | return $r; 232 | } 233 | } -------------------------------------------------------------------------------- /src/InvalidRequest.php: -------------------------------------------------------------------------------- 1 | $fsym, 24 | "limit" => $limit, 25 | "sign" => $sign, 26 | ); 27 | $pairs = $this->getRequest(CryptocompareApi::PUB,"/data/top/pairs", $params); 28 | return $pairs; 29 | } 30 | 31 | /** 32 | * @param string $fsym 33 | * @param string $tsym 34 | * @param int $limit 35 | * @param bool $sign 36 | * @return mixed 37 | * @throws InvalidRequest 38 | * @throws \GuzzleHttp\Exception\GuzzleException 39 | */ 40 | public function getTopExchanges($fsym = "BTC", $tsym = "EUR", $limit = 5, $sign = false) { 41 | 42 | $extraParams = $this->appplicationName;; 43 | 44 | $params = array( 45 | "limit" => $limit, 46 | "fsym" => $fsym, 47 | "tsym" => $tsym, 48 | "extraParams" => $extraParams, 49 | "sign" => $sign 50 | ); 51 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/top/exchanges", $params); 52 | return $r; 53 | } 54 | 55 | /** 56 | * @param string $tsym 57 | * @param int $limit 58 | * @param bool $sign 59 | * @return mixed 60 | * @throws InvalidRequest 61 | * @throws \GuzzleHttp\Exception\GuzzleException 62 | */ 63 | public function getTopVolumes($tsym = "EUR", $limit = 20, $sign = false) { 64 | 65 | $extraParams = $this->appplicationName;; 66 | 67 | $params = array( 68 | "limit" => $limit, 69 | "tsym" => $tsym, 70 | "extraParams" => $extraParams, 71 | "sign" => $sign 72 | ); 73 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/top/volumes", $params); 74 | return $r; 75 | } 76 | 77 | /** 78 | * @param bool $sign 79 | * @return mixed 80 | * @throws InvalidRequest 81 | * @throws \GuzzleHttp\Exception\GuzzleException 82 | */ 83 | public function getList($sign = false) { 84 | 85 | $extraParams = $this->appplicationName;; 86 | 87 | $params = array( 88 | "extraParams" => $extraParams, 89 | "sign" => $sign 90 | ); 91 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/all/exchanges", $params); 92 | return $r; 93 | } 94 | } -------------------------------------------------------------------------------- /src/News.php: -------------------------------------------------------------------------------- 1 | appplicationName; 29 | 30 | $params = array( 31 | "feeds" => $feeds, 32 | "limit" => $limit, 33 | "extraParams" => $extraParams, 34 | "categories" => $categories, 35 | "excludeCategories" => $excludeCategories, 36 | "lang" => $lang, 37 | "lTs" => $lTs, 38 | "sortOrder" => $sortOrder, 39 | "sign" => $sign, 40 | ); 41 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/v2/news/", $params); 42 | return $r; 43 | } 44 | 45 | /** 46 | * @param bool $sign 47 | * @return mixed 48 | * @throws InvalidRequest 49 | * @throws \GuzzleHttp\Exception\GuzzleException 50 | */ 51 | public function getListNewsFeedsEndpoint( $sign= false ) { 52 | $extraParams = $this->appplicationName; 53 | $params = array( 54 | "extraParams" => $extraParams, 55 | "sign" => $sign, 56 | ); 57 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/news/feeds", $params); 58 | return $r; 59 | } 60 | 61 | /** 62 | * @param bool $sign 63 | * @return mixed 64 | * @throws InvalidRequest 65 | * @throws \GuzzleHttp\Exception\GuzzleException 66 | */ 67 | public function getNewsArticleCategoriesEndpoint( $sign= false ) { 68 | $extraParams = $this->appplicationName; 69 | $params = array( 70 | "extraParams" => $extraParams, 71 | "sign" => $sign, 72 | ); 73 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/news/categories", $params); 74 | return $r; 75 | } 76 | 77 | /** 78 | * @param bool $sign 79 | * @return mixed 80 | * @throws InvalidRequest 81 | * @throws \GuzzleHttp\Exception\GuzzleException 82 | */ 83 | public function getNewsFeedAndCategoriesEndpoint( $sign= false ) { 84 | $extraParams = $this->appplicationName; 85 | $params = array( 86 | "extraParams" => $extraParams, 87 | "sign" => $sign, 88 | ); 89 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/news/feedsandcategories", $params); 90 | return $r; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Other.php: -------------------------------------------------------------------------------- 1 | getRequest(CryptocompareApi::PUB, "/stats/rate/limit"); 21 | return $limits; 22 | } 23 | 24 | 25 | /** 26 | * @param bool $sign 27 | * @return mixed 28 | * @throws InvalidRequest 29 | * @throws \GuzzleHttp\Exception\GuzzleException 30 | */ 31 | public function getAllExchangesV2Endpoint($sign = false ) { 32 | 33 | $params = array( 34 | "sign" => $sign, 35 | ); 36 | $exchanges = $this->getRequest(CryptocompareApi::PUB, "/data/v2/all/exchanges", $params); 37 | return $exchanges; 38 | } 39 | 40 | /** 41 | * @param bool $sign 42 | * @return mixed 43 | * @throws InvalidRequest 44 | * @throws \GuzzleHttp\Exception\GuzzleException 45 | */ 46 | public function getIncludedexchanges($sign = false ) { 47 | 48 | $params = array( 49 | "sign" => $sign, 50 | ); 51 | $exchanges = $this->getRequest(CryptocompareApi::PUB, "/data/all/includedexchanges", $params); 52 | return $exchanges; 53 | } 54 | 55 | /** 56 | * @param string $sign 57 | * @return mixed 58 | * @throws InvalidRequest 59 | * @throws \GuzzleHttp\Exception\GuzzleException 60 | */ 61 | public function getAllCoinsWithContentEndpoint($sign = "false") { 62 | $extraParams = $this->appplicationName; 63 | $params = array( 64 | "extraParams" => $extraParams, 65 | "sign" => $sign 66 | ); 67 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/all/coinlist", $params); 68 | return $r; 69 | } 70 | 71 | /** 72 | * @param string $sign 73 | * @return mixed 74 | * @throws InvalidRequest 75 | * @throws \GuzzleHttp\Exception\GuzzleException 76 | */ 77 | public function getAllExchangesStaticInfoEndpoint($sign = "false") { 78 | $extraParams = $this->appplicationName; 79 | $params = array( 80 | "extraParams" => $extraParams, 81 | "sign" => $sign 82 | ); 83 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/exchanges/general", $params); 84 | return $r; 85 | } 86 | 87 | /** 88 | * @param string $sign 89 | * @return mixed 90 | * @throws InvalidRequest 91 | * @throws \GuzzleHttp\Exception\GuzzleException 92 | */ 93 | public function getAllWalletsStaticInfoEndpoint($sign = "false") { 94 | $extraParams = $this->appplicationName; 95 | $params = array( 96 | "extraParams" => $extraParams, 97 | "sign" => $sign 98 | ); 99 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/exchanges/general", $params); 100 | return $r; 101 | } 102 | 103 | /** 104 | * @param string $sign 105 | * @return mixed 106 | * @throws InvalidRequest 107 | * @throws \GuzzleHttp\Exception\GuzzleException 108 | */ 109 | public function getAllCardsStaticInfoEndpoint($sign = "false") { 110 | $extraParams = $this->appplicationName; 111 | $params = array( 112 | "extraParams" => $extraParams, 113 | "sign" => $sign 114 | ); 115 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/cards/general", $params); 116 | return $r; 117 | } 118 | 119 | /** 120 | * @param string $sign 121 | * @return mixed 122 | * @throws InvalidRequest 123 | * @throws \GuzzleHttp\Exception\GuzzleException 124 | */ 125 | public function getAllMiningContractsStaticInfoEndpoint($sign = "false") { 126 | $extraParams = $this->appplicationName; 127 | $params = array( 128 | "extraParams" => $extraParams, 129 | "sign" => $sign 130 | ); 131 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/mining/contracts/general", $params); 132 | return $r; 133 | } 134 | 135 | /** 136 | * @param string $sign 137 | * @return mixed 138 | * @throws InvalidRequest 139 | * @throws \GuzzleHttp\Exception\GuzzleException 140 | */ 141 | public function getAllMiningEquipmentStaticInfoEndpoint($sign = "false") { 142 | $extraParams = $this->appplicationName; 143 | $params = array( 144 | "extraParams" => $extraParams, 145 | "sign" => $sign 146 | ); 147 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/mining/equipment/general", $params); 148 | return $r; 149 | } 150 | 151 | /** 152 | * @param string $sign 153 | * @return mixed 154 | * @throws InvalidRequest 155 | * @throws \GuzzleHttp\Exception\GuzzleException 156 | */ 157 | public function getAllMiningPoolsStaticInfoEndpoint($sign = "false") { 158 | $extraParams = $this->appplicationName; 159 | $params = array( 160 | "extraParams" => $extraParams, 161 | "sign" => $sign 162 | ); 163 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/mining/pools/general", $params); 164 | return $r; 165 | } 166 | } -------------------------------------------------------------------------------- /src/Price.php: -------------------------------------------------------------------------------- 1 | appplicationName;; 26 | $params = array( 27 | "tryConversion" => $tryConversion, 28 | "fsym" => $fsym, 29 | "tsyms" => $tsyms, 30 | "e" => $e, 31 | "extraParams" => $extraParams, 32 | "sign" => $sign 33 | ); 34 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/price", $params); 35 | return $r; 36 | } 37 | 38 | /** 39 | * @param string $tryConversion 40 | * @param array $fsyms 41 | * @param array $tsyms 42 | * @param string $e 43 | * @param bool $sign 44 | * @return mixed 45 | * @throws InvalidRequest 46 | * @throws \GuzzleHttp\Exception\GuzzleException 47 | */ 48 | public function getMultipleSymbolsPriceEndpoint($tryConversion = "true", $fsyms = array("BTC", "ETH"), $tsyms = array("USD", "EUR"), $e = "CCCAGG", $sign = false) 49 | { 50 | $_tsyms = $this->arrayToCommaSeperatedString($tsyms); 51 | $_fsyms = $this->arrayToCommaSeperatedString($fsyms); 52 | $extraParams = $this->appplicationName;; 53 | 54 | $params = array( 55 | "tryConversion" => $tryConversion, 56 | "fsyms" => $_fsyms, 57 | "tsyms" => $_tsyms, 58 | "e" => $e, 59 | "extraParams" => $extraParams, 60 | "sign" => $sign 61 | ); 62 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/pricemulti", $params); 63 | return $r; 64 | } 65 | 66 | 67 | /** 68 | * @param string $tryConversion 69 | * @param array $fsyms 70 | * @param array $tsyms 71 | * @param string $e 72 | * @param bool $sign 73 | * @return mixed 74 | * @throws InvalidRequest 75 | * @throws \GuzzleHttp\Exception\GuzzleException 76 | */ 77 | public function getMultipleSymbolsFullPriceEndpoint($tryConversion = "true", $fsyms = array("BTC", "ETH"), $tsyms = array("USD", "EUR"), $e = "CCCAGG", $sign = false) 78 | { 79 | $_tsyms = $this->arrayToCommaSeperatedString($tsyms); 80 | $_fsyms = $this->arrayToCommaSeperatedString($fsyms); 81 | $extraParams = $this->appplicationName;; 82 | 83 | $params = array( 84 | "tryConversion" => $tryConversion, 85 | "fsyms" => $_fsyms, 86 | "tsyms" => $_tsyms, 87 | "e" => $e, 88 | "extraParams" => $extraParams, 89 | "sign" => $sign 90 | ); 91 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/pricemultifull", $params); 92 | return $r; 93 | } 94 | 95 | /** 96 | * @param string $tryConversion 97 | * @param string $fsym 98 | * @param string $tsym 99 | * @param string $e 100 | * @param bool $sign 101 | * @return mixed 102 | * @throws InvalidRequest 103 | * @throws \GuzzleHttp\Exception\GuzzleException 104 | */ 105 | public function getGenerateAvg($tryConversion = "true", $fsym = "BTC", $tsym = "EUR", $e = "Coinbase,Kraken", $sign = false) 106 | { 107 | 108 | $extraParams = $this->appplicationName;; 109 | 110 | $params = array( 111 | "tryConversion" => $tryConversion, 112 | "fsym" => $fsym, 113 | "tsym" => $tsym, 114 | "e" => $e, 115 | "extraParams" => $extraParams, 116 | "sign" => $sign 117 | ); 118 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/generateAvg", $params); 119 | return $r; 120 | } 121 | 122 | /** 123 | * @param string $tryConversion 124 | * @param array $fsyms 125 | * @param string $tsym 126 | * @param string $e 127 | * @param bool $sign 128 | * @return mixed 129 | * @throws InvalidRequest 130 | * @throws \GuzzleHttp\Exception\GuzzleException 131 | */ 132 | public function getSubsWatchlist($tryConversion = "true", $fsyms = array("BTC", "ETH"), $tsym = "EUR", $e = "CCCAGG", $sign = false) 133 | { 134 | 135 | $_fsyms = $this->arrayToCommaSeperatedString($fsyms); 136 | $extraParams = $this->appplicationName;; 137 | 138 | $params = array( 139 | "tryConversion" => $tryConversion, 140 | "fsyms" => $_fsyms, 141 | "tsym" => $tsym, 142 | "e" => $e, 143 | "extraParams" => $extraParams, 144 | "sign" => $sign 145 | ); 146 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/subsWatchlist", $params); 147 | return $r; 148 | } 149 | 150 | /** 151 | * @param string $tryConversion 152 | * @param string $fsym 153 | * @param array $tsyms 154 | * @param string $e 155 | * @param bool $sign 156 | * @return mixed 157 | * @throws InvalidRequest 158 | * @throws \GuzzleHttp\Exception\GuzzleException 159 | */ 160 | public function getSubs($tryConversion = "true", $fsym = "BTC", $tsyms = array("USD", "EUR"), $e = "CCCAGG", $sign = false) 161 | { 162 | 163 | $_tsyms = $this->arrayToCommaSeperatedString($tsyms); 164 | $extraParams = $this->appplicationName;; 165 | 166 | $params = array( 167 | "tryConversion" => $tryConversion, 168 | "fsym" => $fsym, 169 | "tsyms" => $_tsyms, 170 | "e" => $e, 171 | "extraParams" => $extraParams, 172 | "sign" => $sign 173 | ); 174 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/subs", $params); 175 | return $r; 176 | } 177 | } -------------------------------------------------------------------------------- /src/Social.php: -------------------------------------------------------------------------------- 1 | appplicationName; 27 | 28 | $params = array( 29 | "coinId" => $coinId, 30 | "aggregate" => $aggregate, 31 | "limit" => $limit, 32 | "toTs" => $toTs, 33 | "aggregatePredictableTimePeriods" => $aggregatePredictableTimePeriods, 34 | "extraParams" => $extraParams, 35 | "sign" => $sign 36 | ); 37 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/social/histo/day", $params); 38 | return $r; 39 | } 40 | 41 | /** 42 | * @param bool $coinId 43 | * @param int $aggregate 44 | * @param bool $aggregatePredictableTimePeriods 45 | * @param string $toTs 46 | * @param bool $sign 47 | * @param int $limit 48 | * @return mixed 49 | * @throws InvalidRequest 50 | * @throws \GuzzleHttp\Exception\GuzzleException 51 | */ 52 | public function getHistoricalHourSocialStats($coinId = false, $aggregate = 0, $aggregatePredictableTimePeriods = true, $toTs = "1507469305", $sign = false, $limit = 1440) { 53 | $extraParams = $this->appplicationName; 54 | 55 | $params = array( 56 | "coinId" => $coinId, 57 | "aggregate" => $aggregate, 58 | "limit" => $limit, 59 | "toTs" => $toTs, 60 | "aggregatePredictableTimePeriods" => $aggregatePredictableTimePeriods, 61 | "extraParams" => $extraParams, 62 | "sign" => $sign 63 | ); 64 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/social/histo/day", $params); 65 | return $r; 66 | } 67 | } -------------------------------------------------------------------------------- /src/Streaming.php: -------------------------------------------------------------------------------- 1 | appplicationName; 26 | $params = array( 27 | "extraParams" => $extraParams, 28 | "sign" => $sign 29 | ); 30 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/top/totalvol", $params); 31 | return $r; 32 | } 33 | } -------------------------------------------------------------------------------- /src/Toplists.php: -------------------------------------------------------------------------------- 1 | appplicationName; 25 | $params = array( 26 | "page" => $page, 27 | "limit" => $limit, 28 | "extraParams" => $extraParams, 29 | "sign" => $sign, 30 | "tsym" => $tsym, 31 | ); 32 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/top/totalvolfull", $params); 33 | return $r; 34 | } 35 | 36 | /** 37 | * @param string $tsym 38 | * @param int $page 39 | * @param bool $sign 40 | * @param int $limit 41 | * @return mixed 42 | * @throws InvalidRequest 43 | * @throws \GuzzleHttp\Exception\GuzzleException 44 | */ 45 | 46 | public function getTopTotalMktCapEndpointFull($tsym = "EUR", $page = 0, $sign = false, $limit = 1440) { 47 | $extraParams = $this->appplicationName; 48 | $params = array( 49 | "page" => $page, 50 | "limit" => $limit, 51 | "extraParams" => $extraParams, 52 | "sign" => $sign, 53 | "tsym" => $tsym, 54 | ); 55 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/top/mktcapfull", $params); 56 | return $r; 57 | } 58 | 59 | /** 60 | * @param string $fsym 61 | * @param string $tsym 62 | * @param int $page 63 | * @param bool $sign 64 | * @param int $limit 65 | * @return mixed 66 | * @throws InvalidRequest 67 | * @throws \GuzzleHttp\Exception\GuzzleException 68 | */ 69 | public function getTopExchangesEndpoint($fsym = "BTC", $tsym = "EUR", $page = 0, $sign = false, $limit = 1440) { 70 | $extraParams = $this->appplicationName; 71 | $params = array( 72 | "fsym" => $fsym, 73 | "tsym" => $tsym, 74 | "page" => $page, 75 | "limit" => $limit, 76 | "extraParams" => $extraParams, 77 | "sign" => $sign, 78 | ); 79 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/top/exchanges", $params); 80 | return $r; 81 | } 82 | 83 | /** 84 | * @param string $fsym 85 | * @param string $tsym 86 | * @param int $page 87 | * @param bool $sign 88 | * @param int $limit 89 | * @return mixed 90 | * @throws InvalidRequest 91 | * @throws \GuzzleHttp\Exception\GuzzleException 92 | */ 93 | public function getTopExchangesFullEndpoint($fsym = "BTC", $tsym = "EUR", $page = 0, $sign = false, $limit = 1440) { 94 | $extraParams = $this->appplicationName; 95 | $params = array( 96 | "fsym" => $fsym, 97 | "tsym" => $tsym, 98 | "page" => $page, 99 | "limit" => $limit, 100 | "extraParams" => $extraParams, 101 | "sign" => $sign 102 | ); 103 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/top/exchanges/full", $params); 104 | return $r; 105 | } 106 | 107 | /** 108 | * @param string $fsym 109 | * @param int $page 110 | * @param bool $sign 111 | * @param int $limit 112 | * @return mixed 113 | * @throws InvalidRequest 114 | * @throws \GuzzleHttp\Exception\GuzzleException 115 | */ 116 | public function getTopExchangesVolumes($fsym = "BTC", $page = 0, $sign = false, $limit = 1440) { 117 | $extraParams = $this->appplicationName; 118 | 119 | $params = array( 120 | "fsym" => $fsym, 121 | "page" => $page, 122 | "limit" => $limit, 123 | "extraParams" => $extraParams, 124 | "sign" => $sign 125 | ); 126 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/top/volumes", $params); 127 | return $r; 128 | } 129 | 130 | /** 131 | * @param string $fsym 132 | * @param int $page 133 | * @param bool $sign 134 | * @param int $limit 135 | * @return mixed 136 | * @throws InvalidRequest 137 | * @throws \GuzzleHttp\Exception\GuzzleException 138 | */ 139 | public function getTopPairsEndpoint($fsym = "BTC", $page = 0, $sign = false, $limit = 1440) { 140 | $extraParams = $this->appplicationName; 141 | 142 | $params = array( 143 | "fsym" => $fsym, 144 | "page" => $page, 145 | "limit" => $limit, 146 | "extraParams" => $extraParams, 147 | "sign" => $sign 148 | ); 149 | $r = $this->getRequest(CryptocompareApi::PUB, "/data/top/volumes", $params); 150 | return $r; 151 | } 152 | } -------------------------------------------------------------------------------- /test.php: -------------------------------------------------------------------------------- 1 | getSingleSymbolPriceEndpoint("true", "BTC", "USD", "CCCAGG", "false"); 12 | 13 | print_r($example1); 14 | } catch (Exception $exception ) { 15 | print_r($exception->getTraceAsString()); 16 | } 17 | ?> 18 | -------------------------------------------------------------------------------- /tests/coinTest.php: -------------------------------------------------------------------------------- 1 | testingApiKey); 18 | $data = $historical->getDataExchangeHistoday(); 19 | 20 | $c = count((array) $data->Data); 21 | $this->assertGreaterThan( 22 | 1, 23 | $c, 24 | "Found more then 1 items returned" 25 | ); 26 | } 27 | 28 | public function testGetDataExchangeHistohour() { 29 | 30 | $historical = new \Cryptocompare\Historical($this->testingApiKey); 31 | $data = $historical->getDataExchangeHistohour(); 32 | 33 | $c = count((array) $data->Data); 34 | $this->assertGreaterThan( 35 | 1, 36 | $c, 37 | "Found more then 1 items returned" 38 | ); 39 | } 40 | public function testGetDataHistoday() { 41 | 42 | $historical = new \Cryptocompare\Historical($this->testingApiKey); 43 | $data = $historical->getDataHistoday(); 44 | 45 | $c = count((array) $data->Data); 46 | $this->assertGreaterThan( 47 | 1, 48 | $c, 49 | "Found more then 1 items returned" 50 | ); 51 | } 52 | 53 | public function testGetDataHistohour() { 54 | 55 | $historical = new \Cryptocompare\Historical($this->testingApiKey); 56 | $data = $historical->getDataHistohour(); 57 | 58 | $c = count((array) $data->Data); 59 | $this->assertGreaterThan( 60 | 1, 61 | $c, 62 | "Found more then 1 items returned" 63 | ); 64 | } 65 | public function testGetDataPriceHistorical() { 66 | 67 | $historical = new \Cryptocompare\Historical($this->testingApiKey); 68 | $data = $historical->getDataPriceHistorical(); 69 | 70 | $c = count((array) $data); 71 | $this->assertGreaterThan( 72 | 1, 73 | $c, 74 | "Found more then 1 items returned" 75 | ); 76 | } 77 | 78 | public function testGetDataPriceHistoricalDayAvg() { 79 | 80 | $historical = new \Cryptocompare\Historical($this->testingApiKey); 81 | $data = $historical->getDataPriceHistoricalDayAvg("true", "BTC", "EUR"); 82 | 83 | 84 | $c = $data->EUR; 85 | $this->assertGreaterThan( 86 | 1, 87 | $c, 88 | "Found more then 1 items returned" 89 | ); 90 | } 91 | public function testGetHistoMinute() { 92 | 93 | $historical = new \Cryptocompare\Historical($this->testingApiKey); 94 | $data = $historical->getHistoMinute(); 95 | 96 | $c = count((array) $data->Data); 97 | $this->assertGreaterThan( 98 | 1, 99 | $c, 100 | "Found more then 1 items returned" 101 | ); 102 | } 103 | 104 | } --------------------------------------------------------------------------------