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.3 to 0.0.4

.eslintignore

17

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

@@ -8,9 +8,10 @@ "main": "dist/index.js",

"scripts": {
"lint": "eslint . --fix",
"lint": "eslint . --ext .ts --fix",
"build": "rm -rf ./dist && tsc",
"dev": "ts-node ./src/index",
"test": "jest",
"doc-gen": "typedoc --out ./docs src/",
"doc-gen": "rm -rf ./dist && typedoc --out ./docs src/",
"prepublish": "npm run build",
"publish-doc": "rm -rf ./dist && npm run doc-gen && gh-pages -d ./docs"
"publish-doc": "npm run doc-gen && gh-pages -d ./docs",
"prepare": "husky install"
},

@@ -39,4 +40,9 @@ "repository": {

"eslint": "^7.24.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.5",
"gh-pages": "^3.1.0",
"husky": "^6.0.0",
"jest": "^26.6.3",
"lint-staged": "^10.5.4",
"ts-jest": "^26.5.5",

@@ -50,3 +56,6 @@ "ts-node": "^9.1.1",

"qs": "^6.5.2"
},
"lint-staged": {
"*.ts": "eslint --cache --fix"
}
}
import { CoinGeckoClient } from './CoinGeckoClient';
import { PLATFORMS } from './Enum';
const client = new CoinGeckoClient();
jest.setTimeout(30000)
jest.setTimeout(30000);
describe('CoinGeckoClient test', () => {
it('ping should successful', async () => {
const ping = await client.ping();
expect(ping).toEqual({ gecko_says: '(V3) To the Moon!' })
})
expect(ping).toEqual({ gecko_says: '(V3) To the Moon!' });
});

@@ -23,63 +22,66 @@ it('/search/trending should successful', async () => {

thumb: expect.any(String),
}))
})
}));
});
it('/coins/list should successful', async () => {
const list = await client.coinList({ include_platform: true });
expect(list.length).toBeGreaterThan(1)
})
expect(list.length).toBeGreaterThan(1);
});
it('/coins/market should successful', async () => {
const list = await client.coinMarket({ vs_currency: 'usd', ids: 'origin-protocol,bitcorn' });
expect(list.length).toEqual(2)
expect(list.length).toEqual(2);
expect(list).toMatchSnapshot();
})
});
it('/coins/{id}/tickers should successful', async () => {
const ticker = await client.coinTickers({ id: 'origin-protocol' });
expect(ticker.name).toEqual("Origin Protocol")
expect(ticker.tickers.length).toBeGreaterThan(0)
})
expect(ticker.name).toEqual('Origin Protocol');
expect(ticker.tickers.length).toBeGreaterThan(0);
});
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.name).toEqual('Bitcoin');
expect(coin.localization).not.toBeNull();
expect(coin).toMatchSnapshot();
})
});
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.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)
})
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)
})
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)
})
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)
})
expect(ohlc.length).toBeGreaterThan(0);
expect(ohlc[0].length).toBe(5);
});
it('/simple/market should successful', async () => {

@@ -90,6 +92,6 @@ const price = await client.simpleTokenPrice({ contract_addresses: '0x8207c1ffc5b6804f6024322ccf34f29c3541ae26', id: 'ethereum', vs_currencies: 'btc,eth' });

btc: expect.any(Number),
eth: expect.any(Number)
}
eth: expect.any(Number),
},
});
})
});

@@ -99,8 +101,8 @@ it('/simple/supported_vs_currencies should successful', async () => {

expect(list).toMatchSnapshot();
})
});
describe('Contract', () => {
it('/coins/{id}/contract/{contract_address} should successful', async () => {
const aave = await client.contract({ id: 'ethereum', 'contract_address': '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9' });
const aave = await client.contract({ id: 'ethereum', contract_address: '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9' });
expect(aave.name).toBe('Aave');
})
});

