File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -258,13 +258,14 @@ async function fetchPricesForTimestamps(token: string, timestamps: string[]): Pr
258258 } ) ) ?? { }
259259
260260 const prices : Record < string , number > = { } ;
261-
261+ const failedSet = new Set < string > ( tokenPriceCache . failed || [ ] ) ;
262+
262263 timestamps = timestamps . filter ( ts => {
263264 if ( typeof tokenPriceCache [ ts ] === 'number' ) {
264265 prices [ ts ] = tokenPriceCache [ ts ] ;
265266 return false ;
266267 }
267- return true ;
268+ return ! failedSet . has ( ts + '' ) ;
268269 } ) ;
269270
270271 if ( ! token || timestamps . length === 0 ) {
@@ -275,6 +276,9 @@ async function fetchPricesForTimestamps(token: string, timestamps: string[]): Pr
275276 let success = 0
276277
277278 const fetchPrice = async ( ts : any ) => {
279+ try {
280+
281+
278282 const response = await fetch (
279283 `https://coins.llama.fi/prices/historical/${ ts } /${ token } ?apikey=${ process . env . APIKEY } `
280284 ) ;
@@ -284,7 +288,16 @@ async function fetchPricesForTimestamps(token: string, timestamps: string[]): Pr
284288 success ++
285289 prices [ ts ] = priceValue
286290 tokenPriceCache [ ts ] = priceValue
291+ } else {
292+ if ( ! tokenPriceCache . failed ) tokenPriceCache . failed = [ ] ;
293+ tokenPriceCache . failed . push ( ts + '' ) ;
287294 }
295+
296+
297+ } catch ( error ) {
298+ if ( ! tokenPriceCache . failed ) tokenPriceCache . failed = [ ] ;
299+ tokenPriceCache . failed . push ( ts + '' ) ;
300+ }
288301 }
289302
290303 await PromisePool . withConcurrency ( 15 ) . for ( timestamps ) . process ( fetchPrice )
You can’t perform that action at this time.
0 commit comments