Skip to content

Commit 4c1a19f

Browse files
committed
fix: add fetch timeouts to Limitless and test server
1 parent a043307 commit 4c1a19f

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

‎core/src/exchanges/limitless/fetcher.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class LimitlessFetcher implements IExchangeFetcher<LimitlessRawMarket, Li
102102
const httpClient = new HttpClient({
103103
baseURL: this.apiUrl,
104104
apiKey: this.apiKey,
105+
timeout: 30000,
105106
});
106107
const marketFetcher = new MarketFetcher(httpClient);
107108

@@ -259,7 +260,7 @@ export class LimitlessFetcher implements IExchangeFetcher<LimitlessRawMarket, Li
259260

260261
private async fetchRawEventBySlug(slug: string): Promise<LimitlessRawEvent[]> {
261262
const { HttpClient, MarketFetcher } = await import('@limitless-exchange/sdk');
262-
const httpClient = new HttpClient({ baseURL: this.apiUrl });
263+
const httpClient = new HttpClient({ baseURL: this.apiUrl, timeout: 30000 });
263264
const marketFetcher = new MarketFetcher(httpClient);
264265

265266
const market = await marketFetcher.getMarket(slug);

‎core/src/server/test-server.js‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,32 @@
66
*/
77

88
const BASE_URL = 'http://localhost:3847';
9+
const REQUEST_TIMEOUT_MS = 30_000;
10+
11+
async function fetchWithTimeout(url, options = {}) {
12+
return fetch(url, {
13+
...options,
14+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
15+
});
16+
}
917

1018
async function testHealthCheck() {
1119
console.log('\nTesting health check...');
12-
const response = await fetch(`${BASE_URL}/health`);
20+
const response = await fetchWithTimeout(`${BASE_URL}/health`);
1321
const data = await response.json();
1422
console.log('Health check:', data);
1523
}
1624

1725
async function testVersion() {
1826
console.log('\nTesting version endpoint...');
19-
const response = await fetch(`${BASE_URL}/version`);
27+
const response = await fetchWithTimeout(`${BASE_URL}/version`);
2028
const data = await response.json();
2129
console.log('Version:', data);
2230
}
2331

2432
async function testFetchMarkets() {
2533
console.log('\nTesting fetchMarkets (Polymarket)...');
26-
const response = await fetch(`${BASE_URL}/api/polymarket/fetchMarkets`, {
34+
const response = await fetchWithTimeout(`${BASE_URL}/api/polymarket/fetchMarkets`, {
2735
method: 'POST',
2836
headers: { 'Content-Type': 'application/json' },
2937
body: JSON.stringify({
@@ -42,7 +50,7 @@ async function testFetchMarkets() {
4250

4351
async function testSearchMarkets() {
4452
console.log('\nTesting searchMarkets (Kalshi)...');
45-
const response = await fetch(`${BASE_URL}/api/kalshi/searchMarkets`, {
53+
const response = await fetchWithTimeout(`${BASE_URL}/api/kalshi/searchMarkets`, {
4654
method: 'POST',
4755
headers: { 'Content-Type': 'application/json' },
4856
body: JSON.stringify({
@@ -63,7 +71,7 @@ async function testSearchMarkets() {
6371

6472
async function testGetMarketsBySlug() {
6573
console.log('\nTesting getMarketsBySlug (Polymarket)...');
66-
const response = await fetch(`${BASE_URL}/api/polymarket/getMarketsBySlug`, {
74+
const response = await fetchWithTimeout(`${BASE_URL}/api/polymarket/getMarketsBySlug`, {
6775
method: 'POST',
6876
headers: { 'Content-Type': 'application/json' },
6977
body: JSON.stringify({
@@ -84,7 +92,7 @@ async function testFetchOHLCV() {
8492
console.log('\nTesting fetchOHLCV (Polymarket)...');
8593

8694
// First, get a market to extract an outcome ID
87-
const marketsResponse = await fetch(`${BASE_URL}/api/polymarket/searchMarkets`, {
95+
const marketsResponse = await fetchWithTimeout(`${BASE_URL}/api/polymarket/searchMarkets`, {
8896
method: 'POST',
8997
headers: { 'Content-Type': 'application/json' },
9098
body: JSON.stringify({
@@ -101,7 +109,7 @@ async function testFetchOHLCV() {
101109
const outcomeId = marketsData.data[0].outcomes[0].id;
102110
console.log(` Using outcome ID: ${outcomeId.substring(0, 20)}...`);
103111

104-
const response = await fetch(`${BASE_URL}/api/polymarket/fetchOHLCV`, {
112+
const response = await fetchWithTimeout(`${BASE_URL}/api/polymarket/fetchOHLCV`, {
105113
method: 'POST',
106114
headers: { 'Content-Type': 'application/json' },
107115
body: JSON.stringify({

0 commit comments

Comments
 (0)