@@ -112,6 +112,9 @@ export interface PolymarketRawPosition {
112112
113113const GAMMA_MARKETS_URL = process . env . POLYMARKET_GAMMA_MARKETS_URL || 'https://gamma-api.polymarket.com/markets' ;
114114
115+ // Cloudflare blocks large single-shot Gamma lookups (~50 condition_ids / ~3.5KB query).
116+ const GAMMA_CONDITION_IDS_BATCH_SIZE = 40 ;
117+
115118export class PolymarketFetcher implements IExchangeFetcher < PolymarketRawEvent , PolymarketRawEvent > {
116119 private readonly ctx : FetcherContext ;
117120 private readonly http : AxiosInstance ;
@@ -327,14 +330,17 @@ export class PolymarketFetcher implements IExchangeFetcher<PolymarketRawEvent, P
327330 }
328331
329332 private async resolveConditionIds ( conditionIds : string [ ] ) : Promise < Map < string , string > > {
330- const response = await this . http . get ( GAMMA_MARKETS_URL , {
331- params : { condition_ids : conditionIds . join ( ',' ) } ,
332- } ) ;
333- const markets : any [ ] = Array . isArray ( response . data ) ? response . data : [ ] ;
334333 const result = new Map < string , string > ( ) ;
335- for ( const market of markets ) {
336- if ( market . conditionId && market . id ) {
337- result . set ( market . conditionId , String ( market . id ) ) ;
334+ for ( let offset = 0 ; offset < conditionIds . length ; offset += GAMMA_CONDITION_IDS_BATCH_SIZE ) {
335+ const batch = conditionIds . slice ( offset , offset + GAMMA_CONDITION_IDS_BATCH_SIZE ) ;
336+ const response = await this . http . get ( GAMMA_MARKETS_URL , {
337+ params : { condition_ids : batch . join ( ',' ) } ,
338+ } ) ;
339+ const markets : any [ ] = Array . isArray ( response . data ) ? response . data : [ ] ;
340+ for ( const market of markets ) {
341+ if ( market . conditionId && market . id ) {
342+ result . set ( market . conditionId , String ( market . id ) ) ;
343+ }
338344 }
339345 }
340346 return result ;
0 commit comments