Added a coingecko api key option

-As of Feb 2024 the free "keyless" coingecko api will be deprecated and will likely stop working. There is a free demo api key that can be used which can now be plugged into the explorer settings to allow the coingecko api to continue working. Read more here: https://support.coingecko.com/hc/en-us/articles/21880397454233
This commit is contained in:
Joe Uhren
2024-01-05 14:55:34 -07:00
parent 65c48ea829
commit 9851e2ce9d
4 changed files with 28 additions and 18 deletions
+15 -11
View File
@@ -1,23 +1,27 @@
const request = require('postman-request');
const base_url = 'https://api.coingecko.com/api/v3/';
function get_coin_list(cb) {
request({ uri: base_url + 'coins/list?include_platform=false', json: true}, function (error, response, body) {
function get_coin_list(api_key, cb) {
request({ uri: base_url + 'coins/list?include_platform=false' + (api_key == null || api_key == '' ? '' : '&x_cg_demo_api_key=' + api_key), json: true}, function (error, response, body) {
if (error)
return cb(error, []);
else if (body == null || body == '' || typeof body !== 'object')
return cb('No data returned', []);
return cb('No data returned', []);
else if (body['status'] != null && body['status']['error_message'] != null && body['status']['error_message'] != '')
return cb(body['status']['error_message'], []);
else
return cb(null, body);
});
}
function get_simple_price(id, currency, market_array, cb) {
request({ uri: base_url + `simple/price?ids=${id.toLowerCase()}&vs_currencies=usd${currency == null || currency == '' ? '' : `,${currency}`}`, json: true}, function (error, response, body) {
function get_simple_price(id, currency, market_array, api_key, cb) {
request({ uri: base_url + `simple/price?ids=${id.toLowerCase()}&vs_currencies=usd${currency == null || currency == '' ? '' : `,${currency}`}` + (api_key == null || api_key == '' ? '' : '&x_cg_demo_api_key=' + api_key), json: true}, function (error, response, body) {
if (error)
return cb(error, 0, 0);
else if (body == null || body == '' || typeof body !== 'object')
return cb('No data returned', 0, 0);
else if (body['status'] != null && body['status']['error_message'] != null && body['status']['error_message'] != '')
return cb(body['status']['error_message'], 0, 0);
else {
try {
if (market_array != null) {
@@ -59,21 +63,21 @@ function get_simple_price(id, currency, market_array, cb) {
}
module.exports = {
get_coin_data: function (cb) {
get_coin_list(function (err, coin_list) {
get_coin_data: function (api_key, cb) {
get_coin_list(api_key, function (err, coin_list) {
return cb(err, coin_list);
});
},
get_market_prices: function (id, currency, cb) {
get_simple_price(id, currency, null, function (err, last_price, last_usd) {
get_market_prices: function (id, currency, api_key, cb) {
get_simple_price(id, currency, null, api_key, function (err, last_price, last_usd) {
if (last_price == null)
console.log(`Error: "${currency}" is not a valid coingecko api currency`);
return cb(err, last_price, last_usd);
});
},
get_avg_market_prices: function (id, currency, market_array, cb) {
get_simple_price(id, currency, market_array, function (err, last_price, last_usd) {
get_avg_market_prices: function (id, currency, market_array, api_key, cb) {
get_simple_price(id, currency, market_array, api_key, function (err, last_price, last_usd) {
if (last_price == null)
console.log(`Error: "${currency}" is not a valid coingecko api currency`);
+3
View File
@@ -930,6 +930,9 @@ exports.markets_page = {
// The USD fiat currency is also built-in and automatically returned from the coingecko api so there is no need to specify USD here.
// For more information about which currency values are supported, you can review the vs_currencies parameter of the /simple/price api from here: https://www.coingecko.com/api/documentation
"coingecko_currency": "BTC",
// "coingecko_api_key": Supply a free or paid coingecko api key for fetching USD price and/or market price via the market_price = "COINGECKO" option
// NOTE: As of Feb 2024, the free "keyless" coingecko api will be deprecated and require an api key to continue use
"coingecko_api_key": "",
// default_exchange: a collection of settings that pertain to the default exchange
// When the "show_market_dropdown_menu" setting is disabled, the market header menu will navigate directly to the default exchange page
// The default_exchange.trading_pair is used to determine the last market price when the market_price value is set to AVERAGE