Skip to content

Commit 940eaf1

Browse files
committed
fix: document watchOrderBook limit params
1 parent aed173f commit 940eaf1

21 files changed

Lines changed: 138 additions & 22 deletions

File tree

core/api-doc-config.generated.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,12 @@
537537
"type": "number",
538538
"optional": true,
539539
"description": "Optional limit for orderbook depth"
540+
},
541+
{
542+
"name": "params",
543+
"type": "Record<string, any>",
544+
"optional": true,
545+
"description": "Optional exchange-specific parameters"
540546
}
541547
],
542548
"returns": {
@@ -560,6 +566,12 @@
560566
"type": "number",
561567
"optional": true,
562568
"description": "Optional limit for orderbook depth"
569+
},
570+
{
571+
"name": "params",
572+
"type": "Record<string, any>",
573+
"optional": true,
574+
"description": "Optional exchange-specific parameters"
563575
}
564576
],
565577
"returns": {
@@ -953,4 +965,4 @@
953965
"python": "import pmxt\nimport os\n\nexchange = pmxt.Polymarket(\n private_key=os.getenv('POLYMARKET_PRIVATE_KEY')\n)\n\n# 1. Check balance\nbalances = exchange.fetch_balance()\nif balances:\n balance = balances[0]\n print(f'Available: ${balance.available}')\n\n# 2. Search for a market\nmarkets = exchange.fetch_markets(query='Trump')\nmarket = markets[0]\noutcome = market.yes\n\nprint(f'{market.title}')\nprint(f'Price: {outcome.price * 100:.1f}%')\n\n# 3. Place a limit order\norder = exchange.create_order(\n market_id=market.market_id,\n outcome_id=outcome.outcome_id,\n side='buy',\n type='limit',\n amount=10,\n price=0.50\n)\n\nprint(f'Order placed: {order.id}')\n\n# 4. Check order status\nupdated_order = exchange.fetch_order(order.id)\nprint(f'Status: {updated_order.status}')\nprint(f'Filled: {updated_order.filled}/{updated_order.amount}')\n\n# 5. Cancel if needed\nif updated_order.status == 'open':\n exchange.cancel_order(order.id)\n print('Order cancelled')\n\n# 6. Check positions\npositions = exchange.fetch_positions()\nfor pos in positions:\n pnl_sign = '+' if pos.unrealized_pnl > 0 else ''\n print(f'{pos.outcome_label}: {pnl_sign}${pos.unrealized_pnl:.2f}')",
954966
"typescript": "import pmxt from 'pmxtjs';\n\nconst exchange = new pmxt.Polymarket({\n privateKey: process.env.POLYMARKET_PRIVATE_KEY\n});\n\n// 1. Check balance\nconst [balance] = await exchange.fetchBalance();\nconsole.log(`Available: $${balance.available}`);\n\n// 2. Search for a market\nconst markets = await exchange.fetchMarkets({ query: 'Trump' });\nconst market = markets[0];\nconst outcome = market.yes;\n\nconsole.log(market.title);\nconsole.log(`Price: ${(outcome.price * 100).toFixed(1)}%`);\n\n// 3. Place a limit order\nconst order = await exchange.createOrder({\n marketId: market.marketId,\n outcomeId: outcome.outcomeId,\n side: 'buy',\n type: 'limit',\n amount: 10,\n price: 0.50\n});\n\nconsole.log(`Order placed: ${order.id}`);\n\n// 4. Check order status\nconst updatedOrder = await exchange.fetchOrder(order.id);\nconsole.log(`Status: ${updatedOrder.status}`);\nconsole.log(`Filled: ${updatedOrder.filled}/${updatedOrder.amount}`);\n\n// 5. Cancel if needed\nif (updatedOrder.status === 'open') {\n await exchange.cancelOrder(order.id);\n console.log('Order cancelled');\n}\n\n// 6. Check positions\nconst positions = await exchange.fetchPositions();\npositions.forEach(pos => {\n console.log(`${pos.outcomeLabel}: ${pos.unrealizedPnL > 0 ? '+' : ''}$${pos.unrealizedPnL.toFixed(2)}`);\n});"
955967
}
956-
}
968+
}

