Download the PHP package pangzlab/coingecko-api without Composer
On this page you can find all versions of the php package pangzlab/coingecko-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pangzlab/coingecko-api
More information about pangzlab/coingecko-api
Files in pangzlab/coingecko-api
Informations about the package coingecko-api
coingecko-api
Coingecko API client for PHP
A simple, intuitive and composable API Client for the CoinGecko REST API Service.
API Version Support
- ✔️ API v3
- ✔️ Community Endpoint
- ✔️ Pro Endpoint
Requirements
- ✔️ php: 8.x
- ✔️ guzzlehttp/guzzle: ^7.5
Installation
The best and the easiest way to use this library is thru composer.
You can also download the source directly and require it to your project.
Just take note of the requirements.
[ Composer ]
OR
[ Direct Download ]
📥 Get it from the release
Library
[ Classes ]
This library provides 2 main classes which you can use depending on the type of endpoints you are accessing.
📦 CoinGeckoApiClient
This is the main class that allows building the API endpoints and sending the request.
This is always required.
📦 CoinGeckoUrlBuilder
CoinGecko API endpoints require a URL query which is a set of key value pairs encoded in the URL.
This class enables to dynamically create them with ease without worrying the position
or the casing of the keys.
Although by design can be achieved by using the CoinGeckoApiClient class alone,
using the CoinGeckoUrlBuilder gives you a finer control over the parameters you set and more flexibility in managing the endpoints you're building.
This class is optional depending on the endpoint you need.
Usage
Accessing the API endpoints are fairly straightforward. If not for convenience, you don't really need a set of manuals to start using this library.
You can just go directly to the CoinGecko REST API Official Documenation, find the endpoint you need and start building your request.
Let's use some examples.
🔹 Endpoint request "without"🚫 URL query
🌐 endpoint: /ping
🔹 Endpoint request "with"✔️ URL query
🌐 endpoint: /coins/categoreis
🔹 Endpoint request with path parameter(id)
🌐 endpoint: /exchanges/{id}/volume_chart
🔹 Endpoint request with path parameter(id) and URL Query
🌐 endpoint: /coins/{id}
Features
Set Method
-
Before forming the endpoint, always start calling the set() method to make a clean object before building a request.
Parameter Positioning
- The parameter position is not important. It can be set anywhere as long as it is required by the endpoint.
Send Methods ( Community vs Pro )
- There are 2 methods provided to send a request. The send() and the sendPro()
- send ⇨ used to send a request to Community API endpoints.
-
sendPro ⇨ used to send a request to the exclusive Pro API endpoints. This method requires the x_cg_pro_api_key parameter key encoded in the URL for the request to be accepted.
- Both optionally accepts instance of CoinGeckoUrlBuilder() class.
- Aside from the x_cg_pro_api_key parameter key, there is no major difference between these 2 methods. Both are used the same way.
CoinGeckoUrlBuilder() Method Call with Prefix
-
Method name for building a query string using CoinGeckoUrlBuilder() always have a prefix with.
- (i.e. withId() for id, withVsCurrency() for vs_currency)
Bonus Quirks
There are some benefits of using this CoinGecko client libray.
Aside from it's not required to learn any methods to use
and the parameter positioning of each methods,
there are other features which might not be essential but are available and ready to be used
to provide manageability and flexibility to your coding.
1. Use of reset() instead of set()
⚠️ Calling set() is always the preferred way but you can also build request using the reset() method to cleanup resource. Just make sure to separate the call to send() method to avoid ParseError.
2. Case-insensitive method names
Endpoint name and URL parameter key name are case-insensitive. This means calling ping(), PING() and Ping() are treated the same thing. Additionally you can also use underscore(_) as a separator for names like VS_CURRENCY or vs_Currency. They will be handled properly.
3. Request reusability
API Usage
📋Endpoint List
- companies (beta)
🌐 ping
🌐 ping
1. 📋 endpoint : /ping
Check API server status
[ method ] : ping()
💡 sample usage
🌐 simple
1. 📋 endpoint : /simple/price
Get the current price of any cryptocurrencies in any other supported currencies that you need.
[ method ] : simple()->price()
🔑
URL Keys : 7 ◽️ id of coins, comma-separated if querying more than 1 coinrefers to ◽️ vs_currency of coins, comma-separated if querying more than 1 vs_currencyrefers to ◽️ true/false to include market_cap, default: false ◽️ true/false to include 24hr_vol, default: false ◽️ true/false to include 24hr_change, default: false ◽️ true/false to include last_updated_at of price, default: false ◽️ full or any value between 0 - 18 to specify decimal place for currency price value, default: 2
✔️ withIds('string')
❗️
✔️ withVsCurrencies('string')
❗️
✔️ withIncludeMarketCap('string')
✔️ withInclude24hrVol('string')
✔️ withInclude24hrChange('string')
✔️ withIncludeLastUpdatedAt('string')
✔️ withPrecision('string')
url parameters
ids
➞ string (required) coins/list
vs_currencies
➞ string (required) simple/supported_vs_currencies
include_market_cap
➞ string include_24hr_vol
➞ string include_24hr_change
➞ string include_last_updated_at
➞ string precision
➞ string
💡 sample usage
2. 📋 endpoint : /simple/token_price/{id}
Get current price of tokens (using contract addresses) for a given platform in any other currency that you need.
endpoint parameters
id
➞ The id of the platform issuing tokens (See asset_platforms endpoint for list of options)
[ method ] : simple()->tokenPrice('{id}')
🔑
URL Keys : 7 ◽️ The contract address of tokens, comma separated ◽️ vs_currency of coins, comma-separated if querying more than 1 vs_currency*refers to ◽️ true/false to include market_cap, default: false ◽️ true/false to include 24hr_vol, default: false ◽️ true/false to include 24hr_change, default: false ◽️ true/false to include last_updated_at of price, default: false ◽️ full or any Integer to specify decimal place for currency price value, default: 2
✔️ withContractAddresses('string')
❗️
✔️ withVsCurrencies('string')
❗️
✔️ withIncludeMarketCap('string')
✔️ withInclude24hrVol('string')
✔️ withInclude24hrChange('string')
✔️ withIncludeLastUpdatedAt('string')
✔️ withPrecision('string')
url parameters
contract_addresses
➞ string (required) vs_currencies
➞ string (required) simple/supported_vs_currencies
include_market_cap
➞ string include_24hr_vol
➞ string include_24hr_change
➞ string include_last_updated_at
➞ string precision
➞ string
💡 sample usage
3. 📋 endpoint : /simple/supported_vs_currencies
Get list of supported_vs_currencies.
[ method ] : simple()->supportedVsCurrencies()
💡 sample usage
🌐 coins
1. 📋 endpoint : /coins/list
List all supported coins id, name and symbol (no pagination required)
[ method ] : coins()->list()
🔑
URL Keys : 1 ◽️ flag to include platform contract addresses (eg. 0x.... for Ethereum based tokens). valid values: true, false
✔️ withIncludePlatform('boolean')
url parameters
include_platform
➞ boolean
💡 sample usage
2. 📋 endpoint : /coins/markets
List all supported coins price, market cap, volume, and market related data
[ method ] : coins()->markets()
🔑
URL Keys : 8 ◽️ The target currency of market data (usd, eur, jpy, etc.) ◽️ The ids of the coin, comma separated crytocurrency symbols (base). refers to ◽️ filter by coin category. Refer to /coin/categories/list ◽️ valid values: market_cap_desc, gecko_desc, gecko_asc, market_cap_asc, market_cap_desc, volume_asc, volume_desc, id_asc, id_descsort results by field. ◽️ valid values: 1..250 Total results per page ◽️ Page through results ◽️ Include sparkline 7 days data (eg. true, false) ◽️ Include price change percentage in 1h, 24h, 7d, 14d, 30d, 200d, 1y (eg. '
✔️ withVsCurrency('string')
❗️
✔️ withIds('string')
✔️ withCategory('string')
✔️ withOrder('string')
✔️ withPerPage('integer')
✔️ withPage('integer')
✔️ withSparkline('boolean')
✔️ withPriceChangePercentage('string')
url parameters
vs_currency
➞ string (required) ids
➞ string /coins/list
. category
➞ string order
➞ string per_page
➞ integer page
➞ integer sparkline
➞ boolean price_change_percentage
➞ string 1h,24h,7d
' comma-separated, invalid values will be discarded)
💡 sample usage
3. 📋 endpoint : /coins/{id}
Get current data (name, price, market, ... including exchange tickers) for a coin
endpoint parameters
id
➞ pass the coin id (can be obtained from /coins) eg. bitcoin
[ method ] : coins('{id}')
🔑
URL Keys : 6 ◽️ Include all localized languages in response (true/false) [default: true] ◽️ Include tickers data (true/false) [default: true] ◽️ Include market_data (true/false) [default: true] ◽️ Include community_data data (true/false) [default: true] ◽️ Include developer_data data (true/false) [default: true] ◽️ Include sparkline 7 days data (eg. true, false) [default: false]
✔️ withLocalization('string')
✔️ withTickers('boolean')
✔️ withMarketData('boolean')
✔️ withCommunityData('boolean')
✔️ withDeveloperData('boolean')
✔️ withSparkline('boolean')
url parameters
localization
➞ string tickers
➞ boolean market_data
➞ boolean community_data
➞ boolean developer_data
➞ boolean sparkline
➞ boolean
💡 sample usage
4. 📋 endpoint : /coins/{id}/tickers
Get coin tickers (paginated to 100 items)
endpoint parameters
id
➞ pass the coin id (can be obtained from /coins/list) eg. bitcoin
[ method ] : coins('{id}')->tickers()
🔑
URL Keys : 5 ◽️ filter results by exchange_ids (ref: v3/exchanges/list) ◽️ flag to show exchange_logo ◽️ Page through results ◽️ valid values: trust_score_desc (default), trust_score_asc and volume_desc ◽️ flag to show 2% orderbook depth. valid values: true, false
✔️ withExchangeIds('string')
✔️ withIncludeExchangeLogo('string')
✔️ withPage('integer')
✔️ withOrder('string')
✔️ withDepth('string')
url parameters
exchange_ids
➞ string include_exchange_logo
➞ string page
➞ integer order
➞ string depth
➞ string
💡 sample usage
5. 📋 endpoint : /coins/{id}/history
Get historical data (name, price, market, stats) at a given date for a coin
endpoint parameters
id
➞ pass the coin id (can be obtained from /coins) eg. bitcoin
[ method ] : coins('{id}')->history()
🔑
URL Keys : 2 ◽️ The date of data snapshot in dd-mm-yyyy eg. 30-12-2017 ◽️ Set to false to exclude localized languages in response
✔️ withDate('string')
❗️
✔️ withLocalization('string')
url parameters
date
➞ string (required) localization
➞ string
💡 sample usage
6. 📋 endpoint : /coins/{id}/market_chart
Get historical market data include price, market cap, and 24h volume (granularity auto)
endpoint parameters
id
➞ pass the coin id (can be obtained from /coins) eg. bitcoin
[ method ] : coins('{id}')->marketChart()
🔑
URL Keys : 3 ◽️ The target currency of market data (usd, eur, jpy, etc.) ◽️ Data up to number of days ago (eg. 1,14,30,max) ◽️ Data interval. Possible value: daily
✔️ withVsCurrency('string')
❗️
✔️ withDays('string')
❗️
✔️ withInterval('string')
url parameters
vs_currency
➞ string (required) days
➞ string (required) interval
➞ string
💡 sample usage
7. 📋 endpoint : /coins/{id}/market_chart/range
Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto)
endpoint parameters
id
➞ pass the coin id (can be obtained from /coins) eg. bitcoin
[ method ] : coins('{id}')->marketChart()->range()
🔑
URL Keys : 3 ◽️ The target currency of market data (usd, eur, jpy, etc.) ◽️ From date in UNIX Timestamp (eg. 1392577232) ◽️ To date in UNIX Timestamp (eg. 1422577232)
✔️ withVsCurrency('string')
❗️
✔️ withFrom('string')
❗️
✔️ withTo('string')
❗️url parameters
vs_currency
➞ string (required) from
➞ string (required) to
➞ string (required)
💡 sample usage
🌐 contract
1. 📋 endpoint : /coins/{id}/contract/{contract_address}
Get coin info from contract address
endpoint parameters
id
➞ Asset platform (See asset_platforms endpoint for list of options)
contract_address
➞ Token's contract address
[ method ] : coins('{id}')->contract('{contract_address}')
💡 sample usage
2. 📋 endpoint : /coins/{id}/contract/{contract_address}/market_chart/
Get historical market data include price, market cap, and 24h volume (granularity auto) from a contract address
endpoint parameters
id
➞ The id of the platform issuing tokens (See asset_platforms endpoint for list of options)
contract_address
➞ Token's contract address
[ method ] : coins('{id}')->contract('{contract_address}')->marketChart()
🔑
URL Keys : 2 ◽️ The target currency of market data (usd, eur, jpy, etc.) ◽️ Data up to number of days ago (eg. 1,14,30,max)
✔️ withVsCurrency('string')
❗️
✔️ withDays('string')
❗️url parameters
vs_currency
➞ string (required) days
➞ string (required)
💡 sample usage
3. 📋 endpoint : /coins/{id}/contract/{contract_address}/market_chart/range
Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto) from a contract address
endpoint parameters
id
➞ The id of the platform issuing tokens (See asset_platforms endpoint for list of options)
contract_address
➞ Token's contract address
[ method ] : coins('{id}')->contract('{contract_address}')->marketChart()->range()
🔑
URL Keys : 3 ◽️ The target currency of market data (usd, eur, jpy, etc.) ◽️ From date in UNIX Timestamp (eg. 1392577232) ◽️ To date in UNIX Timestamp (eg. 1422577232)
✔️ withVsCurrency('string')
❗️
✔️ withFrom('string')
❗️
✔️ withTo('string')
❗️url parameters
vs_currency
➞ string (required) from
➞ string (required) to
➞ string (required)
💡 sample usage
🌐 coins
1. 📋 endpoint : /coins/{id}/ohlc
Get coin's OHLC
endpoint parameters
id
➞ pass the coin id (can be obtained from /coins/list) eg. bitcoin
[ method ] : coins('{id}')->ohlc()
🔑
URL Keys : 2 ◽️ The target currency of market data (usd, eur, jpy, etc.) ◽️ Data up to number of days ago (1/7/14/30/90/180/365/max)
✔️ withVsCurrency('string')
❗️
✔️ withDays('string')
❗️url parameters
vs_currency
➞ string (required) days
➞ string (required)
💡 sample usage
🌐 asset_platforms
1. 📋 endpoint : /asset_platforms
List all asset platforms (Blockchain networks)
[ method ] : assetPlatforms()
🔑
URL Keys : 1 ◽️ apply relevant filters to results valid values: "nft" (asset_platform nft-support)
✔️ withFilter('string')
url parameters
filter
➞ string
💡 sample usage
🌐 categories
1. 📋 endpoint : /coins/categories/list
List all categories
[ method ] : coins()->categories()->list()
💡 sample usage
2. 📋 endpoint : /coins/categories
List all categories with market data
[ method ] : coins()->categories()
🔑
URL Keys : 1 ◽️ valid values: market_cap_desc (default), market_cap_asc, name_desc, name_asc, market_cap_change_24h_desc and market_cap_change_24h_asc
✔️ withOrder('string')
url parameters
order
➞ string
💡 sample usage
🌐 exchanges
1. 📋 endpoint : /exchanges
List all exchanges (Active with trading volumes)
[ method ] : exchanges()
🔑
URL Keys : 2 ◽️ Valid values: 1...250Total results per pageDefault value:: 100 ◽️ page through results
✔️ withPerPage('integer')
✔️ withPage('string')
url parameters
per_page
➞ integer page
➞ string
💡 sample usage
2. 📋 endpoint : /exchanges/list
List all supported markets id and name (no pagination required)
[ method ] : exchanges()->list()
💡 sample usage
3. 📋 endpoint : /exchanges/{id}
Get exchange volume in BTC and top 100 tickers only
endpoint parameters
id
➞ pass the exchange id (can be obtained from /exchanges/list) eg. binance
[ method ] : exchanges('{id}')
💡 sample usage
4. 📋 endpoint : /exchanges/{id}/tickers
Get exchange tickers (paginated, 100 tickers per page)
endpoint parameters
id
➞ pass the exchange id (can be obtained from /exchanges/list) eg. binance
[ method ] : exchanges('{id}')->tickers()
🔑
URL Keys : 5 ◽️ filter tickers by coin_ids (ref: v3/coins/list) ◽️ flag to show exchange_logo ◽️ Page through results ◽️ flag to show 2% orderbook depth i.e., cost_to_move_up_usd and cost_to_move_down_usd ◽️ valid values: trust_score_desc (default), trust_score_asc and volume_desc
✔️ withCoinIds('string')
✔️ withIncludeExchangeLogo('string')
✔️ withPage('integer')
✔️ withDepth('string')
✔️ withOrder('string')
url parameters
coin_ids
➞ string include_exchange_logo
➞ string page
➞ integer depth
➞ string order
➞ string
💡 sample usage
🌐 indexes
1. 📋 endpoint : /indexes
List all market indexes
[ method ] : indexes()
🔑
URL Keys : 2 ◽️ Total results per page ◽️ Page through results
✔️ withPerPage('integer')
✔️ withPage('integer')
url parameters
per_page
➞ integer page
➞ integer
💡 sample usage
2. 📋 endpoint : /indexes/{market_id}/{id}
get market index by market id and index id
endpoint parameters
market_id
➞ pass the market id (can be obtained from /exchanges/list)
id
➞ pass the index id (can be obtained from /indexes/list)
[ method ] : indexes('{market_id}','{id}')
💡 sample usage
3. 📋 endpoint : /indexes/list
list market indexes id and name
[ method ] : indexes()->list()
💡 sample usage
🌐 derivatives
1. 📋 endpoint : /derivatives
List all derivative tickers
[ method ] : derivatives()
🔑
URL Keys : 1 ◽️ ['all', 'unexpired'] - expired to show unexpired tickers, all to list all tickers, defaults to unexpired
✔️ withIncludeTickers('string')
url parameters
include_tickers
➞ string
💡 sample usage
2. 📋 endpoint : /derivatives/exchanges
List all derivative exchanges
[ method ] : derivatives()->exchanges()
🔑
URL Keys : 3 ◽️ order results using following params name_asc,name_desc,open_interest_btc_asc,open_interest_btc_desc,trade_volume_24h_btc_asc,trade_volume_24h_btc_desc ◽️ Total results per page ◽️ Page through results
✔️ withOrder('string')
✔️ withPerPage('integer')
✔️ withPage('integer')
url parameters
order
➞ string per_page
➞ integer page
➞ integer
💡 sample usage
3. 📋 endpoint : /derivatives/exchanges/{id}
show derivative exchange data
endpoint parameters
id
➞ pass the exchange id (can be obtained from derivatives/exchanges/list) eg. bitmex
[ method ] : derivatives()->exchanges('{id}')
🔑
URL Keys : 1 ◽️ ['all', 'unexpired'] - expired to show unexpired tickers, all to list all tickers, leave blank to omit tickers data in response
✔️ withIncludeTickers('string')
url parameters
include_tickers
➞ string
💡 sample usage
4. 📋 endpoint : /derivatives/exchanges/list
List all derivative exchanges name and identifier
[ method ] : derivatives()->exchanges()->list()
💡 sample usage
🌐 exchanges
1. 📋 endpoint : /exchanges/{id}/volume_chart
Get volume_chart data for a given exchange
endpoint parameters
id
➞ pass the exchange id (can be obtained from /exchanges/list) eg. binance
[ method ] : exchanges('{id}')->volumeChart()
🔑
URL Keys : 1 ◽️ Data up to number of days ago (eg. 1,14,30)
✔️ withDays('integer')
❗️url parameters
days
➞ integer (required)
💡 sample usage
🌐 nfts (beta)
1. 📋 endpoint : /nfts/list
List all supported NFT ids, paginated by 100 items per page, paginated to 100 items
[ method ] : nfts()->list()
🔑
URL Keys : 4 ◽️ valid values: h24_volume_native_asc, h24_volume_native_desc, floor_price_native_asc, floor_price_native_desc, market_cap_native_asc, market_cap_native_desc, market_cap_usd_asc, market_cap_usd_desc ◽️ The id of the platform issuing tokens (See asset_platforms endpoint for list of options) ◽️ Total results per page ◽️ Page through results
✔️ withOrder('string')
✔️ withAssetPlatformId('string')
✔️ withPerPage('integer')
✔️ withPage('integer')
url parameters
order
➞ string asset_platform_id
➞ string per_page
➞ integer page
➞ integer
💡 sample usage
2. 📋 endpoint : /nfts/{id}
Get current data (name, price_floor, volume_24h ...) for an NFT collection
endpoint parameters
id
➞ id of nft collection (can be obtained from /nfts/list)
[ method ] : nfts('{id}')
💡 sample usage
3. 📋 endpoint : /nfts/{asset_platform_id}/contract/{contract_address}
Get current data (name, price_floor, volume_24h ...) for an NFT collection
endpoint parameters
asset_platform_id
➞ The id of the platform issuing tokens (See asset_platforms endpoint for list of options, use filter=nft param)
contract_address
➞ The contract_address of the nft collection (/nfts/list for list of nft collection with metadata)
[ method ] : nfts('{asset_platform_id}')->contract('{contract_address}')
💡 sample usage
🌐 exchange_rates
1. 📋 endpoint : /exchange_rates
Get BTC-to-Currency exchange rates
[ method ] : exchangeRates()
💡 sample usage
🌐 search
1. 📋 endpoint : /search
Search for coins, categories and markets on CoinGecko
[ method ] : search()
🔑
URL Keys : 1 ◽️ Search string
✔️ withQuery('string')
❗️url parameters
query
➞ string (required)
💡 sample usage
🌐 trending
1. 📋 endpoint : /search/trending
Get trending search coins (Top-7) on CoinGecko in the last 24 hours
[ method ] : search()->trending()
💡 sample usage
🌐 global
1. 📋 endpoint : /global
Get cryptocurrency global data
[ method ] : global()
💡 sample usage
2. 📋 endpoint : /global/decentralized_finance_defi
Get cryptocurrency global decentralized finance(defi) data
[ method ] : global()->decentralizedFinanceDefi()
💡 sample usage
🌐 companies (beta)
1. 📋 endpoint : /companies/public_treasury/{coin_id}
Get public companies data
endpoint parameters
coin_id
➞ bitcoin or ethereum
[ method ] : companies()->publicTreasury('{coin_id}')
💡 sample usage