diff --git a/sdks/typescript/pmxt/client.ts b/sdks/typescript/pmxt/client.ts index 057cf1e3..e99cdcb0 100644 --- a/sdks/typescript/pmxt/client.ts +++ b/sdks/typescript/pmxt/client.ts @@ -46,7 +46,18 @@ import { UnifiedSeries, UserTrade, FirehoseEvent, + MatchRelation, FetchMatchedMarketClustersParams, + FetchMarketMatchesParams, + FetchEventMatchesParams, + CompareMarketPricesParams, + FetchMatchedPricesParams, + FetchArbitrageParams, + MatchResult, + EventMatchResult, + PriceComparison, + ArbitrageOpportunity, + } from "./models.js"; import { ServerManager } from "./server-manager.js"; @@ -1198,6 +1209,7 @@ export abstract class Exchange { } } + async fetchOrderBooks(outcomeIds: (string | MarketOutcome)[]): Promise> { await this.initPromise; try { @@ -1259,9 +1271,6 @@ export abstract class Exchange { async cancelOrder(orderId: string): Promise { await this.initPromise; - if (this.isHosted) { - return this._hostedCancelOrder(orderId); - } try { const args: any[] = []; args.push(orderId); @@ -1286,16 +1295,14 @@ export abstract class Exchange { } } + async fetchOrder(orderId: string): Promise { await this.initPromise; if (this.isHosted) { const route = HOSTED_METHOD_ROUTES.get("fetchOrder")!; const path = formatRoutePath(route, { order_id: orderId }); const data = await _tradingRequest(this, { method: route.method, path }); - const payload = data && typeof data === "object" && "order" in data - ? (data as { order: unknown }).order - : data; - return orderFromV0(payload as Record); + return orderFromV0(data as Record); } try { const args: any[] = []; @@ -1321,20 +1328,9 @@ export abstract class Exchange { } } + async fetchOpenOrders(marketId?: string): Promise { await this.initPromise; - if (this.isHosted) { - const resolvedAddress = resolveWalletAddress(this, undefined); - const route = HOSTED_METHOD_ROUTES.get("fetchOpenOrders")!; - const path = formatRoutePath(route, {}); - const params: Record = { address: resolvedAddress }; - if (marketId !== undefined) params.market_id = marketId; - const data = await _tradingRequest(this, { method: route.method, path, params }); - const list = Array.isArray(data) - ? data - : (data && Array.isArray((data as any).orders) ? (data as any).orders : []); - return list.map((o: unknown) => orderFromV0(o as Record)); - } try { const args: any[] = []; if (marketId !== undefined) args.push(marketId); @@ -1359,16 +1355,9 @@ export abstract class Exchange { } } + async fetchMyTrades(params?: MyTradesParams): Promise { await this.initPromise; - if (this.isHosted) { - const resolvedAddress = resolveWalletAddress(this, undefined); - const route = HOSTED_METHOD_ROUTES.get("fetchMyTrades")!; - const path = formatRoutePath(route, { address: resolvedAddress }); - const data = await _tradingRequest(this, { method: route.method, path }); - const list = Array.isArray(data) ? data : (data && Array.isArray((data as any).trades) ? (data as any).trades : []); - return list.map((t: unknown) => userTradeFromV0(t as Record)); - } try { const args: any[] = []; if (params !== undefined) args.push(params); @@ -1393,6 +1382,7 @@ export abstract class Exchange { } } + async fetchClosedOrders(params?: OrderHistoryParams): Promise { await this.initPromise; if (this.isHosted) { @@ -1422,6 +1412,7 @@ export abstract class Exchange { } } + async fetchAllOrders(params?: OrderHistoryParams): Promise { await this.initPromise; if (this.isHosted) { @@ -1451,6 +1442,7 @@ export abstract class Exchange { } } + async fetchPositions(address?: string): Promise { await this.initPromise; if (this.isHosted) { @@ -1458,9 +1450,7 @@ export abstract class Exchange { const route = HOSTED_METHOD_ROUTES.get("fetchPositions")!; const path = formatRoutePath(route, { address: resolvedAddress }); const data = await _tradingRequest(this, { method: route.method, path }); - const list: unknown[] = Array.isArray(data) - ? data - : (data && Array.isArray((data as any).positions) ? (data as any).positions : []); + const list = Array.isArray(data) ? data : []; return list.map((p) => positionFromV0(p as Record)); } try { @@ -1487,6 +1477,7 @@ export abstract class Exchange { } } + async fetchBalance(address?: string): Promise { await this.initPromise; if (this.isHosted) { @@ -1494,9 +1485,7 @@ export abstract class Exchange { const route = HOSTED_METHOD_ROUTES.get("fetchBalance")!; const path = formatRoutePath(route, { address: resolvedAddress }); const data = await _tradingRequest(this, { method: route.method, path }); - const list: unknown[] = Array.isArray(data) - ? data - : (data && Array.isArray((data as any).balances) ? (data as any).balances : []); + const list = Array.isArray(data) ? data : []; return list.map((b) => balanceFromV0(b as Record)); } try { @@ -1523,6 +1512,7 @@ export abstract class Exchange { } } + async unwatchOrderBook(outcomeId: string | MarketOutcome): Promise { await this.initPromise; try { @@ -1597,7 +1587,7 @@ export abstract class Exchange { } } - async fetchMarketMatches(params?: any): Promise { + async fetchMarketMatches(params?: FetchMarketMatchesParams): Promise { await this.initPromise; try { const args: any[] = []; @@ -1622,7 +1612,7 @@ export abstract class Exchange { } } - async fetchMatches(params: any): Promise { + async fetchMatches(params: any): Promise { await this.initPromise; try { const args: any[] = []; @@ -1647,7 +1637,7 @@ export abstract class Exchange { } } - async fetchEventMatches(params?: any): Promise { + async fetchEventMatches(params?: FetchEventMatchesParams): Promise { await this.initPromise; try { const args: any[] = []; @@ -1672,7 +1662,7 @@ export abstract class Exchange { } } - async compareMarketPrices(params: any): Promise { + async compareMarketPrices(params: any): Promise { await this.initPromise; try { const args: any[] = []; @@ -1697,7 +1687,7 @@ export abstract class Exchange { } } - async fetchRelatedMarkets(params: any): Promise { + async fetchRelatedMarkets(params: any): Promise { await this.initPromise; try { const args: any[] = []; @@ -1722,7 +1712,7 @@ export abstract class Exchange { } } - async fetchMatchedMarkets(params?: FetchMatchedMarketClustersParams): Promise { + async fetchMatchedMarkets(params?: any): Promise { await this.initPromise; try { const args: any[] = []; @@ -1747,7 +1737,8 @@ export abstract class Exchange { } } - async fetchMatchedPrices(params?: any): Promise { + + async fetchMatchedPrices(params?: FetchMatchedPricesParams): Promise { await this.initPromise; try { const args: any[] = []; @@ -1772,7 +1763,7 @@ export abstract class Exchange { } } - async fetchHedges(params: any): Promise { + async fetchHedges(params: any): Promise { await this.initPromise; try { const args: any[] = []; @@ -1797,7 +1788,7 @@ export abstract class Exchange { } } - async fetchArbitrage(params?: any): Promise { + async fetchArbitrage(params?: FetchArbitrageParams): Promise { await this.initPromise; try { const args: any[] = []; diff --git a/sdks/typescript/pmxt/models.ts b/sdks/typescript/pmxt/models.ts index fc5ca349..0f88d0c8 100644 --- a/sdks/typescript/pmxt/models.ts +++ b/sdks/typescript/pmxt/models.ts @@ -1,3 +1,75 @@ + + + +// ===== Router Method Parameter Types ===== + +/** + * Parameters for fetchMarketMatches + */ +export interface FetchMarketMatchesParams { + query?: string; + category?: string; + market?: UnifiedMarket; + marketId?: string; + slug?: string; + url?: string; + relation?: MatchRelation; + minConfidence?: number; + limit?: number; + includePrices?: boolean; + minDifference?: number; + sort?: string; +} + +/** + * Parameters for fetchEventMatches + */ +export interface FetchEventMatchesParams { + query?: string; + category?: string; + event?: UnifiedEvent; + eventId?: string; + slug?: string; + relation?: MatchRelation; + minConfidence?: number; + limit?: number; + includePrices?: boolean; +} + +/** + * Parameters for compareMarketPrices + */ +export interface CompareMarketPricesParams { + marketId: string; + targetMarketIds?: string[]; + minDifference?: number; + limit?: number; +} + +/** + * Parameters for fetchMatchedPrices + */ +export interface FetchMatchedPricesParams { + marketId?: string; + slug?: string; + category?: string; + limit?: number; + minDifference?: number; + sort?: string; +} + +/** + * Parameters for fetchArbitrage + */ +export interface FetchArbitrageParams { + minSpread?: number; + category?: string; + limit?: number; + relations?: MatchRelation | MatchRelation[]; +} + + + /** * Data models for PMXT TypeScript SDK. * diff --git a/sdks/typescript/scripts/generate-client-methods.js b/sdks/typescript/scripts/generate-client-methods.js index d32faf2b..eca15836 100644 --- a/sdks/typescript/scripts/generate-client-methods.js +++ b/sdks/typescript/scripts/generate-client-methods.js @@ -88,6 +88,17 @@ const TYPE_MAP = { // Pagination wrapper — gets its own response handler PaginatedMarketsResult: { converter: null, pattern: 'paginatedMarkets' }, PaginatedEventsResult: { converter: null, pattern: 'paginatedEvents' }, + + FetchMarketMatchesParams: { converter: null, pattern: 'raw' }, + FetchEventMatchesParams: { converter: null, pattern: 'raw' }, + CompareMarketPricesParams: { converter: null, pattern: 'raw' }, + FetchMatchedPricesParams: { converter: null, pattern: 'raw' }, + FetchArbitrageParams: { converter: null, pattern: 'raw' }, + // Router return types + MatchResult: { converter: null, pattern: 'raw' }, + EventMatchResult: { converter: null, pattern: 'raw' }, + PriceComparison: { converter: null, pattern: 'raw' }, + ArbitrageOpportunity: { converter: null, pattern: 'raw' }, }; // SDK types that can appear in generated signatures without extra imports @@ -101,6 +112,16 @@ const SDK_PARAM_TYPES = new Set([ 'MyTradesParams', 'OrderHistoryParams', 'CreateOrderParams', 'MarketFilterCriteria', 'EventFilterCriteria', 'SubscriptionOption', + + 'FetchMarketMatchesParams', + 'FetchEventMatchesParams', + 'CompareMarketPricesParams', + 'FetchMatchedPricesParams', + 'FetchArbitrageParams', + 'MatchResult', + 'EventMatchResult', + 'PriceComparison', + 'ArbitrageOpportunity', ]); // Parameter names that represent outcome IDs and should accept MarketOutcome.