@@ -110,6 +112,8 @@ it('/coins/{id}/contract/{contract_address}/market_chart should successful', async () => {

id: 'ethereum',
'contract_address': '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9', vs_currency: 'aud', days: 5
contract_address: '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9',
vs_currency: 'aud',
days: 5,
});
expect(aave.prices.length).toBeGreaterThan(0);
})
});

@@ -119,5 +123,6 @@ it('/coins/{id}/contract/{contract_address}/market_chart/range should successful', async () => {

id: 'ethereum',
'contract_address': '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9', vs_currency: 'eth',
contract_address: '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9',
vs_currency: 'eth',
from: 1392577232,
to: 1618716149
to: 1618716149,
});

@@ -127,4 +132,4 @@ expect(aave.prices.length).toBeGreaterThan(0);

expect(aave.total_volumes.length).toBeGreaterThan(0);
})
})
});
});

@@ -150,4 +155,4 @@ describe('Exchange', () => {

year_established: expect.any(Number),
})
})
});
});

@@ -160,5 +165,5 @@ it('/exchange/list should successful', async () => {

id: 'aave',
name: 'Aave'
})
})
name: 'Aave',
});
});

@@ -168,3 +173,3 @@ it('/exchange/id should successful', async () => {

expect(aave.name).toEqual('Aave');
})
});

@@ -175,3 +180,3 @@ it('/exchange/id/tickers should successful', async () => {

expect(aave.tickers.length).toBeGreaterThan(1);
})
});

@@ -181,3 +186,3 @@ it('/exchange/id/status_update should successful', async () => {

expect(aave.status_updates.length).toBeGreaterThan(1);
})
});

@@ -187,7 +192,35 @@ it('/exchange/id/volume_chart should successful', async () => {

expect(aave.length).toBeGreaterThan(1);
})
});
});
describe('Finance', () => {
it('/finance_platforms should successful', async () => {
const platform = await client.financePlatforms({});
expect(platform.length).toBeGreaterThan(0);
});
})
it('/finance_products should successful', async () => {
const products = await client.financeProducts({});
expect(products.length).toBeGreaterThan(0);
});
});
})
describe.only('Indexes', () => {
it('/indexes should successful', async () => {
const indexes = await client.indexes();
expect(indexes.length).toBeGreaterThan(0);
expect(indexes[0]).toEqual({
id: expect.any(String),
is_multi_asset_composite: null,
last: null,
market: expect.any(String),
name: expect.any(String),
});
});
it('/finance_products should successful', async () => {
const products = await client.financeProducts({});
expect(products.length).toBeGreaterThan(0);
});
});
});
import axios, { AxiosInstance } from 'axios';
import qs from 'qs';
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';
import {
IndexItem,
CoinListResponseItem,
CoinMarket,
PingResponse,
TrendingResponse,
SimplePriceResponse,
TokenPriceResponse,
CoinFullInfo,
CoinTickerResponse,
CoinHistoryResponse,
CoinMarketChartResponse,
CoinStatusUpdateResponse,
Exchange,
NameIdPair,
ExchangeId,
ExchangeIdTickerResponse,
FinanceProduct,
FinancePlatform,
} from './Inteface';
export class CoinGeckoClient {
http: AxiosInstance;
apiV3Url = 'https://api.coingecko.com/api/v3'
constructor() {
this.http = axios.create({});
}
this.http = axios.create({})
}
private withPathParams(path: string, replacements: any = {}) {
private withPathParams(path: string, replacements: { [x: string]: string } = {}) {
let pathStr = path;
Object.entries(replacements).forEach(([key, value]) => {
pathStr = pathStr.replace('{' + key + '}', value as string)
})
pathStr = pathStr.replace(`{${key}}`, value as string);
});
return pathStr;

@@ -22,7 +43,7 @@ }

