@@ -197,7 +197,7 @@ export const fetchOrders = async (
197197 } else {
198198 logger . error (
199199 "fetch_orders_seaport" ,
200- `Seaport - Error. side=${ side } , cursor=${ cursor } , config. openseaApiUrl=${ config . openseaApiUrl } , url=${ url } , apiKey=${ details ?. apiKey } , realtimeOpenseaApiKey=${ config . realtimeOpenseaApiKey } , error=${ error } , stack=${ error . stack } `
200+ `Seaport - Error. side=${ side } , cursor=${ cursor } , openseaApiUrl=${ config . openseaApiUrl } , url=${ url } , apiKey=${ details ?. apiKey } , realtimeOpenseaApiKey=${ config . realtimeOpenseaApiKey } , error=${ error } , stack=${ error . stack } `
201201 ) ;
202202 }
203203
@@ -214,7 +214,8 @@ export const fetchOrders = async (
214214export const fetchAllOrders = async (
215215 fromTimestamp : number | null = null ,
216216 toTimestamp : number | null = null ,
217- cursor : string | null = null
217+ cursor : string | null = null ,
218+ useProxy = false
218219) => {
219220 let formatFromTimestamp = null ;
220221 let formatToTimestamp = null ;
@@ -248,7 +249,12 @@ export const fetchAllOrders = async (
248249
249250 const headers : any = {
250251 url,
251- "x-api-key" : config . backfillOpenseaApiKey || "" ,
252+ "X-API-KEY" : _ . includes (
253+ [ 5 , 80001 , 80002 , 84531 , 999 , 11155111 ] ,
254+ config . chainId
255+ ) || ( useProxy && config . openseaApiUrl && config . openseaNftApiKey )
256+ ? ""
257+ : config . backfillOpenseaApiKey ,
252258 } ;
253259
254260 if ( config . openseaApiUrl && config . openseaNftApiKey ) {
@@ -336,7 +342,48 @@ export const fetchAllOrders = async (
336342 ) ;
337343
338344 return response . data . next ;
339- } catch ( error ) {
345+ } catch ( error : any ) {
346+ if ( error . response ?. status === 429 || error . response ?. status === 503 ) {
347+ if ( useProxy ) {
348+ logger . warn (
349+ "fetch_all_orders" ,
350+ JSON . stringify (
351+ {
352+ message : `Seaport - Rate Limited. useProxy=${ useProxy } , fromTimestamp=${ formatFromTimestamp } , toTimestamp=${ formatToTimestamp } , cursor=${ cursor } , url=${ options . url } , error=${ error . message } ` ,
353+ openseaApiUrl : config . openseaApiUrl ,
354+ openseaNftApiKey : config . openseaNftApiKey ,
355+ options,
356+ responseData : error . response ?. data ,
357+ responseStatus : error . response ?. status ,
358+ useProxy,
359+ }
360+ )
361+ ) ;
362+ }
363+
364+ if ( ! useProxy && config . openseaApiUrl && config . openseaNftApiKey ) {
365+ headers [ "x-nft-api-key" ] = config . openseaNftApiKey ;
366+
367+ await fetchAllOrders ( fromTimestamp , toTimestamp , cursor , true ) ;
368+ return ;
369+ }
370+ } else if ( error . response ?. status === 401 ) {
371+ logger . error (
372+ "fetch_all_orders" ,
373+ JSON . stringify ( {
374+ topic : "opensea-unauthorized-api-key" ,
375+ message : `UnauthorizedError. context=fetchOrders, message=${ error . message } , url=${ error . config ?. url } ` ,
376+ requestHeaders : error . config ?. headers ,
377+ responseData : JSON . stringify ( error . response ?. data ) ,
378+ } )
379+ ) ;
380+ } else {
381+ logger . error (
382+ "fetch_all_orders" ,
383+ `Seaport - Error. cursor=${ cursor } , openseaApiUrl=${ config . openseaApiUrl } , url=${ url } , backfillOpenseaApiKey=${ config . backfillOpenseaApiKey } , error=${ error } , stack=${ error . stack } `
384+ ) ;
385+ }
386+
340387 throw error ;
341388 }
342389} ;
0 commit comments