pmxtjs 2.31.4 → 2.32.2
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/pmxt/client.d.ts +4 -34
- package/dist/esm/pmxt/client.js +253 -210
- package/dist/pmxt/client.d.ts +4 -34
- package/dist/pmxt/client.js +253 -210
- package/generated/package.json +1 -1
- package/package.json +2 -2
- package/pmxt/client.ts +242 -195
package/dist/pmxt/client.js
CHANGED
|
@@ -10,7 +10,6 @@ exports.PolymarketUS = exports.Smarkets = exports.Metaculus = exports.Opinion =
|
|
|
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");
|
|
13
|
-
const args_js_1 = require("./args.js");
|
|
14
13
|
const errors_js_1 = require("./errors.js");
|
|
15
14
|
const constants_js_1 = require("./constants.js");
|
|
16
15
|
/**
|
|
@@ -459,11 +458,8 @@ class Exchange {
|
|
|
459
458
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
460
459
|
});
|
|
461
460
|
if (!response.ok) {
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
throw (0, errors_js_1.fromServerError)(body.error);
|
|
465
|
-
}
|
|
466
|
-
throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
|
|
461
|
+
const error = await response.json().catch(() => ({}));
|
|
462
|
+
throw new Error(error.error?.message || response.statusText);
|
|
467
463
|
}
|
|
468
464
|
const json = await response.json();
|
|
469
465
|
const data = this.handleResponse(json);
|
|
@@ -474,32 +470,48 @@ class Exchange {
|
|
|
474
470
|
return result;
|
|
475
471
|
}
|
|
476
472
|
catch (error) {
|
|
477
|
-
|
|
478
|
-
throw error;
|
|
479
|
-
throw new errors_js_1.PmxtError(`Failed to loadMarkets: ${error}`);
|
|
473
|
+
throw new Error(`Failed to loadMarkets: ${error}`);
|
|
480
474
|
}
|
|
481
475
|
}
|
|
482
476
|
async fetchMarkets(params) {
|
|
483
477
|
await this.initPromise;
|
|
484
478
|
try {
|
|
485
|
-
const args =
|
|
486
|
-
|
|
487
|
-
|
|
479
|
+
const args = [];
|
|
480
|
+
if (params !== undefined)
|
|
481
|
+
args.push(params);
|
|
482
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarkets`, {
|
|
483
|
+
method: 'POST',
|
|
484
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
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();
|
|
488
492
|
const data = this.handleResponse(json);
|
|
489
493
|
return data.map(convertMarket);
|
|
490
494
|
}
|
|
491
495
|
catch (error) {
|
|
492
|
-
|
|
493
|
-
throw error;
|
|
494
|
-
throw new errors_js_1.PmxtError(`Failed to fetchMarkets: ${error}`);
|
|
496
|
+
throw new Error(`Failed to fetchMarkets: ${error}`);
|
|
495
497
|
}
|
|
496
498
|
}
|
|
497
499
|
async fetchMarketsPaginated(params) {
|
|
498
500
|
await this.initPromise;
|
|
499
501
|
try {
|
|
500
|
-
const args =
|
|
501
|
-
|
|
502
|
-
|
|
502
|
+
const args = [];
|
|
503
|
+
if (params !== undefined)
|
|
504
|
+
args.push(params);
|
|
505
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarketsPaginated`, {
|
|
506
|
+
method: 'POST',
|
|
507
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
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();
|
|
503
515
|
const data = this.handleResponse(json);
|
|
504
516
|
return {
|
|
505
517
|
data: (data.data || []).map(convertMarket),
|
|
@@ -508,70 +520,120 @@ class Exchange {
|
|
|
508
520
|
};
|
|
509
521
|
}
|
|
510
522
|
catch (error) {
|
|
511
|
-
|
|
512
|
-
throw error;
|
|
513
|
-
throw new errors_js_1.PmxtError(`Failed to fetchMarketsPaginated: ${error}`);
|
|
523
|
+
throw new Error(`Failed to fetchMarketsPaginated: ${error}`);
|
|
514
524
|
}
|
|
515
525
|
}
|
|
516
526
|
async fetchEvents(params) {
|
|
517
527
|
await this.initPromise;
|
|
518
528
|
try {
|
|
519
|
-
const args =
|
|
520
|
-
|
|
521
|
-
|
|
529
|
+
const args = [];
|
|
530
|
+
if (params !== undefined)
|
|
531
|
+
args.push(params);
|
|
532
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvents`, {
|
|
533
|
+
method: 'POST',
|
|
534
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
535
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
536
|
+
});
|
|
537
|
+
if (!response.ok) {
|
|
538
|
+
const error = await response.json().catch(() => ({}));
|
|
539
|
+
throw new Error(error.error?.message || response.statusText);
|
|
540
|
+
}
|
|
541
|
+
const json = await response.json();
|
|
522
542
|
const data = this.handleResponse(json);
|
|
523
543
|
return data.map(convertEvent);
|
|
524
544
|
}
|
|
525
545
|
catch (error) {
|
|
526
|
-
|
|
527
|
-
throw error;
|
|
528
|
-
throw new errors_js_1.PmxtError(`Failed to fetchEvents: ${error}`);
|
|
546
|
+
throw new Error(`Failed to fetchEvents: ${error}`);
|
|
529
547
|
}
|
|
530
548
|
}
|
|
531
549
|
async fetchMarket(params) {
|
|
532
550
|
await this.initPromise;
|
|
533
551
|
try {
|
|
534
|
-
const args =
|
|
535
|
-
|
|
536
|
-
|
|
552
|
+
const args = [];
|
|
553
|
+
if (params !== undefined)
|
|
554
|
+
args.push(params);
|
|
555
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarket`, {
|
|
556
|
+
method: 'POST',
|
|
557
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
558
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
559
|
+
});
|
|
560
|
+
if (!response.ok) {
|
|
561
|
+
const error = await response.json().catch(() => ({}));
|
|
562
|
+
throw new Error(error.error?.message || response.statusText);
|
|
563
|
+
}
|
|
564
|
+
const json = await response.json();
|
|
537
565
|
const data = this.handleResponse(json);
|
|
538
566
|
return convertMarket(data);
|
|
539
567
|
}
|
|
540
568
|
catch (error) {
|
|
541
|
-
|
|
542
|
-
throw error;
|
|
543
|
-
throw new errors_js_1.PmxtError(`Failed to fetchMarket: ${error}`);
|
|
569
|
+
throw new Error(`Failed to fetchMarket: ${error}`);
|
|
544
570
|
}
|
|
545
571
|
}
|
|
546
572
|
async fetchEvent(params) {
|
|
547
573
|
await this.initPromise;
|
|
548
574
|
try {
|
|
549
|
-
const args =
|
|
550
|
-
|
|
551
|
-
|
|
575
|
+
const args = [];
|
|
576
|
+
if (params !== undefined)
|
|
577
|
+
args.push(params);
|
|
578
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvent`, {
|
|
579
|
+
method: 'POST',
|
|
580
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
581
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
582
|
+
});
|
|
583
|
+
if (!response.ok) {
|
|
584
|
+
const error = await response.json().catch(() => ({}));
|
|
585
|
+
throw new Error(error.error?.message || response.statusText);
|
|
586
|
+
}
|
|
587
|
+
const json = await response.json();
|
|
552
588
|
const data = this.handleResponse(json);
|
|
553
589
|
return convertEvent(data);
|
|
554
590
|
}
|
|
555
591
|
catch (error) {
|
|
556
|
-
|
|
557
|
-
throw error;
|
|
558
|
-
throw new errors_js_1.PmxtError(`Failed to fetchEvent: ${error}`);
|
|
592
|
+
throw new Error(`Failed to fetchEvent: ${error}`);
|
|
559
593
|
}
|
|
560
594
|
}
|
|
561
595
|
async fetchOrderBook(id) {
|
|
562
596
|
await this.initPromise;
|
|
563
|
-
const resolvedId = resolveOutcomeId(id);
|
|
564
597
|
try {
|
|
565
|
-
const args = [
|
|
566
|
-
|
|
567
|
-
const
|
|
598
|
+
const args = [];
|
|
599
|
+
args.push(id);
|
|
600
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrderBook`, {
|
|
601
|
+
method: 'POST',
|
|
602
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
603
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
604
|
+
});
|
|
605
|
+
if (!response.ok) {
|
|
606
|
+
const error = await response.json().catch(() => ({}));
|
|
607
|
+
throw new Error(error.error?.message || response.statusText);
|
|
608
|
+
}
|
|
609
|
+
const json = await response.json();
|
|
568
610
|
const data = this.handleResponse(json);
|
|
569
611
|
return convertOrderBook(data);
|
|
570
612
|
}
|
|
571
613
|
catch (error) {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
614
|
+
throw new Error(`Failed to fetchOrderBook: ${error}`);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
async submitOrder(built) {
|
|
618
|
+
await this.initPromise;
|
|
619
|
+
try {
|
|
620
|
+
const args = [];
|
|
621
|
+
args.push(built);
|
|
622
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/submitOrder`, {
|
|
623
|
+
method: 'POST',
|
|
624
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
625
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
626
|
+
});
|
|
627
|
+
if (!response.ok) {
|
|
628
|
+
const error = await response.json().catch(() => ({}));
|
|
629
|
+
throw new Error(error.error?.message || response.statusText);
|
|
630
|
+
}
|
|
631
|
+
const json = await response.json();
|
|
632
|
+
const data = this.handleResponse(json);
|
|
633
|
+
return convertOrder(data);
|
|
634
|
+
}
|
|
635
|
+
catch (error) {
|
|
636
|
+
throw new Error(`Failed to submitOrder: ${error}`);
|
|
575
637
|
}
|
|
576
638
|
}
|
|
577
639
|
async cancelOrder(orderId) {
|
|
@@ -585,125 +647,217 @@ class Exchange {
|
|
|
585
647
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
586
648
|
});
|
|
587
649
|
if (!response.ok) {
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
throw (0, errors_js_1.fromServerError)(body.error);
|
|
591
|
-
}
|
|
592
|
-
throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
|
|
650
|
+
const error = await response.json().catch(() => ({}));
|
|
651
|
+
throw new Error(error.error?.message || response.statusText);
|
|
593
652
|
}
|
|
594
653
|
const json = await response.json();
|
|
595
654
|
const data = this.handleResponse(json);
|
|
596
655
|
return convertOrder(data);
|
|
597
656
|
}
|
|
598
657
|
catch (error) {
|
|
599
|
-
|
|
600
|
-
throw error;
|
|
601
|
-
throw new errors_js_1.PmxtError(`Failed to cancelOrder: ${error}`);
|
|
658
|
+
throw new Error(`Failed to cancelOrder: ${error}`);
|
|
602
659
|
}
|
|
603
660
|
}
|
|
604
661
|
async fetchOrder(orderId) {
|
|
605
662
|
await this.initPromise;
|
|
606
663
|
try {
|
|
607
|
-
const args = [
|
|
608
|
-
|
|
609
|
-
const
|
|
664
|
+
const args = [];
|
|
665
|
+
args.push(orderId);
|
|
666
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrder`, {
|
|
667
|
+
method: 'POST',
|
|
668
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
669
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
670
|
+
});
|
|
671
|
+
if (!response.ok) {
|
|
672
|
+
const error = await response.json().catch(() => ({}));
|
|
673
|
+
throw new Error(error.error?.message || response.statusText);
|
|
674
|
+
}
|
|
675
|
+
const json = await response.json();
|
|
610
676
|
const data = this.handleResponse(json);
|
|
611
677
|
return convertOrder(data);
|
|
612
678
|
}
|
|
613
679
|
catch (error) {
|
|
614
|
-
|
|
615
|
-
throw error;
|
|
616
|
-
throw new errors_js_1.PmxtError(`Failed to fetchOrder: ${error}`);
|
|
680
|
+
throw new Error(`Failed to fetchOrder: ${error}`);
|
|
617
681
|
}
|
|
618
682
|
}
|
|
619
683
|
async fetchOpenOrders(marketId) {
|
|
620
684
|
await this.initPromise;
|
|
621
685
|
try {
|
|
622
|
-
const args =
|
|
623
|
-
|
|
624
|
-
|
|
686
|
+
const args = [];
|
|
687
|
+
if (marketId !== undefined)
|
|
688
|
+
args.push(marketId);
|
|
689
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOpenOrders`, {
|
|
690
|
+
method: 'POST',
|
|
691
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
692
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
693
|
+
});
|
|
694
|
+
if (!response.ok) {
|
|
695
|
+
const error = await response.json().catch(() => ({}));
|
|
696
|
+
throw new Error(error.error?.message || response.statusText);
|
|
697
|
+
}
|
|
698
|
+
const json = await response.json();
|
|
625
699
|
const data = this.handleResponse(json);
|
|
626
700
|
return data.map(convertOrder);
|
|
627
701
|
}
|
|
628
702
|
catch (error) {
|
|
629
|
-
|
|
630
|
-
throw error;
|
|
631
|
-
throw new errors_js_1.PmxtError(`Failed to fetchOpenOrders: ${error}`);
|
|
703
|
+
throw new Error(`Failed to fetchOpenOrders: ${error}`);
|
|
632
704
|
}
|
|
633
705
|
}
|
|
634
706
|
async fetchMyTrades(params) {
|
|
635
707
|
await this.initPromise;
|
|
636
708
|
try {
|
|
637
|
-
const args =
|
|
638
|
-
|
|
639
|
-
|
|
709
|
+
const args = [];
|
|
710
|
+
if (params !== undefined)
|
|
711
|
+
args.push(params);
|
|
712
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMyTrades`, {
|
|
713
|
+
method: 'POST',
|
|
714
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
715
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
716
|
+
});
|
|
717
|
+
if (!response.ok) {
|
|
718
|
+
const error = await response.json().catch(() => ({}));
|
|
719
|
+
throw new Error(error.error?.message || response.statusText);
|
|
720
|
+
}
|
|
721
|
+
const json = await response.json();
|
|
640
722
|
const data = this.handleResponse(json);
|
|
641
723
|
return data.map(convertUserTrade);
|
|
642
724
|
}
|
|
643
725
|
catch (error) {
|
|
644
|
-
|
|
645
|
-
throw error;
|
|
646
|
-
throw new errors_js_1.PmxtError(`Failed to fetchMyTrades: ${error}`);
|
|
726
|
+
throw new Error(`Failed to fetchMyTrades: ${error}`);
|
|
647
727
|
}
|
|
648
728
|
}
|
|
649
729
|
async fetchClosedOrders(params) {
|
|
650
730
|
await this.initPromise;
|
|
651
731
|
try {
|
|
652
|
-
const args =
|
|
653
|
-
|
|
654
|
-
|
|
732
|
+
const args = [];
|
|
733
|
+
if (params !== undefined)
|
|
734
|
+
args.push(params);
|
|
735
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchClosedOrders`, {
|
|
736
|
+
method: 'POST',
|
|
737
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
738
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
739
|
+
});
|
|
740
|
+
if (!response.ok) {
|
|
741
|
+
const error = await response.json().catch(() => ({}));
|
|
742
|
+
throw new Error(error.error?.message || response.statusText);
|
|
743
|
+
}
|
|
744
|
+
const json = await response.json();
|
|
655
745
|
const data = this.handleResponse(json);
|
|
656
746
|
return data.map(convertOrder);
|
|
657
747
|
}
|
|
658
748
|
catch (error) {
|
|
659
|
-
|
|
660
|
-
throw error;
|
|
661
|
-
throw new errors_js_1.PmxtError(`Failed to fetchClosedOrders: ${error}`);
|
|
749
|
+
throw new Error(`Failed to fetchClosedOrders: ${error}`);
|
|
662
750
|
}
|
|
663
751
|
}
|
|
664
752
|
async fetchAllOrders(params) {
|
|
665
753
|
await this.initPromise;
|
|
666
754
|
try {
|
|
667
|
-
const args =
|
|
668
|
-
|
|
669
|
-
|
|
755
|
+
const args = [];
|
|
756
|
+
if (params !== undefined)
|
|
757
|
+
args.push(params);
|
|
758
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchAllOrders`, {
|
|
759
|
+
method: 'POST',
|
|
760
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
761
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
762
|
+
});
|
|
763
|
+
if (!response.ok) {
|
|
764
|
+
const error = await response.json().catch(() => ({}));
|
|
765
|
+
throw new Error(error.error?.message || response.statusText);
|
|
766
|
+
}
|
|
767
|
+
const json = await response.json();
|
|
670
768
|
const data = this.handleResponse(json);
|
|
671
769
|
return data.map(convertOrder);
|
|
672
770
|
}
|
|
673
771
|
catch (error) {
|
|
674
|
-
|
|
675
|
-
throw error;
|
|
676
|
-
throw new errors_js_1.PmxtError(`Failed to fetchAllOrders: ${error}`);
|
|
772
|
+
throw new Error(`Failed to fetchAllOrders: ${error}`);
|
|
677
773
|
}
|
|
678
774
|
}
|
|
679
775
|
async fetchPositions(address) {
|
|
680
776
|
await this.initPromise;
|
|
681
777
|
try {
|
|
682
|
-
const args =
|
|
683
|
-
|
|
684
|
-
|
|
778
|
+
const args = [];
|
|
779
|
+
if (address !== undefined)
|
|
780
|
+
args.push(address);
|
|
781
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchPositions`, {
|
|
782
|
+
method: 'POST',
|
|
783
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
784
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
785
|
+
});
|
|
786
|
+
if (!response.ok) {
|
|
787
|
+
const error = await response.json().catch(() => ({}));
|
|
788
|
+
throw new Error(error.error?.message || response.statusText);
|
|
789
|
+
}
|
|
790
|
+
const json = await response.json();
|
|
685
791
|
const data = this.handleResponse(json);
|
|
686
792
|
return data.map(convertPosition);
|
|
687
793
|
}
|
|
688
794
|
catch (error) {
|
|
689
|
-
|
|
690
|
-
throw error;
|
|
691
|
-
throw new errors_js_1.PmxtError(`Failed to fetchPositions: ${error}`);
|
|
795
|
+
throw new Error(`Failed to fetchPositions: ${error}`);
|
|
692
796
|
}
|
|
693
797
|
}
|
|
694
798
|
async fetchBalance(address) {
|
|
695
799
|
await this.initPromise;
|
|
696
800
|
try {
|
|
697
|
-
const args =
|
|
698
|
-
|
|
699
|
-
|
|
801
|
+
const args = [];
|
|
802
|
+
if (address !== undefined)
|
|
803
|
+
args.push(address);
|
|
804
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchBalance`, {
|
|
805
|
+
method: 'POST',
|
|
806
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
807
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
808
|
+
});
|
|
809
|
+
if (!response.ok) {
|
|
810
|
+
const error = await response.json().catch(() => ({}));
|
|
811
|
+
throw new Error(error.error?.message || response.statusText);
|
|
812
|
+
}
|
|
813
|
+
const json = await response.json();
|
|
700
814
|
const data = this.handleResponse(json);
|
|
701
815
|
return data.map(convertBalance);
|
|
702
816
|
}
|
|
703
817
|
catch (error) {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
818
|
+
throw new Error(`Failed to fetchBalance: ${error}`);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
async unwatchOrderBook(id) {
|
|
822
|
+
await this.initPromise;
|
|
823
|
+
try {
|
|
824
|
+
const args = [];
|
|
825
|
+
args.push(id);
|
|
826
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/unwatchOrderBook`, {
|
|
827
|
+
method: 'POST',
|
|
828
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
829
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
830
|
+
});
|
|
831
|
+
if (!response.ok) {
|
|
832
|
+
const error = await response.json().catch(() => ({}));
|
|
833
|
+
throw new Error(error.error?.message || response.statusText);
|
|
834
|
+
}
|
|
835
|
+
const json = await response.json();
|
|
836
|
+
this.handleResponse(json);
|
|
837
|
+
}
|
|
838
|
+
catch (error) {
|
|
839
|
+
throw new Error(`Failed to unwatchOrderBook: ${error}`);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
async unwatchAddress(address) {
|
|
843
|
+
await this.initPromise;
|
|
844
|
+
try {
|
|
845
|
+
const args = [];
|
|
846
|
+
args.push(address);
|
|
847
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/unwatchAddress`, {
|
|
848
|
+
method: 'POST',
|
|
849
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
850
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
851
|
+
});
|
|
852
|
+
if (!response.ok) {
|
|
853
|
+
const error = await response.json().catch(() => ({}));
|
|
854
|
+
throw new Error(error.error?.message || response.statusText);
|
|
855
|
+
}
|
|
856
|
+
const json = await response.json();
|
|
857
|
+
this.handleResponse(json);
|
|
858
|
+
}
|
|
859
|
+
catch (error) {
|
|
860
|
+
throw new Error(`Failed to unwatchAddress: ${error}`);
|
|
707
861
|
}
|
|
708
862
|
}
|
|
709
863
|
async close() {
|
|
@@ -716,19 +870,14 @@ class Exchange {
|
|
|
716
870
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
717
871
|
});
|
|
718
872
|
if (!response.ok) {
|
|
719
|
-
const
|
|
720
|
-
|
|
721
|
-
throw (0, errors_js_1.fromServerError)(body.error);
|
|
722
|
-
}
|
|
723
|
-
throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
|
|
873
|
+
const error = await response.json().catch(() => ({}));
|
|
874
|
+
throw new Error(error.error?.message || response.statusText);
|
|
724
875
|
}
|
|
725
876
|
const json = await response.json();
|
|
726
877
|
this.handleResponse(json);
|
|
727
878
|
}
|
|
728
879
|
catch (error) {
|
|
729
|
-
|
|
730
|
-
throw error;
|
|
731
|
-
throw new errors_js_1.PmxtError(`Failed to close: ${error}`);
|
|
880
|
+
throw new Error(`Failed to close: ${error}`);
|
|
732
881
|
}
|
|
733
882
|
}
|
|
734
883
|
// END GENERATED METHODS
|
|
@@ -855,37 +1004,6 @@ class Exchange {
|
|
|
855
1004
|
throw new errors_js_1.PmxtError(`Failed to watch order book: ${error}`);
|
|
856
1005
|
}
|
|
857
1006
|
}
|
|
858
|
-
/**
|
|
859
|
-
* Unsubscribe from a previously watched order book stream.
|
|
860
|
-
*
|
|
861
|
-
* @param outcomeId - Outcome ID to stop watching
|
|
862
|
-
*/
|
|
863
|
-
async unwatchOrderBook(outcomeId) {
|
|
864
|
-
await this.initPromise;
|
|
865
|
-
const resolvedOutcomeId = resolveOutcomeId(outcomeId);
|
|
866
|
-
try {
|
|
867
|
-
const args = [resolvedOutcomeId];
|
|
868
|
-
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/unwatchOrderBook`, {
|
|
869
|
-
method: 'POST',
|
|
870
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
871
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
872
|
-
});
|
|
873
|
-
if (!response.ok) {
|
|
874
|
-
const body = await response.json().catch(() => ({}));
|
|
875
|
-
if (body.error && typeof body.error === "object") {
|
|
876
|
-
throw (0, errors_js_1.fromServerError)(body.error);
|
|
877
|
-
}
|
|
878
|
-
throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
|
|
879
|
-
}
|
|
880
|
-
const json = await response.json();
|
|
881
|
-
this.handleResponse(json);
|
|
882
|
-
}
|
|
883
|
-
catch (error) {
|
|
884
|
-
if (error instanceof errors_js_1.PmxtError)
|
|
885
|
-
throw error;
|
|
886
|
-
throw new errors_js_1.PmxtError(`Failed to unwatch order book: ${error}`);
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
1007
|
/**
|
|
890
1008
|
* Watch real-time trade updates via WebSocket.
|
|
891
1009
|
*
|
|
@@ -995,37 +1113,6 @@ class Exchange {
|
|
|
995
1113
|
throw new errors_js_1.PmxtError(`Failed to watch address: ${error}`);
|
|
996
1114
|
}
|
|
997
1115
|
}
|
|
998
|
-
/**
|
|
999
|
-
* Stop watching a previously registered wallet address and release its resource updates.
|
|
1000
|
-
*
|
|
1001
|
-
* @param address - Public wallet to be watched
|
|
1002
|
-
* @returns
|
|
1003
|
-
*/
|
|
1004
|
-
async unwatchAddress(address) {
|
|
1005
|
-
await this.initPromise;
|
|
1006
|
-
try {
|
|
1007
|
-
const args = [address];
|
|
1008
|
-
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/unwatchAddress`, {
|
|
1009
|
-
method: 'POST',
|
|
1010
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
1011
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
1012
|
-
});
|
|
1013
|
-
if (!response.ok) {
|
|
1014
|
-
const body = await response.json().catch(() => ({}));
|
|
1015
|
-
if (body.error && typeof body.error === "object") {
|
|
1016
|
-
throw (0, errors_js_1.fromServerError)(body.error);
|
|
1017
|
-
}
|
|
1018
|
-
throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
|
|
1019
|
-
}
|
|
1020
|
-
const json = await response.json();
|
|
1021
|
-
return this.handleResponse(json);
|
|
1022
|
-
}
|
|
1023
|
-
catch (error) {
|
|
1024
|
-
if (error instanceof errors_js_1.PmxtError)
|
|
1025
|
-
throw error;
|
|
1026
|
-
throw new errors_js_1.PmxtError(`Failed to unwatch address: ${error}`);
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
1116
|
// Trading Methods (require authentication)
|
|
1030
1117
|
/**
|
|
1031
1118
|
* Build an order payload without submitting it to the exchange.
|
|
@@ -1114,50 +1201,6 @@ class Exchange {
|
|
|
1114
1201
|
throw new errors_js_1.PmxtError(`Failed to build order: ${error}`);
|
|
1115
1202
|
}
|
|
1116
1203
|
}
|
|
1117
|
-
/**
|
|
1118
|
-
* Submit a pre-built order returned by {@link buildOrder}.
|
|
1119
|
-
*
|
|
1120
|
-
* @param built - The BuiltOrder payload from buildOrder()
|
|
1121
|
-
* @returns The submitted order
|
|
1122
|
-
*
|
|
1123
|
-
* @example
|
|
1124
|
-
* ```typescript
|
|
1125
|
-
* const built = await exchange.buildOrder({
|
|
1126
|
-
* outcome: market.yes,
|
|
1127
|
-
* side: "buy",
|
|
1128
|
-
* type: "limit",
|
|
1129
|
-
* amount: 10,
|
|
1130
|
-
* price: 0.55
|
|
1131
|
-
* });
|
|
1132
|
-
* const order = await exchange.submitOrder(built);
|
|
1133
|
-
* console.log(order.id, order.status);
|
|
1134
|
-
* ```
|
|
1135
|
-
*/
|
|
1136
|
-
async submitOrder(built) {
|
|
1137
|
-
await this.initPromise;
|
|
1138
|
-
try {
|
|
1139
|
-
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/submitOrder`, {
|
|
1140
|
-
method: 'POST',
|
|
1141
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
1142
|
-
body: JSON.stringify({ args: [built], credentials: this.getCredentials() }),
|
|
1143
|
-
});
|
|
1144
|
-
if (!response.ok) {
|
|
1145
|
-
const body = await response.json().catch(() => ({}));
|
|
1146
|
-
if (body.error && typeof body.error === "object") {
|
|
1147
|
-
throw (0, errors_js_1.fromServerError)(body.error);
|
|
1148
|
-
}
|
|
1149
|
-
throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
|
|
1150
|
-
}
|
|
1151
|
-
const json = await response.json();
|
|
1152
|
-
const data = this.handleResponse(json);
|
|
1153
|
-
return convertOrder(data);
|
|
1154
|
-
}
|
|
1155
|
-
catch (error) {
|
|
1156
|
-
if (error instanceof errors_js_1.PmxtError)
|
|
1157
|
-
throw error;
|
|
1158
|
-
throw new errors_js_1.PmxtError(`Failed to submit order: ${error}`);
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
1204
|
/**
|
|
1162
1205
|
* Create a new order.
|
|
1163
1206
|
*
|