Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions core/src/exchanges/polymarket_us/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ export class PolymarketUSWebSocket {
await this.ensureInitialized();

if (!this.bookSubscriptions.has(slug)) {
if (!this.socket) {
throw new Error('[polymarket_us] Socket not available after connect');
}
this.bookSubscriptions.add(slug);
this.socket!.subscribeMarketData(`book:${slug}`, [slug]);
this.socket.subscribeMarketData(`book:${slug}`, [slug]);
}

const dataPromise = new Promise<OrderBook>((resolve, reject) => {
Expand All @@ -97,8 +100,11 @@ export class PolymarketUSWebSocket {
await this.ensureInitialized();

if (!this.tradeSubscriptions.has(slug)) {
if (!this.socket) {
throw new Error('[polymarket_us] Socket not available after connect');
}
this.tradeSubscriptions.add(slug);
this.socket!.subscribeTrades(`trade:${slug}`, [slug]);
this.socket.subscribeTrades(`trade:${slug}`, [slug]);
}

const dataPromise = new Promise<Trade[]>((resolve, reject) => {
Expand Down
1 change: 1 addition & 0 deletions sdks/typescript/pmxt/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export class Router extends Exchange {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
body: JSON.stringify({ args: [query], credentials: this.getCredentials() }),
signal: AbortSignal.timeout(30_000),
});
if (!response.ok) {
const body = await response.json().catch(() => ({}));
Expand Down
10 changes: 8 additions & 2 deletions sdks/typescript/pmxt/ws-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ export class SidecarWsClient {
message.credentials = credentials;
}

this.ws!.send(JSON.stringify(message));
if (!this.ws) {
throw new PmxtError('[ws-client] Cannot send: WebSocket not connected');
}
this.ws.send(JSON.stringify(message));

return this.waitForData(requestId, timeoutMs);
}
Expand Down Expand Up @@ -278,7 +281,10 @@ export class SidecarWsClient {
message.credentials = credentials;
}

this.ws!.send(JSON.stringify(message));
if (!this.ws) {
throw new PmxtError('[ws-client] Cannot send: WebSocket not connected');
}
this.ws.send(JSON.stringify(message));

// Wait for first data event
await this.waitForData(requestId, timeoutMs);
Expand Down
Loading