File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -173,17 +173,26 @@ const asCoingeckoAssetResponse = asArray(
173173 } )
174174)
175175
176+ type CoingeckoAssetResponse = ReturnType < typeof asCoingeckoAssetResponse >
177+
176178const DEFAULT_WAIT_MS = 2 * 1000
177179const MAX_WAIT_MS = 5 * 60 * 1000
178180
179181export const coingeckoAssets = async ( ) : Promise < AssetMap > => {
182+ const assets = await coingeckoAssetsInternal ( )
183+ return assetMapReducer ( assets )
184+ }
185+
186+ export const coingeckoAssetsInternal = async (
187+ maxAssets : number = Infinity
188+ ) : Promise < CoingeckoAssetResponse > => {
180189 let page = 1
181190 const perPage = 250
182- let out : ReturnType < typeof asCoingeckoAssetResponse > = [ ]
191+ let out : CoingeckoAssetResponse = [ ]
183192 let wait = DEFAULT_WAIT_MS
184193 while ( true ) {
185194 const response = await fetch (
186- `${ uri } /api/v3/coins/markets?x_cg_pro_api_key=${ apiKey } &vs_currency=usd&per_page=${ perPage } &page=${ page } &order=market_cap_asc `
195+ `${ uri } /api/v3/coins/markets?x_cg_pro_api_key=${ apiKey } &vs_currency=usd&per_page=${ perPage } &page=${ page } &order=market_cap_desc `
187196 )
188197 if ( ! response . ok ) {
189198 const text = await response . text ( )
@@ -214,7 +223,8 @@ export const coingeckoAssets = async (): Promise<AssetMap> => {
214223 `Querying coingeckoAssets page ${ page } . Found ${ out . length } assets so far`
215224 )
216225 page ++
226+ if ( out . length >= maxAssets ) break
217227 }
218228 logger ( `Finished coingeckoAssets query found ${ out . length } assets` )
219- return assetMapReducer ( out )
229+ return out
220230}
You can’t perform that action at this time.
0 commit comments