pmxtjs 2.20.3 → 2.21.1
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 +17 -0
- package/dist/esm/index.js +4 -1
- package/dist/esm/pmxt/client.js +181 -69
- package/dist/esm/pmxt/errors.d.ts +55 -0
- package/dist/esm/pmxt/errors.js +132 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +7 -1
- package/dist/pmxt/client.js +181 -69
- package/dist/pmxt/errors.d.ts +55 -0
- package/dist/pmxt/errors.js +150 -0
- package/generated/package.json +1 -1
- package/index.ts +4 -1
- package/package.json +2 -2
- package/pmxt/client.ts +154 -69
- package/pmxt/errors.ts +163 -0
package/dist/esm/index.d.ts
CHANGED
|
@@ -20,13 +20,30 @@
|
|
|
20
20
|
import { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi } from "./pmxt/client.js";
|
|
21
21
|
import { ServerManager } from "./pmxt/server-manager.js";
|
|
22
22
|
import * as models from "./pmxt/models.js";
|
|
23
|
+
import * as errors from "./pmxt/errors.js";
|
|
23
24
|
export { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi, PolymarketOptions } from "./pmxt/client.js";
|
|
24
25
|
export { ServerManager } from "./pmxt/server-manager.js";
|
|
25
26
|
export { MarketList } from "./pmxt/models.js";
|
|
26
27
|
export type * from "./pmxt/models.js";
|
|
28
|
+
export * from "./pmxt/errors.js";
|
|
27
29
|
declare function stopServer(): Promise<void>;
|
|
28
30
|
declare function restartServer(): Promise<void>;
|
|
29
31
|
declare const pmxt: {
|
|
32
|
+
fromServerError(errorData: any): errors.PmxtError;
|
|
33
|
+
PmxtError: typeof errors.PmxtError;
|
|
34
|
+
BadRequest: typeof errors.BadRequest;
|
|
35
|
+
AuthenticationError: typeof errors.AuthenticationError;
|
|
36
|
+
PermissionDenied: typeof errors.PermissionDenied;
|
|
37
|
+
NotFoundError: typeof errors.NotFoundError;
|
|
38
|
+
OrderNotFound: typeof errors.OrderNotFound;
|
|
39
|
+
MarketNotFound: typeof errors.MarketNotFound;
|
|
40
|
+
EventNotFound: typeof errors.EventNotFound;
|
|
41
|
+
RateLimitExceeded: typeof errors.RateLimitExceeded;
|
|
42
|
+
InvalidOrder: typeof errors.InvalidOrder;
|
|
43
|
+
InsufficientFunds: typeof errors.InsufficientFunds;
|
|
44
|
+
ValidationError: typeof errors.ValidationError;
|
|
45
|
+
NetworkError: typeof errors.NetworkError;
|
|
46
|
+
ExchangeNotAvailable: typeof errors.ExchangeNotAvailable;
|
|
30
47
|
MarketList: typeof models.MarketList;
|
|
31
48
|
Exchange: typeof Exchange;
|
|
32
49
|
Polymarket: typeof Polymarket;
|
package/dist/esm/index.js
CHANGED
|
@@ -20,9 +20,11 @@
|
|
|
20
20
|
import { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi } from "./pmxt/client.js";
|
|
21
21
|
import { ServerManager } from "./pmxt/server-manager.js";
|
|
22
22
|
import * as models from "./pmxt/models.js";
|
|
23
|
+
import * as errors from "./pmxt/errors.js";
|
|
23
24
|
export { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi } from "./pmxt/client.js";
|
|
24
25
|
export { ServerManager } from "./pmxt/server-manager.js";
|
|
25
26
|
export { MarketList } from "./pmxt/models.js";
|
|
27
|
+
export * from "./pmxt/errors.js";
|
|
26
28
|
const defaultManager = new ServerManager();
|
|
27
29
|
async function stopServer() {
|
|
28
30
|
await defaultManager.stop();
|
|
@@ -42,6 +44,7 @@ const pmxt = {
|
|
|
42
44
|
ServerManager,
|
|
43
45
|
stopServer,
|
|
44
46
|
restartServer,
|
|
45
|
-
...models
|
|
47
|
+
...models,
|
|
48
|
+
...errors
|
|
46
49
|
};
|
|
47
50
|
export default pmxt;
|
package/dist/esm/pmxt/client.js
CHANGED
|
@@ -8,6 +8,7 @@ import { Configuration, DefaultApi, } from "../generated/src/index.js";
|
|
|
8
8
|
import { MarketList, } from "./models.js";
|
|
9
9
|
import { ServerManager } from "./server-manager.js";
|
|
10
10
|
import { buildArgsWithOptionalOptions } from "./args.js";
|
|
11
|
+
import { PmxtError, fromServerError } from "./errors.js";
|
|
11
12
|
// Converter functions
|
|
12
13
|
function convertMarket(raw) {
|
|
13
14
|
const outcomes = (raw.outcomes || []).map((o) => ({
|
|
@@ -204,7 +205,7 @@ export class Exchange {
|
|
|
204
205
|
this.api = new DefaultApi(this.config);
|
|
205
206
|
}
|
|
206
207
|
catch (error) {
|
|
207
|
-
throw new
|
|
208
|
+
throw new PmxtError(`Failed to start PMXT server: ${error}\n\n` +
|
|
208
209
|
`Please ensure 'pmxt-core' is installed: npm install -g pmxt-core\n` +
|
|
209
210
|
`Or start the server manually: pmxt-server`);
|
|
210
211
|
}
|
|
@@ -213,7 +214,10 @@ export class Exchange {
|
|
|
213
214
|
handleResponse(response) {
|
|
214
215
|
if (!response.success) {
|
|
215
216
|
const error = response.error || {};
|
|
216
|
-
|
|
217
|
+
if (error && typeof error === "object" && (error.code || error.message)) {
|
|
218
|
+
throw fromServerError(error);
|
|
219
|
+
}
|
|
220
|
+
throw new PmxtError(error.message || "Unknown error");
|
|
217
221
|
}
|
|
218
222
|
return response.data;
|
|
219
223
|
}
|
|
@@ -269,14 +273,19 @@ export class Exchange {
|
|
|
269
273
|
body: JSON.stringify(requestBody)
|
|
270
274
|
});
|
|
271
275
|
if (!response.ok) {
|
|
272
|
-
const
|
|
273
|
-
|
|
276
|
+
const body = await response.json().catch(() => ({}));
|
|
277
|
+
if (body.error && typeof body.error === "object") {
|
|
278
|
+
throw fromServerError(body.error);
|
|
279
|
+
}
|
|
280
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
274
281
|
}
|
|
275
282
|
const json = await response.json();
|
|
276
283
|
return this.handleResponse(json);
|
|
277
284
|
}
|
|
278
285
|
catch (error) {
|
|
279
|
-
|
|
286
|
+
if (error instanceof PmxtError)
|
|
287
|
+
throw error;
|
|
288
|
+
throw new PmxtError(`Failed to call API '${operationId}': ${error}`);
|
|
280
289
|
}
|
|
281
290
|
}
|
|
282
291
|
// BEGIN GENERATED METHODS
|
|
@@ -291,8 +300,11 @@ export class Exchange {
|
|
|
291
300
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
292
301
|
});
|
|
293
302
|
if (!response.ok) {
|
|
294
|
-
const
|
|
295
|
-
|
|
303
|
+
const body = await response.json().catch(() => ({}));
|
|
304
|
+
if (body.error && typeof body.error === "object") {
|
|
305
|
+
throw fromServerError(body.error);
|
|
306
|
+
}
|
|
307
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
296
308
|
}
|
|
297
309
|
const json = await response.json();
|
|
298
310
|
const data = this.handleResponse(json);
|
|
@@ -303,7 +315,9 @@ export class Exchange {
|
|
|
303
315
|
return result;
|
|
304
316
|
}
|
|
305
317
|
catch (error) {
|
|
306
|
-
|
|
318
|
+
if (error instanceof PmxtError)
|
|
319
|
+
throw error;
|
|
320
|
+
throw new PmxtError(`Failed to loadMarkets: ${error}`);
|
|
307
321
|
}
|
|
308
322
|
}
|
|
309
323
|
async fetchMarkets(params) {
|
|
@@ -316,15 +330,20 @@ export class Exchange {
|
|
|
316
330
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
317
331
|
});
|
|
318
332
|
if (!response.ok) {
|
|
319
|
-
const
|
|
320
|
-
|
|
333
|
+
const body = await response.json().catch(() => ({}));
|
|
334
|
+
if (body.error && typeof body.error === "object") {
|
|
335
|
+
throw fromServerError(body.error);
|
|
336
|
+
}
|
|
337
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
321
338
|
}
|
|
322
339
|
const json = await response.json();
|
|
323
340
|
const data = this.handleResponse(json);
|
|
324
341
|
return data.map(convertMarket);
|
|
325
342
|
}
|
|
326
343
|
catch (error) {
|
|
327
|
-
|
|
344
|
+
if (error instanceof PmxtError)
|
|
345
|
+
throw error;
|
|
346
|
+
throw new PmxtError(`Failed to fetchMarkets: ${error}`);
|
|
328
347
|
}
|
|
329
348
|
}
|
|
330
349
|
async fetchMarketsPaginated(params) {
|
|
@@ -337,8 +356,11 @@ export class Exchange {
|
|
|
337
356
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
338
357
|
});
|
|
339
358
|
if (!response.ok) {
|
|
340
|
-
const
|
|
341
|
-
|
|
359
|
+
const body = await response.json().catch(() => ({}));
|
|
360
|
+
if (body.error && typeof body.error === "object") {
|
|
361
|
+
throw fromServerError(body.error);
|
|
362
|
+
}
|
|
363
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
342
364
|
}
|
|
343
365
|
const json = await response.json();
|
|
344
366
|
const data = this.handleResponse(json);
|
|
@@ -349,7 +371,9 @@ export class Exchange {
|
|
|
349
371
|
};
|
|
350
372
|
}
|
|
351
373
|
catch (error) {
|
|
352
|
-
|
|
374
|
+
if (error instanceof PmxtError)
|
|
375
|
+
throw error;
|
|
376
|
+
throw new PmxtError(`Failed to fetchMarketsPaginated: ${error}`);
|
|
353
377
|
}
|
|
354
378
|
}
|
|
355
379
|
async fetchEvents(params) {
|
|
@@ -362,15 +386,20 @@ export class Exchange {
|
|
|
362
386
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
363
387
|
});
|
|
364
388
|
if (!response.ok) {
|
|
365
|
-
const
|
|
366
|
-
|
|
389
|
+
const body = await response.json().catch(() => ({}));
|
|
390
|
+
if (body.error && typeof body.error === "object") {
|
|
391
|
+
throw fromServerError(body.error);
|
|
392
|
+
}
|
|
393
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
367
394
|
}
|
|
368
395
|
const json = await response.json();
|
|
369
396
|
const data = this.handleResponse(json);
|
|
370
397
|
return data.map(convertEvent);
|
|
371
398
|
}
|
|
372
399
|
catch (error) {
|
|
373
|
-
|
|
400
|
+
if (error instanceof PmxtError)
|
|
401
|
+
throw error;
|
|
402
|
+
throw new PmxtError(`Failed to fetchEvents: ${error}`);
|
|
374
403
|
}
|
|
375
404
|
}
|
|
376
405
|
async fetchMarket(params) {
|
|
@@ -383,15 +412,20 @@ export class Exchange {
|
|
|
383
412
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
384
413
|
});
|
|
385
414
|
if (!response.ok) {
|
|
386
|
-
const
|
|
387
|
-
|
|
415
|
+
const body = await response.json().catch(() => ({}));
|
|
416
|
+
if (body.error && typeof body.error === "object") {
|
|
417
|
+
throw fromServerError(body.error);
|
|
418
|
+
}
|
|
419
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
388
420
|
}
|
|
389
421
|
const json = await response.json();
|
|
390
422
|
const data = this.handleResponse(json);
|
|
391
423
|
return convertMarket(data);
|
|
392
424
|
}
|
|
393
425
|
catch (error) {
|
|
394
|
-
|
|
426
|
+
if (error instanceof PmxtError)
|
|
427
|
+
throw error;
|
|
428
|
+
throw new PmxtError(`Failed to fetchMarket: ${error}`);
|
|
395
429
|
}
|
|
396
430
|
}
|
|
397
431
|
async fetchEvent(params) {
|
|
@@ -404,15 +438,20 @@ export class Exchange {
|
|
|
404
438
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
405
439
|
});
|
|
406
440
|
if (!response.ok) {
|
|
407
|
-
const
|
|
408
|
-
|
|
441
|
+
const body = await response.json().catch(() => ({}));
|
|
442
|
+
if (body.error && typeof body.error === "object") {
|
|
443
|
+
throw fromServerError(body.error);
|
|
444
|
+
}
|
|
445
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
409
446
|
}
|
|
410
447
|
const json = await response.json();
|
|
411
448
|
const data = this.handleResponse(json);
|
|
412
449
|
return convertEvent(data);
|
|
413
450
|
}
|
|
414
451
|
catch (error) {
|
|
415
|
-
|
|
452
|
+
if (error instanceof PmxtError)
|
|
453
|
+
throw error;
|
|
454
|
+
throw new PmxtError(`Failed to fetchEvent: ${error}`);
|
|
416
455
|
}
|
|
417
456
|
}
|
|
418
457
|
async fetchOrderBook(id) {
|
|
@@ -426,15 +465,20 @@ export class Exchange {
|
|
|
426
465
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
427
466
|
});
|
|
428
467
|
if (!response.ok) {
|
|
429
|
-
const
|
|
430
|
-
|
|
468
|
+
const body = await response.json().catch(() => ({}));
|
|
469
|
+
if (body.error && typeof body.error === "object") {
|
|
470
|
+
throw fromServerError(body.error);
|
|
471
|
+
}
|
|
472
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
431
473
|
}
|
|
432
474
|
const json = await response.json();
|
|
433
475
|
const data = this.handleResponse(json);
|
|
434
476
|
return convertOrderBook(data);
|
|
435
477
|
}
|
|
436
478
|
catch (error) {
|
|
437
|
-
|
|
479
|
+
if (error instanceof PmxtError)
|
|
480
|
+
throw error;
|
|
481
|
+
throw new PmxtError(`Failed to fetchOrderBook: ${error}`);
|
|
438
482
|
}
|
|
439
483
|
}
|
|
440
484
|
async cancelOrder(orderId) {
|
|
@@ -448,15 +492,20 @@ export class Exchange {
|
|
|
448
492
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
449
493
|
});
|
|
450
494
|
if (!response.ok) {
|
|
451
|
-
const
|
|
452
|
-
|
|
495
|
+
const body = await response.json().catch(() => ({}));
|
|
496
|
+
if (body.error && typeof body.error === "object") {
|
|
497
|
+
throw fromServerError(body.error);
|
|
498
|
+
}
|
|
499
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
453
500
|
}
|
|
454
501
|
const json = await response.json();
|
|
455
502
|
const data = this.handleResponse(json);
|
|
456
503
|
return convertOrder(data);
|
|
457
504
|
}
|
|
458
505
|
catch (error) {
|
|
459
|
-
|
|
506
|
+
if (error instanceof PmxtError)
|
|
507
|
+
throw error;
|
|
508
|
+
throw new PmxtError(`Failed to cancelOrder: ${error}`);
|
|
460
509
|
}
|
|
461
510
|
}
|
|
462
511
|
async fetchOrder(orderId) {
|
|
@@ -470,15 +519,20 @@ export class Exchange {
|
|
|
470
519
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
471
520
|
});
|
|
472
521
|
if (!response.ok) {
|
|
473
|
-
const
|
|
474
|
-
|
|
522
|
+
const body = await response.json().catch(() => ({}));
|
|
523
|
+
if (body.error && typeof body.error === "object") {
|
|
524
|
+
throw fromServerError(body.error);
|
|
525
|
+
}
|
|
526
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
475
527
|
}
|
|
476
528
|
const json = await response.json();
|
|
477
529
|
const data = this.handleResponse(json);
|
|
478
530
|
return convertOrder(data);
|
|
479
531
|
}
|
|
480
532
|
catch (error) {
|
|
481
|
-
|
|
533
|
+
if (error instanceof PmxtError)
|
|
534
|
+
throw error;
|
|
535
|
+
throw new PmxtError(`Failed to fetchOrder: ${error}`);
|
|
482
536
|
}
|
|
483
537
|
}
|
|
484
538
|
async fetchOpenOrders(marketId) {
|
|
@@ -491,15 +545,20 @@ export class Exchange {
|
|
|
491
545
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
492
546
|
});
|
|
493
547
|
if (!response.ok) {
|
|
494
|
-
const
|
|
495
|
-
|
|
548
|
+
const body = await response.json().catch(() => ({}));
|
|
549
|
+
if (body.error && typeof body.error === "object") {
|
|
550
|
+
throw fromServerError(body.error);
|
|
551
|
+
}
|
|
552
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
496
553
|
}
|
|
497
554
|
const json = await response.json();
|
|
498
555
|
const data = this.handleResponse(json);
|
|
499
556
|
return data.map(convertOrder);
|
|
500
557
|
}
|
|
501
558
|
catch (error) {
|
|
502
|
-
|
|
559
|
+
if (error instanceof PmxtError)
|
|
560
|
+
throw error;
|
|
561
|
+
throw new PmxtError(`Failed to fetchOpenOrders: ${error}`);
|
|
503
562
|
}
|
|
504
563
|
}
|
|
505
564
|
async fetchMyTrades(params) {
|
|
@@ -512,15 +571,20 @@ export class Exchange {
|
|
|
512
571
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
513
572
|
});
|
|
514
573
|
if (!response.ok) {
|
|
515
|
-
const
|
|
516
|
-
|
|
574
|
+
const body = await response.json().catch(() => ({}));
|
|
575
|
+
if (body.error && typeof body.error === "object") {
|
|
576
|
+
throw fromServerError(body.error);
|
|
577
|
+
}
|
|
578
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
517
579
|
}
|
|
518
580
|
const json = await response.json();
|
|
519
581
|
const data = this.handleResponse(json);
|
|
520
582
|
return data.map(convertUserTrade);
|
|
521
583
|
}
|
|
522
584
|
catch (error) {
|
|
523
|
-
|
|
585
|
+
if (error instanceof PmxtError)
|
|
586
|
+
throw error;
|
|
587
|
+
throw new PmxtError(`Failed to fetchMyTrades: ${error}`);
|
|
524
588
|
}
|
|
525
589
|
}
|
|
526
590
|
async fetchClosedOrders(params) {
|
|
@@ -533,15 +597,20 @@ export class Exchange {
|
|
|
533
597
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
534
598
|
});
|
|
535
599
|
if (!response.ok) {
|
|
536
|
-
const
|
|
537
|
-
|
|
600
|
+
const body = await response.json().catch(() => ({}));
|
|
601
|
+
if (body.error && typeof body.error === "object") {
|
|
602
|
+
throw fromServerError(body.error);
|
|
603
|
+
}
|
|
604
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
538
605
|
}
|
|
539
606
|
const json = await response.json();
|
|
540
607
|
const data = this.handleResponse(json);
|
|
541
608
|
return data.map(convertOrder);
|
|
542
609
|
}
|
|
543
610
|
catch (error) {
|
|
544
|
-
|
|
611
|
+
if (error instanceof PmxtError)
|
|
612
|
+
throw error;
|
|
613
|
+
throw new PmxtError(`Failed to fetchClosedOrders: ${error}`);
|
|
545
614
|
}
|
|
546
615
|
}
|
|
547
616
|
async fetchAllOrders(params) {
|
|
@@ -554,15 +623,20 @@ export class Exchange {
|
|
|
554
623
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
555
624
|
});
|
|
556
625
|
if (!response.ok) {
|
|
557
|
-
const
|
|
558
|
-
|
|
626
|
+
const body = await response.json().catch(() => ({}));
|
|
627
|
+
if (body.error && typeof body.error === "object") {
|
|
628
|
+
throw fromServerError(body.error);
|
|
629
|
+
}
|
|
630
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
559
631
|
}
|
|
560
632
|
const json = await response.json();
|
|
561
633
|
const data = this.handleResponse(json);
|
|
562
634
|
return data.map(convertOrder);
|
|
563
635
|
}
|
|
564
636
|
catch (error) {
|
|
565
|
-
|
|
637
|
+
if (error instanceof PmxtError)
|
|
638
|
+
throw error;
|
|
639
|
+
throw new PmxtError(`Failed to fetchAllOrders: ${error}`);
|
|
566
640
|
}
|
|
567
641
|
}
|
|
568
642
|
async fetchPositions(address) {
|
|
@@ -575,15 +649,20 @@ export class Exchange {
|
|
|
575
649
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
576
650
|
});
|
|
577
651
|
if (!response.ok) {
|
|
578
|
-
const
|
|
579
|
-
|
|
652
|
+
const body = await response.json().catch(() => ({}));
|
|
653
|
+
if (body.error && typeof body.error === "object") {
|
|
654
|
+
throw fromServerError(body.error);
|
|
655
|
+
}
|
|
656
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
580
657
|
}
|
|
581
658
|
const json = await response.json();
|
|
582
659
|
const data = this.handleResponse(json);
|
|
583
660
|
return data.map(convertPosition);
|
|
584
661
|
}
|
|
585
662
|
catch (error) {
|
|
586
|
-
|
|
663
|
+
if (error instanceof PmxtError)
|
|
664
|
+
throw error;
|
|
665
|
+
throw new PmxtError(`Failed to fetchPositions: ${error}`);
|
|
587
666
|
}
|
|
588
667
|
}
|
|
589
668
|
async fetchBalance(address) {
|
|
@@ -596,15 +675,20 @@ export class Exchange {
|
|
|
596
675
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
597
676
|
});
|
|
598
677
|
if (!response.ok) {
|
|
599
|
-
const
|
|
600
|
-
|
|
678
|
+
const body = await response.json().catch(() => ({}));
|
|
679
|
+
if (body.error && typeof body.error === "object") {
|
|
680
|
+
throw fromServerError(body.error);
|
|
681
|
+
}
|
|
682
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
601
683
|
}
|
|
602
684
|
const json = await response.json();
|
|
603
685
|
const data = this.handleResponse(json);
|
|
604
686
|
return data.map(convertBalance);
|
|
605
687
|
}
|
|
606
688
|
catch (error) {
|
|
607
|
-
|
|
689
|
+
if (error instanceof PmxtError)
|
|
690
|
+
throw error;
|
|
691
|
+
throw new PmxtError(`Failed to fetchBalance: ${error}`);
|
|
608
692
|
}
|
|
609
693
|
}
|
|
610
694
|
async close() {
|
|
@@ -617,14 +701,19 @@ export class Exchange {
|
|
|
617
701
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
618
702
|
});
|
|
619
703
|
if (!response.ok) {
|
|
620
|
-
const
|
|
621
|
-
|
|
704
|
+
const body = await response.json().catch(() => ({}));
|
|
705
|
+
if (body.error && typeof body.error === "object") {
|
|
706
|
+
throw fromServerError(body.error);
|
|
707
|
+
}
|
|
708
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
622
709
|
}
|
|
623
710
|
const json = await response.json();
|
|
624
711
|
this.handleResponse(json);
|
|
625
712
|
}
|
|
626
713
|
catch (error) {
|
|
627
|
-
|
|
714
|
+
if (error instanceof PmxtError)
|
|
715
|
+
throw error;
|
|
716
|
+
throw new PmxtError(`Failed to close: ${error}`);
|
|
628
717
|
}
|
|
629
718
|
}
|
|
630
719
|
// END GENERATED METHODS
|
|
@@ -670,7 +759,9 @@ export class Exchange {
|
|
|
670
759
|
return data.map(convertCandle);
|
|
671
760
|
}
|
|
672
761
|
catch (error) {
|
|
673
|
-
|
|
762
|
+
if (error instanceof PmxtError)
|
|
763
|
+
throw error;
|
|
764
|
+
throw new PmxtError(`Failed to fetch OHLCV: ${error}`);
|
|
674
765
|
}
|
|
675
766
|
}
|
|
676
767
|
/**
|
|
@@ -701,7 +792,9 @@ export class Exchange {
|
|
|
701
792
|
return data.map(convertTrade);
|
|
702
793
|
}
|
|
703
794
|
catch (error) {
|
|
704
|
-
|
|
795
|
+
if (error instanceof PmxtError)
|
|
796
|
+
throw error;
|
|
797
|
+
throw new PmxtError(`Failed to fetch trades: ${error}`);
|
|
705
798
|
}
|
|
706
799
|
}
|
|
707
800
|
// WebSocket Streaming Methods
|
|
@@ -744,7 +837,9 @@ export class Exchange {
|
|
|
744
837
|
return convertOrderBook(data);
|
|
745
838
|
}
|
|
746
839
|
catch (error) {
|
|
747
|
-
|
|
840
|
+
if (error instanceof PmxtError)
|
|
841
|
+
throw error;
|
|
842
|
+
throw new PmxtError(`Failed to watch order book: ${error}`);
|
|
748
843
|
}
|
|
749
844
|
}
|
|
750
845
|
/**
|
|
@@ -795,7 +890,9 @@ export class Exchange {
|
|
|
795
890
|
return data.map(convertTrade);
|
|
796
891
|
}
|
|
797
892
|
catch (error) {
|
|
798
|
-
|
|
893
|
+
if (error instanceof PmxtError)
|
|
894
|
+
throw error;
|
|
895
|
+
throw new PmxtError(`Failed to watch trades: ${error}`);
|
|
799
896
|
}
|
|
800
897
|
}
|
|
801
898
|
/**
|
|
@@ -838,7 +935,9 @@ export class Exchange {
|
|
|
838
935
|
return convertSubscriptionSnapshot(data);
|
|
839
936
|
}
|
|
840
937
|
catch (error) {
|
|
841
|
-
|
|
938
|
+
if (error instanceof PmxtError)
|
|
939
|
+
throw error;
|
|
940
|
+
throw new PmxtError(`Failed to watch address: ${error}`);
|
|
842
941
|
}
|
|
843
942
|
}
|
|
844
943
|
/**
|
|
@@ -862,7 +961,9 @@ export class Exchange {
|
|
|
862
961
|
return this.handleResponse(response);
|
|
863
962
|
}
|
|
864
963
|
catch (error) {
|
|
865
|
-
|
|
964
|
+
if (error instanceof PmxtError)
|
|
965
|
+
throw error;
|
|
966
|
+
throw new PmxtError(`Failed to unwatch address: ${error}`);
|
|
866
967
|
}
|
|
867
968
|
}
|
|
868
969
|
// Trading Methods (require authentication)
|
|
@@ -909,11 +1010,11 @@ export class Exchange {
|
|
|
909
1010
|
let outcomeId = params.outcomeId;
|
|
910
1011
|
if (params.outcome) {
|
|
911
1012
|
if (marketId !== undefined || outcomeId !== undefined) {
|
|
912
|
-
throw new
|
|
1013
|
+
throw new PmxtError("Cannot specify both 'outcome' and 'marketId'/'outcomeId'. Use one or the other.");
|
|
913
1014
|
}
|
|
914
1015
|
const outcome = params.outcome;
|
|
915
1016
|
if (!outcome.marketId) {
|
|
916
|
-
throw new
|
|
1017
|
+
throw new PmxtError("outcome.marketId is not set. Ensure the outcome comes from a fetched market.");
|
|
917
1018
|
}
|
|
918
1019
|
marketId = outcome.marketId;
|
|
919
1020
|
outcomeId = outcome.outcomeId;
|
|
@@ -943,7 +1044,9 @@ export class Exchange {
|
|
|
943
1044
|
return data;
|
|
944
1045
|
}
|
|
945
1046
|
catch (error) {
|
|
946
|
-
|
|
1047
|
+
if (error instanceof PmxtError)
|
|
1048
|
+
throw error;
|
|
1049
|
+
throw new PmxtError(`Failed to build order: ${error}`);
|
|
947
1050
|
}
|
|
948
1051
|
}
|
|
949
1052
|
/**
|
|
@@ -980,7 +1083,9 @@ export class Exchange {
|
|
|
980
1083
|
return convertOrder(data);
|
|
981
1084
|
}
|
|
982
1085
|
catch (error) {
|
|
983
|
-
|
|
1086
|
+
if (error instanceof PmxtError)
|
|
1087
|
+
throw error;
|
|
1088
|
+
throw new PmxtError(`Failed to submit order: ${error}`);
|
|
984
1089
|
}
|
|
985
1090
|
}
|
|
986
1091
|
/**
|
|
@@ -1009,11 +1114,11 @@ export class Exchange {
|
|
|
1009
1114
|
let outcomeId = params.outcomeId;
|
|
1010
1115
|
if (params.outcome) {
|
|
1011
1116
|
if (marketId !== undefined || outcomeId !== undefined) {
|
|
1012
|
-
throw new
|
|
1117
|
+
throw new PmxtError("Cannot specify both 'outcome' and 'marketId'/'outcomeId'. Use one or the other.");
|
|
1013
1118
|
}
|
|
1014
1119
|
const outcome = params.outcome;
|
|
1015
1120
|
if (!outcome.marketId) {
|
|
1016
|
-
throw new
|
|
1121
|
+
throw new PmxtError("outcome.marketId is not set. Ensure the outcome comes from a fetched market.");
|
|
1017
1122
|
}
|
|
1018
1123
|
marketId = outcome.marketId;
|
|
1019
1124
|
outcomeId = outcome.outcomeId;
|
|
@@ -1043,7 +1148,9 @@ export class Exchange {
|
|
|
1043
1148
|
return convertOrder(data);
|
|
1044
1149
|
}
|
|
1045
1150
|
catch (error) {
|
|
1046
|
-
|
|
1151
|
+
if (error instanceof PmxtError)
|
|
1152
|
+
throw error;
|
|
1153
|
+
throw new PmxtError(`Failed to create order: ${error}`);
|
|
1047
1154
|
}
|
|
1048
1155
|
}
|
|
1049
1156
|
/**
|
|
@@ -1088,14 +1195,19 @@ export class Exchange {
|
|
|
1088
1195
|
body: JSON.stringify(body)
|
|
1089
1196
|
});
|
|
1090
1197
|
if (!response.ok) {
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1198
|
+
const body = await response.json().catch(() => ({}));
|
|
1199
|
+
if (body.error && typeof body.error === "object") {
|
|
1200
|
+
throw fromServerError(body.error);
|
|
1201
|
+
}
|
|
1202
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
1093
1203
|
}
|
|
1094
1204
|
const json = await response.json();
|
|
1095
1205
|
return this.handleResponse(json);
|
|
1096
1206
|
}
|
|
1097
1207
|
catch (error) {
|
|
1098
|
-
|
|
1208
|
+
if (error instanceof PmxtError)
|
|
1209
|
+
throw error;
|
|
1210
|
+
throw new PmxtError(`Failed to get execution price: ${error}`);
|
|
1099
1211
|
}
|
|
1100
1212
|
}
|
|
1101
1213
|
// ----------------------------------------------------------------------------
|