Skip to content

Commit

Permalink
added categories to the CoinGeckoClient (#46)
Browse files Browse the repository at this point in the history
* added categories to the api

* cleaned import

* updated readme

* added categories to the client
  • Loading branch information
kevupton authored Aug 5, 2024
1 parent 4748ff2 commit 124e64d
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 43 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

* Added categories to the client

### 0.0.30 (2024-04-23)

### 0.0.29 (2023-08-30)

### 0.0.28 (2023-08-14)
Expand Down
82 changes: 42 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,48 @@ const trendingSearch = await client.trending();

## Supported API method

| Endpoint | function | tested? |
| ---------------------------------------------------------- | ---------------------------------: | :-----: |
| /ping | client.ping() ||
| /simple/price | client.simplePrice() ||
| /simple/token_price/:id | client.simplePriceId() ||
| /simple/supported_vs_currencies | client.simpleSupportedCurrencies() ||
| /coins/list | client.coinList() ||
| /coins/markets | client.coinMarkets() ||
| /coins/:id | client.coinId() ||
| /coins/:id/tickers | client.coinIdTickers() ||
| /coins/:id/history | client.coinIdHistory() ||
| /coins/:id/market_history | client.coinIdMarketHistory() ||
| /coins/id/market_chart | client.coinIdMarketChart() ||
| /coins/{id}/market_chart/range | client.coinIdMarketChartRange() ||
| /coins/{id}/status_updates | client.coinIdStatusUpdates() ||
| /coins/{id}/ohlc | client.coinIdOHLC() ||
| /coins/{id}/contract/{contract_address} | client.contract() ||
| /coins/{id}/contract/{contract_address}/market_chart/ | client.contractMarketChart() ||
| /coins/{id}/contract/{contract_address}/market_chart/range | client.contractMarketChartRange() ||
| /exchanges | client.exchanges() ||
| /exchanges/list | client.exchangeList() ||
| /exchanges/{id}/tickers | client.exchangeIdTickers() ||
| /exchanges/{id}/status_update | client.exchangeIdStatusUpdates() ||
| /exchanges/{id}/volume_chart | client.exchangeIdVolumeChart() ||
| /finance_platforms | client.financePlatforms() ||
| /finance_products | client.financeProducts() ||
| /indexes | client.indexes() ||
| /indexes/{market_id}/{id} | client.indexesMarketId() ||
| /indexes/list | client.indexesList() ||
| /indexes/list_by_market_and_id/{market_id}/{id} | client.financeProducts() ||
| /derivatives | client./derivatives() ||
| /derivatives/exchanges | client./derivativesExchanges() ||
| /derivatives/exchanges/{id} | client./derivativesExchangesId() ||
| /status_updates | client.statusUpdates() ||
| /exchange_rates | client.exhangesRates() ||
| /search | client.search() ||
| /search/trending | client.trending() ||
| /global | client.global() ||
| /status_updates | client.statusUpdates() ||
| /global/decentralized_finance_defi | client.globalDefi() ||
| Endpoint | function | tested? |
|------------------------------------------------------------|------------------------------------------:| :-----: |
| /ping | client.ping() ||
| /simple/price | client.simplePrice() ||
| /simple/token_price/:id | client.simplePriceId() ||
| /simple/supported_vs_currencies | client.simpleSupportedCurrencies() ||
| /coins/list | client.coinList() ||
| /coins/markets | client.coinMarkets() ||
| /coins/:id | client.coinId() ||
| /coins/:id/tickers | client.coinIdTickers() ||
| /coins/:id/history | client.coinIdHistory() ||
| /coins/:id/market_history | client.coinIdMarketHistory() ||
| /coins/id/market_chart | client.coinIdMarketChart() ||
| /coins/{id}/market_chart/range | client.coinIdMarketChartRange() ||
| /coins/{id}/status_updates | client.coinIdStatusUpdates() ||
| /coins/{id}/ohlc | client.coinIdOHLC() ||
| /coins/{id}/contract/{contract_address} | client.contract() ||
| /coins/{id}/contract/{contract_address}/market_chart/ | client.contractMarketChart() ||
| /coins/{id}/contract/{contract_address}/market_chart/range | client.contractMarketChartRange() ||
| /coins/categories/list | client.coinCategoriesList() ||
| /coins/categories | client.coinCategoriesListWithMarketData() ||
| /exchanges | client.exchanges() ||
| /exchanges/list | client.exchangeList() ||
| /exchanges/{id}/tickers | client.exchangeIdTickers() ||
| /exchanges/{id}/status_update | client.exchangeIdStatusUpdates() ||
| /exchanges/{id}/volume_chart | client.exchangeIdVolumeChart() ||
| /finance_platforms | client.financePlatforms() ||
| /finance_products | client.financeProducts() ||
| /indexes | client.indexes() ||
| /indexes/{market_id}/{id} | client.indexesMarketId() ||
| /indexes/list | client.indexesList() ||
| /indexes/list_by_market_and_id/{market_id}/{id} | client.financeProducts() ||
| /derivatives | client./derivatives() ||
| /derivatives/exchanges | client./derivativesExchanges() ||
| /derivatives/exchanges/{id} | client./derivativesExchangesId() ||
| /status_updates | client.statusUpdates() ||
| /exchange_rates | client.exhangesRates() ||
| /search | client.search() ||
| /search/trending | client.trending() ||
| /global | client.global() ||
| /status_updates | client.statusUpdates() ||
| /global/decentralized_finance_defi | client.globalDefi() ||


## Development
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coingecko-api-v3",
"version": "0.0.29",
"version": "0.0.30",
"description": "The nodejs api library for accessing coingecko api v3 , develop with typescript",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
28 changes: 28 additions & 0 deletions src/CoinGeckoClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,34 @@ describe("CoinGeckoClient test", () => {
});
});

