@@ -139,12 +139,12 @@ app.get("/marketcap", cache.serve(30), async (req, res) => {
139
139
} )
140
140
)
141
141
. then ( ( ) => {
142
- const billion = 1000000000 ;
143
-
144
142
// filter false value in array
145
143
const checkNullList = list . filter ( Boolean ) ;
146
144
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
+ ) ;
148
148
149
149
res . setHeader (
150
150
"Cache-Control" ,
@@ -201,6 +201,62 @@ app.get("/explorers", async (req, res) => {
201
201
} ) ;
202
202
} ) ;
203
203
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
+
204
260
const listener = app . listen ( port , function ( ) {
205
261
console . log ( "Your app is listening on port " + listener . address ( ) . port ) ;
206
262
} ) ;
0 commit comments