From 4c1a19f6997b6000ca4192e58c6a2fd9f8772bb9 Mon Sep 17 00:00:00 2001 From: Samuel Tinnerholm Date: Fri, 5 Jun 2026 14:38:34 +0000 Subject: [PATCH] fix: add fetch timeouts to Limitless and test server --- core/src/exchanges/limitless/fetcher.ts | 3 ++- core/src/server/test-server.js | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/src/exchanges/limitless/fetcher.ts b/core/src/exchanges/limitless/fetcher.ts index aca7f6bf..01819d9a 100644 --- a/core/src/exchanges/limitless/fetcher.ts +++ b/core/src/exchanges/limitless/fetcher.ts @@ -102,6 +102,7 @@ export class LimitlessFetcher implements IExchangeFetcher { const { HttpClient, MarketFetcher } = await import('@limitless-exchange/sdk'); - const httpClient = new HttpClient({ baseURL: this.apiUrl }); + const httpClient = new HttpClient({ baseURL: this.apiUrl, timeout: 30000 }); const marketFetcher = new MarketFetcher(httpClient); const market = await marketFetcher.getMarket(slug); diff --git a/core/src/server/test-server.js b/core/src/server/test-server.js index 4b8a6454..e1975ba6 100644 --- a/core/src/server/test-server.js +++ b/core/src/server/test-server.js @@ -6,24 +6,32 @@ */ const BASE_URL = 'http://localhost:3847'; +const REQUEST_TIMEOUT_MS = 30_000; + +async function fetchWithTimeout(url, options = {}) { + return fetch(url, { + ...options, + signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS), + }); +} async function testHealthCheck() { console.log('\nTesting health check...'); - const response = await fetch(`${BASE_URL}/health`); + const response = await fetchWithTimeout(`${BASE_URL}/health`); const data = await response.json(); console.log('Health check:', data); } async function testVersion() { console.log('\nTesting version endpoint...'); - const response = await fetch(`${BASE_URL}/version`); + const response = await fetchWithTimeout(`${BASE_URL}/version`); const data = await response.json(); console.log('Version:', data); } async function testFetchMarkets() { console.log('\nTesting fetchMarkets (Polymarket)...'); - const response = await fetch(`${BASE_URL}/api/polymarket/fetchMarkets`, { + const response = await fetchWithTimeout(`${BASE_URL}/api/polymarket/fetchMarkets`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ @@ -42,7 +50,7 @@ async function testFetchMarkets() { async function testSearchMarkets() { console.log('\nTesting searchMarkets (Kalshi)...'); - const response = await fetch(`${BASE_URL}/api/kalshi/searchMarkets`, { + const response = await fetchWithTimeout(`${BASE_URL}/api/kalshi/searchMarkets`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ @@ -63,7 +71,7 @@ async function testSearchMarkets() { async function testGetMarketsBySlug() { console.log('\nTesting getMarketsBySlug (Polymarket)...'); - const response = await fetch(`${BASE_URL}/api/polymarket/getMarketsBySlug`, { + const response = await fetchWithTimeout(`${BASE_URL}/api/polymarket/getMarketsBySlug`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ @@ -84,7 +92,7 @@ async function testFetchOHLCV() { console.log('\nTesting fetchOHLCV (Polymarket)...'); // First, get a market to extract an outcome ID - const marketsResponse = await fetch(`${BASE_URL}/api/polymarket/searchMarkets`, { + const marketsResponse = await fetchWithTimeout(`${BASE_URL}/api/polymarket/searchMarkets`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ @@ -101,7 +109,7 @@ async function testFetchOHLCV() { const outcomeId = marketsData.data[0].outcomes[0].id; console.log(` Using outcome ID: ${outcomeId.substring(0, 20)}...`); - const response = await fetch(`${BASE_URL}/api/polymarket/fetchOHLCV`, { + const response = await fetchWithTimeout(`${BASE_URL}/api/polymarket/fetchOHLCV`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({