GithubHelp home page GithubHelp logo

Comments (3)

pattihis avatar pattihis commented on August 31, 2024

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.

LborV avatar LborV commented on August 31, 2024

Hi! I just create fork with this functionality, check out
https://github.com/LborV/coingecko-api

from coingecko-api.

dariuszwit avatar dariuszwit commented on August 31, 2024

Solution

  1. 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';

  1. 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.
image

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.