cryptocompare
CryptoCompare JavaScript API
Install
npm install --save cryptocompare
Usage
Note: cryptocompare depends on fetch()
being defined globally.
-
If you are using this in electron, it should work without any configuration.
-
If you are using this in Node.js, you will need to use node-fetch
.
-
The package works without an API key but the IP limits will slowly be reduced over time, to create an API key just go to https://www.cryptocompare.com/cryptopian/api-keys and make sure you give it the "Read All Price Streaming and Polling Endpoints" permission
Example:
global.fetch = require('node-fetch')
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
Methods
coinList()
Get the current list of all cryptocurrencies and the following information about each coin.
coinList()
No parameters
Returns
(Object)...
BaseImageUrl
(String) The base url for all the images from the ImageUrl field (https://www.cryptocompare.com),BaseLinkUrl
The base url for all the links from the Url field (https://www.cryptocompare.com)Data
(Object) Contains the following infomration about each coin.
Id
(String)Url
(String) Url to the CryptoCompare page for the coin. (Ex: /coins/eth/overview
) Url must be appended to https://www.cryptocompare.com
.ImageUrl
(String) Url to get the coin logo image. (Ex: /media/351001/404.png
). Url must be appended to https://www.cryptocompare.com
.Name
(String) Ticker name of the given cryptocurrency.Symbol
(String) Ticker symbol of the given cryptocurrency (usually the same as the name).CoinName
(String) Name of the given cryptocurrency.FullName
(String) Name of the given cryptocurrency concatenated with the symbol (Ex: Ethereum (ETH)
).Algorithm
(String) Name cryptographic algorithm for that coin.ProofType
(String) The proof type of the cryptocurrency.ProofType
(String) The proof type of the cryptocurrency.FullyPremined
(String) Returns "1" if the coin was premined, if not it returns "0".TotalCoinSupply
(String) Total supply of the cryptocurrency.PreMinedValue
(String) Value of premined coins.TotalCoinsFreeFloat
(String)SortOrder
(String) The order CryptoCompare ranks the coin inside their internal system.Sponsored
(Boolean) Is true
when the coin is sponsored by CryptoCompare, is false
otherwise.
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.coinList()
.then(coinList => {
console.log(coinList)
})
.catch(console.error)
exchangeList()
Returns all the exchanges that CryptoCompare has integrated with.
exchangeList()
No parameters
Returns
(Object)
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.exchangeList()
.then(exchangeList => {
console.log(exchangeList)
})
.catch(console.error)
price()
Get the current price of any cryptocurrency in any other currency.
price(fsym, tsyms[, options])
fsym
(String) From Symboltsyms
(Array of Strings | String) To Symbol(s)options
(Object)
tryConversion
(Boolean) By default, if the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. Set tryConversion
to false
to disable using BTC for conversion.exchanges
(Array of Strings | Array) Exchanges to get price data from. By default, average data is used. (You can get a list of top exchanges for a given pair with topExchanges()
.)
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.price('BTC', ['USD', 'EUR'])
.then(prices => {
console.log(prices)
})
.catch(console.error)
cc.price('BTC', 'USD')
.then(prices => {
console.log(prices)
})
.catch(console.error)
priceMulti()
Works like price()
, except it allows you to specify a matrix of From Symbols.
priceMulti(fsyms, tsyms[, options])
fsyms
(Array of Strings | String) From Symbol(s)tsyms
(Array of Strings | String) To Symbol(s)options
(Object)
tryConversion
(Boolean) By default, if the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. Set tryConversion
to false
to disable using BTC for conversion.exchanges
(Array of Strings | Array) Exchanges to get price data from. By default, average data is used. (You can get a list of top exchanges for a given pair with topExchanges()
.)
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.priceMulti(['BTC', 'ETH'], ['USD', 'EUR'])
.then(prices => {
console.log(prices)
})
.catch(console.error)
cc.priceMulti('BTC', 'USD')
.then(prices => {
console.log(prices)
})
.catch(console.error)
priceFull()
Get all the current trading info (price, vol, open, high, low, etc.) of any list of cryptocurrencies in any other currency.
priceFull(fsyms, tsyms[, options])
fsyms
(Array of Strings | String) From Symbol(s)tsyms
(Array of Strings | String) To Symbol(s)options
(Object)
tryConversion
(Boolean) By default, if the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. Set tryConversion
to false
to disable using BTC for conversion.exchanges
(Array of Strings | Array) Exchanges to get price data from. By default, average data is used. (You can get a list of top exchanges for a given pair with topExchanges()
.)
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.priceFull(['BTC', 'ETH'], ['USD', 'EUR'])
.then(prices => {
console.log(prices)
})
.catch(console.error)
priceHistorical()
Get the price of any cryptocurrency in any other currency at a given timestamp. The price comes from the daily info - so it would be the price at the end of the day GMT based on the requested timestamp.
priceHistorical(fsym, tsyms, time[, options])
fsym
(String) From Symboltsyms
(Array of Strings | String) To Symbol(s)time
(Date) Date in history that you want price data foroptions
(Object)
tryConversion
(Boolean) By default, if the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. Set tryConversion
to false
to disable using BTC for conversion.exchanges
(Array of Strings | Array) Exchanges to get price data from. By default, average data is used. (You can get a list of top exchanges for a given pair with topExchanges()
.)
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.priceHistorical('BTC', ['USD', 'EUR'], new Date('2017-01-01'))
.then(prices => {
console.log(prices)
})
.catch(console.error)
generateAvg()
Compute the current trading info (price, vol, open, high, low etc) of the requested pair as a volume weighted average based on the markets requested.
generateAvg(fsym, tsym, markets[, tryConversion])
fsym
(String) From Symboltsym
(String) To Symbolmarkets
(Array) Array of markets to base the average on. (You can get a list of top exchanges for a given pair with topExchanges()
.)tryConversion
(Boolean) By default, if the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. Set tryConversion
to false
to disable using BTC for conversion.
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.generateAvg('BTC', 'USD', ['Coinbase', 'Kraken', 'Bitstamp', 'Bitfinex'])
.then(data => {
console.log(data)
})
.catch(console.error)
topPairs()
Get top pairs by volume for a currency.
topPairs(fsym[, limit])
fsym
(String) From Symbollimit
(Number) Limit the number of pairs you receive (default 5).
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.topPairs('BTC', 2)
.then(pairs => {
console.log(pairs)
})
.catch(console.error)
topExchanges()
Get top exchanges by volume for a currency pair.
topExchanges(fsym, tsym[, limit])
fsym
(String) From Symboltsym
(String) To Symbollimit
(Number) Limit the number of exchanges you receive (default 5).
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.topExchanges('BTC', 'USD', 2)
.then(exchanges => {
console.log(exchanges)
})
.catch(console.error)
topExchangesFull()
Get full data on top exchanges by volume for a currency pair.
topExchangesFull(fsym, tsym[, limit])
fsym
(String) From Symboltsym
(String) To Symbollimit
(Number) Limit the number of exchanges you receive (default 5).
histoDay()
Get open, high, low, close, volumefrom and volumeto from the daily historical data. The values are based on 00:00 GMT time.
histoDay(fsym, tsym[, options])
fsym
(String) From Symboltsym
(String) To Symboloptions
(Object)
aggregate
(Number) Number of data points to aggregate.aggregatePredictableTimePeriods
(Boolean) Generate predictable time periods.allData
(Boolean) Returns all data.toTs
(Number) Last unix timestamp to return data for.limit
(Number | 'none'
) Limit the number of days to lookup. Default is 30. If you set it to the string 'none'
, you will get all available data.tryConversion
(Boolean) By default, if the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. Set tryConversion
to false
to disable using BTC for conversion.timestamp
(Date) By default, histoDay()
gets historical data for the past several days. Use the timestamp
option to set a historical start point.exchange
(String) Exchange to get history data from. By default, average data is used. (You can get a list of top exchanges for a given pair with topExchanges()
.)
cc.histoDay('BTC', 'USD')
.then(data => {
console.log(data)
})
.catch(console.error)
histoHour()
Get open, high, low, close, volumefrom and volumeto from the hourly historical data.
histoHour(fsym, tsym[, options])
fsym
(String) From Symboltsym
(String) To Symboloptions
(Object)
aggregate
(Number) Number of data points to aggregate.aggregatePredictableTimePeriods
(Boolean) Generate predictable time periods.toTs
(Number) Last unix timestamp to return data forlimit
(Number) Limit the number of hours to lookup. Default is 168.tryConversion
(Boolean) By default, if the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. Set tryConversion
to false
to disable using BTC for conversion.timestamp
(Date) By default, histoHour()
gets historical data for the past several hours. Use the timestamp
option to set a historical start point.exchange
(String) Exchange to get history data from. By default, average data is used. (You can get a list of top exchanges for a given pair with topExchanges()
.)
cc.histoHour('BTC', 'USD')
.then(data => {
console.log(data)
})
.catch(console.error)
histoMinute()
Get open, high, low, close, volumefrom and volumeto from the minute-by-minute historical data.
histoMinute(fsym, tsym[, options])
fsym
(String) From Symboltsym
(String) To Symboloptions
(Object)
aggregate
(Number) Number of data points to aggregate.aggregatePredictableTimePeriods
(Boolean) Generate predictable time periods.toTs
(Number) Last unix timestamp to return data forlimit
(Number) Limit the number of minutes to lookup. Default is 1440.tryConversion
(Boolean) By default, if the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. Set tryConversion
to false
to disable using BTC for conversion.timestamp
(Date) By default, histoMinute()
gets historical data for the past several minutes. Use the timestamp
option to set a historical start point.exchange
(String) Exchange to get history data from. By default, average data is used. (You can get a list of top exchanges for a given pair with topExchanges()
.)
cc.histoMinute('BTC', 'USD')
.then(data => {
console.log(data)
})
.catch(console.error)
newsList()
Returns news articles from the providers that CryptoCompare has integrated with.
newsList(lang[, options])
lang
(String) Preferred language - English (EN) or Portuguese (PT)options
(Object)
feeds
(Array of Strings | Array) Specific news feeds to retrieve news from, if empty, defaults to all of them. (You can get a list of news feeds with newsFeedsAndCategories().Feeds
..)categories
(Array of Strings | Array) Category of news articles to return, if empty, defaults to all of them. (You can get a list of news categories with newsFeedsAndCategories().Categories
..)excludeCategories
(Array of Strings | Array) News article categories to exclude from results, if empty, defaults to none. (You can get a list of news categories with newsFeedsAndCategories().Categories
..)lTs
(Date) Returns news before that timestamp
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.newsList('EN')
.then(newsList => {
console.log(newsList)
})
.catch(console.error)
newsFeedsAndCategories()
Returns all the news feeds (providers) that CryptoCompare has integrated with and the full list of categories.
newsFeedsAndCategories()
No parameters
Returns
(Object)
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.exchangeList()
.then(newsFeedsAndCategories => {
console.log(newsFeedsAndCategories)
})
.catch(console.error)
constituentExchangeList()
Returns all the constituent exchanges in the request instrument.
constituentExchangeList([options])
options
(Object)
instrument
(String) The type of average instrument.
Returns
(Object)
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.constituentExchangeList()
.then(exchanges => {
console.log(exchanges)
})
.catch(console.error)
latestSocial()
Returns latest social stats data for the coin requested.
Note: Requires a valid API key.
latestSocial([options])
options
(Object)
coinId
(Number) The id of the coin.
Returns
(Object)
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.latestSocial()
.then(social => {
console.log(social)
})
.catch(console.error)
histoSocial()
Returns social stats data for the coin requested.
Note: Requires a valid API key.
histoSocial(timePeriod[, options])
timePeriod
(String) Time period - 'day' or 'hour'options
(Object)
coinId
(Number) The id of the coin.aggregate
(Number) Time period to aggregate the data over.aggregatePredictableTimePeriods
(Boolean) Only used if aggregate
param included. If false, then it will create time slots based on when the call is made.limit
(Number) Number of data points to return.toTs
(Number) Last unix timestamp to return data for
Returns
(Array of Objects)
const cc = require('cryptocompare')
cc.setApiKey('<your-api-key>')
cc.histoSocial('hour')
.then(socialStats => {
console.log(socialStats)
})
.catch(console.error)
License
MIT