-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcryptocurrencies.js
38 lines (33 loc) · 930 Bytes
/
cryptocurrencies.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const axios = require('axios');
const { cmc_api, api_key } = require('./constants');
const testData = require('./test-data.json');
const env = require('../environment');
const cmc_instance = axios.create({
baseURL: cmc_api,
headers: { 'X-CMC_PRO_API_KEY': api_key }
});
const getAll = async (limit = 200) => {
try {
if (!env.USE_REAL_COINMARKETCAP_DATA) {
return testData;
}
let response = await cmc_instance.get(`/cryptocurrency/listings/latest?start=1&limit=${limit}`);
return response.data.data;
} catch (err) {
console.log(err);
}
}
const getBySymbol = async (symbol) => {
if (!symbol || !symbol.length)
return { error: true, message: 'Need a symbol' };
try {
let response = await cmc_instance.get(`/cryptocurrency/quotes/latest?symbol=${symbol}`);
return response.data.data;
} catch (err) {
console.log(err)
}
}
module.exports = {
getAll,
getBySymbol,
}