private async makeRequest<T>(action: API_ROUTES, params: any = {}) {
const requestUrl = this.apiV3Url + this.withPathParams(action, params) + '?' + qs.stringify(params);
console.log(requestUrl)
const requestUrl = `${this.apiV3Url + this.withPathParams(action, params)}?${qs.stringify(params)}`;
const res = await this.http.get<T>(requestUrl);
return res.data;
}
/**

@@ -35,2 +56,3 @@ * Check API server status

}
public async trending() {

@@ -86,3 +108,3 @@ return this.makeRequest<TrendingResponse>(API_ROUTES.SEARCH_TRENDING);

* @param input.id pass the coin id (can be obtained from /coins) eg. bitcoin
* @param input.localization Include all localized languages in response (true/false)
* @param input.localization Include all localized languages in response (true/false)
* @param input.tickers nclude tickers data (true/false) [default: true]

@@ -116,3 +138,3 @@ * @param input.market_data Include market_data (true/false) [default: true]

* @param input.id pass the coin id (can be obtained from /coins) eg. bitcoin
* @param input.exchange_ids filter results by exchange_ids (ref: v3/exchanges/list)
* @param input.exchange_ids filter results by exchange_ids (ref: v3/exchanges/list)
* @param input.include_exchange_logo flag to show exchange_logo

@@ -140,3 +162,3 @@ * @param input.page Page through results

* @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.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

@@ -156,3 +178,3 @@ * @returns {CoinHistoryResponse}

* 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

@@ -177,3 +199,3 @@ * @param input.id pass the coin id (can be obtained from /coins) eg. bitcoin

* 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

@@ -197,3 +219,3 @@ * @param input.id pass the coin id (can be obtained from /coins) eg. bitcoin

* Get status updates for a given coin (beta)
*
*
* @see https://www.coingecko.com/api/documentations/v3#/coins/get_coins__id__status_updates

@@ -315,3 +337,3 @@ * @category Coin

/**
* Get historical market data include price, market cap, and 24h volume (granularity auto) from a contract address
* 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_

@@ -483,2 +505,65 @@ * @returns current data for a coin

/**
* List all finance platforms
* @see https://www.coingecko.com/api/documentations/v3#/finance_(beta)/get_finance_platforms
* @param input.per_page Total results per page
* @param input.page Data up to number of days ago (eg. 1,14,30)
* @category Finance
* @returns {Finance[]}
*/
public async financePlatforms(input?: {
per_page?: number,
page?: number,
}) {
return this.makeRequest<Array<FinancePlatform>>(API_ROUTES.FINANCE_PLATFORM, input);
}
/**
* List all finance products
* @see https://www.coingecko.com/api/documentations/v3#/finance_(beta)/get_finance_products
* @param input.per_page Total results per page
* @param input.page Data up to number of days ago (eg. 1,14,30)
* @category Finance
* @returns {Finance[]}
*/
public async financeProducts(input?: {
per_page?: number,
page?: number,
start_at?: string,
end_at?: string;
}) {
return this.makeRequest<Array<FinanceProduct>>(API_ROUTES.FINANCE_PRODUCT, input);
}
/**
* List all market indexes
* @see https://www.coingecko.com/api/documentations/v3#/indexes_(beta)/get_indexes
* @param input.per_page Total results per page
* @param input.page Data up to number of days ago (eg. 1,14,30)
* @category Indexes
* @returns {IndexItem[]}
*/
public async indexes(input?: {
per_page?: number,
page?: number,
}) {
return this.makeRequest<IndexItem[]>(API_ROUTES.INDEXES, input);
}
/**
* get market index by market id and index id
* @see https://www.coingecko.com/api/documentations/v3#/indexes_(beta)/get_indexes__market_id___id_
* @param input.market_id pass the market id (can be obtained from /exchanges/list)
* @param input.path_id pass the index id (can be obtained from /indexes/list)
* @param input.id pass the index id (can be obtained from /indexes/list)
* @category Indexes
* @returns {IndexItem[]}
*/
public async indexesMarketId(input?: {
market_id?: number,
path_id?: number,
id?: number
}) {
return this.makeRequest<IndexItem[]>(API_ROUTES.INDEXES_MARKET_ID, input);
}
}

@@ -8,15 +8,15 @@ 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",
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",
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}',

@@ -26,4 +26,10 @@ EXCHANGE_ID_TICKER = '/exchanges/{id}/tickers',

