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
31 changes: 26 additions & 5 deletions sdks/typescript/pmxt/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function queryHasNestedObject(query: Record<string, unknown>): 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 })),
Expand All @@ -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;
}


Expand Down Expand Up @@ -659,7 +665,7 @@ export abstract class Exchange {
}
}

async fetchMarketsPaginated(params?: any): Promise<PaginatedMarketsResult> {
async fetchMarketsPaginated(params?: MarketFetchParams): Promise<PaginatedMarketsResult> {
await this.initPromise;
try {
const args: any[] = [];
Expand Down Expand Up @@ -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<number> {
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;
}

/**
Expand Down Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions sdks/typescript/pmxt/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export interface MarketOutcome {

/** Exchange-specific metadata */
metadata?: Record<string, any>;

/** Best bid price from the order book (when includePrices=True) */
bestBid?: number;

/** Best ask price from the order book (when includePrices=True) */
bestAsk?: number;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down
Loading