Comments (3)
Paid subscriptions also have a different base url:
https://pro-api.coingecko.com/api/v3/ping?x_cg_pro_api_key=YOUR_API_KEY
While the class CoinGeckoClient has
BASE_URI = 'https://api.coingecko.com';
Any easy way to do this with this client?
from coingecko-api.
Hi! I just create fork with this functionality, check out
https://github.com/LborV/coingecko-api
from coingecko-api.
Solution
- Make a change in code in a file CoinGeckoClient.php:
From:
protected const BASE_URI = 'https://api.coingecko.com';
To:
protected` const BASE_URI = 'https://pro-api.coingecko.com';
- Make a change in a file Api.php, in function get():
public function get(string $uri, array $query = []): array
{
$query['x_cg_pro_api_key'] = 'CG-XXXXXXXXXXXXX;
$response = $this->client->getHttpClient()->request('GET', '/api/' . $this->version
. $uri, ['query' => $query]);
$this->client->setLastResponse($response);
return $this->transformer->transform($response);
}
/*******/
Alternative way, without changes in Api.php:
Adding API Key
Add this as an additional parameter.
For example:
$parameters = array(
"ids" => $id_crypto_coin,
"order" => "volume_desc",
"per_page" => $per_page,
"sparkline" => "true",
"price_change_percentage" => "1h,24h,7d",
"x_cg_pro_api_key" => "CG-XXXXXXXXXXX"
);
$data = $myCoinGeckoClient->coins()->getMarkets($national_currency, $parameters);
And that's it.
Explanation
Request is sent as a string query:
https://pro-api.coingecko.com/api/v3/coins/markets?vs_currency=usd&x_cg_pro_api_key=CG-XXXXXXXXXXXXXXXXX&order=market_cap_desc&per_page=100&page=1&sparkline=false&locale=en
and API key can be add in any part of the query string.
Warnings!
This library is not complete.
Here is an example from Ping.php.
Now is:
public function ping(): array { return $this->get('/ping'); }
It should be:
public function ping( array $params = [] ): array { return $this->get('/ping', $params); }
Just change it in your project if you want to use Ping request with Coin Gecko PRO.
If you do not use Ping at all, you do not need to make this change.
Another example comes from Coins.php.
Now is:
public function getMarketChart(string $id, string $vsCurrency, string $days): array { $params['vs_currency'] = $vsCurrency; $params['days'] = $days; return $this->get('/coins/' . $id . '/market_chart', $params); }
Should be:
public function getMarketChart(string $id, string $vsCurrency, string $days, array $params = [] ): array { $params['vs_currency'] = $vsCurrency; $params['days'] = $days; return $this->get('/coins/' . $id . '/market_chart', $params); }
from coingecko-api.
Related Issues (13)
- How get server headers for a request? HOT 2
- Execption handling HOT 2
- Add new API parameter "interval" for coin market-charts
- cURL error 6: Could not resolve host: api.coingecko.com
- TransformResponseException does not comply with psr-4 autoloading
- I have with issue SSL certificate has expired
- green chart image HOT 1
- Guzzle 7 HOT 4
- Having an issue with GuzzleHTTP HOT 4
- Error?
- [InvalidArgumentException] laravel 5.x HOT 1
- getMarkets - cant use pagination with this call.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coingecko-api.