Skip to content

Commit bfa8560

Browse files
authored
Merge pull request #16 from tendermint/cyrus/coingecko
Add coingecko cosmos marketcap
2 parents ed44d5d + 11b22e5 commit bfa8560

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ npm run start
7676

7777
**200**: Returns a list of Explorers wallets
7878

79+
### GET `/coingecko-cosmos-marketcap`
80+
81+
**200**: Returns the value of total market cap of Cosmos projects using Coingecko API
82+
7983
---
8084

8185
### Algolia bump

src/index.js

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ app.get("/marketcap", cache.serve(30), async (req, res) => {
139139
})
140140
)
141141
.then(() => {
142-
const billion = 1000000000;
143-
144142
// filter false value in array
145143
const checkNullList = list.filter(Boolean);
146144
const sum = checkNullList.reduce((a, b) => a + b, 0);
147-
const totalMarketcap = Number((Math.round(sum) / billion).toFixed(2));
145+
const totalMarketcap = Number(
146+
(Math.round(sum) / 1000 / 1000 / 1000).toFixed(2)
147+
);
148148

149149
res.setHeader(
150150
"Cache-Control",
@@ -201,6 +201,62 @@ app.get("/explorers", async (req, res) => {
201201
});
202202
});
203203

204+
app.get("/coingecko-cosmos-marketcap", cache.serve(30), async (req, res) => {
205+
const data = [
206+
"cosmos",
207+
"iris-network",
208+
"terra-luna",
209+
"terrausd",
210+
"binancecoin",
211+
"okb",
212+
"crypto-com-chain",
213+
"thorchain",
214+
"fetch-ai",
215+
"kucoin-shares",
216+
"mirror-protocol",
217+
"kava",
218+
"band-protocol",
219+
"oasis-network",
220+
"akash-network",
221+
"secret",
222+
"anchor-protocol",
223+
"injective-protocol",
224+
"bluezelle",
225+
"switcheo",
226+
"certik",
227+
"sentinel-group",
228+
"hard-protocol",
229+
"oraichain-token",
230+
"foam-protocol",
231+
"kira-network",
232+
"e-money",
233+
"likecoin",
234+
"starname",
235+
"sifchain",
236+
"bitsong",
237+
];
238+
const tokenIdStrings = data.toString();
239+
240+
await axios
241+
.get(
242+
`https://api.coingecko.com/api/v3/simple/price?ids=${tokenIdStrings}&vs_currencies=usd&include_market_cap=true`
243+
)
244+
.then((response) => {
245+
const marketcap = Object.values(response.data).map(
246+
(i) => i.usd_market_cap || 0
247+
);
248+
const sum = marketcap.reduce((a, b) => a + b, 0);
249+
const totalMarketcap = Number(
250+
(Math.round(sum) / 1000 / 1000 / 1000).toFixed(2)
251+
);
252+
253+
res.send(JSON.stringify(totalMarketcap));
254+
})
255+
.catch((err) => {
256+
console.log(err);
257+
});
258+
});
259+
204260
const listener = app.listen(port, function () {
205261
console.log("Your app is listening on port " + listener.address().port);
206262
});

0 commit comments

Comments
 (0)