pmxtjs 2.14.1 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.d.ts +6 -2
- package/dist/esm/index.js +6 -2
- package/dist/esm/pmxt/client.d.ts +98 -88
- package/dist/esm/pmxt/client.js +423 -233
- package/dist/esm/pmxt/models.d.ts +32 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +9 -1
- package/dist/pmxt/client.d.ts +98 -88
- package/dist/pmxt/client.js +428 -234
- package/dist/pmxt/models.d.ts +32 -0
- package/generated/package.json +1 -1
- package/index.ts +6 -2
- package/package.json +4 -3
- package/pmxt/client.ts +417 -262
- package/pmxt/models.ts +43 -0
package/dist/pmxt/client.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* OpenAPI client, matching the Python API exactly.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.Limitless = exports.Kalshi = exports.Polymarket = exports.Exchange = void 0;
|
|
9
|
+
exports.Baozi = exports.Probable = exports.Myriad = exports.KalshiDemo = exports.Limitless = exports.Kalshi = exports.Polymarket = exports.Exchange = void 0;
|
|
10
10
|
const index_js_1 = require("../generated/src/index.js");
|
|
11
11
|
const models_js_1 = require("./models.js");
|
|
12
12
|
const server_manager_js_1 = require("./server-manager.js");
|
|
@@ -118,6 +118,18 @@ function convertBalance(raw) {
|
|
|
118
118
|
locked: raw.locked,
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
+
function convertUserTrade(raw) {
|
|
122
|
+
return {
|
|
123
|
+
id: raw.id,
|
|
124
|
+
price: raw.price,
|
|
125
|
+
amount: raw.amount,
|
|
126
|
+
side: raw.side || "unknown",
|
|
127
|
+
timestamp: raw.timestamp,
|
|
128
|
+
orderId: raw.orderId,
|
|
129
|
+
outcomeId: raw.outcomeId,
|
|
130
|
+
marketId: raw.marketId,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
121
133
|
function convertEvent(raw) {
|
|
122
134
|
const markets = models_js_1.MarketList.from((raw.markets || []).map(convertMarket));
|
|
123
135
|
return {
|
|
@@ -252,74 +264,116 @@ class Exchange {
|
|
|
252
264
|
throw new Error(`Failed to call API '${operationId}': ${error}`);
|
|
253
265
|
}
|
|
254
266
|
}
|
|
255
|
-
//
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
+
// BEGIN GENERATED METHODS
|
|
268
|
+
async loadMarkets(reload = false) {
|
|
269
|
+
await this.initPromise;
|
|
270
|
+
try {
|
|
271
|
+
const args = [];
|
|
272
|
+
args.push(reload);
|
|
273
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/loadMarkets`, {
|
|
274
|
+
method: 'POST',
|
|
275
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
276
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
277
|
+
});
|
|
278
|
+
if (!response.ok) {
|
|
279
|
+
const error = await response.json().catch(() => ({}));
|
|
280
|
+
throw new Error(error.error?.message || response.statusText);
|
|
281
|
+
}
|
|
282
|
+
const json = await response.json();
|
|
283
|
+
const data = this.handleResponse(json);
|
|
284
|
+
const result = {};
|
|
285
|
+
for (const [key, value] of Object.entries(data)) {
|
|
286
|
+
result[key] = convertMarket(value);
|
|
287
|
+
}
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
throw new Error(`Failed to loadMarkets: ${error}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
267
294
|
async fetchMarkets(params) {
|
|
268
295
|
await this.initPromise;
|
|
269
296
|
try {
|
|
270
297
|
const args = [];
|
|
271
|
-
if (params)
|
|
298
|
+
if (params !== undefined)
|
|
272
299
|
args.push(params);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
credentials: this.getCredentials()
|
|
277
|
-
};
|
|
278
|
-
const response = await this.api.fetchMarkets({
|
|
279
|
-
exchange: this.exchangeName,
|
|
280
|
-
fetchMarketsRequest: requestBody,
|
|
300
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarkets`, {
|
|
301
|
+
method: 'POST',
|
|
302
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
303
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
281
304
|
});
|
|
282
|
-
|
|
305
|
+
if (!response.ok) {
|
|
306
|
+
const error = await response.json().catch(() => ({}));
|
|
307
|
+
throw new Error(error.error?.message || response.statusText);
|
|
308
|
+
}
|
|
309
|
+
const json = await response.json();
|
|
310
|
+
const data = this.handleResponse(json);
|
|
283
311
|
return data.map(convertMarket);
|
|
284
312
|
}
|
|
285
313
|
catch (error) {
|
|
286
|
-
throw new Error(`Failed to
|
|
314
|
+
throw new Error(`Failed to fetchMarkets: ${error}`);
|
|
287
315
|
}
|
|
288
316
|
}
|
|
289
|
-
|
|
290
|
-
* Fetch a single market by lookup parameters.
|
|
291
|
-
* Returns the first matching market or throws if not found.
|
|
292
|
-
*
|
|
293
|
-
* @param params - Lookup parameters (marketId, outcomeId, slug, eventId, query)
|
|
294
|
-
* @returns A single unified market
|
|
295
|
-
* @throws Error if no market matches
|
|
296
|
-
*
|
|
297
|
-
* @example
|
|
298
|
-
* ```typescript
|
|
299
|
-
* const market = await exchange.fetchMarket({ marketId: '663583' });
|
|
300
|
-
* const market = await exchange.fetchMarket({ outcomeId: '10991849...' });
|
|
301
|
-
* const market = await exchange.fetchMarket({ slug: 'will-trump-win' });
|
|
302
|
-
* ```
|
|
303
|
-
*/
|
|
304
|
-
async fetchMarket(params) {
|
|
317
|
+
async fetchMarketsPaginated(params) {
|
|
305
318
|
await this.initPromise;
|
|
306
319
|
try {
|
|
307
320
|
const args = [];
|
|
308
|
-
if (params)
|
|
321
|
+
if (params !== undefined)
|
|
309
322
|
args.push(params);
|
|
323
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarketsPaginated`, {
|
|
324
|
+
method: 'POST',
|
|
325
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
326
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
327
|
+
});
|
|
328
|
+
if (!response.ok) {
|
|
329
|
+
const error = await response.json().catch(() => ({}));
|
|
330
|
+
throw new Error(error.error?.message || response.statusText);
|
|
310
331
|
}
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
332
|
+
const json = await response.json();
|
|
333
|
+
const data = this.handleResponse(json);
|
|
334
|
+
return {
|
|
335
|
+
data: (data.data || []).map(convertMarket),
|
|
336
|
+
total: data.total,
|
|
337
|
+
nextCursor: data.nextCursor,
|
|
314
338
|
};
|
|
315
|
-
|
|
316
|
-
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
throw new Error(`Failed to fetchMarketsPaginated: ${error}`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
async fetchEvents(params) {
|
|
345
|
+
await this.initPromise;
|
|
346
|
+
try {
|
|
347
|
+
const args = [];
|
|
348
|
+
if (params !== undefined)
|
|
349
|
+
args.push(params);
|
|
350
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvents`, {
|
|
317
351
|
method: 'POST',
|
|
318
|
-
headers: {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
352
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
353
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
354
|
+
});
|
|
355
|
+
if (!response.ok) {
|
|
356
|
+
const error = await response.json().catch(() => ({}));
|
|
357
|
+
throw new Error(error.error?.message || response.statusText);
|
|
358
|
+
}
|
|
359
|
+
const json = await response.json();
|
|
360
|
+
const data = this.handleResponse(json);
|
|
361
|
+
return data.map(convertEvent);
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
throw new Error(`Failed to fetchEvents: ${error}`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
async fetchMarket(params) {
|
|
368
|
+
await this.initPromise;
|
|
369
|
+
try {
|
|
370
|
+
const args = [];
|
|
371
|
+
if (params !== undefined)
|
|
372
|
+
args.push(params);
|
|
373
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarket`, {
|
|
374
|
+
method: 'POST',
|
|
375
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
376
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
323
377
|
});
|
|
324
378
|
if (!response.ok) {
|
|
325
379
|
const error = await response.json().catch(() => ({}));
|
|
@@ -330,42 +384,19 @@ class Exchange {
|
|
|
330
384
|
return convertMarket(data);
|
|
331
385
|
}
|
|
332
386
|
catch (error) {
|
|
333
|
-
throw new Error(`Failed to
|
|
387
|
+
throw new Error(`Failed to fetchMarket: ${error}`);
|
|
334
388
|
}
|
|
335
389
|
}
|
|
336
|
-
/**
|
|
337
|
-
* Fetch a single event by lookup parameters.
|
|
338
|
-
* Returns the first matching event or throws if not found.
|
|
339
|
-
*
|
|
340
|
-
* @param params - Lookup parameters (eventId, slug, query)
|
|
341
|
-
* @returns A single unified event
|
|
342
|
-
* @throws Error if no event matches
|
|
343
|
-
*
|
|
344
|
-
* @example
|
|
345
|
-
* ```typescript
|
|
346
|
-
* const event = await exchange.fetchEvent({ eventId: 'TRUMP25DEC' });
|
|
347
|
-
* const event = await exchange.fetchEvent({ slug: 'us-election' });
|
|
348
|
-
* ```
|
|
349
|
-
*/
|
|
350
390
|
async fetchEvent(params) {
|
|
351
391
|
await this.initPromise;
|
|
352
392
|
try {
|
|
353
393
|
const args = [];
|
|
354
|
-
if (params)
|
|
394
|
+
if (params !== undefined)
|
|
355
395
|
args.push(params);
|
|
356
|
-
}
|
|
357
|
-
const requestBody = {
|
|
358
|
-
args,
|
|
359
|
-
credentials: this.getCredentials()
|
|
360
|
-
};
|
|
361
|
-
const url = `${this.config.basePath}/api/${this.exchangeName}/fetchEvent`;
|
|
362
|
-
const response = await fetch(url, {
|
|
396
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvent`, {
|
|
363
397
|
method: 'POST',
|
|
364
|
-
headers: {
|
|
365
|
-
|
|
366
|
-
...this.config.headers
|
|
367
|
-
},
|
|
368
|
-
body: JSON.stringify(requestBody)
|
|
398
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
399
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
369
400
|
});
|
|
370
401
|
if (!response.ok) {
|
|
371
402
|
const error = await response.json().catch(() => ({}));
|
|
@@ -376,9 +407,230 @@ class Exchange {
|
|
|
376
407
|
return convertEvent(data);
|
|
377
408
|
}
|
|
378
409
|
catch (error) {
|
|
379
|
-
throw new Error(`Failed to
|
|
410
|
+
throw new Error(`Failed to fetchEvent: ${error}`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
async fetchOrderBook(id) {
|
|
414
|
+
await this.initPromise;
|
|
415
|
+
try {
|
|
416
|
+
const args = [];
|
|
417
|
+
args.push(id);
|
|
418
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrderBook`, {
|
|
419
|
+
method: 'POST',
|
|
420
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
421
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
422
|
+
});
|
|
423
|
+
if (!response.ok) {
|
|
424
|
+
const error = await response.json().catch(() => ({}));
|
|
425
|
+
throw new Error(error.error?.message || response.statusText);
|
|
426
|
+
}
|
|
427
|
+
const json = await response.json();
|
|
428
|
+
const data = this.handleResponse(json);
|
|
429
|
+
return convertOrderBook(data);
|
|
430
|
+
}
|
|
431
|
+
catch (error) {
|
|
432
|
+
throw new Error(`Failed to fetchOrderBook: ${error}`);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
async cancelOrder(orderId) {
|
|
436
|
+
await this.initPromise;
|
|
437
|
+
try {
|
|
438
|
+
const args = [];
|
|
439
|
+
args.push(orderId);
|
|
440
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/cancelOrder`, {
|
|
441
|
+
method: 'POST',
|
|
442
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
443
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
444
|
+
});
|
|
445
|
+
if (!response.ok) {
|
|
446
|
+
const error = await response.json().catch(() => ({}));
|
|
447
|
+
throw new Error(error.error?.message || response.statusText);
|
|
448
|
+
}
|
|
449
|
+
const json = await response.json();
|
|
450
|
+
const data = this.handleResponse(json);
|
|
451
|
+
return convertOrder(data);
|
|
452
|
+
}
|
|
453
|
+
catch (error) {
|
|
454
|
+
throw new Error(`Failed to cancelOrder: ${error}`);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
async fetchOrder(orderId) {
|
|
458
|
+
await this.initPromise;
|
|
459
|
+
try {
|
|
460
|
+
const args = [];
|
|
461
|
+
args.push(orderId);
|
|
462
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrder`, {
|
|
463
|
+
method: 'POST',
|
|
464
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
465
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
466
|
+
});
|
|
467
|
+
if (!response.ok) {
|
|
468
|
+
const error = await response.json().catch(() => ({}));
|
|
469
|
+
throw new Error(error.error?.message || response.statusText);
|
|
470
|
+
}
|
|
471
|
+
const json = await response.json();
|
|
472
|
+
const data = this.handleResponse(json);
|
|
473
|
+
return convertOrder(data);
|
|
474
|
+
}
|
|
475
|
+
catch (error) {
|
|
476
|
+
throw new Error(`Failed to fetchOrder: ${error}`);
|
|
380
477
|
}
|
|
381
478
|
}
|
|
479
|
+
async fetchOpenOrders(marketId) {
|
|
480
|
+
await this.initPromise;
|
|
481
|
+
try {
|
|
482
|
+
const args = [];
|
|
483
|
+
if (marketId !== undefined)
|
|
484
|
+
args.push(marketId);
|
|
485
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOpenOrders`, {
|
|
486
|
+
method: 'POST',
|
|
487
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
488
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
489
|
+
});
|
|
490
|
+
if (!response.ok) {
|
|
491
|
+
const error = await response.json().catch(() => ({}));
|
|
492
|
+
throw new Error(error.error?.message || response.statusText);
|
|
493
|
+
}
|
|
494
|
+
const json = await response.json();
|
|
495
|
+
const data = this.handleResponse(json);
|
|
496
|
+
return data.map(convertOrder);
|
|
497
|
+
}
|
|
498
|
+
catch (error) {
|
|
499
|
+
throw new Error(`Failed to fetchOpenOrders: ${error}`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
async fetchMyTrades(params) {
|
|
503
|
+
await this.initPromise;
|
|
504
|
+
try {
|
|
505
|
+
const args = [];
|
|
506
|
+
if (params !== undefined)
|
|
507
|
+
args.push(params);
|
|
508
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMyTrades`, {
|
|
509
|
+
method: 'POST',
|
|
510
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
511
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
512
|
+
});
|
|
513
|
+
if (!response.ok) {
|
|
514
|
+
const error = await response.json().catch(() => ({}));
|
|
515
|
+
throw new Error(error.error?.message || response.statusText);
|
|
516
|
+
}
|
|
517
|
+
const json = await response.json();
|
|
518
|
+
const data = this.handleResponse(json);
|
|
519
|
+
return data.map(convertUserTrade);
|
|
520
|
+
}
|
|
521
|
+
catch (error) {
|
|
522
|
+
throw new Error(`Failed to fetchMyTrades: ${error}`);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
async fetchClosedOrders(params) {
|
|
526
|
+
await this.initPromise;
|
|
527
|
+
try {
|
|
528
|
+
const args = [];
|
|
529
|
+
if (params !== undefined)
|
|
530
|
+
args.push(params);
|
|
531
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchClosedOrders`, {
|
|
532
|
+
method: 'POST',
|
|
533
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
534
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
535
|
+
});
|
|
536
|
+
if (!response.ok) {
|
|
537
|
+
const error = await response.json().catch(() => ({}));
|
|
538
|
+
throw new Error(error.error?.message || response.statusText);
|
|
539
|
+
}
|
|
540
|
+
const json = await response.json();
|
|
541
|
+
const data = this.handleResponse(json);
|
|
542
|
+
return data.map(convertOrder);
|
|
543
|
+
}
|
|
544
|
+
catch (error) {
|
|
545
|
+
throw new Error(`Failed to fetchClosedOrders: ${error}`);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
async fetchAllOrders(params) {
|
|
549
|
+
await this.initPromise;
|
|
550
|
+
try {
|
|
551
|
+
const args = [];
|
|
552
|
+
if (params !== undefined)
|
|
553
|
+
args.push(params);
|
|
554
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchAllOrders`, {
|
|
555
|
+
method: 'POST',
|
|
556
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
557
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
558
|
+
});
|
|
559
|
+
if (!response.ok) {
|
|
560
|
+
const error = await response.json().catch(() => ({}));
|
|
561
|
+
throw new Error(error.error?.message || response.statusText);
|
|
562
|
+
}
|
|
563
|
+
const json = await response.json();
|
|
564
|
+
const data = this.handleResponse(json);
|
|
565
|
+
return data.map(convertOrder);
|
|
566
|
+
}
|
|
567
|
+
catch (error) {
|
|
568
|
+
throw new Error(`Failed to fetchAllOrders: ${error}`);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
async fetchPositions() {
|
|
572
|
+
await this.initPromise;
|
|
573
|
+
try {
|
|
574
|
+
const args = [];
|
|
575
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchPositions`, {
|
|
576
|
+
method: 'POST',
|
|
577
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
578
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
579
|
+
});
|
|
580
|
+
if (!response.ok) {
|
|
581
|
+
const error = await response.json().catch(() => ({}));
|
|
582
|
+
throw new Error(error.error?.message || response.statusText);
|
|
583
|
+
}
|
|
584
|
+
const json = await response.json();
|
|
585
|
+
const data = this.handleResponse(json);
|
|
586
|
+
return data.map(convertPosition);
|
|
587
|
+
}
|
|
588
|
+
catch (error) {
|
|
589
|
+
throw new Error(`Failed to fetchPositions: ${error}`);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
async fetchBalance() {
|
|
593
|
+
await this.initPromise;
|
|
594
|
+
try {
|
|
595
|
+
const args = [];
|
|
596
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchBalance`, {
|
|
597
|
+
method: 'POST',
|
|
598
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
599
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
600
|
+
});
|
|
601
|
+
if (!response.ok) {
|
|
602
|
+
const error = await response.json().catch(() => ({}));
|
|
603
|
+
throw new Error(error.error?.message || response.statusText);
|
|
604
|
+
}
|
|
605
|
+
const json = await response.json();
|
|
606
|
+
const data = this.handleResponse(json);
|
|
607
|
+
return data.map(convertBalance);
|
|
608
|
+
}
|
|
609
|
+
catch (error) {
|
|
610
|
+
throw new Error(`Failed to fetchBalance: ${error}`);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
async close() {
|
|
614
|
+
await this.initPromise;
|
|
615
|
+
try {
|
|
616
|
+
const args = [];
|
|
617
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/close`, {
|
|
618
|
+
method: 'POST',
|
|
619
|
+
headers: { 'Content-Type': 'application/json', ...this.config.headers },
|
|
620
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
621
|
+
});
|
|
622
|
+
if (!response.ok) {
|
|
623
|
+
const error = await response.json().catch(() => ({}));
|
|
624
|
+
throw new Error(error.error?.message || response.statusText);
|
|
625
|
+
}
|
|
626
|
+
const json = await response.json();
|
|
627
|
+
this.handleResponse(json);
|
|
628
|
+
}
|
|
629
|
+
catch (error) {
|
|
630
|
+
throw new Error(`Failed to close: ${error}`);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
// END GENERATED METHODS
|
|
382
634
|
/**
|
|
383
635
|
* Get historical price candles.
|
|
384
636
|
*
|
|
@@ -424,37 +676,6 @@ class Exchange {
|
|
|
424
676
|
throw new Error(`Failed to fetch OHLCV: ${error}`);
|
|
425
677
|
}
|
|
426
678
|
}
|
|
427
|
-
/**
|
|
428
|
-
* Get current order book for an outcome.
|
|
429
|
-
*
|
|
430
|
-
* @param outcomeId - Outcome ID
|
|
431
|
-
* @returns Current order book
|
|
432
|
-
*
|
|
433
|
-
* @example
|
|
434
|
-
* ```typescript
|
|
435
|
-
* const orderBook = await exchange.fetchOrderBook(outcomeId);
|
|
436
|
-
* console.log(`Best bid: ${orderBook.bids[0].price}`);
|
|
437
|
-
* console.log(`Best ask: ${orderBook.asks[0].price}`);
|
|
438
|
-
* ```
|
|
439
|
-
*/
|
|
440
|
-
async fetchOrderBook(outcomeId) {
|
|
441
|
-
await this.initPromise;
|
|
442
|
-
try {
|
|
443
|
-
const requestBody = {
|
|
444
|
-
args: [outcomeId],
|
|
445
|
-
credentials: this.getCredentials()
|
|
446
|
-
};
|
|
447
|
-
const response = await this.api.fetchOrderBook({
|
|
448
|
-
exchange: this.exchangeName,
|
|
449
|
-
fetchOrderBookRequest: requestBody,
|
|
450
|
-
});
|
|
451
|
-
const data = this.handleResponse(response);
|
|
452
|
-
return convertOrderBook(data);
|
|
453
|
-
}
|
|
454
|
-
catch (error) {
|
|
455
|
-
throw new Error(`Failed to fetch order book: ${error}`);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
679
|
/**
|
|
459
680
|
* Get trade history for an outcome.
|
|
460
681
|
*
|
|
@@ -640,129 +861,6 @@ class Exchange {
|
|
|
640
861
|
throw new Error(`Failed to create order: ${error}`);
|
|
641
862
|
}
|
|
642
863
|
}
|
|
643
|
-
/**
|
|
644
|
-
* Cancel an open order.
|
|
645
|
-
*
|
|
646
|
-
* @param orderId - Order ID to cancel
|
|
647
|
-
* @returns Cancelled order
|
|
648
|
-
*/
|
|
649
|
-
async cancelOrder(orderId) {
|
|
650
|
-
await this.initPromise;
|
|
651
|
-
try {
|
|
652
|
-
const requestBody = {
|
|
653
|
-
args: [orderId],
|
|
654
|
-
credentials: this.getCredentials()
|
|
655
|
-
};
|
|
656
|
-
const response = await this.api.cancelOrder({
|
|
657
|
-
exchange: this.exchangeName,
|
|
658
|
-
cancelOrderRequest: requestBody,
|
|
659
|
-
});
|
|
660
|
-
const data = this.handleResponse(response);
|
|
661
|
-
return convertOrder(data);
|
|
662
|
-
}
|
|
663
|
-
catch (error) {
|
|
664
|
-
throw new Error(`Failed to cancel order: ${error}`);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* Get details of a specific order.
|
|
669
|
-
*
|
|
670
|
-
* @param orderId - Order ID
|
|
671
|
-
* @returns Order details
|
|
672
|
-
*/
|
|
673
|
-
async fetchOrder(orderId) {
|
|
674
|
-
await this.initPromise;
|
|
675
|
-
try {
|
|
676
|
-
const requestBody = {
|
|
677
|
-
args: [orderId],
|
|
678
|
-
credentials: this.getCredentials()
|
|
679
|
-
};
|
|
680
|
-
const response = await this.api.fetchOrder({
|
|
681
|
-
exchange: this.exchangeName,
|
|
682
|
-
fetchOrderRequest: requestBody,
|
|
683
|
-
});
|
|
684
|
-
const data = this.handleResponse(response);
|
|
685
|
-
return convertOrder(data);
|
|
686
|
-
}
|
|
687
|
-
catch (error) {
|
|
688
|
-
throw new Error(`Failed to fetch order: ${error}`);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
* Get all open orders, optionally filtered by market.
|
|
693
|
-
*
|
|
694
|
-
* @param marketId - Optional market ID to filter by
|
|
695
|
-
* @returns List of open orders
|
|
696
|
-
*/
|
|
697
|
-
async fetchOpenOrders(marketId) {
|
|
698
|
-
await this.initPromise;
|
|
699
|
-
try {
|
|
700
|
-
const args = [];
|
|
701
|
-
if (marketId) {
|
|
702
|
-
args.push(marketId);
|
|
703
|
-
}
|
|
704
|
-
const requestBody = {
|
|
705
|
-
args,
|
|
706
|
-
credentials: this.getCredentials()
|
|
707
|
-
};
|
|
708
|
-
const response = await this.api.fetchOpenOrders({
|
|
709
|
-
exchange: this.exchangeName,
|
|
710
|
-
fetchOpenOrdersRequest: requestBody,
|
|
711
|
-
});
|
|
712
|
-
const data = this.handleResponse(response);
|
|
713
|
-
return data.map(convertOrder);
|
|
714
|
-
}
|
|
715
|
-
catch (error) {
|
|
716
|
-
throw new Error(`Failed to fetch open orders: ${error}`);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
// Account Methods
|
|
720
|
-
/**
|
|
721
|
-
* Get current positions across all markets.
|
|
722
|
-
*
|
|
723
|
-
* @returns List of positions
|
|
724
|
-
*/
|
|
725
|
-
async fetchPositions() {
|
|
726
|
-
await this.initPromise;
|
|
727
|
-
try {
|
|
728
|
-
const requestBody = {
|
|
729
|
-
args: [],
|
|
730
|
-
credentials: this.getCredentials()
|
|
731
|
-
};
|
|
732
|
-
const response = await this.api.fetchPositions({
|
|
733
|
-
exchange: this.exchangeName,
|
|
734
|
-
fetchPositionsRequest: requestBody,
|
|
735
|
-
});
|
|
736
|
-
const data = this.handleResponse(response);
|
|
737
|
-
return data.map(convertPosition);
|
|
738
|
-
}
|
|
739
|
-
catch (error) {
|
|
740
|
-
throw new Error(`Failed to fetch positions: ${error}`);
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* Get account balance.
|
|
745
|
-
*
|
|
746
|
-
* @returns List of balances (by currency)
|
|
747
|
-
*/
|
|
748
|
-
async fetchBalance() {
|
|
749
|
-
await this.initPromise;
|
|
750
|
-
try {
|
|
751
|
-
const requestBody = {
|
|
752
|
-
args: [],
|
|
753
|
-
credentials: this.getCredentials()
|
|
754
|
-
};
|
|
755
|
-
const response = await this.api.fetchBalance({
|
|
756
|
-
exchange: this.exchangeName,
|
|
757
|
-
fetchBalanceRequest: requestBody,
|
|
758
|
-
});
|
|
759
|
-
const data = this.handleResponse(response);
|
|
760
|
-
return data.map(convertBalance);
|
|
761
|
-
}
|
|
762
|
-
catch (error) {
|
|
763
|
-
throw new Error(`Failed to fetch balance: ${error}`);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
864
|
/**
|
|
767
865
|
* Calculate the average execution price for a given amount by walking the order book.
|
|
768
866
|
* Uses the sidecar server for calculation to ensure consistency.
|
|
@@ -1116,3 +1214,99 @@ class Limitless extends Exchange {
|
|
|
1116
1214
|
}
|
|
1117
1215
|
}
|
|
1118
1216
|
exports.Limitless = Limitless;
|
|
1217
|
+
/**
|
|
1218
|
+
* Kalshi Demo exchange client (paper trading / sandbox environment).
|
|
1219
|
+
*
|
|
1220
|
+
* Uses Kalshi's demo environment — same API as Kalshi but against test accounts.
|
|
1221
|
+
* Credentials are separate from production Kalshi credentials.
|
|
1222
|
+
*
|
|
1223
|
+
* @example
|
|
1224
|
+
* ```typescript
|
|
1225
|
+
* const kalshiDemo = new KalshiDemo({
|
|
1226
|
+
* apiKey: process.env.KALSHI_DEMO_API_KEY,
|
|
1227
|
+
* privateKey: process.env.KALSHI_DEMO_PRIVATE_KEY
|
|
1228
|
+
* });
|
|
1229
|
+
* const balance = await kalshiDemo.fetchBalance();
|
|
1230
|
+
* ```
|
|
1231
|
+
*/
|
|
1232
|
+
class KalshiDemo extends Exchange {
|
|
1233
|
+
constructor(options = {}) {
|
|
1234
|
+
super("kalshi-demo", options);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
exports.KalshiDemo = KalshiDemo;
|
|
1238
|
+
/**
|
|
1239
|
+
* Myriad exchange client.
|
|
1240
|
+
*
|
|
1241
|
+
* AMM-based prediction market exchange. Requires an API key for trading.
|
|
1242
|
+
* The `privateKey` field is used as the wallet address.
|
|
1243
|
+
*
|
|
1244
|
+
* @example
|
|
1245
|
+
* ```typescript
|
|
1246
|
+
* // Public data (no auth)
|
|
1247
|
+
* const myriad = new Myriad();
|
|
1248
|
+
* const markets = await myriad.fetchMarkets();
|
|
1249
|
+
*
|
|
1250
|
+
* // Trading (requires auth)
|
|
1251
|
+
* const myriad = new Myriad({
|
|
1252
|
+
* apiKey: process.env.MYRIAD_API_KEY,
|
|
1253
|
+
* privateKey: process.env.MYRIAD_WALLET_ADDRESS
|
|
1254
|
+
* });
|
|
1255
|
+
* ```
|
|
1256
|
+
*/
|
|
1257
|
+
class Myriad extends Exchange {
|
|
1258
|
+
constructor(options = {}) {
|
|
1259
|
+
super("myriad", options);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
exports.Myriad = Myriad;
|
|
1263
|
+
/**
|
|
1264
|
+
* Probable exchange client.
|
|
1265
|
+
*
|
|
1266
|
+
* BSC-based CLOB exchange. Requires all four credential fields for trading.
|
|
1267
|
+
*
|
|
1268
|
+
* @example
|
|
1269
|
+
* ```typescript
|
|
1270
|
+
* // Public data (no auth)
|
|
1271
|
+
* const probable = new Probable();
|
|
1272
|
+
* const markets = await probable.fetchMarkets();
|
|
1273
|
+
*
|
|
1274
|
+
* // Trading (requires auth)
|
|
1275
|
+
* const probable = new Probable({
|
|
1276
|
+
* privateKey: process.env.PROBABLE_PRIVATE_KEY,
|
|
1277
|
+
* apiKey: process.env.PROBABLE_API_KEY,
|
|
1278
|
+
* apiSecret: process.env.PROBABLE_API_SECRET,
|
|
1279
|
+
* passphrase: process.env.PROBABLE_PASSPHRASE
|
|
1280
|
+
* });
|
|
1281
|
+
* ```
|
|
1282
|
+
*/
|
|
1283
|
+
class Probable extends Exchange {
|
|
1284
|
+
constructor(options = {}) {
|
|
1285
|
+
super("probable", options);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
exports.Probable = Probable;
|
|
1289
|
+
/**
|
|
1290
|
+
* Baozi exchange client.
|
|
1291
|
+
*
|
|
1292
|
+
* Solana-based on-chain pari-mutuel betting exchange.
|
|
1293
|
+
* Requires a Solana private key for trading.
|
|
1294
|
+
*
|
|
1295
|
+
* @example
|
|
1296
|
+
* ```typescript
|
|
1297
|
+
* // Public data (no auth)
|
|
1298
|
+
* const baozi = new Baozi();
|
|
1299
|
+
* const markets = await baozi.fetchMarkets();
|
|
1300
|
+
*
|
|
1301
|
+
* // Trading (requires auth)
|
|
1302
|
+
* const baozi = new Baozi({
|
|
1303
|
+
* privateKey: process.env.BAOZI_PRIVATE_KEY
|
|
1304
|
+
* });
|
|
1305
|
+
* ```
|
|
1306
|
+
*/
|
|
1307
|
+
class Baozi extends Exchange {
|
|
1308
|
+
constructor(options = {}) {
|
|
1309
|
+
super("baozi", options);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
exports.Baozi = Baozi;
|