0.0.51 • Published 3 years ago
@coingecko/cg-api-ts v0.0.51
CoinGecko API Wrapper
Installation
npm i --save @coingecko/cg-api-ts
yarn add @coingecko/cg-api-ts
Available Endpoint
Endpoint | Status | Testing | Function |
---|---|---|---|
/ping | / | / | getPing |
/simple/price | / | / | getSimplePrice |
/simple/supported_vs_currencies | / | / | getSimpleSupportedVsCurrencies |
/simple/token_price/{id} | x | x | |
/coins/list | / | / | getCoinsList |
/coins/markets | x | x | |
/coins/{id} | / | x | getCoinsId |
/coins/{id}/market_chart | / | / | getCoinsIdMarketChart |
/coins/{id}/status_updates | / | / | getCoinsIdStatusUpdates |
/status_updates | / | / | getStatusUpdates |
/global | / | / | getGlobal |
Usage
import { CoinGeckoAPI } from "@coingecko/cg-api-ts";
const cg = new CoinGeckoAPI(fetch);
// sometimes fetch is not bind properly need to use following:
// export const cg = new CoinGeckoAPI(window.fetch.bind(window));
cg.getPing()
.then(({ data, response, endpoint }) => {
console.log(data);
console.log(response);
console.log(endpoint);
})
// Error Handling
.catch(err => {
if (err.type === APIError.SERVER) {
// Resouces not found (Error 404)
console.error("API resources not found");
} else if (err.type === APIError.DOWN) {
// CoinGecko API Down (Error 500)
console.error("API Down");
} else if (err.type === APIError.TIMEOUT) {
// API Request timeout after 20s (default)
console.error("API Timeout");
console.error(err.message); // Request timeout after 20000ms
} else {
console.error(err.message);
}
});
Browser
CoinGeckoAPI class used fetch API, which requires browser support for Fetch API. Consider using Polyfill library
Promise style
import { CoinGeckoAPI, APIError } from "@coingecko/cg-api-ts";
const cg = new CoinGeckoAPI(fetch);
cg.getPing().then(({ data, response }) => {
if (data) {
console.log("Server online");
} else {
console.error("Server not responding properly");
}
});
Async Await
(async () => {
const cg = new CoinGeckoAPI(fetch);
const { data, response } = await cg.getPing();
if (data) {
console.log("Server online");
} else {
console.error("Server offline");
}
})();
Nodejs
const nodeFetch = require("node-fetch");
const cg = new CoinGeckoAPI(nodeFetch);
cg.getPing().then(({ data, response }) => {
if (data) {
console.log("Server online");
} else {
console.error("Server offline");
}
});
0.0.51
3 years ago
0.0.50
3 years ago
0.0.48
3 years ago
0.0.49
3 years ago
0.0.47
3 years ago
0.0.46
3 years ago
0.0.45
3 years ago
0.0.44
3 years ago
0.0.43
3 years ago
0.0.41
4 years ago
0.0.40
4 years ago
0.0.39
4 years ago
0.0.38
4 years ago
0.0.37
4 years ago
0.0.36
4 years ago
0.0.35
4 years ago
0.0.34
4 years ago
0.0.33
4 years ago
0.0.32
4 years ago
0.0.31
4 years ago
0.0.30
4 years ago
0.0.29
4 years ago
0.0.28
4 years ago
0.0.27
4 years ago
0.0.26
4 years ago
0.0.24
4 years ago
0.0.23
4 years ago
0.0.22
4 years ago
0.0.21
4 years ago
0.0.20
4 years ago
0.0.19
4 years ago
0.0.18
4 years ago
0.0.17
4 years ago
0.0.15
4 years ago
0.0.16
4 years ago
0.0.14
4 years ago
0.0.13
4 years ago
0.0.12
4 years ago
0.0.11
4 years ago
0.0.10
5 years ago
0.0.9
5 years ago
0.0.8
5 years ago
0.0.7
5 years ago
0.0.6
5 years ago
0.0.5
5 years ago
0.0.4
5 years ago
0.0.3
5 years ago
0.0.2
5 years ago
0.0.1
5 years ago