EXCHANGE_ID_VOL_CHART = '/exchanges/{id}/volume_chart',
FINANCE_PLATFORM = '/finance_platforms',
FINANCE_PRODUCT = '/finance_products',
INDEXES = '/indexes',
INDEXES_LIST = '/indexes/list',
INDEXES_MARKET_ID = '/indexes/{market_id}/{id}',
INDEXES_LIST_MARKET_AND_ID = '/indexes/list_by_market_and_id/{market_id}/{id}'
}
export type PLATFORMS = 'ethereum' | 'tron'

@@ -7,2 +7,15 @@ import { PLATFORMS } from './Enum';

export interface BasicCoin {
id?: string;
name?: string;
symbol?: string;
}
export interface Coin extends BasicCoin {
market_cap_rank?: number;
thumb?: string;
large?: string;
score?: number;
}
export interface Exchange {

@@ -23,18 +36,6 @@ id: string;

export interface TrendingResponse {
coins?: Coins[];
exchanges?: Exchange[];
}
export interface Coins {
item?: Coin;
}
export interface BasicCoin {
export interface TrendingItem {
id?: string;
name?: string;
symbol?: string;
}
export interface Coin extends BasicCoin {
market_cap_rank?: number;

@@ -46,2 +47,11 @@ thumb?: string;

export interface Trending {
item?: TrendingItem;
}
export interface TrendingResponse {
coins?: Trending[];
exchanges?: Exchange[];
}
export interface CoinListResponseItem extends BasicCoin {

@@ -53,3 +63,2 @@ platforms?: {

export interface CoinMarket extends BasicCoin {

@@ -81,3 +90,2 @@ image?: string;

export interface SimplePriceResponse {

@@ -131,2 +139,8 @@ [coin: string]: {

}
export interface CodeAdditionsDeletions4_Weeks {
additions?: number;
deletions?: number;
}
export interface DeveloperData {

@@ -145,5 +159,5 @@ forks?: number;

export interface CodeAdditionsDeletions4_Weeks {
additions?: number;
deletions?: number;
export interface ReposURL {
github?: string[];
bitbucket?: any[];
}

@@ -165,6 +179,2 @@

export interface ReposURL {
github?: string[];
bitbucket?: any[];
}
export interface PublicInterestStats {

@@ -252,3 +262,2 @@ alexa_rank?: number;

export interface CoinFullInfo {

@@ -311,3 +320,3 @@ id?: string;

zh: string;
"zh-tw": string;
'zh-tw': string;
ko: string;

@@ -329,3 +338,2 @@ ar: string;

export interface CoinMarketChartResponse {

@@ -337,7 +345,2 @@ prices: Array<Array<number>>,

export interface CoinStatusUpdateResponse {
status_updates: StatusUpdate[];
}
export interface Project {

@@ -361,2 +364,6 @@ type: string;

export interface CoinStatusUpdateResponse {
status_updates: StatusUpdate[];
}
export interface NameIdPair {

@@ -397,1 +404,30 @@ name: string;

}
export interface FinancePlatform {
name?: string;
facts?: string;
category?: string;
centralized?: boolean;
website_url?: string;
}
export interface FinanceProduct {
platform?: string;
identifier?: string;
supply_rate_percentage?: string;
borrow_rate_percentage?: null;
number_duration?: null;
length_duration?: null;
start_at?: number;
end_at?: number;
value_at?: number;
redeem_at?: number;
}
export interface IndexItem {
name?: string;
id?: string;
market?: string;
last?: null;
is_multi_asset_composite?: null;
}
{
"compilerOptions": {
"declaration": true,
"target": "ES2015",
"module": "commonjs",
"outDir": "dist",
"target": "ES2015",
"module": "commonjs",
"outDir": "dist",
"rootDir": "src",

@@ -11,8 +11,3 @@ "strict": true,

},
"exclude": [
"node_modules",
"test",
"__snapshots__",
"lib"
]
"exclude": ["node_modules", "test", "__snapshots__", "lib"]
}
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