Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

coingecko-api-v3

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coingecko-api-v3 - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

2

package.json
{
"name": "coingecko-api-v3",
"version": "0.0.2",
"version": "0.0.3",
"description": "The nodejs api library for accessing coingecko api v3 , develop with typescript",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

import { CoinGeckoClient } from './CoinGeckoClient';
import { PLATFORMS } from './Enum';

@@ -36,3 +37,3 @@ const client = new CoinGeckoClient();

it.only('/coins/{id}/tickers should successful', async () => {
it('/coins/{id}/tickers should successful', async () => {
const ticker = await client.coinTickers({ id: 'origin-protocol' });

@@ -43,4 +44,44 @@ expect(ticker.name).toEqual("Origin Protocol")

it('/coins/{id}/history should successful', async () => {
const coin = await client.coinHistory({ id: 'bitcoin', date: '01-04-2021' });
expect(coin.name).toEqual("Bitcoin")
expect(coin.localization).not.toBeNull();
expect(coin).toMatchSnapshot();
})
it.only('/simple/market should successful', async () => {
it('/coins/{id}/history should successful with no localization', async () => {
const coin = await client.coinHistory({ id: 'bitcoin', date: '01-04-2021', localization: false });
expect(coin.name).toEqual("Bitcoin")
expect(coin.localization).toEqual(undefined);
})
it('/coins/{id}/market_chart should successful', async () => {
const marketChart = await client.coinMarketChart({ id: 'bitcoin', vs_currency: 'aud', interval: 'hourly', days: 1 });
expect(marketChart.prices.length).toBeGreaterThan(12)
expect(marketChart.prices[0].length).toBe(2)
expect(marketChart.prices[0][0]).toBeGreaterThan(0)
expect(marketChart.prices[0][1]).toBeGreaterThan(0)
})
it('/coins/{id}/market_chart/range should successful', async () => {
const marketChart = await client.coinMarketChartRange({ id: 'bitcoin', vs_currency: 'aud', from: 1392577232, to: 1618716149 });
expect(marketChart.prices.length).toBeGreaterThan(12)
expect(marketChart.prices[0].length).toBe(2)
expect(marketChart.prices[0][0]).toBeGreaterThan(0)
expect(marketChart.prices[0][1]).toBeGreaterThan(0)
})
it('/coins/{id}/status_updates should successful', async () => {
const statusUpdate = await client.coinStatusUpdates({ id: 'litecoin' });
expect(statusUpdate.status_updates.length).toBeGreaterThan(0)
})
it('/coins/{id}/ohlc should successful', async () => {
const ohlc = await client.coinOHLC({ id: 'litecoin', vs_currency: 'aud', days: 30 });
expect(ohlc.length).toBeGreaterThan(0)
expect(ohlc[0].length).toBe(5)
})
it('/simple/market should successful', async () => {
const price = await client.simpleTokenPrice({ contract_addresses: '0x8207c1ffc5b6804f6024322ccf34f29c3541ae26', id: 'ethereum', vs_currencies: 'btc,eth' });

@@ -59,4 +100,85 @@ expect(price).toMatchObject({

})
describe('Contract', () => {
it('/coins/{id}/contract/{contract_address} should successful', async () => {
const aave = await client.contract({ id: 'ethereum', 'contract_address': '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9' });
expect(aave.name).toBe('Aave');
})
it('/coins/{id}/contract/{contract_address}/market_chart should successful', async () => {
const aave = await client.contractMarketChart({
id: 'ethereum',
'contract_address': '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9', vs_currency: 'aud', days: 5
});
expect(aave.prices.length).toBeGreaterThan(0);
})
it('/coins/{id}/contract/{contract_address}/market_chart/range should successful', async () => {
const aave = await client.contractMarketChartRange({
id: 'ethereum',
'contract_address': '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9', vs_currency: 'eth',
from: 1392577232,
to: 1618716149
});
expect(aave.prices.length).toBeGreaterThan(0);
expect(aave.market_caps.length).toBeGreaterThan(0);
expect(aave.total_volumes.length).toBeGreaterThan(0);
})
})
describe('Exchange', () => {
it('/exchanges should successful', async () => {
const exchanges = await client.exchanges({
});
expect(exchanges.length).toBeGreaterThan(0);
expect(exchanges[0]).toEqual({
id: expect.any(String),
name: expect.any(String),
country: expect.any(String),
description: expect.any(String),
has_trading_incentive: expect.any(Boolean),
image: expect.any(String),
trade_volume_24h_btc: expect.any(Number),
trade_volume_24h_btc_normalized: expect.any(Number),
trust_score: expect.any(Number),
trust_score_rank: expect.any(Number),
url: expect.any(String),
year_established: expect.any(Number),
})
})
it('/exchange/list should successful', async () => {
const exchanges = await client.exchangeList();
expect(exchanges.length).toBeGreaterThan(0);
expect(exchanges[0]).toEqual({
id: 'aave',
name: 'Aave'
})
})
it('/exchange/id should successful', async () => {
const aave = await client.exchangeId('aave');
expect(aave.name).toEqual('Aave');
})
it('/exchange/id/tickers should successful', async () => {
const aave = await client.exchangeIdTickers({ id: 'aave' });
expect(aave.name).toEqual('Aave');
expect(aave.tickers.length).toBeGreaterThan(1);
})
it('/exchange/id/status_update should successful', async () => {
const aave = await client.exchangeIdStatusUpdates({ id: 'whitebit' });
expect(aave.status_updates.length).toBeGreaterThan(1);
})
it('/exchange/id/volume_chart should successful', async () => {
const aave = await client.exchangeIdVolumeChart({ id: 'whitebit', days: 1 });
expect(aave.length).toBeGreaterThan(1);
})
})
})
import axios, { AxiosInstance } from 'axios';
import qs from 'qs';
import { API_ROUTES } from './Enum';
import { CoinListResponseItem, CoinMarket, PingResponse, TrendingResponse, SimplePriceResponse, TokenPriceResponse, CoinFullInfo, CoinTickerResponse } from './Inteface';
import { API_ROUTES, PLATFORMS } from './Enum';
import { CoinListResponseItem, CoinMarket, PingResponse, TrendingResponse, SimplePriceResponse, TokenPriceResponse, CoinFullInfo, CoinTickerResponse, CoinHistoryResponse, CoinMarketChartResponse, CoinStatusUpdateResponse, Exchange, NameIdPair, ExchangeId, ExchangeIdTickerResponse, StatusUpdate } from './Inteface';

@@ -132,2 +132,113 @@ export class CoinGeckoClient {

/**
* Get historical data (name, price, market, stats) at a given date for a coin
*
* @category Coin
* @param input.id pass the coin id (can be obtained from /coins) eg. bitcoin
* @param input.date The date of data snapshot in dd-mm-yyyy eg. 30-12-2017
* @param input.localization Set to false to exclude localized languages in response
* @returns {CoinHistoryResponse}
*/
public async coinHistory(input: {
id: string,
date: string,
localization?: boolean,
}) {
return this.makeRequest<CoinHistoryResponse>(API_ROUTES.COIN_HISTORY, input);
}
/**
* Get historical market data include price, market cap, and 24h volume (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.
*
* @category Coin
* @param input.id pass the coin id (can be obtained from /coins) eg. bitcoin
* @param input.vs_currency The target currency of market data (usd, eur, jpy, etc.)
* @param input.days Data up to number of days ago (eg. 1,14,30,max)
* @param input.interval Data interval. Possible value: daily
* @returns {CoinMarketChartResponse}
*/
public async coinMarketChart(input: {
id: string,
vs_currency: string,
days: number | 'max',
interval?: string,
}) {
return this.makeRequest<CoinMarketChartResponse>(API_ROUTES.COIN_MARKET_CHART, input);
}
/**
* 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.
*
* @category Coin
* @param input.id pass the coin id (can be obtained from /coins) eg. bitcoin
* @param input.vs_currency The target currency of market data (usd, eur, jpy, etc.)
* @param input.from From date in UNIX Timestamp (eg. 1392577232)
* @param input.to To date in UNIX Timestamp (eg. 1618716149)
* @returns {CoinMarketChartResponse}
*/
public async coinMarketChartRange(input: {
id: string,
vs_currency: string,
from: number,
to: number,
}) {
return this.makeRequest<CoinMarketChartResponse>(API_ROUTES.COIN_MARKET_CHART_RANGE, input);
}
/**
* Get status updates for a given coin (beta)
*
* @see https://www.coingecko.com/api/documentations/v3#/coins/get_coins__id__status_updates
* @category Coin
* @param input.id pass the coin id (can be obtained from /coins) eg. bitcoin
* @param input.per_page Total results per page
* @param input.page Page through results
* @returns {CoinStatusUpdateResponse}
*/
public async coinStatusUpdates(input: {
id: string,
per_page?: number,
page?: number,
}) {
return this.makeRequest<CoinStatusUpdateResponse>(API_ROUTES.COIN_STATUS_UPDATES, input);
}
/**
* Get coin's OHLC (Beta)
* ```
* Candle’s body:
* 1 - 2 days: 30 minutes
* 3 - 30 days: 4 hours
* 31 and before: 4 days
* ```
* @see https://www.coingecko.com/api/documentations/v3#/coins/get_coins__id__ohlc
* @category Coin
* @param input.id pass the coin id (can be obtained from /coins) eg. bitcoin
* @param input.vs_currency The target currency of market data (usd, eur, jpy, etc.)
* @param input.days Data up to number of days ago (1/7/14/30/90/180/365/max)
* @returns {CoinStatusUpdateResponse}
* Sample output
* ```
* [
* [
* 1618113600000,
* 79296.36,
* 79296.36,
* 79279.94,
* 79279.94
* ]
* . ... ... . .. . .. . . . . .
* ]
*```
*/
public async coinOHLC(input: {
id: string,
vs_currency: string,
days: number | 'max',
}) {
return this.makeRequest<Array<Array<number>>>(API_ROUTES.COIN_OHLC, input);
}
/**
* Get the current price of any cryptocurrencies in any other supported currencies that you need.

@@ -196,2 +307,170 @@ * @param input.vs_currency vs_currency of coins, comma-separated if querying more than 1 vs_currency. *refers to simple/supported_vs_currencies

/**
* Get historical market data include price, market cap, and 24h volume (granularity auto) from a contract address
* @see https://www.coingecko.com/api/documentations/v3#/contract/get_coins__id__contract__contract_address_
* @returns current data for a coin
* @param input.id Asset platform (only ethereum is supported at this moment)
* @param input.contract_address Token’s contract address
* @category Contract
* @returns {CoinFullInfo}
*/
public async contract(input: {
id: PLATFORMS,
contract_address: string,
}) {
return this.makeRequest<CoinFullInfo>(API_ROUTES.CONTRACT, input);
}
/**
* Get historical market data include price, market cap, and 24h volume (granularity auto)
* @see https://www.coingecko.com/api/documentations/v3#/contract/get_coins__id__contract__contract_address__market_chart_
* @returns current data for a coin
* @param input.id Asset platform (only ethereum is supported at this moment)
* @param input.contract_address Token’s contract address
* @param input.vs_currency The target currency of market data (usd, eur, jpy, etc.)
* @param input.days Data up to number of days ago (eg. 1,14,30,max)
* @category Contract
* @returns {CoinMarketChartResponse}
*/
public async contractMarketChart(input: {
id: PLATFORMS,
contract_address: string,
vs_currency: string;
days: number | 'max'
}) {
return this.makeRequest<CoinMarketChartResponse>(API_ROUTES.CONTRACT_MARKET_CHART, input);
}
/**
* Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto) from a contract address
* @see https://www.coingecko.com/api/documentations/v3#/contract/get_coins__id__contract__contract_address__market_chart_range
* @returns current data for a coin
* @param input.id Asset platform (only ethereum is supported at this moment)
* @param input.contract_address Token’s contract address
* @param input.vs_currency The target currency of market data (usd, eur, jpy, etc.)
* @param input.from From date in UNIX Timestamp (eg. 1392577232)
* @param input.to From date in UNIX Timestamp (eg. 1618716149)
* @category Contract
* @returns {CoinMarketChartResponse} Get historical market data include price, market cap, and 24h volume
*/
public async contractMarketChartRange(input: {
id: PLATFORMS,
contract_address: string,
vs_currency: string;
from?: number,
to: number,
}) {
return this.makeRequest<CoinMarketChartResponse>(API_ROUTES.CONTRACT_MARKET_CHART_RANGE, input);
}
/**
* List all exchanges
* @see https://www.coingecko.com/api/documentations/v3#/exchanges_(beta)/get_exchanges
* @returns List all exchanges
* @param input.per_page Total results per page (valid values: 1…250)
* @param input.page Page through results
* @category Exchange
* @returns {CoinMarketChartResponse} Get historical market data include price, market cap, and 24h volume
*/
public async exchanges(input: {
per_page?: number,
page?: number,
}) {
return this.makeRequest<Exchange[]>(API_ROUTES.EXCHANGES, input);
}
/**
* List all supported markets id and name (no pagination required)
* @see https://www.coingecko.com/api/documentations/v3#/exchanges_(beta)/get_exchanges_list
* @returns Use this to obtain all the markets’ id in order to make API calls
* @category Exchange
* @returns {NameIdPair[]} Get historical market data include price, market cap, and 24h volume
*/
public async exchangeList() {
return this.makeRequest<NameIdPair[]>(API_ROUTES.EXCHANGE_LIST);
}
/**
* List all supported markets id and name (no pagination required)
* @see https://www.coingecko.com/api/documentations/v3#/exchanges_(beta)/get_exchanges__id_
* @param id the exchange id (can be obtained from /exchanges/list) eg. binance
* @returns Use this to obtain all the markets’ id in order to make API calls
* ```
* IMPORTANT:
* Ticker object is limited to 100 items, to get more tickers, use /exchanges/{id}/tickers
* Ticker is_stale is true when ticker that has not been updated/unchanged from the exchange for a while.
* Ticker is_anomaly is true if ticker’s price is outliered by our system.
* You are responsible for managing how you want to display these information (e.g. footnote, different background, change opacity, hide)
* ```
* @category Exchange
* @returns {ExchangeId} Get exchange volume in BTC and top 100 tickers only
*/
public async exchangeId(id: string) {
return this.makeRequest<ExchangeId>(API_ROUTES.EXCHANGE_ID, { id });
}
/**
* Get exchange tickers (paginated, 100 tickers per page)
* @see https://www.coingecko.com/api/documentations/v3#/exchanges_(beta)/get_exchanges__id__tickers
* @param input.id pass the exchange id (can be obtained from /exchanges/list) eg. binance
* @param input.coin_ids filter tickers by coin_ids (ref: v3/coins/list)
* @param input.include_exchange_logo flag to show exchange_logo
* @param input.page Page through results
* @param input.depth flag to show 2% orderbook depth i.e., cost_to_move_up_usd and cost_to_move_down_usd
* @returns Use this to obtain all the markets’ id in order to make API calls
* ```
* IMPORTANT:
* Ticker object is limited to 100 items, to get more tickers, use /exchanges/{id}/tickers
* Ticker is_stale is true when ticker that has not been updated/unchanged from the exchange for a while.
* Ticker is_anomaly is true if ticker’s price is outliered by our system.
* You are responsible for managing how you want to display these information (e.g. footnote, different background, change opacity, hide)
* ```
* @category Exchange
* @returns {ExchangeIdTickerResponse} Get exchange volume in BTC and top 100 tickers only
*/
public async exchangeIdTickers(input: {
id: string,
coin_ids?: string,
include_exchange_logo?: boolean,
page?: number,
depth?: string,
order?: 'trust_score_desc' | 'trust_score_asc' | 'volume_desc'
}) {
return this.makeRequest<ExchangeIdTickerResponse>(API_ROUTES.EXCHANGE_ID_TICKER, input);
}
/**
* Get status updates for a given exchange (beta)
* @see https://www.coingecko.com/api/documentations/v3#/exchanges_(beta)/get_exchanges__id__status_updates
* @param input.id pass the exchange id (can be obtained from /exchanges/list) eg. binance
* @param input.page Page through results
* @param input.per_page Total results per page
* @returns Get status updates for a given exchange
* @category Exchange
* @returns {CoinStatusUpdateResponse} Get status updates for a given exchange
*/
public async exchangeIdStatusUpdates(input: {
id: string,
page?: number,
per_page?: number,
}) {
return this.makeRequest<CoinStatusUpdateResponse>(API_ROUTES.EXCHANGE_ID_STATUS_UPDATES, input);
}
/**
* Get status updates for a given exchange (beta)
* @see https://www.coingecko.com/api/documentations/v3#/exchanges_(beta)/get_exchanges__id__volume_chart
* @param input.id pass the exchange id (can be obtained from /exchanges/list) eg. binance
* @param input.days Data up to number of days ago (eg. 1,14,30)
* @returns Get status updates for a given exchange
* @category Exchange
* @returns {CoinStatusUpdateResponse} Get status updates for a given exchange
*/
public async exchangeIdVolumeChart(input: {
id: string,
days: number,
}) {
return this.makeRequest<Array<Array<number>>>(API_ROUTES.EXCHANGE_ID_VOL_CHART, input);
}
}

@@ -8,8 +8,21 @@ export enum API_ROUTES {

COIN_TICKERS = '/coins/{id}/tickers',
COIN_HISTORY = "/coins/{id}/history",
COIN_MARKET_CHART = "/coins/{id}/market_chart",
COIN_MARKET_CHART_RANGE = "/coins/{id}/market_chart/range",
COIN_STATUS_UPDATES = "/coins/{id}/status_updates",
COIN_OHLC = "/coins/{id}/ohlc",
SIMPLE_PRICE = '/simple/price',
SIMPLE_SUPPORTED_CURRENCIES = '/simple/supported_vs_currencies',
SIMPLE_TOKEN_PRICE = '/simple/token_price/{id}',
CONTRACT = "/coins/{id}/contract/{contract_address}",
CONTRACT_MARKET_CHART = "/coins/{id}/contract/{contract_address}/market_chart",
CONTRACT_MARKET_CHART_RANGE = "/coins/{id}/contract/{contract_address}/market_chart/range",
EXCHANGES = "/exchanges",
EXCHANGE_LIST = "/exchanges/list",
EXCHANGE_ID = '/exchanges/{id}',
EXCHANGE_ID_TICKER = '/exchanges/{id}/tickers',
EXCHANGE_ID_STATUS_UPDATES = '/exchanges/{id}/status_updates',
EXCHANGE_ID_VOL_CHART = '/exchanges/{id}/volume_chart',
}
export type PLATFORMS = 'etherium' | 'tron'
export type PLATFORMS = 'ethereum' | 'tron'

@@ -7,5 +7,21 @@ import { PLATFORMS } from './Enum';

export interface Exchange {
id: string;
name: string;
year_established: number;
country: string;
description: string;
url: string;
image: string;
has_trading_incentive: boolean;
trust_score: number;
trust_score_rank: number;
trade_volume_24h_btc: number;
trade_volume_24h_btc_normalized: number;
}
export interface TrendingResponse {
coins?: Coins[];
exchanges?: any[];
exchanges?: Exchange[];
}

@@ -269,1 +285,101 @@

}
export interface Localization {
en: string;
de: string;
es: string;
fr: string;
it: string;
pl: string;
ro: string;
hu: string;
nl: string;
pt: string;
sv: string;
vi: string;
tr: string;
ru: string;
ja: string;
zh: string;
"zh-tw": string;
ko: string;
ar: string;
th: string;
id: string;
[u: string]: string;
}
export interface CoinHistoryResponse extends BasicCoin {
localization: Localization;
image: Image;
market_data: MarketData;
community_data: CommunityData;
developer_data: DeveloperData;
public_interest_stats: PublicInterestStats;
}
export interface CoinMarketChartResponse {
prices: Array<Array<number>>,
market_caps: Array<Array<number>>,
total_volumes: Array<Array<number>>
}
export interface CoinStatusUpdateResponse {
status_updates: StatusUpdate[];
}
export interface Project {
type: string;
id: string;
name: string;
symbol: string;
image: Image;
}
export interface StatusUpdate {
description: string;
category: string;
created_at: Date;
user: string;
user_title: string;
pin: boolean;
project: Project;
}
export interface NameIdPair {
name: string;
id: string;
}
export interface ExchangeId {
name: string;
year_established: number;
country: null;
description: string;
url: string;
image: string;
facebook_url: string;
reddit_url: string;
telegram_url: string;
slack_url: string;
other_url_1: string;
other_url_2: string;
twitter_handle: string;
has_trading_incentive: boolean;
centralized: boolean;
public_notice: string;
alert_notice: string;
trust_score: null;
trust_score_rank: number;
trade_volume_24h_btc: number;
trade_volume_24h_btc_normalized: number;
tickers: Ticker[];
status_updates: any[];
}
export interface ExchangeIdTickerResponse {
name: string
tickers: Ticker[]
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc