File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- const axios = require ( ' axios' ) ;
1+ const axios = require ( " axios" ) ;
22
33async function fetchCoinGeckoPrices ( client , tokens , network ) {
4- const stringifiedTokens = tokens . join ( ',' ) ;
4+ const stringifiedTokens = tokens . join ( "," ) ;
55
6- const url = `https://api.coingecko.com/api/v3/simple/token_price/${ network } ?contract_addresses=${ stringifiedTokens } &vs_currencies=usd` ;
7- try {
8- const { data } = await axios . get ( url ) ;
6+ let url = `https://api.coingecko.com/api/v3/simple/token_price/${ network } ?contract_addresses=${ stringifiedTokens } &vs_currencies=usd` ;
7+ if ( process . env . COINGECK_API_KEY ) {
8+ url = `${ url } &x_cg_pro_api_key=${ process . env . COINGECK_API_KEY } ` ;
9+ }
10+ try {
11+ const { data } = await axios . get ( url ) ;
912
10- for ( const [ key , value ] of Object . entries ( data ) ) {
11- client . setex ( key , 600 , value [ ' usd' ] ) ;
12- }
13- return data ;
14- } catch ( error ) {
15- console . error ( `Failed loading data for ${ tokens } : ${ error } ` ) ;
16- return { } ;
17- }
13+ for ( const [ key , value ] of Object . entries ( data ) ) {
14+ client . setex ( key , 600 , value [ " usd" ] ) ;
15+ }
16+ return data ;
17+ } catch ( error ) {
18+ console . error ( `Failed loading data for ${ tokens } : ${ error } ` ) ;
19+ return { } ;
20+ }
1821}
1922
20- module . exports = fetchCoinGeckoPrices ;
23+ module . exports = fetchCoinGeckoPrices ;
You can’t perform that action at this time.
0 commit comments