core/src/BaseExchange.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,9 +1248,10 @@ export abstract class PredictionMarketExchange {
12481248
*
12491249
* @param outcomeId - The Outcome ID to watch
12501250
* @param limit - Optional limit for orderbook depth
1251+
* @param params - Optional exchange-specific parameters
12511252
* @returns Promise that resolves with the current orderbook state
12521253
*/
1253-
async watchOrderBook(outcomeId: string, limit?: number): Promise<OrderBook> {
1254+
async watchOrderBook(outcomeId: string, limit?: number, params: Record<string, any> = {}): Promise<OrderBook> {
12541255
throw new Error(`watchOrderBook() is not supported by ${this.name}`);
12551256
}
12561257

@@ -1262,15 +1263,16 @@ export abstract class PredictionMarketExchange {
12621263
*
12631264
* @param outcomeIds - Array of Outcome IDs to watch
12641265
* @param limit - Optional limit for orderbook depth
1266+
* @param params - Optional exchange-specific parameters
12651267
* @returns Promise that resolves with order books keyed by ID
12661268
*/
1267-
async watchOrderBooks(outcomeIds: string[], limit?: number): Promise<Record<string, OrderBook>> {
1269+
async watchOrderBooks(outcomeIds: string[], limit?: number, params: Record<string, any> = {}): Promise<Record<string, OrderBook>> {
12681270
// Default implementation: subscribe to each ID individually.
12691271
// Exchanges with native batch support (e.g. Kalshi) override this
12701272
// to send a single subscribe message for all tickers.
12711273
const entries = await Promise.all(
12721274
outcomeIds.map(async (oid): Promise<[string, OrderBook]> => {
1273-
const book = await this.watchOrderBook(oid, limit);
1275+
const book = await this.watchOrderBook(oid, limit, params);
12741276
return [oid, book];
12751277
}),
12761278
);

core/src/exchanges/baozi/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ export class BaoziExchange extends PredictionMarketExchange {
405405
// WebSocket
406406
// -----------------------------------------------------------------------
407407

408-
async watchOrderBook(outcomeId: string): Promise<OrderBook> {
408+
async watchOrderBook(outcomeId: string, _limit?: number, _params: Record<string, any> = {}): Promise<OrderBook> {
409409
if (!this.ws) {
410410
this.ws = new BaoziWebSocket();
411411
}

core/src/exchanges/gemini-titan/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class GeminiTitanExchange extends PredictionMarketExchange {
224224
return this.geminiWs;
225225
}
226226

227-
async watchOrderBook(outcomeId: string): Promise<OrderBook> {
227+
async watchOrderBook(outcomeId: string, _limit?: number, _params: Record<string, any> = {}): Promise<OrderBook> {
228228
const { instrumentSymbol } = fromOutcomeId(outcomeId);
229229
return this.ensureWebSocket().watchOrderBook(instrumentSymbol);
230230
}

core/src/exchanges/kalshi/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export class KalshiExchange extends PredictionMarketExchange {
341341

342342
private ws?: KalshiWebSocket;
343343

344-
async watchOrderBook(outcomeId: string, limit?: number): Promise<OrderBook> {
344+
async watchOrderBook(outcomeId: string, limit?: number, _params: Record<string, any> = {}): Promise<OrderBook> {
345345
const auth = this.ensureAuth();
346346
if (!this.ws) {
347347
const wsConfigWithUrl: KalshiWebSocketConfig = {
@@ -354,7 +354,7 @@ export class KalshiExchange extends PredictionMarketExchange {
354354
return this.ws.watchOrderBook(marketTicker);
355355
}
356356

357-
async watchOrderBooks(outcomeIds: string[], limit?: number): Promise<Record<string, OrderBook>> {
357+
async watchOrderBooks(outcomeIds: string[], limit?: number, _params: Record<string, any> = {}): Promise<Record<string, OrderBook>> {
358358
const auth = this.ensureAuth();
359359
if (!this.ws) {
360360
const wsConfigWithUrl: KalshiWebSocketConfig = {

core/src/exchanges/limitless/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ export class LimitlessExchange extends PredictionMarketExchange {
450450
// WebSocket
451451
// ------------------------------------------------------------------------
452452

453-
async watchOrderBook(outcomeId: string, limit?: number): Promise<OrderBook> {
453+
async watchOrderBook(outcomeId: string, limit?: number, _params: Record<string, any> = {}): Promise<OrderBook> {
454454
const slug = await this.resolveSlug(outcomeId);
455455
const ws = this.ensureWs();
456456
return ws.watchOrderBook(slug);

core/src/exchanges/myriad/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export class MyriadExchange extends PredictionMarketExchange {
243243
// WebSocket (poll-based)
244244
// ------------------------------------------------------------------------
245245

246-
async watchOrderBook(outcomeId: string, _limit?: number): Promise<OrderBook> {
246+
async watchOrderBook(outcomeId: string, _limit?: number, _params: Record<string, any> = {}): Promise<OrderBook> {
247247
this.ensureAuth();
248248
if (!this.ws) {
249249
this.ws = new MyriadWebSocket(

core/src/exchanges/opinion/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ export class OpinionExchange extends PredictionMarketExchange {
387387
// WebSocket
388388
// -------------------------------------------------------------------------
389389

390-
async watchOrderBook(outcomeId: string): Promise<OrderBook> {
390+
async watchOrderBook(outcomeId: string, _limit?: number, _params: Record<string, any> = {}): Promise<OrderBook> {
391391
const ws = this.ensureWebSocket();
392392
const marketId = this.resolveMarketId(outcomeId);
393393
return ws.watchOrderBook(marketId);

core/src/exchanges/polymarket/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ export class PolymarketExchange extends PredictionMarketExchange {
517517
// ----------------------------------------------------------------------------
518518

519519

520-
async watchOrderBook(outcomeId: string, limit?: number): Promise<OrderBook> {
520+
async watchOrderBook(outcomeId: string, limit?: number, _params: Record<string, any> = {}): Promise<OrderBook> {
521521
return this.ensureWs().watchOrderBook(outcomeId);
522522
}
523523

core/src/exchanges/polymarket_us/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export class PolymarketUSExchange extends PredictionMarketExchange {
381381
return this.wsWrapper;
382382
}
383383

384-
override async watchOrderBook(outcomeId: string, _limit?: number): Promise<OrderBook> {
384+
override async watchOrderBook(outcomeId: string, _limit?: number, _params: Record<string, any> = {}): Promise<OrderBook> {
385385
return this.run(() => this.ensureWs().watchOrderBook(outcomeId));
386386
}
387387

0 commit comments

Comments
 (0)