Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update api.js / userInput.json for custom coingecki API key #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import { round } from 'mathjs';
import { getCoinGeckoName, getNetworkTimeMinimum } from './networks.js';
import { sleep, transformDDMMYYYtoUnix } from './utils.js';

import { promises as fs } from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';

// Resolve directory name
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// Load configuration
const configPath = path.resolve(__dirname, '../config/userInput.json');
const config = JSON.parse(await fs.readFile(configPath, 'utf8'));
const coingeckoApiKey = config.coingecko_apikey;

export async function addPriceData(obj){
let priceObject = await _getPriceObject(obj);
var prices;
Expand All @@ -25,7 +39,12 @@ export async function addPriceData(obj){
}

async function _getPriceObject(obj){
const CoinGeckoClient = new CoinGecko();
const CoinGeckoClient = new CoinGecko({
headers: {
'x_cg_pro_api_key': coingeckoApiKey
}
});

var priceObject;
let start = transformDDMMYYYtoUnix(obj.data.list[0].day);
let end = transformDDMMYYYtoUnix(obj.data.list.slice(-1)[0].day);
Expand Down