coingecko-api-typed
Version:
A Node.js wrapper for the CoinGecko API with no dependencies (with generated inline d.ts typings!).
577 lines (576 loc) • 27.6 kB
TypeScript
export = CoinGecko;
/**
* @typedef {Object} ReturnObject
* @description - Return object for requests in the class. Helper for reference.
* @param {boolean} success - Whether the response status code returned a successful code (>200 && <300)
* @param {string} message - The response status message
* @param {number} code - The response status code
* @param {object|*} data - The body data in json format from the request
* @property {boolean} success - Whether the response status code returned a successful code (>200 && <300)
* @property {string} message - The response status message
* @property {number} code - The response status code
* @property {object|*} data - The body data in json format from the request
*/
/**
* @class CoinGecko
* @author Mark Miscavage <markmiscavage@protonmail.com>
* @description A Node.js wrapper for the CoinGecko API with no dependencies. For more information, visit: https://www.coingecko.com/api/docs/v3
* @example
* const CoinGecko = require('coingecko-api-typed');
* const CoinGeckoClient = new CoinGecko();
* @public
* @version 1.0.19
* @license MIT
* @kind class
*/
declare class CoinGecko {
/**
* @description Check API server status
* @function ping
* @returns {Promise<ReturnObject>}
*/
ping(): Promise<ReturnObject>;
/**
* @description Get cryptocurrency global data
* @function global
* @returns {Promise<ReturnObject>}
*/
global(): Promise<ReturnObject>;
/**
* @description Calls related to coins
*/
get coins(): {
/**
* @description List all coins with data (name, price, market, developer, community, etc) - paginated by 50
* @function coins.all()
* @param {object} params - Parameters to pass through to the request
* @param {string} params.order - Order results by CoinGecko.ORDER[*]
* @param {number} params.per_page - Total results per page
* @param {number} params.page - Page through results
* @param {boolean} params.localization [default: true] - Set to false to exclude localized languages in response
* @param {boolean} params.sparkline [default: false] - Include sparkline 7 days data
* @returns {Promise<ReturnObject>}
*/
all: (params?: {
order: string;
per_page: number;
page: number;
localization: boolean;
sparkline: boolean;
}) => Promise<ReturnObject>;
/**
* @description Use this to obtain all the coins’ id in order to make API calls
* @function coins.list()
* @returns {Promise<ReturnObject>}
*/
list: () => Promise<ReturnObject>;
/**
* @description Use this to obtain all the coins market data (price, market cap, volume)
* @function coins.markets()
* @param {object} params - Parameters to pass through to the request
* @param {string} params.vs_currency [default: usd] - The target currency of market data (usd, eur, jpy, etc.)
* @param {array|string} params.ids - List of coin id to filter if you want specific results
* @param {string} params.order - Order results by CoinGecko.ORDER[*]
* @param {number} params.per_page - Total results per page
* @param {number} params.page - Page through results
* @param {boolean} params.sparkline [default: false] - Include sparkline 7 days data (true/false)
* @returns {Promise<ReturnObject>}
*/
markets: (params?: {
vs_currency: string;
ids: any[] | string;
order: string;
per_page: number;
page: number;
sparkline: boolean;
}) => Promise<ReturnObject>;
/**
* @description Get current data (name, price, market, … including exchange tickers) for a coin.
* @function coins.fetch()
* @param {string} coinId - (Required) The coin id (can be obtained from coins.list()) eg. bitcoin
* @param {object} params - Parameters to pass through to the request
* @param {boolean} params.tickers [default: true] - Include ticker data
* @param {boolean} params.market_data [default: true] - Include market data
* @param {boolean} params.community_data [default: true] - Include community data
* @param {boolean} params.developer_data [default: true] - Include developer data
* @param {boolean} params.localization [default: true] - Set to false to exclude localized languages in response
* @param {boolean} params.sparkline [default: false] - Include sparkline 7 days data (true/false)
* @returns {Promise<ReturnObject>}
*/
fetch: (coinId: string, params?: {
tickers: boolean;
market_data: boolean;
community_data: boolean;
developer_data: boolean;
localization: boolean;
sparkline: boolean;
}) => Promise<ReturnObject>;
/**
* @description Get coin tickers (paginated to 100 items).
* @function coins.fetchTickers()
* @param {string} coinId - (Required) The coin id (can be obtained from coins.list()) eg. bitcoin
* @param {object} params - Parameters to pass through to the request
* @param {string} params.page - Page through results
* @param {number} params.exchange_ids - Filter tickers by exchange_ids
* @param {string} params.order [default: trust_score_desc] - Order results by CoinGecko.ORDER.TRUST_SCORE_DESC or CoinGecko.ORDER.VOLUME_DESC
* @returns {Promise<ReturnObject>}
*/
fetchTickers: (coinId: string, params?: {
page: string;
exchange_ids: number;
order: string;
}) => Promise<ReturnObject>;
/**
* @description Get historical data (name, price, market, stats) at a given date for a coin
* @function coins.fetchHistory()
* @param {string} coinId - (Required) The coin id (can be obtained from coins.list()) eg. bitcoin
* @param {object} params - Parameters to pass through to the request
* @param {string} params.date - (Required) The date of data snapshot in dd-mm-yyyy eg. 30-12-2017
* @param {boolean} params.localization [default: true] - Set to false to exclude localized languages in response
* @returns {Promise<ReturnObject>}
*/
fetchHistory: (coinId: string, params?: {
date: string;
localization: boolean;
}) => Promise<ReturnObject>;
/**
* @description Get historical market data include price, market cap, and 24h volume (granularity auto)
* @function coins.fetchMarketChart()
* @param {string} coinId - (Required) The coin id (can be obtained from coins.list()) eg. bitcoin
* @param {object} params - Parameters to pass through to the request
* @param {string} params.vs_currency [default: usd] - (Required) The target currency of market data (usd, eur, jpy, etc.)
* @param {string} params.days [default: 1] - (Required) Data up to number of days ago (eg. 1,14,30,max)
* @returns {Promise<ReturnObject>}
*/
fetchMarketChart: (coinId: string, params?: {
vs_currency: string;
days: string;
}) => Promise<ReturnObject>;
/**
* @description 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.
* @function coins.fetchMarketChartRange()
* @param {string} coinId - (Required) The coin id (can be obtained from coins.list()) eg. bitcoin
* @param {object} params - Parameters to pass through to the request
* @param {string} params.vs_currency [default: usd] - (Required) The target currency of market data (usd, eur, jpy, etc.)
* @param {number} params.from - (Required) From date in UNIX Timestamp (eg. 1392577232)
* @param {number} params.to - (Required) To date in UNIX Timestamp (eg. 1422577232)
* @returns {Promise<ReturnObject>}
*/
fetchMarketChartRange: (coinId: string, params?: {
vs_currency: string;
from: number;
to: number;
}) => Promise<ReturnObject>;
/**
* @description Get status updates for a given coin
* @function coins.fetchStatusUpdates()
* @param {string} coinId - (Required) The coin id (can be obtained from coins.list()) eg. bitcoin
* @param {object} params - Parameters to pass through to the request
* @param {number} params.per_page - Total results per page
* @param {number} params.page - Page through results
* @returns {Promise<ReturnObject>}
*/
fetchStatusUpdates: (coinId: string, params?: {
per_page: number;
page: number;
}) => Promise<ReturnObject>;
/**
* @description Get coin info from contract address
* @function coins.fetchCoinContractInfo()
* @param {object} contractAddress - (Required) Token’s contract address
* @param {string} assetPlatform [default: ethereum] - (Required) Asset platform (only ethereum is supported at this moment)
* @returns {Promise<ReturnObject>}
*/
fetchCoinContractInfo: (contractAddress: object, assetPlatform?: string) => Promise<ReturnObject>;
/**
* @description Get historical market data include price, market cap, and 24h volume (granularity auto) from a contract address
* @function coins.fetchCoinContractMarketChart()
* @param {object} contractAddress - (Required) Token’s contract address
* @param {string} assetPlatform [default: ethereum] - (Required) Asset platform (only ethereum is supported at this moment)
* @param {object} params - Parameters to pass through to the request
* @param {string} params.vs_currency [default: usd] - (Required) The target currency of market data (usd, eur, jpy, etc.)
* @param {string} params.days [default: 1] - (Required) Data up to number of days ago (eg. 1,14,30,max)
* @returns {Promise<ReturnObject>}
*/
fetchCoinContractMarketChart: (contractAddress: object, assetPlatform?: string, params?: {
vs_currency: string;
days: string;
}) => Promise<ReturnObject>;
/**
* @description Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto)
* @function coins.fetchCoinContractMarketChartRange()
* @param {object} contractAddress - (Required) Token’s contract address
* @param {string} assetPlatform [default: ethereum] - (Required) Asset platform (only ethereum is supported at this moment)
* @param {object} params - Parameters to pass through to the request
* @param {string} params.vs_currency [default: usd] - (Required) The target currency of market data (usd, eur, jpy, etc.)
* @param {number} params.from - (Required) From date in UNIX Timestamp (eg. 1392577232)
* @param {number} params.to - (Required) To date in UNIX Timestamp (eg. 1422577232)
* @returns {Promise<ReturnObject>}
*/
fetchCoinContractMarketChartRange: (contractAddress: object, assetPlatform?: string, params?: {
vs_currency: string;
from: number;
to: number;
}) => Promise<ReturnObject>;
};
/**
* @description Calls related to exchanges
*/
get exchanges(): {
/**
* @description List all exchanges
* @function exchanges.all()
* @returns {Promise<ReturnObject>}
*/
all: () => Promise<ReturnObject>;
/**
* @description List all supported markets id and name
* @function exchanges.list()
* @returns {Promise<ReturnObject>}
*/
list: () => Promise<ReturnObject>;
/**
* @description Get exchange volume in BTC and top 100 tickers only for a given exchange
* @function exchanges.fetch()
* @param {string} exchangeId - (Required) The exchange id (can be obtained from exchanges.all()) eg. binance
* @returns {Promise<ReturnObject>}
*/
fetch: (exchangeId: string) => Promise<ReturnObject>;
/**
* @description Get tickers for a given exchange
* @function exchanges.fetchTickers()
* @param {string} exchangeId - (Required) The exchange id (can be obtained from exchanges.all()) eg. binance
* @param {object} params - Parameters to pass through to the request
* @param {number} params.page - Page through results
* @param {number} params.coin_ids - Filter tickers by coin_ids
* @param {string} params.order [default: trust_score_desc] - Order results by CoinGecko.ORDER.TRUST_SCORE_DESC or CoinGecko.ORDER.VOLUME_DESC
* @returns {Promise<ReturnObject>}
*/
fetchTickers: (exchangeId: string, params?: {
page: number;
coin_ids: number;
order: string;
}) => Promise<ReturnObject>;
/**
* @description Get status updates for a given exchange
* @function exchanges.fetchStatusUpdates()
* @param {string} exchangeId - (Required) The exchange id (can be obtained from exchanges.all()) eg. binance
* @param {object} params - Parameters to pass through to the request
* @param {number} params.per_page - Total results per page
* @param {number} params.page - Page through results
* @returns {Promise<ReturnObject>}
*/
fetchStatusUpdates: (exchangeId: string, params?: {
per_page: number;
page: number;
}) => Promise<ReturnObject>;
/**
* @description Get volume chart data for a given exchange, returned in BTC
* @function exchanges.fetchVolumeChart()
* @param {string} exchangeId - (Required) The exchange id (can be obtained from exchanges.all()) eg. binance
* @param {object} params - Parameters to pass through to the request
* @param {number} params.days - Data up to number of days ago (eg. 1, 14, 30)
* @returns {Promise<ReturnObject>}
*/
fetchVolumeChart: (exchangeId: string, params?: {
days: number;
}) => Promise<ReturnObject>;
};
/**
* @description Calls related to status updates
*/
get statusUpdates(): {
/**
* @description List all status_updates with data (description, category, created_at, user, user_title and pin)
* @function statusUpdates.all()
* @param {object} params - Parameters to pass through to the request
* @param {number} params.category - Filter results by CoinGecko.STATUS_UPDATE_CATEGORY[*]
* @param {number} params.project_type - Filter results by CoinGecko.STATUS_UPDATE_PROJECT_TYPE[*] (If left empty returns both status from coins and markets)
* @param {number} params.per_page - Total results per page
* @param {number} params.page - Page through results
* @returns {Promise<ReturnObject>}
*/
all: (params?: {
category: number;
project_type: number;
per_page: number;
page: number;
}) => Promise<ReturnObject>;
};
/**
* @description Calls related to events
*/
get events(): {
/**
* @description Get events, paginated by 100
* @function events.all()
* @param {object} params - Parameters to pass through to the request
* @param {number} params.country_code - country_code of event (eg. ‘US’). Use events.fetchHistory() for list of country_codes
* @param {string} params.type - Type of event (eg.‘Conference’). Use events.fetchTypes() for list of types. Or use CoinGecko.EVENT_TYPE[*]
* @param {number} params.page - Page of results (paginated by 100)
* @param {boolean} params.upcoming_events_only [default: true] - Lists only upcoming events
* @param {string} params.from_date - Lists events after this date yyyy-mm-dd
* @param {string} params.to_date - Lists events before this date yyyy-mm-dd (set upcoming_events_only to false if fetching past events)
* @returns {Promise<ReturnObject>}
*/
all: (params?: {
country_code: number;
type: string;
page: number;
upcoming_events_only: boolean;
from_date: string;
to_date: string;
}) => Promise<ReturnObject>;
/**
* @description Get list of event countries
* @function events.fetchCountries()
* @returns {Promise<ReturnObject>}
*/
fetchCountries: () => Promise<ReturnObject>;
/**
* @description Get list of event types
* @function events.fetchTypes()
* @returns {Promise<ReturnObject>}
*/
fetchTypes: () => Promise<ReturnObject>;
};
/**
* @description Calls related to exchange rates
*/
get exchangeRates(): {
/**
* @description Get BTC-to-Currency exchange rates
* @function exchangeRates.all()
* @returns {Promise<ReturnObject>}
*/
all: () => Promise<ReturnObject>;
};
/**
* @description Calls related to "simple" endpoints
*/
get simple(): {
/**
* @description Get the current price of any cryptocurrencies in any other supported currencies that you need
* @function simple.price()
* @param {object} params - Parameters to pass through to the request
* @param {array|string} params.ids - (Required) A single id or a list of coin ids to filter if you want specific results. Use coins.list() for a list of coin ids.
* @param {array|string} params.vs_currencies [default: usd] - A single id or a list of ids. Use simple.supportedVsCurrencies() for a list of vsCurrency ids.
* @param {boolean} params.include_24hr_vol [default: false] - To include 24hr_vol (true/false)
* @param {boolean} params.include_last_updated_at [default: false] - To include last_updated_at of price (true/false)
* @returns {Promise<ReturnObject>}
*/
price: (params?: {
ids: any[] | string;
vs_currencies: any[] | string;
include_24hr_vol: boolean;
include_last_updated_at: boolean;
}) => Promise<ReturnObject>;
/**
* @description Get list of supported vs/comparisons currencies
* @function simple.supportedVsCurrencies()
* @returns {Promise<ReturnObject>}
*/
supportedVsCurrencies: () => Promise<ReturnObject>;
/**
* @description Get current price of tokens (using contract addresses) for a given platform in any other currency that you need
* @function simple.fetchTokenPrice()
* @param {object} params - Parameters to pass through to the request
* @param {string} assetPlatform [default: ethereum] - (Required) Asset platform (only ethereum is supported at this moment)
* @param {string|array} params.contract_addresses - (Required) Token’s contract address
* @param {string|array} params.vs_currencies - (Required) vs_currency of coins. Use simple.supportedVsCurrencies() for a list of vsCurrency ids.
* @param {boolean} params.include_market_cap [default: false] - Include market cap in results or not
* @param {boolean} params.include_24hr_vol [default: false] - Include 24hr volume in results or not
* @param {boolean} params.include_24hr_change [default: false] - Include 24hr change in results or not
* @param {boolean} params.include_last_updated_at [default: false] - Include last updated date in results or not
* @returns {Promise<ReturnObject>}
*/
fetchTokenPrice: (params?: object, assetPlatform?: string) => Promise<ReturnObject>;
};
/**
* @description Calls related to finance endpoints
*/
get finance(): {
/**
* @description List all finance platforms
* @function finance.fetchPlatforms()
* @param {object} params - Parameters to pass through to the request
* @param {number} params.per_page - Total results per page
* @param {number} params.page - Page of results (paginated to 100 by default)
* @returns {Promise<ReturnObject>}
*/
fetchPlatforms: (params?: {
per_page: number;
page: number;
}) => Promise<ReturnObject>;
/**
* @description List all finance products
* @function finance.fetchProducts()
* @param {object} params - Parameters to pass through to the request
* @param {number} params.per_page - Total results per page
* @param {number} params.page - Page of results (paginated to 100 by default)
* @param {string} params.start_at - Start date of the financial products
* @param {string} params.end_at - End date of the financial products
* @returns {Promise<ReturnObject>}
*/
fetchProducts: (params?: {
per_page: number;
page: number;
start_at: string;
end_at: string;
}) => Promise<ReturnObject>;
};
/**
* @description Calls related to index endpoints
*/
get indexes(): {
/**
* @description List all market indexes
* @function indexes.all()
* @param {object} params - Parameters to pass through to the request
* @param {number} params.per_page - Total results per page
* @param {number} params.page - Page of results
* @returns {Promise<ReturnObject>}
*/
all: (params?: {
per_page: number;
page: number;
}) => Promise<ReturnObject>;
/**
* @description Fetch market index by id
* @function indexes.fetch()
* @param {string} marketId - (Required) The market id (can be obtained from exchanges.list())
* @param {string} indexId - (Required) The index id (can be obtained from indexes.list())
* @returns {Promise<ReturnObject>}
*/
fetch: (marketId: string, indexId: string) => Promise<ReturnObject>;
/**
* @description List market indexes id and name
* @function indexes.list()
* @returns {Promise<ReturnObject>}
*/
list: () => Promise<ReturnObject>;
};
/**
* @description Calls related to derivative endpoints
*/
get derivatives(): {
/**
* @description List all derivative tickers
* @function derivatives.fetchTickers()
* @returns {Promise<ReturnObject>}
*/
fetchTickers: () => Promise<ReturnObject>;
/**
* @description List all derivative exchanges
* @function derivatives.allExchanges()
* @param {object} params - Parameters to pass through to the request
* @param {string} params.order - Order results by CoinGecko.ORDER[*]
* @param {number} params.per_page - Total results per page
* @param {number} params.page - Page of results
* @returns {Promise<ReturnObject>}
*/
allExchanges: (params?: {
order: string;
per_page: number;
page: number;
}) => Promise<ReturnObject>;
/**
* @description Show derivative exchange data
* @function derivatives.fetchExchange()
* @param {string} exchangeId - (Required) The exchange id (can be obtained from derivatives.listExchanges()) e.g. bitmex
* @param {object} params - Parameters to pass through to the request
* @param {boolean} params.include_tickers [default: false] - Include the tickers information
* @returns {Promise<ReturnObject>}
*/
fetchExchange: (exchangeId: string, params?: {
include_tickers: boolean;
}) => Promise<ReturnObject>;
/**
* @description List all derivative exchanges name and identifier
* @function derivatives.listExchanges()
* @returns {Promise<ReturnObject>}
*/
listExchanges: () => Promise<ReturnObject>;
};
/**
* @description Build options for https.request
* @function _buildRequestOptions
* @protected
* @param {string} path - Relative path for API
* @param {object} params - Object representing query strings for url parameters
* @returns {Object} - {path, method, host, port} Options for request
*/
protected _buildRequestOptions(path: string, params: object): any;
/**
* @description Perform https request
* @function _request
* @protected
* @param {string} path - Relative path for API
* @param {object} params - Object representing query strings for url parameters
* @returns {Promise<ReturnObject>} Body of https request data results
*/
protected _request(path: string, params: object): Promise<ReturnObject>;
}
declare namespace CoinGecko {
export { API_VERSION, REQUESTS_PER_SECOND, ORDER, STATUS_UPDATE_CATEGORY, STATUS_UPDATE_PROJECT_TYPE, EVENT_TYPE, TIMEOUT, CoinGecko as default, ReturnObject };
}
type ReturnObject = any;
/**
* @description The current version for the CoinGecko API
* @kind constant
*/
declare const API_VERSION: "3";
/**
* @description The maximum number of requests per second for the CoinGecko API
* @kind constant
*/
declare const REQUESTS_PER_SECOND: 10;
declare namespace ORDER {
const GECKO_ASC: string;
const GECKO_DESC: string;
const MARKET_CAP_ASC: string;
const MARKET_CAP_DESC: string;
const VOLUME_ASC: string;
const VOLUME_DESC: string;
const COIN_NAME_ASC: string;
const COIN_NAME_DESC: string;
const PRICE_ASC: string;
const PRICE_DESC: string;
const HOUR_24_ASC: string;
const HOUR_24_DESC: string;
const TRUST_SCORE_DESC: string;
const NAME_ASC: string;
const NAME_DESC: string;
const OPEN_INTEREST_BTC_ASC: string;
const OPEN_INTEREST_BTC_DESC: string;
const TRADE_VOLUME_24H_BTC_ASC: string;
const TRADE_VOLUME_24H_BTC_DESC: string;
}
declare namespace STATUS_UPDATE_CATEGORY {
const GENERAL: string;
const MILESTONE: string;
const PARTNERSHIP: string;
const EXCHANGE_LISTING: string;
const SOFTWARE_RELEASE: string;
const FUND_MOVEMENT: string;
const NEW_LISTINGS: string;
const EVENT: string;
}
declare namespace STATUS_UPDATE_PROJECT_TYPE {
const COIN: string;
const MARKET: string;
}
declare namespace EVENT_TYPE {
const EVENT_1: string;
export { EVENT_1 as EVENT };
export const CONFERENCE: string;
export const MEETUP: string;
}
/**
* @description Timeout for connecton to CoinGecko API in milliseconds (default: 30 seconds)
* @kind constant
*/
declare const TIMEOUT: 30000;