From 12e903627dbaee5aecbcdc33e4f44f34a2892f5f Mon Sep 17 00:00:00 2001 From: "Samuel EF. Tinnerholm" Date: Sun, 24 May 2026 17:52:50 +0300 Subject: [PATCH] fix: type safety and SDK parity fixes in TypeScript client Fixes #453 Fixes #454 Fixes #462 Fixes #470 Fixes #502 Fixes #503 --- sdks/typescript/pmxt/client.ts | 31 ++++++++++++++++++++++++++----- sdks/typescript/pmxt/models.ts | 9 +++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/sdks/typescript/pmxt/client.ts b/sdks/typescript/pmxt/client.ts index 0e051ae8..9979d3f8 100644 --- a/sdks/typescript/pmxt/client.ts +++ b/sdks/typescript/pmxt/client.ts @@ -104,7 +104,7 @@ function queryHasNestedObject(query: Record): boolean { // Converter functions function convertMarket(raw: any): UnifiedMarket { - return { + const market: UnifiedMarket = { ...raw, resolutionDate: raw.resolutionDate ? new Date(raw.resolutionDate) : undefined, outcomes: (raw.outcomes || []).map((o: any) => ({ ...o })), @@ -113,6 +113,12 @@ function convertMarket(raw: any): UnifiedMarket { up: raw.up ? { ...raw.up } : undefined, down: raw.down ? { ...raw.down } : undefined, }; + Object.defineProperty(market, 'question', { + get() { return this.title; }, + enumerable: false, + configurable: true, + }); + return market; } @@ -659,7 +665,7 @@ export abstract class Exchange { } } - async fetchMarketsPaginated(params?: any): Promise { + async fetchMarketsPaginated(params?: MarketFetchParams): Promise { await this.initPromise; try { const args: any[] = []; @@ -2043,9 +2049,18 @@ export abstract class Exchange { * @param amount - The amount to execute * @returns The volume-weighted average price, or 0 if insufficient liquidity */ - async getExecutionPrice(orderBook: OrderBook, side: 'buy' | 'sell', amount: number): Promise { - const result = await this.getExecutionPriceDetailed(orderBook, side, amount); - return result.fullyFilled ? result.price : 0; + getExecutionPrice(orderBook: OrderBook, side: 'buy' | 'sell', amount: number): number { + const levels = side === 'buy' ? orderBook.asks : orderBook.bids; + let remaining = amount; + let totalCost = 0; + for (const level of levels) { + const fill = Math.min(remaining, level.size); + totalCost += fill * level.price; + remaining -= fill; + if (remaining <= 0) break; + } + if (remaining > 0) return 0; + return totalCost / amount; } /** @@ -2400,9 +2415,15 @@ export abstract class Exchange { * Options for initializing Polymarket client. */ export interface PolymarketOptions { + /** Venue-specific API key (e.g. Polymarket CLOB key). Optional. */ + apiKey?: string; + /** Private key for authentication (optional) */ privateKey?: string; + /** Hosted pmxt API key. Enables hosted mode when set. */ + pmxtApiKey?: string; + /** Base URL of the PMXT sidecar server */ baseUrl?: string; diff --git a/sdks/typescript/pmxt/models.ts b/sdks/typescript/pmxt/models.ts index 22309083..8d7bbaee 100644 --- a/sdks/typescript/pmxt/models.ts +++ b/sdks/typescript/pmxt/models.ts @@ -29,6 +29,12 @@ export interface MarketOutcome { /** Exchange-specific metadata */ metadata?: Record; + + /** Best bid price from the order book (when includePrices=True) */ + bestBid?: number; + + /** Best ask price from the order book (when includePrices=True) */ + bestAsk?: number; } /** @@ -103,6 +109,9 @@ export interface UnifiedMarket { /** Convenience access to the Down outcome for binary markets. */ down?: MarketOutcome; + + /** Alias for `title`. Matches the Python SDK's `market.question` property. */ + readonly question?: string; } /**