@@ -372,21 +372,24 @@ export const priceValid = (price: number, tickSize: TickSize): boolean =>
372372
373373export const getClobMarketInfo = async ( {
374374 conditionId,
375+ clobVersion = 'v1' ,
376+ clobBaseUrl,
375377} : {
376378 conditionId : string ;
379+ clobVersion ?: 'v1' | 'v2' ;
380+ clobBaseUrl ?: string ;
377381} ) : Promise < ClobMarketInfo > => {
378- const cachedMarketInfo = clobMarketInfoCache . get ( conditionId ) ;
382+ const clobEndpoint = getClobEndpoint ( { clobVersion, clobBaseUrl } ) ;
383+ const cacheKey = `${ clobEndpoint } :${ conditionId } ` ;
384+ const cachedMarketInfo = clobMarketInfoCache . get ( cacheKey ) ;
379385
380386 if ( cachedMarketInfo ) {
381387 return cachedMarketInfo ;
382388 }
383389
384- const response = await fetch (
385- `${ getClobEndpoint ( ) } /clob-markets/${ conditionId } ` ,
386- {
387- method : 'GET' ,
388- } ,
389- ) ;
390+ const response = await fetch ( `${ clobEndpoint } /clob-markets/${ conditionId } ` , {
391+ method : 'GET' ,
392+ } ) ;
390393
391394 if ( ! response . ok ) {
392395 throw new Error ( 'Failed to get CLOB market info' ) ;
@@ -398,25 +401,31 @@ export const getClobMarketInfo = async ({
398401 throw new Error ( 'Invalid CLOB market info response' ) ;
399402 }
400403
401- clobMarketInfoCache . set ( conditionId , marketInfo ) ;
402- reportedClobMarketInfoFailures . delete ( conditionId ) ;
404+ clobMarketInfoCache . set ( cacheKey , marketInfo ) ;
405+ reportedClobMarketInfoFailures . delete ( cacheKey ) ;
403406 return marketInfo ;
404407} ;
405408
406409export const getClobMarketInfoSafe = async ( {
407410 conditionId,
411+ clobVersion = 'v1' ,
412+ clobBaseUrl,
408413} : {
409414 conditionId : string ;
415+ clobVersion ?: 'v1' | 'v2' ;
416+ clobBaseUrl ?: string ;
410417} ) : Promise < ClobMarketInfo | undefined > => {
418+ const failureKey = `${ getClobEndpoint ( { clobVersion, clobBaseUrl } ) } :${ conditionId } ` ;
419+
411420 try {
412- return await getClobMarketInfo ( { conditionId } ) ;
421+ return await getClobMarketInfo ( { conditionId, clobVersion , clobBaseUrl } ) ;
413422 } catch ( error ) {
414- if ( ! reportedClobMarketInfoFailures . has ( conditionId ) ) {
423+ if ( ! reportedClobMarketInfoFailures . has ( failureKey ) ) {
415424 Logger . error (
416425 ensureClobMarketInfoError ( error ) ,
417426 getClobMarketInfoFailureContext ( conditionId ) ,
418427 ) ;
419- reportedClobMarketInfoFailures . add ( conditionId ) ;
428+ reportedClobMarketInfoFailures . add ( failureKey ) ;
420429 }
421430
422431 return undefined ;
@@ -2065,7 +2074,11 @@ export const previewOrder = async (
20652074 } ) ,
20662075 Promise . resolve ( '0' ) ,
20672076 side === Side . BUY
2068- ? getClobMarketInfoSafe ( { conditionId : outcomeId } )
2077+ ? getClobMarketInfoSafe ( {
2078+ conditionId : outcomeId ,
2079+ clobVersion : isV2 ? 'v2' : 'v1' ,
2080+ clobBaseUrl : isV2 ? clobBaseUrl : undefined ,
2081+ } )
20692082 : Promise . resolve ( undefined ) ,
20702083 ] ) ;
20712084 if ( ! book ) {
0 commit comments