coingecko-api-v3
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "coingecko-api-v3", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "The nodejs api library for accessing coingecko api v3 , develop with typescript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# coingecko-api-v3 | ||
The nodejs api library for accessing coingecko api v3 , develop with typescript | ||
Official document here - https://www.coingecko.com/api/documentations/v3 | ||
API document generated - https://samuraitruong.github.io/coingecko-api-v3/classes/coingeckoclient.coingeckoclient-1.html | ||
## Get started | ||
``` | ||
npm install coingecko-api-v3 | ||
``` | ||
```js | ||
const client = new CoinGeckoClient(); | ||
const trendingSearch = await client.trendingSearch(); | ||
``` | ||
## Methods | ||
@@ -24,78 +24,85 @@ import { CoinGeckoClient } from './CoinGeckoClient'; | ||
}); | ||
describe('coins', () => { | ||
it('/coins/list should successful', async () => { | ||
const list = await client.coinList({ include_platform: true }); | ||
expect(list.length).toBeGreaterThan(1); | ||
}); | ||
it('/coins/list should successful', async () => { | ||
const list = await client.coinList({ include_platform: true }); | ||
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).toMatchSnapshot(); | ||
}); | ||
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).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); | ||
}); | ||
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); | ||
}); | ||
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('/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('/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}/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 should successful', async () => { | ||
const marketChart = await client.coinMarketChart({ | ||
id: 'bitcoin', vs_currency: 'aud', interval: 'hourly', days: 1, | ||
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); | ||
}); | ||
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, | ||
it('/coins/{id}/status_updates should successful', async () => { | ||
const statusUpdate = await client.coinStatusUpdates({ id: 'litecoin' }); | ||
expect(statusUpdate.status_updates.length).toBeGreaterThan(0); | ||
}); | ||
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('/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); | ||
}); | ||
describe('simple', () => { | ||
it('/simple/market should successful', async () => { | ||
const price = await client.simpleTokenPrice({ | ||
contract_addresses: '0x8207c1ffc5b6804f6024322ccf34f29c3541ae26', | ||
id: 'ethereum', | ||
vs_currencies: 'btc,eth', | ||
}); | ||
expect(price).toMatchObject({ | ||
'0x8207c1ffc5b6804f6024322ccf34f29c3541ae26': { | ||
btc: expect.any(Number), | ||
eth: expect.any(Number), | ||
}, | ||
}); | ||
}); | ||
it('/simple/market should successful', async () => { | ||
const price = await client.simpleTokenPrice({ contract_addresses: '0x8207c1ffc5b6804f6024322ccf34f29c3541ae26', id: 'ethereum', vs_currencies: 'btc,eth' }); | ||
expect(price).toMatchObject({ | ||
'0x8207c1ffc5b6804f6024322ccf34f29c3541ae26': { | ||
btc: expect.any(Number), | ||
eth: expect.any(Number), | ||
}, | ||
it('/simple/supported_vs_currencies should successful', async () => { | ||
const list = await client.simpleSupportedCurrencies(); | ||
expect(list).toMatchSnapshot(); | ||
}); | ||
}); | ||
it('/simple/supported_vs_currencies should successful', async () => { | ||
const list = await client.simpleSupportedCurrencies(); | ||
expect(list).toMatchSnapshot(); | ||
}); | ||
describe('Contract', () => { | ||
@@ -197,3 +204,3 @@ it('/coins/{id}/contract/{contract_address} should successful', async () => { | ||
describe.only('Indexes', () => { | ||
describe('Indexes', () => { | ||
it('/indexes should successful', async () => { | ||
@@ -211,7 +218,79 @@ const indexes = await client.indexes(); | ||
it('/finance_products should successful', async () => { | ||
const products = await client.financeProducts({}); | ||
expect(products.length).toBeGreaterThan(0); | ||
it('/indexes/list should successful', async () => { | ||
const list = await client.indexesList(); | ||
expect(list.length).toBeGreaterThan(0); | ||
}); | ||
}); | ||
describe('Derivatives', () => { | ||
it('/derivatives should successful', async () => { | ||
const list = await client.derivatives({ include_tickers: 'all' }); | ||
expect(list.length).toBeGreaterThan(0); | ||
}); | ||
it('/derivatives/exchanges should successful', async () => { | ||
const list = await client.derivativesExchanges({ order: 'name_asc', per_page: 10 }); | ||
expect(list.length).toBeGreaterThan(0); | ||
}); | ||
it('/derivatives/exchanges/id should successful', async () => { | ||
const list = await client.derivativesExchangesId({ id: 'bitmex' }); | ||
expect(list.length).toBeGreaterThan(0); | ||
}); | ||
it('/derivatives/exchanges/list should successful', async () => { | ||
const list = await client.derivativesExchangesList(); | ||
expect(list.length).toBeGreaterThan(0); | ||
expect(list[0]).toEqual({ | ||
name: expect.any(String), | ||
id: expect.any(String), | ||
}); | ||
}); | ||
}); | ||
describe('Status Updates', () => { | ||
it('/status_updates', async () => { | ||
const list = await client.statusUpdates(); | ||
expect(list.status_updates.length).toBeGreaterThan(0); | ||
}); | ||
}); | ||
describe('Events', () => { | ||
it('/events', async () => { | ||
const list = await client.events(); | ||
expect(list.data.length).toBeGreaterThan(0); | ||
}); | ||
it.only('/events/countries', async () => { | ||
const list = await client.eventsCountries(); | ||
expect(list.data.length).toBeGreaterThan(0); | ||
expect(list.data[2]).toEqual({ | ||
country: expect.any(String), | ||
code: expect.any(String), | ||
}); | ||
}); | ||
it.only('/events/types', async () => { | ||
const list = await client.eventsTypes(); | ||
expect(list).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe('Exchange Rates', () => { | ||
it('/events', async () => { | ||
const list = await client.exchangeRates(); | ||
expect(list.rates).not.toBeNull(); | ||
}); | ||
}); | ||
describe('Global', () => { | ||
it.only('/global', async () => { | ||
const list = await client.global(); | ||
expect(list.data).not.toBeNull(); | ||
}); | ||
it.only('/global/decentralized_finance_defi', async () => { | ||
const list = await client.globalDefi(); | ||
expect(list.data).not.toBeNull(); | ||
}); | ||
}); | ||
}); |
@@ -23,2 +23,9 @@ import axios, { AxiosInstance } from 'axios'; | ||
FinancePlatform, | ||
Derivative, | ||
DerivativeExchange, | ||
EventResponse, | ||
EventCountryResponse, | ||
ExchangeRatesResponse, | ||
GlobalResponse, | ||
GlobalDefiResponse, | ||
} from './Inteface'; | ||
@@ -560,2 +567,161 @@ | ||
} | ||
/** | ||
* list market indexes id and name | ||
* @see https://www.coingecko.com/api/documentations/v3#/indexes_(beta)/get_indexes_list | ||
* @category Indexes | ||
* @returns {NameIdPair[]} | ||
*/ | ||
public async indexesList() { | ||
return this.makeRequest<NameIdPair[]>(API_ROUTES.INDEXES_LIST); | ||
} | ||
/** | ||
* List all derivative tickers | ||
* @see https://www.coingecko.com/api/documentations/v3#/derivatives_(beta)/get_derivatives | ||
* @param input.include_tickers 'all’, ‘unexpired’] - expired to show unexpired tickers, all to list all tickers, defaults to unexpired | ||
* @category Derivatives | ||
* @returns {Derivative[]} | ||
*/ | ||
public async derivatives(input: { | ||
include_tickers?: 'all' | 'unexpired' | ||
}) { | ||
return this.makeRequest<Derivative[]>(API_ROUTES.DERIVATIVES, input); | ||
} | ||
/** | ||
* List all derivative tickers | ||
* @see https://www.coingecko.com/api/documentations/v3#/derivatives_(beta)/get_derivatives_exchanges | ||
* @param input.order 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 | ||
* @param input.page Page through results | ||
* @param input.per_page Total results per page | ||
* @category Derivatives | ||
* @returns {DerivativeExchange[]} | ||
*/ | ||
public async derivativesExchanges(input: { | ||
// eslint-disable-next-line max-len | ||
order?: 'name_asc' | 'name_desc' | 'open_interest_btc_asc' | 'open_interest_btc_desc' | 'trade_volume_24h_btc_asc' | 'trade_volume_24h_btc_desc'; | ||
per_page?: number, | ||
page?: number | ||
}) { | ||
return this.makeRequest<DerivativeExchange[]>(API_ROUTES.DERIVATIVES_EXCHANGES, input); | ||
} | ||
/** | ||
* show derivative exchange data | ||
* @see https://www.coingecko.com/api/documentations/v3#/derivatives_(beta)/get_derivatives_exchanges__id_ | ||
* @param input.id pass the exchange id (can be obtained from derivatives/exchanges/list) eg. bitmex | ||
* @param input.include_tickers ['all’, ‘unexpired’] - expired to show unexpired tickers, all to list all tickers, leave blank to omit tickers data in response | ||
* @category Derivatives | ||
* @returns {DerivativeExchange[]} | ||
*/ | ||
public async derivativesExchangesId(input: { | ||
id: string | ||
include_tickers?: 'all' | 'unexpired', | ||
}) { | ||
return this.makeRequest<DerivativeExchange[]>(API_ROUTES.DERIVATIVES_EXCHANGES_ID, input); | ||
} | ||
/** | ||
* List all derivative exchanges name and identifier | ||
* @see https://www.coingecko.com/api/documentations/v3#/derivatives_(beta)/get_derivatives_exchanges_list | ||
* @category Derivatives | ||
* @returns {NameIdPair[]} | ||
*/ | ||
public async derivativesExchangesList() { | ||
return this.makeRequest<NameIdPair[]>(API_ROUTES.DERIVATIVES_EXCHANGES_LIST); | ||
} | ||
/** | ||
* List all status_updates with data (description, category, created_at, user, user_title and pin) | ||
* @see https://www.coingecko.com/api/documentations/v3#/status_updates_(beta)/get_status_updates | ||
* @param input.category Filtered by category (eg. general, milestone, partnership, exchange_listing, software_release, fund_movement, new_listings, event) | ||
* @param input.project_type Filtered by Project Type (eg. coin, market). If left empty returns both status from coins and markets. | ||
* @param input.per_page Total results per page | ||
* @param input.page Page through results | ||
* @category Status Updates | ||
* @returns {CoinStatusUpdateResponse} | ||
*/ | ||
public async statusUpdates(input?: { | ||
category?: string, | ||
project_type?: string, | ||
per_page?: number, | ||
page?: number | ||
}) { | ||
return this.makeRequest<CoinStatusUpdateResponse>(API_ROUTES.STATUS_UPDATES, input); | ||
} | ||
/** | ||
* Get events, paginated by 100 | ||
* @see https://www.coingecko.com/api/documentations/v3#/events/get_events | ||
* @param input.country_code country_code of event (eg. ‘US’). use /api/v3/events/countries for list of country_codes | ||
* @param input.type ype of event (eg. ‘Conference’). use /api/v3/events/types for list of types | ||
* @param input.page page of results (paginated by 100) | ||
* @param input.upcoming_events_only lists only upcoming events.(defaults to true, set to false to list all events) | ||
* @param input.from_date lists events after this date yyyy-mm-dd | ||
* @param input.to_date lists events before this date yyyy-mm-dd (set upcoming_events_only to false if fetching past events) | ||
* @category Events | ||
* @returns {EventResponse} | ||
*/ | ||
public async events(input?: { | ||
country_code?: string, | ||
type?: string, | ||
page?: number, | ||
upcoming_events_only?: boolean, | ||
from_date?: string, | ||
to_date?: string | ||
}) { | ||
return this.makeRequest<EventResponse>(API_ROUTES.EVENTS, input); | ||
} | ||
/** | ||
* Get list of event countries | ||
* @see https://www.coingecko.com/api/documentations/v3#/events/get_events_countries | ||
* @category Events | ||
* @returns {EventCountryResponse} | ||
*/ | ||
public async eventsCountries() { | ||
return this.makeRequest<EventCountryResponse>(API_ROUTES.EVENTS_COUNTRIES); | ||
} | ||
/** | ||
* Get list of events types | ||
* @see https://www.coingecko.com/api/documentations/v3#/events/get_events_types | ||
* @category Events | ||
* @returns {EventCountryResponse} | ||
*/ | ||
public async eventsTypes() { | ||
return this.makeRequest<EventCountryResponse>(API_ROUTES.EVENTS_TYPES); | ||
} | ||
/** | ||
* Get BTC-to-Currency exchange rates | ||
* @see https://www.coingecko.com/api/documentations/v3#/exchange_rates/get_exchange_rates | ||
* @category Exchange Rates | ||
* @returns {ExchangeRatesResponse} | ||
*/ | ||
public async exchangeRates() { | ||
return this.makeRequest<ExchangeRatesResponse>(API_ROUTES.EXCHANGE_RATES); | ||
} | ||
/** | ||
* Get cryptocurrency global data | ||
* @see https://www.coingecko.com/api/documentations/v3#/global/get_global | ||
* @category Global | ||
* @returns {GlobalResponse} Get global data - total_volume, total_market_cap, ongoing icos etc | ||
*/ | ||
public async global() { | ||
return this.makeRequest<GlobalResponse>(API_ROUTES.GLOBAL); | ||
} | ||
/** | ||
* Get cryptocurrency global decentralized finance(defi) data | ||
* @see https://www.coingecko.com/api/documentations/v3#/global/get_global | ||
* @category Global | ||
* @returns {GlobalDefiResponse} Get Top 100 Cryptocurrency Global Eecentralized Finance(defi) data | ||
*/ | ||
public async globalDefi() { | ||
return this.makeRequest<GlobalDefiResponse>(API_ROUTES.GLOBAL_DEFI); | ||
} | ||
} |
@@ -30,5 +30,16 @@ export enum API_ROUTES { | ||
INDEXES_MARKET_ID = '/indexes/{market_id}/{id}', | ||
INDEXES_LIST_MARKET_AND_ID = '/indexes/list_by_market_and_id/{market_id}/{id}' | ||
INDEXES_LIST_MARKET_AND_ID = '/indexes/list_by_market_and_id/{market_id}/{id}', | ||
DERIVATIVES = '/derivatives', | ||
DERIVATIVES_EXCHANGES = '/derivatives/exchanges', | ||
DERIVATIVES_EXCHANGES_ID = '/derivatives/exchanges/{id}', | ||
DERIVATIVES_EXCHANGES_LIST = '/derivatives/exchanges/list', | ||
STATUS_UPDATES = '/status_updates', | ||
EVENTS = '/events', | ||
EVENTS_COUNTRIES = '/events/countries', | ||
EVENTS_TYPES = '/events/types', | ||
EXCHANGE_RATES = '/exchange_rates', | ||
GLOBAL = '/global', | ||
GLOBAL_DEFI = '/global/decentralized_finance_defi' | ||
} | ||
export type PLATFORMS = 'ethereum' | 'tron' |
@@ -7,2 +7,5 @@ import { PLATFORMS } from './Enum'; | ||
export interface ResponseWithData<T> { | ||
data: T | ||
} | ||
export interface BasicCoin { | ||
@@ -421,1 +424,96 @@ id?: string; | ||
} | ||
export interface Derivative { | ||
market?: string; | ||
symbol?: string; | ||
index_id?: string; | ||
price?: string; | ||
price_percentage_change_24h?: number; | ||
contract_type?: string; | ||
index?: number; | ||
basis?: number; | ||
spread?: number; | ||
funding_rate?: number; | ||
open_interest?: number; | ||
volume_24h?: number; | ||
last_traded_at?: number; | ||
expired_at?: null; | ||
} | ||
export interface DerivativeExchange { | ||
name?: string; | ||
id?: string; | ||
open_interest_btc?: number; | ||
trade_volume_24h_btc?: string; | ||
number_of_perpetual_pairs?: number; | ||
number_of_futures_pairs?: number; | ||
image?: string; | ||
year_established?: number; | ||
country?: string; | ||
description?: string; | ||
url?: string; | ||
} | ||
export interface Country { | ||
country: string, | ||
code: string | ||
} | ||
export interface EventCountryResponse { | ||
data: Country[] | ||
} | ||
export interface EventResponse { | ||
data: any[], | ||
count: number; | ||
page: number | ||
} | ||
export interface EventsTypeResponse { | ||
data: string[], | ||
count: number; | ||
} | ||
export interface ExchangeRatesResponse { | ||
rates: { | ||
[x: string]: { | ||
name: string, | ||
type: string, | ||
value: number, | ||
unit: string | ||
} | ||
} | ||
} | ||
export interface GlobalData { | ||
active_cryptocurrencies: number; | ||
upcoming_icos: number; | ||
ongoing_icos: number; | ||
ended_icos: number; | ||
markets: number; | ||
total_market_cap: { [key: string]: number }; | ||
total_volume: { [key: string]: number }; | ||
market_cap_percentage: { [key: string]: number }; | ||
market_cap_change_percentage_24h_usd: number; | ||
updated_at: number; | ||
} | ||
export interface GlobalDefiData { | ||
/** | ||
* Defi Market Capitalization in USD | ||
*/ | ||
defi_market_cap: string; | ||
/** | ||
* Ethereum Market Capitalization in USD | ||
*/ | ||
eth_market_cap: string; | ||
defi_to_eth_ratio: string; | ||
trading_volume_24h: string; | ||
defi_dominance: string; | ||
top_coin_name: string; | ||
top_coin_defi_dominance: number; | ||
} | ||
export type GlobalResponse = ResponseWithData<GlobalData>; | ||
export type GlobalDefiResponse = ResponseWithData<GlobalDefiData>; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
624988
35245
22