describe("Category", () => {
it("/coins/categories/list should successful", async () => {
const list = await client.coinCategoriesList();
expect(list).toContainEqual({
category_id: expect.any(String),
name: expect.any(String),
});
});

it("/coins/categories should successful", async () => {
const list = await client.coinCategoriesListWithMarketData();
expect(list).toContainEqual({
id: expect.any(String),
name: expect.any(String),
market_cap: expect.any(Number),
market_cap_change_24h: expect.any(Number),
content: expect.any(String),
top_3_coins: expect.arrayContaining([
expect.any(String),
expect.any(String),
expect.any(String),
]),
volume_24h: expect.any(Number),
updated_at: expect.any(String),
});
});
});

describe("Simple", () => {
it("/simple/market should successful", async () => {
const price = await client.simpleTokenPrice({
Expand Down
30 changes: 28 additions & 2 deletions src/CoinGeckoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
Options,
HttpResponse,
SearchResponse,
Category,
CategoryWithMarketData,
} from "./Interface";

/**
Expand Down Expand Up @@ -233,7 +235,6 @@ valid values: true, false
| "gecko_desc"
| "gecko_asc"
| "market_cap_asc"
| "market_cap_desc"
| "volume_asc"
| "volume_desc"
| "id_asc"
Expand Down Expand Up @@ -400,7 +401,7 @@ valid values: true, false
* @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}
* @returns {Array<Array<number>>}
* Sample output
* ```
* [
Expand All @@ -423,6 +424,31 @@ valid values: true, false
return this.makeRequest<Array<Array<number>>>(API_ROUTES.COIN_OHLC, input);
}

/**
* Get all the coins categories on CoinGecko.
* @see https://docs.coingecko.com/reference/coins-categories-list
* @returns List of all categories
* @category Category
* @returns {Array<Category>}
*/
public async coinCategoriesList() {
return this.makeRequest<Array<Category>>(API_ROUTES.COIN_CATEGORIES_LIST);
}

/**
* Get all the coins categories with market data (market cap, volume, etc.) on CoinGecko
* @see https://docs.coingecko.com/reference/coins-categories
* @param input.order sort results by field, default: market_cap_desc
* @returns List of all categories with market data
* @category Category
* @returns {Array<Category>}
*/
public async coinCategoriesListWithMarketData(input: {
order?: 'market_cap_desc' | 'market_cap_asc' | 'name_asc' | 'name_desc' | 'market_cap_change_24h_asc' | 'market_cap_change_24h_desc' ;
} = {}) {
return this.makeRequest<Array<CategoryWithMarketData>>(API_ROUTES.COIN_CATEGORIES, input);
}

/**
* Get the current price of any cryptocurrencies in any other supported currencies that you need.
* @param input.vs_currencies vs_currency of coins, comma-separated if querying more than 1 vs_currency. *refers to simple/supported_vs_currencies
Expand Down
2 changes: 2 additions & 0 deletions src/Enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export enum API_ROUTES {
COIN_MARKET_CHART = "/coins/{id}/market_chart",
COIN_MARKET_CHART_RANGE = "/coins/{id}/market_chart/range",
COIN_OHLC = "/coins/{id}/ohlc",
COIN_CATEGORIES_LIST = '/coins/categories/list',
COIN_CATEGORIES = '/coins/categories',
SIMPLE_PRICE = "/simple/price",
SIMPLE_SUPPORTED_CURRENCIES = "/simple/supported_vs_currencies",
SIMPLE_TOKEN_PRICE = "/simple/token_price/{id}",
Expand Down
16 changes: 16 additions & 0 deletions src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ export interface CoinMarket extends BasicCoin {
last_updated?: Date;
}

export interface Category {
category_id: string;
name: string;
}

export interface CategoryWithMarketData {
id: string;
name: string;
market_cap: number;
market_cap_change_24h: number;
content: string;
top_3_coins: Array<string>;
volume_24h: number;
updated_at: string;
}

export interface SimplePriceResponse {
[coin: string]: {
/**
Expand Down

0 comments on commit 124e64d

Please sign in to comment.