A Node.js wrapper for the CoinGecko API with no dependencies.
Latest version: 1.0.7
npm install coingeckojs
For complete API documentation, up-to-date parameters, responses and errors, please refer to https://www.coingecko.com/api/docs/v3.
//1. Import coingeckojs
const CoinGecko = require('coingeckojs');
//2. Initiate the CoinGecko API Client
const CoinGeckoClient = new CoinGecko();
//3. Make calls
var func = async() => {
let data = await CoinGeckoClient.ping();
};
This module provides helper constants for use in calls.
Order results in specific calls by using one of the following values.
Key | Usage | Description |
---|---|---|
GECKO_ASC |
CoinGecko.ORDER.GECKO_ASC |
Order results by CoinGecko's scoring system (ascending) |
GECKO_DESC |
CoinGecko.ORDER.GECKO_DESC |
Order results by CoinGecko's scoring system (descending) |
MARKET_CAP_ASC |
CoinGecko.ORDER.MARKET_CAP_ASC |
Order results by market cap (ascending) |
MARKET_CAP_DESC |
CoinGecko.ORDER.MARKET_CAP_DESC |
Order results by market cap (descending) |
VOLUME_ASC |
CoinGecko.ORDER.VOLUME_ASC |
Order results by volume (ascending) |
VOLUME_DESC |
CoinGecko.ORDER.VOLUME_DESC |
Order results by volume (descending) |
COIN_NAME_ASC |
CoinGecko.ORDER.COIN_NAME_ASC |
Order results by coin name (ascending) |
COIN_NAME_DESC |
CoinGecko.ORDER.COIN_NAME_DESC |
Order results by coin name (descending) |
PRICE_ASC |
CoinGecko.ORDER.PRICE_ASC |
Order results by price (ascending) |
PRICE_DESC |
CoinGecko.ORDER.PRICE_DESC |
Order results by price (descending) |
HOUR_24_ASC |
CoinGecko.ORDER.HOUR_24_ASC |
Order results by 24 hour change (ascending) |
HOUR_24_DESC |
CoinGecko.ORDER.HOUR_24_DESC |
Order results by 24 hour change (descending) |
TRUST_SCORE_DESC |
CoinGecko.ORDER.TRUST_SCORE_DESC |
Order results by CoinGecko's trust scoring system (descending) |
Available status update categories to filter by.
Key | Usage | Description |
---|---|---|
GENERAL |
CoinGecko.STATUS_UPDATE_CATEGORY.GENERAL |
Filter status update results by general news |
MILESTONE |
CoinGecko.STATUS_UPDATE_CATEGORY.MILESTONE |
Filter status update results by milestones |
PARTNERSHIP |
CoinGecko.STATUS_UPDATE_CATEGORY.PARTNERSHIP |
Filter status update results by partnerships |
EXCHANGE_LISTING |
CoinGecko.STATUS_UPDATE_CATEGORY.EXCHANGE_LISTING |
Filter status update results by exchange listings |
SOFTWARE_RELEASE |
CoinGecko.STATUS_UPDATE_CATEGORY.SOFTWARE_RELEASE |
Filter status update results by software releases |
FUND_MOVEMENT |
CoinGecko.STATUS_UPDATE_CATEGORY.FUND_MOVEMENT |
Filter status update results by fund movements |
NEW_LISTINGS |
CoinGecko.STATUS_UPDATE_CATEGORY.NEW_LISTINGS |
Filter status update results by new listings |
EVENT |
CoinGecko.STATUS_UPDATE_CATEGORY.EVENT |
Filter status update results by events |
Available status update project types to filter by.
Key | Usage | Description |
---|---|---|
COIN |
CoinGecko.STATUS_UPDATE_PROJECT_TYPE.COIN |
Filter status update results by coins only |
MARKET |
CoinGecko.STATUS_UPDATE_PROJECT_TYPE.MARKET |
Filter status update results by markets only |
List of event types (most recent from CoinGeckoClient.events.fetchTypes()
)
Key | Usage | Description |
---|---|---|
EVENT |
CoinGecko.EVENT_TYPE.EVENT |
Filter events by events only |
CONFERENCE |
CoinGecko.EVENT_TYPE.CONFERENCE |
Filter events by conferences only |
MEETUP |
CoinGecko.EVENT_TYPE.MEETUP |
Filter events by meetups only |
All calls using the CoinGeckoClient are asynchronous.
All calls are returned in the following format:
{
success: Boolean,
message: String,
code: Number,
data: Object
}
The CoinGeckoClient splits up the currently available calls outline in the official CoinGecko API documentation into five parts. (Aside from the ping
and global
calls.)
Namespace | Usage | Description |
---|---|---|
coins |
CoinGeckoClient.coins[...] |
Calls related to coins |
exchanges |
CoinGeckoClient.exchanges[...] |
Calls related to exchanges |
statusUpdates |
CoinGeckoClient.statusUpdates[...] |
Calls related to status updates |
events |
CoinGeckoClient.events[...] |
Calls related to events |
exchangeRates |
CoinGeckoClient.exchangeRates[...] |
Calls related to exchange rates |
Check API server status.
Check API server status.
Usage Example:
let data = await CoinGeckoClient.ping();
Get cryptocurrency global data.
Get cryptocurrency global data.
Usage Example:
let data = await CoinGeckoClient.global();
Calls related to coins.
List all coins with data (name, price, market, developer, community, etc) - paginated by 50.
Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins
Params:
params
:Object
- Parameters to pass through to the requestparams.order
:String
- Order results byCoinGecko.ORDER[*]
params.per_page
:Number
- Total results per pageparams.page
:Number
- Page through resultsparams.localization
:Boolean
[default:true
] - Set to false to exclude localized languages in responseparams.sparkline
:Boolean
[default:false
] - Include sparkline 7 days data
Usage Example:
let data = await CoinGeckoClient.coins.all();
Use this to obtain all the coins’ id in order to make API calls
Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins_list
Usage Example:
let data = await CoinGeckoClient.coins.list();
Use this to obtain all the coins market data (price, market cap, volume).
Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins_markets
Params:
params
:Object
- Parameters to pass through to the requestparams.order
:String
- Order results byCoinGecko.ORDER[*]
params.per_page
:Number
- Total results per pageparams.page
:Number
- Page through resultsparams.localization
:Boolean
[default:true
] - Set to false to exclude localized languages in responseparams.sparkline
:Boolean
[default:false
] - Include sparkline 7 days dataparams.vs_currency
:String
[default:usd
] - The target currency of market data (usd
,eur
,jpy
, etc.)params.ids
:Array|String
- List of coin id to filter if you want specific results
Usage Example:
let data = await CoinGeckoClient.coins.markets();
Get current data (name, price, market, … including exchange tickers) for a coin.
Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins__id_
Params:
coinId
:String
- (Required) The coin id (can be obtained fromcoins.list()
) eg.bitcoin
params
:Object
- Parameters to pass through to the requestparams.tickers
:Boolean
- [default:true
] - Include ticker dataparams.market_data
:Boolean
- [default:true
] - Include market dataparams.community_data
:Boolean
- [default:true
] - Include community dataparams.developer_data
:Boolean
- [default:true
] - Include developer dataparams.localization
:Boolean
[default:true
] - Set to false to exclude localized languages in responseparams.sparkline
:Boolean
[default:false
] - Include sparkline 7 days data
Usage Example:
let data = await CoinGeckoClient.coins.fetch('bitcoin', {});
Get coin tickers (paginated to 100 items).
Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins__id__tickers
Params:
coinId
:String
- (Required) The coin id (can be obtained fromcoins.list()
) eg.bitcoin
params
:Object
- Parameters to pass through to the requestparams.page
:Number
- Page through resultsparams.exchange_ids
:Array|String
- Filter tickers by exchange_ids (can be obtained fromexchanges.list()
) eg.binance
params.order
:String
- [default:trust_score_desc
] - Order results byCoinGecko.ORDER.TRUST_SCORE_DESC
orCoinGecko.ORDER.VOLUME_DESC
Usage Example:
let data = await CoinGeckoClient.coins.fetchTickers('bitcoin');
Get historical data (name, price, market, stats) at a given date for a coin.
Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins__id__history
Params:
coinId
:String
- (Required) The coin id (can be obtained fromcoins.list()
) eg.bitcoin
params
:Object
- Parameters to pass through to the requestparams.date
:String
- (Required) The date of data snapshot in dd-mm-yyyy eg.30-12-2017
params.localization
:Boolean
[default:true
] - Set to false to exclude localized languages in response
Usage Example:
let data = await CoinGeckoClient.coins.fetchHistory('bitcoin', {
date: '30-12-2017'
});
Get historical market data include price, market cap, and 24h volume (granularity auto).
Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins__id__market_chart
Params:
coinId
:String
- (Required) The coin id (can be obtained fromcoins.list()
) eg.bitcoin
params
:Object
- Parameters to pass through to the requestparams.days
:String
- Data up to number of days ago (eg.1
,14
,30
,max
)params.vs_currency
:String
[default:usd
] - The target currency of market data (usd
,eur
,jpy
, etc.)
Usage Example:
let data = await CoinGeckoClient.coins.fetchMarketChart('bitcoin');
Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto) Minutely data will be used for duration within 1 day, Hourly data will be used for duration between 1 day and 90 days, Daily data will be used for duration above 90 days.
Official documentation: https://www.coingecko.com/api/documentations/v3#/coins/get_coins__id__market_chart_range
Params:
coinId
:String
- (Required) The coin id (can be obtained fromcoins.list()
) eg.bitcoin
params
:Object
- Parameters to pass through to the requestparams.vs_currency
: string - (Required) The target currency of market data (usd, eur, jpy, etc.)params.from
: integer - (Required) From date in UNIX Timestamp (eg. 1392577232)params.to
: integer - (Required) To date in UNIX Timestamp (eg. 1392577232)
Usage Example:
let data = await CoinGeckoClient.coins.fetchMarketChartRange('tomochain', {
"vs_currency": "usd",
"from" : 1542100000,
"to": 1542170000
});
Response Example:
{ prices: [ [ 1542153600000, 0.41064796105544843 ] ],
market_caps: [ [ 1542153600000, 22585637.85804966 ] ],
total_volumes: [ [ 1542153600000, 1244349.338658666 ] ] }
Get status updates for a given coin.
Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins__id__status_updates
Params:
coinId
:String
- (Required) The coin id (can be obtained fromcoins.list()
) eg.bitcoin
params
:Object
- Parameters to pass through to the requestparams.per_page
:Number
- Total results per pageparams.page
:Number
- Page through results
Usage Example:
let data = await CoinGeckoClient.coins.fetchStatusUpdates('bitcoin');
Get coin info from contract address.
Official documentation: https://www.coingecko.com/api/docs/v3#/coins/get_coins__id__contract__contract_address_
Params:
contractAddress
:String
- (Required) Token’s contract addressassetPlatform
:String
[default:ethereum
] - Asset platform (onlyethereum
is supported at this moment).
Usage Example:
// 0x contract address (as a test)
let zrx = '0xe41d2489571d322189246dafa5ebde1f4699f498';
let data = await CoinGeckoClient.coins.fetchCoinContractInfo(zrx);
Calls related to exchanges.
List all exchanges.
Official documentation: https://www.coingecko.com/api/docs/v3#/exchanges_(beta)/get_exchanges
Usage Example:
let data = await CoinGeckoClient.exchanges.all();
List all supported markets id and name (no pagination required).
Official documentation: https://www.coingecko.com/api/docs/v3#/exchanges_(beta)/get_exchanges_list
Usage Example:
let data = await CoinGeckoClient.exchanges.list();
Get exchange volume in BTC and top 100 tickers only for a given exchange.
Official documentation: https://www.coingecko.com/api/docs/v3#/exchanges_(beta)/get_exchanges__id_
Params:
exchangeId
:String
- (Required) The exchange id (can be obtained fromexchanges.all()
) eg.binance
Usage Example:
let data = await CoinGeckoClient.exchanges.fetch('binance');
Get tickers for a given exchange.
Official documentation: https://www.coingecko.com/api/docs/v3#/exchanges_(beta)/get_exchanges__id__tickers
Params:
exchangeId
:String
- (Required) The exchange id (can be obtained fromexchanges.all()
) eg.binance
params
:Object
- Parameters to pass through to the requestparams.page
:Number
- Page through resultsparams.coin_ids
:Array|String
- Filter tickers by coin_ids (can be obtained fromcoins.list()
) eg.bitcoin
params.order
:String
- [default:trust_score_desc
] - Order results byCoinGecko.ORDER.TRUST_SCORE_DESC
orCoinGecko.ORDER.VOLUME_DESC
Usage Example:
let data = await CoinGeckoClient.exchanges.fetchTickers('binance');
Get status updates for a given exchange.
Official documentation: https://www.coingecko.com/api/docs/v3#/exchanges_(beta)/get_exchanges__id__status_updates
Params:
exchangeId
:String
- (Required) The exchange id (can be obtained fromexchanges.all()
) eg.binance
params
:Object
- Parameters to pass through to the requestparams.page
:Number
- Page through resultsparams.per_page
:Number
- Total results per page
Usage Example:
let data = await CoinGeckoClient.exchanges.fetchStatusUpdates('binance');
Get volume chart data for a given exchange, returned in BTC
Official documentation: https://www.coingecko.com/en/api#operations-exchanges%20(beta)-get_exchanges__id__volume_chart
Params:
exchangeId
:String
- (Required) The exchange id (can be obtained fromexchanges.all()
) eg.binance
params
:Object
- Parameters to pass through to the requestparams.days
:Number
- Data up to number of days ago (eg. 1, 14, 30)
Usage Example:
let data = await CoinGeckoClient.exchanges.fetchVolumeChart('binance', {
days: 1,
});
Calls related to status updates.
List all status_updates with data (description, category, created_at, user, user_title and pin).
Official documentation: https://www.coingecko.com/api/docs/v3#/status_updates_(beta)/get_status_updates
Params:
params
:Object
- Parameters to pass through to the requestparams.category
:Number
- Filter results byCoinGecko.STATUS_UPDATE_CATEGORY[*]
params.project_type
:Number
- Filter results byCoinGecko.STATUS_UPDATE_PROJECT_TYPE[*]
(If left empty returns both status fromcoins
andmarkets
)params.page
:Number
- Page through resultsparams.per_page
:Number
- Total results per page
Usage Example:
let data = await CoinGeckoClient.statusUpdates.all();
Calls related to events.
Get events, paginated by 100.
Official documentation: https://www.coingecko.com/api/docs/v3#/events/get_events
Params:
params
:Object
- Parameters to pass through to the requestparams.country_code
:Number
- country_code of event (eg.US
). Useevents.fetchHistory()
for list ofcountry_codes
params.type
:String
- Type of event (eg.Conference
). Useevents.fetchTypes()
for list of types. Or useCoinGecko.EVENT_TYPE[*]
params.page
:Number
- Page through resultsparams.upcoming_events_only
:Boolean
- [default:true
] - Lists only upcoming eventsparams.from_date
:String
- Lists events after this date yyyy-mm-ddparams.to_date
:String
- Lists events before this date yyyy-mm-dd (setupcoming_events_only
to false if fetching past events)
Usage Example:
let data = await CoinGeckoClient.events.all();
Get list of event countries.
Official documentation: https://www.coingecko.com/api/docs/v3#/events/get_events_countries
Usage Example:
let data = await CoinGeckoClient.events.fetchCountries();
Get list of event types.
Official documentation: https://www.coingecko.com/api/docs/v3#/events/get_events_types
Usage Example:
let data = await CoinGeckoClient.events.fetchTypes();
Calls related to exchange rates.
Get BTC-to-Currency exchange rates.
Official documentation: https://www.coingecko.com/api/docs/v3#/exchange_rates/get_exchange_rates
Usage Example:
let data = await CoinGeckoClient.exchangeRates.all();
Calls related to simple endpoints.
Get the current price of any cryptocurrencies in any other supported currencies that you need.
Official documentation: https://www.coingecko.com/api/docs/v3#/simple/get_simple_price
Params:
params
:Object
- Parameters to pass through to the requestparams.ids
:Array|String
- (Required) A single id or a list of coin ids to filter if you want specific results. Usecoins.list()
for a list of coin ids.params.vs_currencies
:Array|String
- [default:usd
] - A single id or a list of ids. Usesimple.supportedVsCurrencies()
for a list of vsCurrency ids.params.include_24hr_vol
:Boolean
- [default:false
] - To include 24hr volume.params.include_last_updated_at
:Boolean
- [default:false
] - To include last_updated_at of price.
Usage Example:
let data = await CoinGeckoClient.simple.price({
ids: ['bitcoin', 'ethereum'],
vs_currencies: ['eur', 'usd'],
});
Get list of supported vs/comparisons currencies.
Official documentation: https://www.coingecko.com/api/docs/v3#/simple/get_simple_supported_vs_currencies
Usage Example:
let data = await CoinGeckoClient.simple.supportedVsCurrencies();
Get current price of tokens (using contract addresses) for a given platform in any other currency that you need.
Official documentation: https://www.coingecko.com/en/api#operations-simple-get_simple_token_price__id_
Params:
params
:Object
- Parameters to pass through to the requestassetPlatform
:String
- [default:ethereum
] - (Required) Asset platform (only ethereum is supported at this moment)params.contract_addresses
:String|Array
- (Required) Token’s contract addressparams.vs_currencies
:String|Array
- (Required) vs_currency of coins. Usesimple.supportedVsCurrencies()
for a list of vsCurrency ids.params.include_market_cap
:Boolean
- [default:false
] - Include market cap in results or notparams.include_24hr_vol
:Boolean
- [default:false
] - Include 24hr volume in results or notparams.include_24hr_change
:Boolean
- [default:false
] - Include 24hr change in results or notparams.include_last_updated_at
:Boolean
- [default:false
] - Include last updated date in results or not
Usage Example:
// 0x contract address (as a test)
var zrx = '0xe41d2489571d322189246dafa5ebde1f4699f498';
let data = await CoinGeckoClient.simple.fetchTokenPrice({
contract_addresses: zrx,
vs_currencies: 'usd',
});
Thank you Mark Miscavage