Skip to content
Open
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
95 changes: 23 additions & 72 deletions sdks/typescript/pmxt/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -1030,36 +1041,6 @@ export abstract class Exchange {
}
}

async fetchEventsPaginated(params?: any): Promise<PaginatedEventsResult> {
await this.initPromise;
try {
const args: any[] = [];
if (params !== undefined) args.push(params);
const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchEventsPaginated`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
body: JSON.stringify({ args, credentials: this.getCredentials() }),
});
if (!response.ok) {
const body = await response.json().catch(() => ({}));
if (body.error && typeof body.error === "object") {
throw fromServerError(body.error);
}
throw new PmxtError(body.error?.message || response.statusText);
}
const json = await response.json();
const data = this.handleResponse(json);
return {
data: (data.data || []).map(convertEvent),
total: data.total,
nextCursor: data.nextCursor,
};
} catch (error) {
if (error instanceof PmxtError) throw error;
throw new PmxtError(`Failed to fetchEventsPaginated: ${error}`);
}
}

async fetchEvents(params?: EventFetchParams): Promise<UnifiedEvent[]> {
await this.initPromise;
try {
Expand Down Expand Up @@ -1259,9 +1240,6 @@ export abstract class Exchange {

async cancelOrder(orderId: string): Promise<Order> {
await this.initPromise;
if (this.isHosted) {
return this._hostedCancelOrder(orderId);
}
try {
const args: any[] = [];
args.push(orderId);
Expand Down Expand Up @@ -1292,10 +1270,7 @@ export abstract class Exchange {
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<string, unknown>);
return orderFromV0(data as Record<string, unknown>);
}
try {
const args: any[] = [];
Expand Down Expand Up @@ -1323,18 +1298,6 @@ export abstract class Exchange {

async fetchOpenOrders(marketId?: string): Promise<Order[]> {
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<string, string> = { 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<string, unknown>));
}
try {
const args: any[] = [];
if (marketId !== undefined) args.push(marketId);
Expand All @@ -1361,14 +1324,6 @@ export abstract class Exchange {

async fetchMyTrades(params?: MyTradesParams): Promise<UserTrade[]> {
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<string, unknown>));
}
try {
const args: any[] = [];
if (params !== undefined) args.push(params);
Expand Down Expand Up @@ -1458,9 +1413,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<string, unknown>));
}
try {
Expand Down Expand Up @@ -1494,9 +1447,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<string, unknown>));
}
try {
Expand Down Expand Up @@ -1597,7 +1548,7 @@ export abstract class Exchange {
}
}

async fetchMarketMatches(params?: any): Promise<any[]> {
async fetchMarketMatches(params?: FetchMarketMatchesParams): Promise<MatchResult[]> {
await this.initPromise;
try {
const args: any[] = [];
Expand All @@ -1622,7 +1573,7 @@ export abstract class Exchange {
}
}

async fetchMatches(params: any): Promise<any[]> {
async fetchMatches(params: any): Promise<MatchResult[]> {
await this.initPromise;
try {
const args: any[] = [];
Expand All @@ -1647,7 +1598,7 @@ export abstract class Exchange {
}
}

async fetchEventMatches(params?: any): Promise<any[]> {
async fetchEventMatches(params?: FetchEventMatchesParams): Promise<EventMatchResult[]> {
await this.initPromise;
try {
const args: any[] = [];
Expand All @@ -1672,7 +1623,7 @@ export abstract class Exchange {
}
}

async compareMarketPrices(params: any): Promise<any[]> {
async compareMarketPrices(params: any): Promise<PriceComparison[]> {
await this.initPromise;
try {
const args: any[] = [];
Expand All @@ -1697,7 +1648,7 @@ export abstract class Exchange {
}
}

async fetchRelatedMarkets(params: any): Promise<any[]> {
async fetchRelatedMarkets(params: any): Promise<PriceComparison[]> {
await this.initPromise;
try {
const args: any[] = [];
Expand All @@ -1722,7 +1673,7 @@ export abstract class Exchange {
}
}

async fetchMatchedMarkets(params?: FetchMatchedMarketClustersParams): Promise<any[]> {
async fetchMatchedMarkets(params?: any): Promise<any[]> {
await this.initPromise;
try {
const args: any[] = [];
Expand All @@ -1747,7 +1698,7 @@ export abstract class Exchange {
}
}

async fetchMatchedPrices(params?: any): Promise<any[]> {
async fetchMatchedPrices(params?: FetchMatchedPricesParams): Promise<any[]> {
await this.initPromise;
try {
const args: any[] = [];
Expand All @@ -1772,7 +1723,7 @@ export abstract class Exchange {
}
}

async fetchHedges(params: any): Promise<any[]> {
async fetchHedges(params: any): Promise<PriceComparison[]> {
await this.initPromise;
try {
const args: any[] = [];
Expand All @@ -1797,7 +1748,7 @@ export abstract class Exchange {
}
}

async fetchArbitrage(params?: any): Promise<any[]> {
async fetchArbitrage(params?: FetchArbitrageParams): Promise<ArbitrageOpportunity[]> {
await this.initPromise;
try {
const args: any[] = [];
Expand Down
72 changes: 72 additions & 0 deletions sdks/typescript/pmxt/models.ts
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down
20 changes: 20 additions & 0 deletions sdks/typescript/scripts/generate-client-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ const TYPE_MAP = {
// Pagination wrapper — gets its own response handler
PaginatedMarketsResult: { converter: null, pattern: 'paginatedMarkets' },
PaginatedEventsResult: { converter: null, pattern: 'paginatedEvents' },

'FetchMarketMatchesParams': 'FetchMarketMatchesParams',
'FetchEventMatchesParams': 'FetchEventMatchesParams',
'CompareMarketPricesParams': 'CompareMarketPricesParams',
'FetchMatchedPricesParams': 'FetchMatchedPricesParams',
'FetchArbitrageParams': 'FetchArbitrageParams',
'MatchResult': 'MatchResult',
'EventMatchResult': 'EventMatchResult',
'PriceComparison': 'PriceComparison',
'ArbitrageOpportunity': 'ArbitrageOpportunity',
};

// SDK types that can appear in generated signatures without extra imports
Expand All @@ -101,6 +111,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.
Expand Down
Loading