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