├── .gitignore ├── .scrutinizer.yml ├── .travis.yml ├── CoinGeckoLogo.png ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml.dist ├── src ├── Api │ ├── Api.php │ ├── Coins.php │ ├── Contract.php │ ├── Derivatives.php │ ├── Events.php │ ├── ExchangeRates.php │ ├── Exchanges.php │ ├── Finance.php │ ├── Globals.php │ ├── Indexes.php │ ├── Ping.php │ ├── Simple.php │ └── StatusUpdates.php ├── CoinGeckoClient.php ├── Exceptions │ └── TransformResponseException.php └── Message │ └── ResponseTransformer.php └── tests ├── Api ├── ApiTestCase.php ├── CoinsTest.php ├── ContractTest.php ├── DerivativesTest.php ├── EventsTest.php ├── ExchangeRatesTest.php ├── ExchangesTest.php ├── FinanceTest.php ├── GlobalsTest.php ├── IndexesTest.php ├── PingTest.php ├── SimpleTest.php └── StatusUpdatesTest.php ├── CoinGeckoClientTest.php └── Message └── ResponseTransformerTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | composer.lock 3 | build 4 | phpunit.xml 5 | .phpunit.result.cache -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | imports: 2 | - php 3 | 4 | tools: 5 | external_code_coverage: true -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - '7.2' 5 | - '7.3' 6 | - '7.4' 7 | 8 | sudo: false 9 | 10 | cache: 11 | directories: 12 | - $HOME/.composer/cache 13 | 14 | install: 15 | - travis_retry composer self-update && composer --version 16 | - travis_retry composer update --prefer-dist --no-interaction 17 | 18 | before_script: 19 | - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter 20 | - chmod +x ./cc-test-reporter 21 | - ./cc-test-reporter before-build 22 | 23 | script: 24 | - composer validate --strict 25 | - vendor/bin/phpunit 26 | 27 | after_script: 28 | - if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi 29 | - wget https://scrutinizer-ci.com/ocular.phar 30 | - php ocular.phar code-coverage:upload --format=php-clover ./build/logs/clover.xml 31 | 32 | notifications: 33 | email: 34 | recipients: 35 | - codenix.sv@gmail.com 36 | on_success: never 37 | on_failure: always -------------------------------------------------------------------------------- /CoinGeckoLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codenix-sv/coingecko-api/6946e36d8f5e989658405f9e0fb90b7a53c8b561/CoinGeckoLogo.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Volodymyr Svyryd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP API client for coingecko.com 2 | 3 | [![Build Status](https://travis-ci.com/codenix-sv/coingecko-api.svg?branch=master)](https://travis-ci.com/codenix-sv/coingecko-api) 4 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/codenix-sv/coingecko-api/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/codenix-sv/coingecko-api/?branch=master) 5 | [![Test Coverage](https://api.codeclimate.com/v1/badges/650015976f280641822a/test_coverage)](https://codeclimate.com/github/codenix-sv/coingecko-api/test_coverage) 6 | [![Maintainability](https://api.codeclimate.com/v1/badges/650015976f280641822a/maintainability)](https://codeclimate.com/github/codenix-sv/coingecko-api/maintainability) 7 | [![License: MIT](https://img.shields.io/github/license/codenix-sv/coingecko-api)](https://github.com/codenix-sv/coingecko-api/blob/master/LICENSE) 8 | 9 | ![image info](./CoinGeckoLogo.png) 10 | 11 | A simple API client, written with PHP for [coingecko.com](https://coingecko.com). 12 | 13 | CoinGecko provides a fundamental analysis of the crypto market. In addition to tracking price, volume and market capitalization, CoinGecko tracks community growth, open-source code development, major events and on-chain metrics. 14 | 15 | For additional information about API visit [coingecko.com/api](https://www.coingecko.com/api) 16 | 17 | CoinGecko API [Terms of Service](https://www.coingecko.com/en/api_terms) 18 | ## Requirements 19 | 20 | * PHP >= 7.2 21 | * ext-json 22 | 23 | ## Installation 24 | 25 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). 26 | 27 | Either run 28 | 29 | ```bash 30 | $ composer require codenix-sv/coingecko-api 31 | ``` 32 | or add 33 | 34 | ```json 35 | "codenix-sv/coingecko-api": "^1.0" 36 | ``` 37 | ## Basic usage 38 | 39 | ### Example 40 | ```php 41 | use Codenixsv\CoinGeckoApi\CoinGeckoClient; 42 | 43 | $client = new CoinGeckoClient(); 44 | $data = $client->ping(); 45 | ``` 46 | 47 | You can get last response (`ResponseInterface::class`) uses `getLastResponse` method: 48 | ```php 49 | use Codenixsv\CoinGeckoApi\CoinGeckoClient; 50 | 51 | $client = new CoinGeckoClient(); 52 | $data = $client->derivatives()->getExchanges(); 53 | $response = $client->getLastResponse(); 54 | $headers = $response->getHeaders(); 55 | ``` 56 | 57 | ## Available methods 58 | 59 | ### Ping 60 | 61 | #### [ping](https://www.coingecko.com/api/documentations/v3#/ping/get_ping) 62 | 63 | Check API server status 64 | 65 | ```php 66 | $data = $client->ping(); 67 | ``` 68 | 69 | ### Simple 70 | 71 | #### [getPrice](https://www.coingecko.com/api/documentations/v3#/simple/get_simple_price) 72 | 73 | Get the current price of any cryptocurrencies in any other supported currencies that you need. 74 | 75 | ```php 76 | $data = $client->simple()->getPrice('0x,bitcoin', 'usd,rub'); 77 | ``` 78 | 79 | #### [getTokenPrice](https://www.coingecko.com/api/documentations/v3#/simple/get_simple_price) 80 | 81 | Get current price of tokens (using contract addresses) for a given platform in any other currency that you need. 82 | 83 | ```php 84 | $data = $client->simple()->getTokenPrice('ethereum','0xE41d2489571d322189246DaFA5ebDe1F4699F498', 'usd,rub'); 85 | ``` 86 | 87 | #### [getSupportedVsCurrencies](https://www.coingecko.com/api/documentations/v3#/simple/get_simple_supported_vs_currencies) 88 | 89 | Get list of supported_vs_currencies. 90 | 91 | ```php 92 | $data = $client->simple()->getSupportedVsCurrencies(); 93 | ``` 94 | 95 | ### Coins 96 | 97 | #### [getList](https://www.coingecko.com/api/documentations/v3#/coins/get_coins_list) 98 | 99 | List all supported coins id, name and symbol (no pagination required) 100 | 101 | ```php 102 | $data = $client->coins()->getList(); 103 | ``` 104 | 105 | #### [getMarkets](https://www.coingecko.com/api/documentations/v3#/coins/get_coins_markets) 106 | 107 | List all supported coins price, market cap, volume, and market related data 108 | 109 | ```php 110 | $data = $result = $client->coins()->getMarkets('usd'); 111 | ``` 112 | 113 | #### [getCoin](https://www.coingecko.com/api/documentations/v3#/coins/get_coins__id_) 114 | 115 | Get current data (name, price, market, ... including exchange tickers) for a coin 116 | 117 | ```php 118 | $result = $client->coins()->getCoin('bitcoin', ['tickers' => 'false', 'market_data' => 'false']); 119 | ``` 120 | 121 | #### [getTickers](https://www.coingecko.com/api/documentations/v3#/coins/get_coins__id__tickers) 122 | 123 | Get coin tickers (paginated to 100 items) 124 | 125 | ```php 126 | $result = $client->coins()->getTickers('bitcoin'); 127 | ``` 128 | 129 | #### [getHistory](https://www.coingecko.com/api/documentations/v3#/coins/get_coins__id__history) 130 | 131 | Get historical data (name, price, market, stats) at a given date for a coin 132 | 133 | ```php 134 | $result = $client->coins()->getHistory('bitcoin', '30-12-2017'); 135 | ``` 136 | 137 | #### [getMarketChart](https://www.coingecko.com/api/documentations/v3#/coins/get_coins__id__market_chart) 138 | 139 | Get historical market data include price, market cap, and 24h volume (granularity auto) 140 | 141 | ```php 142 | $result = $client->coins()->getMarketChart('bitcoin', 'usd', 'max'); 143 | ``` 144 | 145 | #### [getMarketChartRange](https://www.coingecko.com/api/documentations/v3#/coins/get_coins__id__market_chart_range) 146 | 147 | Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto) 148 | 149 | ```php 150 | $result = $client->coins()->getMarketChartRange('bitcoin', 'usd', '1392577232', '1422577232'); 151 | ``` 152 | 153 | #### [getMarketChartRange](https://www.coingecko.com/api/documentations/v3#/coins/get_coins__id__status_updates) [BETA] 154 | 155 | Get status updates for a given coin 156 | 157 | ```php 158 | $result = $client->coins()->getStatusUpdates('0x'); 159 | ``` 160 | 161 | ### Contract 162 | 163 | #### [getContract](https://www.coingecko.com/api/documentations/v3#/contract/get_coins__id__contract__contract_address_) 164 | 165 | Get coin info from contract address 166 | 167 | ```php 168 | $data = $client->contract()->getContract('ethereum', '0xE41d2489571d322189246DaFA5ebDe1F4699F498'); 169 | ``` 170 | 171 | #### [getMarketChart](https://www.coingecko.com/api/documentations/v3#/contract/get_coins__id__contract__contract_address__market_chart_) 172 | 173 | Get historical market data include price, market cap, and 24h volume (granularity auto) from a contract address 174 | 175 | ```php 176 | $result = $client->contract()->getMarketChart('ethereum', '0xE41d2489571d322189246DaFA5ebDe1F4699F498', 'usd', '1'); 177 | ``` 178 | 179 | #### [getMarketChartRange](https://www.coingecko.com/api/documentations/v3#/contract/get_coins__id__contract__contract_address__market_chart_range) 180 | 181 | Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto) from a contract address 182 | 183 | ```php 184 | $result = $result = $client->contract()->getMarketChartRange('ethereum', '0xE41d2489571d322189246DaFA5ebDe1F4699F498', 'usd', '11392577232', ' 1422577232'); 185 | ``` 186 | 187 | ### Exchange [BETA] 188 | 189 | #### [getExchanges](https://www.coingecko.com/api/documentations/v3#/exchanges_(beta)/get_exchanges) 190 | 191 | List all exchanges 192 | 193 | ```php 194 | $data = $client->exchanges()->getExchanges(); 195 | ``` 196 | 197 | #### [getList](https://www.coingecko.com/api/documentations/v3#/exchanges_(beta)/get_exchanges_list) 198 | 199 | List all supported markets id and name (no pagination required) 200 | 201 | ```php 202 | $data = $client->exchanges()->getList(); 203 | ``` 204 | 205 | #### [getExchange](https://www.coingecko.com/api/documentations/v3#/exchanges_(beta)/get_exchanges__id_) 206 | 207 | Get exchange volume in BTC and top 100 tickers only 208 | 209 | ```php 210 | $data = $client->exchanges()->getExchange('binance'); 211 | ``` 212 | 213 | #### [getTickers](https://www.coingecko.com/api/documentations/v3#/exchanges_(beta)/get_exchanges__id__tickers) 214 | 215 | Get exchange tickers (paginated) 216 | 217 | ```php 218 | $data = $client->exchanges()->getTickers('binance', ['coin_ids' => '0x,bitcoin']); 219 | ``` 220 | 221 | #### [getStatusUpdates](https://www.coingecko.com/api/documentations/v3#/exchanges_(beta)/get_exchanges__id__status_updates) 222 | 223 | Get status updates for a given exchange (beta) 224 | 225 | ```php 226 | $data = $client->exchanges()->getStatusUpdates('binance'); 227 | ``` 228 | 229 | #### [getVolumeChart](https://www.coingecko.com/api/documentations/v3#/exchanges_(beta)/get_exchanges__id__volume_chart) 230 | 231 | Get volume_chart data for a given exchange (beta) 232 | 233 | ```php 234 | $data = $client->exchanges()->getVolumeChart('binance', '1'); 235 | ``` 236 | 237 | ### Finance [BETA] 238 | 239 | #### [getPlatforms](https://www.coingecko.com/api/documentations/v3#/finance_(beta)/get_finance_platforms) 240 | 241 | List all finance platforms 242 | 243 | ```php 244 | $data = $client->finance()->getPlatforms(); 245 | ``` 246 | 247 | #### [getProducts](https://www.coingecko.com/api/documentations/v3#/finance_(beta)/get_finance_products) 248 | 249 | List all finance products 250 | 251 | ```php 252 | $data = $client->finance()->getProducts(); 253 | ``` 254 | 255 | ### Indexes [BETA] 256 | 257 | #### [getIndexes](https://www.coingecko.com/api/documentations/v3#/indexes_(beta)/get_indexes) 258 | 259 | List all market indexes 260 | 261 | ```php 262 | $data = $client->indexes()->getIndexes(); 263 | ``` 264 | 265 | #### [getIndex](https://www.coingecko.com/api/documentations/v3#/indexes_(beta)/get_indexes__id_) 266 | 267 | Get market index by id 268 | 269 | ```php 270 | $data = $client->indexes()->getIndex('BAT'); 271 | ``` 272 | 273 | #### [getList](https://www.coingecko.com/api/documentations/v3#/indexes_(beta)/get_indexes_list) 274 | 275 | List market indexes id and name 276 | 277 | ```php 278 | $data = $client->indexes()->getList(); 279 | ``` 280 | 281 | ### Derivatives [BETA] 282 | 283 | #### [getDerivatives](https://www.coingecko.com/api/documentations/v3#/derivatives_(beta)/get_derivatives) 284 | 285 | List all derivative tickers 286 | 287 | ```php 288 | $data = $client->derivatives()->getDerivatives(); 289 | ``` 290 | 291 | #### [getExchanges](https://www.coingecko.com/api/documentations/v3#/derivatives_(beta)/get_derivatives_exchanges) 292 | 293 | List all derivative exchanges 294 | 295 | ```php 296 | $data = $client->derivatives()->getExchanges(); 297 | ``` 298 | 299 | #### [getExchange](https://www.coingecko.com/api/documentations/v3#/derivatives_(beta)/get_derivatives_exchanges__id_) 300 | 301 | Show derivative exchange data 302 | 303 | ```php 304 | $data = $client->derivatives()->getExchange('binance_futures'); 305 | ``` 306 | 307 | #### [getExchangeList](https://www.coingecko.com/api/documentations/v3#/derivatives_(beta)/get_derivatives_exchanges_list) 308 | 309 | List all derivative exchanges name and identifier 310 | 311 | ```php 312 | $data = $client->derivatives()->getExchangeList(); 313 | ``` 314 | 315 | 316 | ### Status updates [BETA] 317 | 318 | #### [getStatusUpdates](https://www.coingecko.com/api/documentations/v3#/status_updates_(beta)/get_status_updates) 319 | 320 | List all status_updates with data (description, category, created_at, user, user_title and pin) 321 | 322 | ```php 323 | $data = $client->statusUpdates()->getStatusUpdates(); 324 | ``` 325 | 326 | ### Events [BETA] 327 | 328 | #### [getEvents](https://www.coingecko.com/api/documentations/v3#/events/get_events) 329 | 330 | Get events, paginated by 100 331 | 332 | ```php 333 | $data = $client->events()->getEvents(); 334 | ``` 335 | 336 | #### [getCountries](https://www.coingecko.com/api/documentations/v3#/events/get_events_countries) 337 | 338 | Get list of event countries 339 | 340 | ```php 341 | $data = $client->events()->getCountries(); 342 | ``` 343 | 344 | #### [getTypes](https://www.coingecko.com/api/documentations/v3#/events/get_events_types) 345 | 346 | Get list of events types 347 | 348 | ```php 349 | $data = $client->events()->getTypes(); 350 | ``` 351 | 352 | ### Exchange rates [BETA] 353 | 354 | #### [getExchangeRates](https://www.coingecko.com/api/documentations/v3#/exchange_rates/get_exchange_rates) 355 | 356 | Get BTC-to-Currency exchange rates 357 | 358 | ```php 359 | $data = $client->exchangeRates()->getExchangeRates(); 360 | ``` 361 | 362 | ### Global [BETA] 363 | 364 | #### [getGlobal](https://www.coingecko.com/api/documentations/v3#/global/get_global) 365 | 366 | Get cryptocurrency global data 367 | 368 | ```php 369 | $data = $client->globals()->getGlobal(); 370 | ``` 371 | 372 | ## License 373 | 374 | `codenix-sv/coingecko-api` is released under the MIT License. See the bundled [LICENSE](./LICENSE) for details. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codenix-sv/coingecko-api", 3 | "type": "library", 4 | "description": "PHP REST API client for coingecko.com", 5 | "homepage": "https://github.com/codenix-sv/coingecko-api", 6 | "keywords": ["client", "api", "php", "coingecko.com", "rest"], 7 | "license": "MIT", 8 | "support": { 9 | "issues": "https://github.com/codenix-sv/coingecko-api/issues?state=open", 10 | "source": "https://github.com/codenix-sv/coingecko-api" 11 | }, 12 | "authors": [ 13 | { 14 | "name": "Volodymyr Svyryd", 15 | "email": "codenix.sv@gmail.com", 16 | "role": "Developer" 17 | } 18 | ], 19 | "require": { 20 | "php": "^7.2|^8.0", 21 | "ext-json": "*", 22 | "guzzlehttp/guzzle": "~6.0|^7.0.1" 23 | }, 24 | "require-dev": { 25 | "phpunit/phpunit": "^8.0" 26 | }, 27 | "autoload": { 28 | "psr-4": { "Codenixsv\\CoinGeckoApi\\": "src/" } 29 | }, 30 | "autoload-dev": { 31 | "psr-4": { "Codenixsv\\CoinGeckoApi\\Tests\\": "tests/"} 32 | }, 33 | "prefer-stable": true 34 | } 35 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests 16 | 17 | 18 | 19 | 20 | ./src 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/Api/Api.php: -------------------------------------------------------------------------------- 1 | client = $client; 24 | $this->transformer = new ResponseTransformer(); 25 | } 26 | 27 | /** 28 | * @param string $uri 29 | * @param array $query 30 | * @return array 31 | * @throws Exception 32 | */ 33 | public function get(string $uri, array $query = []): array 34 | { 35 | $response = $this->client->getHttpClient()->request('GET', '/api/' . $this->version 36 | . $uri, ['query' => $query]); 37 | $this->client->setLastResponse($response); 38 | 39 | return $this->transformer->transform($response); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Api/Coins.php: -------------------------------------------------------------------------------- 1 | get('/coins/list'); 18 | } 19 | 20 | /** 21 | * @param string $vsCurrency 22 | * @param array $params 23 | * @return array 24 | * @throws Exception 25 | */ 26 | public function getMarkets(string $vsCurrency, array $params = []): array 27 | { 28 | $params['vs_currency'] = $vsCurrency; 29 | 30 | return $this->get('/coins/markets', $params); 31 | } 32 | 33 | /** 34 | * @param string $id 35 | * @param array $params 36 | * @return array 37 | * @throws Exception 38 | */ 39 | public function getCoin(string $id, array $params = []): array 40 | { 41 | return $this->get('/coins/' . $id, $params); 42 | } 43 | 44 | /** 45 | * @param string $id 46 | * @param array $params 47 | * @return array 48 | * @throws Exception 49 | */ 50 | public function getTickers(string $id, array $params = []): array 51 | { 52 | return $this->get('/coins/' . $id . '/tickers', $params); 53 | } 54 | 55 | /** 56 | * @param string $id 57 | * @param string $date 58 | * @param array $params 59 | * @return array 60 | * @throws Exception 61 | */ 62 | public function getHistory(string $id, string $date, array $params = []): array 63 | { 64 | $params['date'] = $date; 65 | return $this->get('/coins/' . $id . '/history', $params); 66 | } 67 | 68 | /** 69 | * @param string $id 70 | * @param string $vsCurrency 71 | * @param string $days 72 | * @return array 73 | * @throws Exception 74 | */ 75 | public function getMarketChart(string $id, string $vsCurrency, string $days): array 76 | { 77 | $params['vs_currency'] = $vsCurrency; 78 | $params['days'] = $days; 79 | return $this->get('/coins/' . $id . '/market_chart', $params); 80 | } 81 | 82 | /** 83 | * @param string $id 84 | * @param string $vsCurrency 85 | * @param string $from 86 | * @param string $to 87 | * @return array 88 | * @throws Exception 89 | */ 90 | public function getMarketChartRange(string $id, string $vsCurrency, string $from, string $to): array 91 | { 92 | $params['vs_currency'] = $vsCurrency; 93 | $params['from'] = $from; 94 | $params['to'] = $to; 95 | return $this->get('/coins/' . $id . '/market_chart/range', $params); 96 | } 97 | 98 | /** 99 | * @param string $id 100 | * @param array $params 101 | * @return array 102 | * @throws Exception 103 | */ 104 | public function getStatusUpdates(string $id, array $params = []): array 105 | { 106 | return $this->get('/coins/' . $id . '/status_updates', $params); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/Api/Contract.php: -------------------------------------------------------------------------------- 1 | get('/coins/' . $id . '/contract/' . $contractAddress); 20 | } 21 | 22 | /** 23 | * @param string $id 24 | * @param string $contractAddress 25 | * @param string $vsCurrency 26 | * @param string $days 27 | * @return array 28 | * @throws Exception 29 | */ 30 | public function getMarketChart(string $id, string $contractAddress, string $vsCurrency, string $days): array 31 | { 32 | $params = ['days' => $days, 'vs_currency' => $vsCurrency]; 33 | 34 | return $this->get('/coins/' . $id . '/contract/' . $contractAddress . '/market_chart', $params); 35 | } 36 | 37 | /** 38 | * @param string $id 39 | * @param string $contractAddress 40 | * @param string $vsCurrency 41 | * @param string $from 42 | * @param string $to 43 | * @return array 44 | * @throws Exception 45 | */ 46 | public function getMarketChartRange( 47 | string $id, 48 | string $contractAddress, 49 | string $vsCurrency, 50 | string $from, 51 | string $to 52 | ): array { 53 | $params['vs_currency'] = $vsCurrency; 54 | $params['from'] = $from; 55 | $params['to'] = $to; 56 | return $this->get('/coins/' . $id . '/contract/' . $contractAddress . '/market_chart/range', $params); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Api/Derivatives.php: -------------------------------------------------------------------------------- 1 | get('/derivatives', $params); 19 | } 20 | 21 | /** 22 | * @param array $params 23 | * @return array 24 | * @throws Exception 25 | */ 26 | public function getExchanges(array $params = []): array 27 | { 28 | return $this->get('/derivatives/exchanges', $params); 29 | } 30 | 31 | /** 32 | * @param string $id 33 | * @param array $params 34 | * @return array 35 | * @throws Exception 36 | */ 37 | public function getExchange(string $id, $params = []): array 38 | { 39 | return $this->get('/derivatives/exchanges/' . $id, $params); 40 | } 41 | 42 | /** 43 | * @return array 44 | * @throws Exception 45 | */ 46 | public function getExchangeList(): array 47 | { 48 | return $this->get('/derivatives/exchanges/list'); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Api/Events.php: -------------------------------------------------------------------------------- 1 | get('/events', $params); 19 | } 20 | 21 | /** 22 | * @return array 23 | * @throws Exception 24 | */ 25 | public function getCountries(): array 26 | { 27 | return $this->get('/events/countries'); 28 | } 29 | 30 | /** 31 | * @return array 32 | * @throws Exception 33 | */ 34 | public function getTypes(): array 35 | { 36 | return $this->get('/events/types'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Api/ExchangeRates.php: -------------------------------------------------------------------------------- 1 | get('/exchange_rates'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Api/Exchanges.php: -------------------------------------------------------------------------------- 1 | get('/exchanges', $params); 19 | } 20 | 21 | /** 22 | * @return array 23 | * @throws Exception 24 | */ 25 | public function getList(): array 26 | { 27 | return $this->get('/exchanges/list'); 28 | } 29 | 30 | /** 31 | * @param string $id 32 | * @return array 33 | * @throws Exception 34 | */ 35 | public function getExchange(string $id): array 36 | { 37 | return $this->get('/exchanges/' . $id); 38 | } 39 | 40 | /** 41 | * @param string $id 42 | * @param array $params 43 | * @return array 44 | * @throws Exception 45 | */ 46 | public function getTickers(string $id, array $params = []): array 47 | { 48 | return $this->get('/exchanges/' . $id . '/tickers', $params); 49 | } 50 | 51 | /** 52 | * @param string $id 53 | * @param array $params 54 | * @return array 55 | * @throws Exception 56 | */ 57 | public function getStatusUpdates(string $id, array $params = []): array 58 | { 59 | return $this->get('/exchanges/' . $id . '/status_updates', $params); 60 | } 61 | 62 | /** 63 | * @param string $id 64 | * @param string $days 65 | * @return array 66 | * @throws Exception 67 | */ 68 | public function getVolumeChart(string $id, string $days): array 69 | { 70 | return $this->get('/exchanges/' . $id . '/volume_chart', ['days' => $days]); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Api/Finance.php: -------------------------------------------------------------------------------- 1 | get('/finance_platforms', $params); 19 | } 20 | 21 | /** 22 | * @param array $params 23 | * @return array 24 | * @throws Exception 25 | */ 26 | public function getProducts(array $params = []): array 27 | { 28 | return $this->get('/finance_products', $params); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Api/Globals.php: -------------------------------------------------------------------------------- 1 | get('/global'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Api/Indexes.php: -------------------------------------------------------------------------------- 1 | get('/indexes', $params); 19 | } 20 | 21 | /** 22 | * @param string $id 23 | * @return array 24 | * @throws Exception 25 | */ 26 | public function getIndex(string $id): array 27 | { 28 | return $this->get('/indexes/' . $id); 29 | } 30 | 31 | /** 32 | * @return array 33 | * @throws Exception 34 | */ 35 | public function getList(): array 36 | { 37 | return $this->get('/indexes/list'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Api/Ping.php: -------------------------------------------------------------------------------- 1 | get('/ping'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Api/Simple.php: -------------------------------------------------------------------------------- 1 | get('/simple/price', $params); 24 | } 25 | 26 | /** 27 | * @param string $id 28 | * @param string $contractAddresses 29 | * @param string $vsCurrencies 30 | * @param array $params 31 | * @return array 32 | * @throws Exception 33 | */ 34 | public function getTokenPrice( 35 | string $id, 36 | string $contractAddresses, 37 | string $vsCurrencies, 38 | array $params = [] 39 | ): array { 40 | $params['contract_addresses'] = $contractAddresses; 41 | $params['vs_currencies'] = $vsCurrencies; 42 | 43 | return $this->get('/simple/token_price/' . $id, $params); 44 | } 45 | 46 | /** 47 | * @return array 48 | * @throws Exception 49 | */ 50 | public function getSupportedVsCurrencies() 51 | { 52 | return $this->get('/simple/supported_vs_currencies'); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Api/StatusUpdates.php: -------------------------------------------------------------------------------- 1 | get('/status_updates', $params); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/CoinGeckoClient.php: -------------------------------------------------------------------------------- 1 | httpClient = $client ?: new Client(['base_uri' => self::BASE_URI]); 40 | } 41 | 42 | public function getHttpClient(): Client 43 | { 44 | return $this->httpClient; 45 | } 46 | 47 | /** 48 | * @return array 49 | * @throws Exception 50 | */ 51 | public function ping(): array 52 | { 53 | return (new Ping($this))->ping(); 54 | } 55 | 56 | public function simple(): Simple 57 | { 58 | return new Simple($this); 59 | } 60 | 61 | public function coins(): Coins 62 | { 63 | return new Coins($this); 64 | } 65 | 66 | public function contract(): Contract 67 | { 68 | return new Contract($this); 69 | } 70 | 71 | public function exchanges(): Exchanges 72 | { 73 | return new Exchanges($this); 74 | } 75 | 76 | public function finance(): Finance 77 | { 78 | return new Finance($this); 79 | } 80 | 81 | public function indexes(): Indexes 82 | { 83 | return new Indexes($this); 84 | } 85 | 86 | public function derivatives(): Derivatives 87 | { 88 | return new Derivatives($this); 89 | } 90 | 91 | public function statusUpdates(): StatusUpdates 92 | { 93 | return new StatusUpdates($this); 94 | } 95 | 96 | public function events(): Events 97 | { 98 | return new Events($this); 99 | } 100 | 101 | public function exchangeRates(): ExchangeRates 102 | { 103 | return new ExchangeRates($this); 104 | } 105 | 106 | public function globals(): Globals 107 | { 108 | return new Globals($this); 109 | } 110 | 111 | public function setLastResponse(ResponseInterface $response) 112 | { 113 | return $this->lastResponse = $response; 114 | } 115 | 116 | public function getLastResponse(): ?ResponseInterface 117 | { 118 | return $this->lastResponse; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/Exceptions/TransformResponseException.php: -------------------------------------------------------------------------------- 1 | getBody(); 25 | if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) { 26 | $content = json_decode($body, true); 27 | if (JSON_ERROR_NONE === json_last_error()) { 28 | return $content; 29 | } 30 | 31 | throw new TransformResponseException('Error transforming response to array. JSON_ERROR: ' 32 | . json_last_error() . ' --' . $body . '---'); 33 | } 34 | 35 | throw new TransformResponseException('Error transforming response to array. Content-Type 36 | is not application/json'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Api/ApiTestCase.php: -------------------------------------------------------------------------------- 1 | transactions)) === 0) { 23 | return null; 24 | } 25 | 26 | return $this->transactions[$count - 1]['request'] ?? null; 27 | } 28 | 29 | protected function getMockClient() 30 | { 31 | $mock = new MockHandler([ 32 | new Response(200, ['Content-Type' => 'application/json'], json_encode(['fo' => 'bar'])), 33 | ]); 34 | 35 | $handlerStack = HandlerStack::create($mock); 36 | $handlerStack->push(Middleware::history($this->transactions)); 37 | 38 | $this->mockClient = new Client(['handler' => $handlerStack]); 39 | 40 | return $this->mockClient; 41 | } 42 | 43 | protected function tearDown(): void 44 | { 45 | $this->mockClient = null; 46 | $this->transactions = []; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/Api/CoinsTest.php: -------------------------------------------------------------------------------- 1 | createApi()->getList(); 15 | 16 | $request = $this->getLastRequest(); 17 | $this->assertEquals( 18 | '/api/v3/coins/list', 19 | $request->getUri()->__toString() 20 | ); 21 | } 22 | 23 | public function testGetMarkets() 24 | { 25 | $this->createApi()->getMarkets('usd', ['per_page' => 10, 'sparkline' => 'true']); 26 | 27 | $request = $this->getLastRequest(); 28 | $this->assertEquals( 29 | '/api/v3/coins/markets?per_page=10&sparkline=true&vs_currency=usd', 30 | $request->getUri()->__toString() 31 | ); 32 | } 33 | 34 | public function testGetCoin() 35 | { 36 | $this->createApi()->getCoin('bitcoin', ['tickers' => 'false', 'market_data' => 'false']); 37 | 38 | $request = $this->getLastRequest(); 39 | $this->assertEquals( 40 | '/api/v3/coins/bitcoin?tickers=false&market_data=false', 41 | $request->getUri()->__toString() 42 | ); 43 | } 44 | 45 | public function testGetTickers() 46 | { 47 | $this->createApi()->getTickers('bitcoin'); 48 | 49 | $request = $this->getLastRequest(); 50 | $this->assertEquals( 51 | '/api/v3/coins/bitcoin/tickers', 52 | $request->getUri()->__toString() 53 | ); 54 | } 55 | 56 | public function testGetHistory() 57 | { 58 | $this->createApi()->getHistory('bitcoin', '30-12-2017'); 59 | 60 | $request = $this->getLastRequest(); 61 | $this->assertEquals( 62 | '/api/v3/coins/bitcoin/history?date=30-12-2017', 63 | $request->getUri()->__toString() 64 | ); 65 | } 66 | 67 | public function testGetMarketChart() 68 | { 69 | $this->createApi()->getMarketChart('bitcoin', 'usd', 'max'); 70 | 71 | $request = $this->getLastRequest(); 72 | $this->assertEquals( 73 | '/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=max', 74 | $request->getUri()->__toString() 75 | ); 76 | } 77 | 78 | public function testGetMarketChartRange() 79 | { 80 | $this->createApi()->getMarketChartRange('bitcoin', 'usd', '1392577232', '1422577232'); 81 | 82 | $request = $this->getLastRequest(); 83 | $this->assertEquals( 84 | '/api/v3/coins/bitcoin/market_chart/range?vs_currency=usd&from=1392577232&to=1422577232', 85 | $request->getUri()->__toString() 86 | ); 87 | } 88 | 89 | public function testGetStatusUpdates() 90 | { 91 | $this->createApi()->getStatusUpdates('0x'); 92 | 93 | $request = $this->getLastRequest(); 94 | $this->assertEquals( 95 | '/api/v3/coins/0x/status_updates', 96 | $request->getUri()->__toString() 97 | ); 98 | } 99 | 100 | private function createApi(): Coins 101 | { 102 | return new Coins(new CoinGeckoClient($this->getMockClient())); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /tests/Api/ContractTest.php: -------------------------------------------------------------------------------- 1 | createApi()->getContract('ethereum', '0xE41d2489571d322189246DaFA5ebDe1F4699F498'); 15 | 16 | $request = $this->getLastRequest(); 17 | $this->assertEquals( 18 | '/api/v3/coins/ethereum/contract/0xE41d2489571d322189246DaFA5ebDe1F4699F498', 19 | $request->getUri()->__toString() 20 | ); 21 | } 22 | 23 | public function testGetMarketChart() 24 | { 25 | $this->createApi()->getMarketChart('ethereum', '0xE41d2489571d322189246DaFA5ebDe1F4699F498', 'usd', '1'); 26 | 27 | $request = $this->getLastRequest(); 28 | $this->assertEquals( 29 | '/api/v3/coins/ethereum/contract/0xE41d2489571d322189246DaFA5ebDe1F4699F498/market_chart' 30 | . '?days=1&vs_currency=usd', 31 | $request->getUri()->__toString() 32 | ); 33 | } 34 | 35 | public function testGetMarketChartRange() 36 | { 37 | $this->createApi()->getMarketChartRange( 38 | 'ethereum', 39 | '0xE41d2489571d322189246DaFA5ebDe1F4699F498', 40 | 'usd', 41 | '11392577232', 42 | ' 1422577232' 43 | ); 44 | 45 | $request = $this->getLastRequest(); 46 | $this->assertEquals( 47 | '/api/v3/coins/ethereum/contract/0xE41d2489571d322189246DaFA5ebDe1F4699F498/market_chart/range?' 48 | . 'vs_currency=usd&from=11392577232&to=%201422577232', 49 | $request->getUri()->__toString() 50 | ); 51 | } 52 | 53 | private function createApi(): Contract 54 | { 55 | return new Contract(new CoinGeckoClient($this->getMockClient())); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/Api/DerivativesTest.php: -------------------------------------------------------------------------------- 1 | createApi()->getDerivatives(); 15 | 16 | $request = $this->getLastRequest(); 17 | $this->assertEquals('/api/v3/derivatives', $request->getUri()->__toString()); 18 | } 19 | 20 | public function testGetExchanges() 21 | { 22 | $this->createApi()->getExchanges(); 23 | 24 | $request = $this->getLastRequest(); 25 | $this->assertEquals('/api/v3/derivatives/exchanges', $request->getUri()->__toString()); 26 | } 27 | 28 | public function testGetExchange() 29 | { 30 | $this->createApi()->getExchange('binance_futures'); 31 | 32 | $request = $this->getLastRequest(); 33 | $this->assertEquals('/api/v3/derivatives/exchanges/binance_futures', $request->getUri()->__toString()); 34 | } 35 | 36 | public function testGetExchangeList() 37 | { 38 | $this->createApi()->getExchangeList(); 39 | 40 | $request = $this->getLastRequest(); 41 | $this->assertEquals('/api/v3/derivatives/exchanges/list', $request->getUri()->__toString()); 42 | } 43 | 44 | private function createApi(): Derivatives 45 | { 46 | return new Derivatives(new CoinGeckoClient($this->getMockClient())); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/Api/EventsTest.php: -------------------------------------------------------------------------------- 1 | createApi()->getEvents(); 15 | 16 | $request = $this->getLastRequest(); 17 | $this->assertEquals('/api/v3/events', $request->getUri()->__toString()); 18 | } 19 | 20 | public function testGetCountries() 21 | { 22 | $this->createApi()->getCountries(); 23 | 24 | $request = $this->getLastRequest(); 25 | $this->assertEquals('/api/v3/events/countries', $request->getUri()->__toString()); 26 | } 27 | 28 | public function testGetTypes() 29 | { 30 | $this->createApi()->getTypes(); 31 | 32 | $request = $this->getLastRequest(); 33 | $this->assertEquals('/api/v3/events/types', $request->getUri()->__toString()); 34 | } 35 | 36 | private function createApi(): Events 37 | { 38 | return new Events(new CoinGeckoClient($this->getMockClient())); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/Api/ExchangeRatesTest.php: -------------------------------------------------------------------------------- 1 | getMockClient())); 15 | $api->getExchangeRates(); 16 | 17 | $this->assertEquals('/api/v3/exchange_rates', $this->getLastRequest()->getUri()->__toString()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Api/ExchangesTest.php: -------------------------------------------------------------------------------- 1 | createApi()->getExchanges(); 15 | 16 | $request = $this->getLastRequest(); 17 | $this->assertEquals('/api/v3/exchanges', $request->getUri()->__toString()); 18 | } 19 | 20 | public function testGetList() 21 | { 22 | $this->createApi()->getList(); 23 | 24 | $request = $this->getLastRequest(); 25 | $this->assertEquals('/api/v3/exchanges/list', $request->getUri()->__toString()); 26 | } 27 | 28 | public function testGetExchange() 29 | { 30 | $this->createApi()->getExchange('binance'); 31 | 32 | $request = $this->getLastRequest(); 33 | $this->assertEquals('/api/v3/exchanges/binance', $request->getUri()->__toString()); 34 | } 35 | 36 | public function testGetTickers() 37 | { 38 | $this->createApi()->getTickers('binance', ['coin_ids' => '0x,bitcoin']); 39 | 40 | $request = $this->getLastRequest(); 41 | $this->assertEquals( 42 | '/api/v3/exchanges/binance/tickers?coin_ids=0x%2Cbitcoin', 43 | $request->getUri()->__toString() 44 | ); 45 | } 46 | 47 | public function testGetStatusUpdates() 48 | { 49 | $this->createApi()->getStatusUpdates('binance'); 50 | 51 | $request = $this->getLastRequest(); 52 | $this->assertEquals('/api/v3/exchanges/binance/status_updates', $request->getUri()->__toString()); 53 | } 54 | 55 | public function testGetVolumeChart() 56 | { 57 | $this->createApi()->getVolumeChart('binance', '1'); 58 | 59 | $request = $this->getLastRequest(); 60 | $this->assertEquals('/api/v3/exchanges/binance/volume_chart?days=1', $request->getUri()->__toString()); 61 | } 62 | 63 | private function createApi(): Exchanges 64 | { 65 | return new Exchanges(new CoinGeckoClient($this->getMockClient())); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tests/Api/FinanceTest.php: -------------------------------------------------------------------------------- 1 | createApi()->getPlatforms(); 15 | 16 | $request = $this->getLastRequest(); 17 | $this->assertEquals('/api/v3/finance_platforms', $request->getUri()->__toString()); 18 | } 19 | 20 | public function testGetProducts() 21 | { 22 | $this->createApi()->getProducts(); 23 | 24 | $request = $this->getLastRequest(); 25 | $this->assertEquals('/api/v3/finance_products', $request->getUri()->__toString()); 26 | } 27 | 28 | private function createApi(): Finance 29 | { 30 | return new Finance(new CoinGeckoClient($this->getMockClient())); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Api/GlobalsTest.php: -------------------------------------------------------------------------------- 1 | getMockClient())); 15 | $api->getGlobal(); 16 | 17 | $this->assertEquals('/api/v3/global', $this->getLastRequest()->getUri()->__toString()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Api/IndexesTest.php: -------------------------------------------------------------------------------- 1 | createApi()->getIndexes(); 15 | 16 | $request = $this->getLastRequest(); 17 | $this->assertEquals('/api/v3/indexes', $request->getUri()->__toString()); 18 | } 19 | 20 | public function testGetIndex() 21 | { 22 | $this->createApi()->getIndex('BAT'); 23 | 24 | $request = $this->getLastRequest(); 25 | $this->assertEquals('/api/v3/indexes/BAT', $request->getUri()->__toString()); 26 | } 27 | 28 | public function testGetList() 29 | { 30 | $this->createApi()->getList(); 31 | 32 | $request = $this->getLastRequest(); 33 | $this->assertEquals('/api/v3/indexes/list', $request->getUri()->__toString()); 34 | } 35 | 36 | private function createApi(): Indexes 37 | { 38 | return new Indexes(new CoinGeckoClient($this->getMockClient())); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/Api/PingTest.php: -------------------------------------------------------------------------------- 1 | getMockClient())); 15 | $api->ping(); 16 | 17 | $this->assertEquals('/api/v3/ping', $this->getLastRequest()->getUri()->__toString()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Api/SimpleTest.php: -------------------------------------------------------------------------------- 1 | createApi()->getPrice('0x,bitcoin', 'usd,rub'); 15 | 16 | $request = $this->getLastRequest(); 17 | $this->assertEquals( 18 | '/api/v3/simple/price?ids=0x%2Cbitcoin&vs_currencies=usd%2Crub', 19 | $request->getUri()->__toString() 20 | ); 21 | } 22 | 23 | public function testGetTokenPrice() 24 | { 25 | $api = $this->createApi(); 26 | $api->getTokenPrice('ethereum', '0xE41d2489571d322189246DaFA5ebDe1F4699F498', 'usd,rub'); 27 | 28 | $request = $this->getLastRequest(); 29 | $this->assertEquals( 30 | '/api/v3/simple/token_price/ethereum?contract_addresses' 31 | . '=0xE41d2489571d322189246DaFA5ebDe1F4699F498&vs_currencies=usd%2Crub', 32 | $request->getUri()->__toString() 33 | ); 34 | } 35 | 36 | public function testGetSupportedVsCurrencies() 37 | { 38 | $this->createApi()->getSupportedVsCurrencies(); 39 | 40 | $request = $this->getLastRequest(); 41 | $this->assertEquals( 42 | '/api/v3/simple/supported_vs_currencies', 43 | $request->getUri()->__toString() 44 | ); 45 | } 46 | 47 | private function createApi(): Simple 48 | { 49 | return new Simple(new CoinGeckoClient($this->getMockClient())); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/Api/StatusUpdatesTest.php: -------------------------------------------------------------------------------- 1 | getMockClient())); 15 | $api->getStatusUpdates(); 16 | 17 | $this->assertEquals('/api/v3/status_updates', $this->getLastRequest()->getUri()->__toString()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/CoinGeckoClientTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf(Client::class, $client->getHttpClient()); 30 | } 31 | 32 | public function testPing() 33 | { 34 | $client = new CoinGeckoClient(); 35 | 36 | $this->assertIsArray($client->ping()); 37 | } 38 | 39 | public function testSimple() 40 | { 41 | $client = new CoinGeckoClient(); 42 | 43 | $this->assertInstanceOf(Simple::class, $client->simple()); 44 | } 45 | 46 | public function testCoins() 47 | { 48 | $client = new CoinGeckoClient(); 49 | 50 | $this->assertInstanceOf(Coins::class, $client->coins()); 51 | } 52 | 53 | public function testContract() 54 | { 55 | $client = new CoinGeckoClient(); 56 | 57 | $this->assertInstanceOf(Contract::class, $client->contract()); 58 | } 59 | 60 | public function testExchanges() 61 | { 62 | $client = new CoinGeckoClient(); 63 | 64 | $this->assertInstanceOf(Exchanges::class, $client->exchanges()); 65 | } 66 | 67 | public function testFinance() 68 | { 69 | $client = new CoinGeckoClient(); 70 | 71 | $this->assertInstanceOf(Finance::class, $client->finance()); 72 | } 73 | 74 | public function testIndexes() 75 | { 76 | $client = new CoinGeckoClient(); 77 | 78 | $this->assertInstanceOf(Indexes::class, $client->indexes()); 79 | } 80 | 81 | public function testDerivatives() 82 | { 83 | $client = new CoinGeckoClient(); 84 | 85 | $this->assertInstanceOf(Derivatives::class, $client->derivatives()); 86 | } 87 | 88 | public function testStatusUpdates() 89 | { 90 | $client = new CoinGeckoClient(); 91 | 92 | $this->assertInstanceOf(StatusUpdates::class, $client->statusUpdates()); 93 | } 94 | 95 | public function testEvents() 96 | { 97 | $client = new CoinGeckoClient(); 98 | 99 | $this->assertInstanceOf(Events::class, $client->events()); 100 | } 101 | 102 | public function testExchangeRates() 103 | { 104 | $client = new CoinGeckoClient(); 105 | 106 | $this->assertInstanceOf(ExchangeRates::class, $client->exchangeRates()); 107 | } 108 | 109 | public function testGlobals() 110 | { 111 | $client = new CoinGeckoClient(); 112 | 113 | $this->assertInstanceOf(Globals::class, $client->globals()); 114 | } 115 | 116 | public function testGetLastResponseIsNull() 117 | { 118 | $client = new CoinGeckoClient(); 119 | 120 | $this->assertNull($client->getLastResponse()); 121 | } 122 | 123 | public function testSetLastResponse() 124 | { 125 | $client = new CoinGeckoClient(); 126 | $response = $this->createMock(ResponseInterface::class); 127 | $client->setLastResponse($response); 128 | 129 | $this->assertInstanceOf(ResponseInterface::class, $client->getLastResponse()); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /tests/Message/ResponseTransformerTest.php: -------------------------------------------------------------------------------- 1 | 'bar']; 18 | $response = new Response(200, ['Content-Type' => 'application/json'], json_encode($data)); 19 | 20 | $this->assertEquals($data, $transformer->transform($response)); 21 | } 22 | 23 | public function testTransformWithEmptyBody() 24 | { 25 | $transformer = new ResponseTransformer(); 26 | $data = []; 27 | $response = new Response(200, ['Content-Type' => 'application/json'], json_encode($data)); 28 | 29 | $this->assertEquals($data, $transformer->transform($response)); 30 | } 31 | 32 | public function testTransformThrowTransformResponseException() 33 | { 34 | $transformer = new ResponseTransformer(); 35 | $response = new Response(200, ['Content-Type' => 'application/json'], ''); 36 | 37 | $this->expectException(TransformResponseException::class); 38 | 39 | $transformer->transform($response); 40 | } 41 | 42 | public function testTransformWithIncorrectContentType() 43 | { 44 | $transformer = new ResponseTransformer(); 45 | $data = []; 46 | $response = new Response(200, ['Content-Type' => 'application/javascript'], json_encode($data)); 47 | 48 | $this->expectException(TransformResponseException::class); 49 | 50 | $this->assertEquals($data, $transformer->transform($response)); 51 | } 52 | } 53 | --------------------------------------------------------------------------------