Skip to content

Commit

Permalink
Initialize update
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelooblan2016 committed Nov 14, 2021
0 parents commit 3475e66
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/node_modules
44 changes: 44 additions & 0 deletions ApiCoinMarketCap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const axios = require('axios');
const { type } = require('os');
const env = require('./env.json');

class ApiCoinMarketCap {

constructor () {
this.baseUrl = env.base_url;
this.baseParams = env.base_params;
}

async getMarketPrices(start = 1, limit = 100, options = {}) {
let baseUrl = this.baseUrl;
let baseParams = this.baseParams;
baseParams.start = start;
baseParams.limit = limit;
baseParams = this.setBaseParams(baseParams, options);
let baseParamsImploded = Object.keys(baseParams).map( (key) => [key, baseParams[key]].join("=")).join("&");

let apiUrl = [
baseUrl,
baseParamsImploded
].join("?");

const { data } = await axios.get(apiUrl);

return data.data;
}

setBaseParams(baseParams, options) {
baseParams.sortBy = typeof options['sortBy'] != 'undefined' ? options['sortBy'] : baseParams.sortBy;
baseParams.sortType = typeof options['sortType'] != 'undefined' ? options['sortType'] : baseParams.sortType;
baseParams.convert = typeof options['convert'] != 'undefined' && typeof options['convert'] === 'object' ? options['convert'] : baseParams.convert;
baseParams.cryptoType =typeof options['cryptoType'] != 'undefined' ? options['cryptoType'] : baseParams.cryptoType;
baseParams.tagType = typeof options['tagType'] != 'undefined' ? options['tagType'] : baseParams.tagType;
baseParams.audited = typeof options['audited'] != 'undefined' ? options['audited'] : baseParams.audited;
baseParams.aux = typeof options['aux'] != 'undefined' && typeof options['aux'] === 'object' ? options['aux'] : baseParams.aux;
baseParams.tagSlugs = typeof options['tagSlugs'] != 'undefined' ? options['tagSlugs'] : baseParams.tagSlugs;

return baseParams;
}
}

module.exports = new ApiCoinMarketCap;
30 changes: 30 additions & 0 deletions env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"base_url":"https://api.coinmarketcap.com/data-api/v3/cryptocurrency/listing",
"base_params": {
"start": 1,
"limit": 100,
"sortBy": "market_cap",
"sortType": "desc",
"convert": ["USD","BTC","ETH"],
"cryptoType": "all",
"tagType": "all",
"audited":"false",
"aux": [
"ath",
"atl",
"high24h",
"low24h",
"num_market_pairs",
"cmc_rank",
"date_added",
"tags",
"platform",
"max_supply",
"circulating_supply",
"total_supply",
"volume_7d",
"volume_30d"
],
"tagSlugs":"polygon-ecosystem"
}
}
54 changes: 54 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"axios": "^0.24.0"
}
}

0 comments on commit 3475e66

Please sign in to comment.