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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmxtjs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.32.2",
|
|
4
4
|
"description": "Unified prediction market data API - The ccxt for prediction markets",
|
|
5
5
|
"author": "PMXT Contributors",
|
|
6
6
|
"repository": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"unified"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"pmxt-core": "2.
|
|
46
|
+
"pmxt-core": "2.32.2"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/jest": "^30.0.0",
|
package/pmxt/client.ts
CHANGED
|
@@ -585,11 +585,8 @@ export abstract class Exchange {
|
|
|
585
585
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
586
586
|
});
|
|
587
587
|
if (!response.ok) {
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
throw fromServerError(body.error);
|
|
591
|
-
}
|
|
592
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
588
|
+
const error = await response.json().catch(() => ({}));
|
|
589
|
+
throw new Error(error.error?.message || response.statusText);
|
|
593
590
|
}
|
|
594
591
|
const json = await response.json();
|
|
595
592
|
const data = this.handleResponse(json);
|
|
@@ -599,31 +596,47 @@ export abstract class Exchange {
|
|
|
599
596
|
}
|
|
600
597
|
return result;
|
|
601
598
|
} catch (error) {
|
|
602
|
-
|
|
603
|
-
throw new PmxtError(`Failed to loadMarkets: ${error}`);
|
|
599
|
+
throw new Error(`Failed to loadMarkets: ${error}`);
|
|
604
600
|
}
|
|
605
601
|
}
|
|
606
602
|
|
|
607
603
|
async fetchMarkets(params?: any): Promise<UnifiedMarket[]> {
|
|
608
604
|
await this.initPromise;
|
|
609
605
|
try {
|
|
610
|
-
const args =
|
|
611
|
-
|
|
612
|
-
const
|
|
606
|
+
const args: any[] = [];
|
|
607
|
+
if (params !== undefined) args.push(params);
|
|
608
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarkets`, {
|
|
609
|
+
method: 'POST',
|
|
610
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
611
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
612
|
+
});
|
|
613
|
+
if (!response.ok) {
|
|
614
|
+
const error = await response.json().catch(() => ({}));
|
|
615
|
+
throw new Error(error.error?.message || response.statusText);
|
|
616
|
+
}
|
|
617
|
+
const json = await response.json();
|
|
613
618
|
const data = this.handleResponse(json);
|
|
614
619
|
return data.map(convertMarket);
|
|
615
620
|
} catch (error) {
|
|
616
|
-
|
|
617
|
-
throw new PmxtError(`Failed to fetchMarkets: ${error}`);
|
|
621
|
+
throw new Error(`Failed to fetchMarkets: ${error}`);
|
|
618
622
|
}
|
|
619
623
|
}
|
|
620
624
|
|
|
621
625
|
async fetchMarketsPaginated(params?: any): Promise<PaginatedMarketsResult> {
|
|
622
626
|
await this.initPromise;
|
|
623
627
|
try {
|
|
624
|
-
const args =
|
|
625
|
-
|
|
626
|
-
const
|
|
628
|
+
const args: any[] = [];
|
|
629
|
+
if (params !== undefined) args.push(params);
|
|
630
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarketsPaginated`, {
|
|
631
|
+
method: 'POST',
|
|
632
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
633
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
634
|
+
});
|
|
635
|
+
if (!response.ok) {
|
|
636
|
+
const error = await response.json().catch(() => ({}));
|
|
637
|
+
throw new Error(error.error?.message || response.statusText);
|
|
638
|
+
}
|
|
639
|
+
const json = await response.json();
|
|
627
640
|
const data = this.handleResponse(json);
|
|
628
641
|
return {
|
|
629
642
|
data: (data.data || []).map(convertMarket),
|
|
@@ -631,68 +644,119 @@ export abstract class Exchange {
|
|
|
631
644
|
nextCursor: data.nextCursor,
|
|
632
645
|
};
|
|
633
646
|
} catch (error) {
|
|
634
|
-
|
|
635
|
-
throw new PmxtError(`Failed to fetchMarketsPaginated: ${error}`);
|
|
647
|
+
throw new Error(`Failed to fetchMarketsPaginated: ${error}`);
|
|
636
648
|
}
|
|
637
649
|
}
|
|
638
650
|
|
|
639
651
|
async fetchEvents(params?: any): Promise<UnifiedEvent[]> {
|
|
640
652
|
await this.initPromise;
|
|
641
653
|
try {
|
|
642
|
-
const args =
|
|
643
|
-
|
|
644
|
-
const
|
|
654
|
+
const args: any[] = [];
|
|
655
|
+
if (params !== undefined) args.push(params);
|
|
656
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvents`, {
|
|
657
|
+
method: 'POST',
|
|
658
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
659
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
660
|
+
});
|
|
661
|
+
if (!response.ok) {
|
|
662
|
+
const error = await response.json().catch(() => ({}));
|
|
663
|
+
throw new Error(error.error?.message || response.statusText);
|
|
664
|
+
}
|
|
665
|
+
const json = await response.json();
|
|
645
666
|
const data = this.handleResponse(json);
|
|
646
667
|
return data.map(convertEvent);
|
|
647
668
|
} catch (error) {
|
|
648
|
-
|
|
649
|
-
throw new PmxtError(`Failed to fetchEvents: ${error}`);
|
|
669
|
+
throw new Error(`Failed to fetchEvents: ${error}`);
|
|
650
670
|
}
|
|
651
671
|
}
|
|
652
672
|
|
|
653
673
|
async fetchMarket(params?: any): Promise<UnifiedMarket> {
|
|
654
674
|
await this.initPromise;
|
|
655
675
|
try {
|
|
656
|
-
const args =
|
|
657
|
-
|
|
658
|
-
const
|
|
676
|
+
const args: any[] = [];
|
|
677
|
+
if (params !== undefined) args.push(params);
|
|
678
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarket`, {
|
|
679
|
+
method: 'POST',
|
|
680
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
681
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
682
|
+
});
|
|
683
|
+
if (!response.ok) {
|
|
684
|
+
const error = await response.json().catch(() => ({}));
|
|
685
|
+
throw new Error(error.error?.message || response.statusText);
|
|
686
|
+
}
|
|
687
|
+
const json = await response.json();
|
|
659
688
|
const data = this.handleResponse(json);
|
|
660
689
|
return convertMarket(data);
|
|
661
690
|
} catch (error) {
|
|
662
|
-
|
|
663
|
-
throw new PmxtError(`Failed to fetchMarket: ${error}`);
|
|
691
|
+
throw new Error(`Failed to fetchMarket: ${error}`);
|
|
664
692
|
}
|
|
665
693
|
}
|
|
666
694
|
|
|
667
695
|
async fetchEvent(params?: any): Promise<UnifiedEvent> {
|
|
668
696
|
await this.initPromise;
|
|
669
697
|
try {
|
|
670
|
-
const args =
|
|
671
|
-
|
|
672
|
-
const
|
|
698
|
+
const args: any[] = [];
|
|
699
|
+
if (params !== undefined) args.push(params);
|
|
700
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvent`, {
|
|
701
|
+
method: 'POST',
|
|
702
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
703
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
704
|
+
});
|
|
705
|
+
if (!response.ok) {
|
|
706
|
+
const error = await response.json().catch(() => ({}));
|
|
707
|
+
throw new Error(error.error?.message || response.statusText);
|
|
708
|
+
}
|
|
709
|
+
const json = await response.json();
|
|
673
710
|
const data = this.handleResponse(json);
|
|
674
711
|
return convertEvent(data);
|
|
675
712
|
} catch (error) {
|
|
676
|
-
|
|
677
|
-
throw new PmxtError(`Failed to fetchEvent: ${error}`);
|
|
713
|
+
throw new Error(`Failed to fetchEvent: ${error}`);
|
|
678
714
|
}
|
|
679
715
|
}
|
|
680
716
|
|
|
681
|
-
async fetchOrderBook(id: string
|
|
717
|
+
async fetchOrderBook(id: string): Promise<OrderBook> {
|
|
682
718
|
await this.initPromise;
|
|
683
|
-
const resolvedId = resolveOutcomeId(id);
|
|
684
719
|
try {
|
|
685
|
-
const args: any[] = [
|
|
686
|
-
|
|
687
|
-
const
|
|
720
|
+
const args: any[] = [];
|
|
721
|
+
args.push(id);
|
|
722
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrderBook`, {
|
|
723
|
+
method: 'POST',
|
|
724
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
725
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
726
|
+
});
|
|
727
|
+
if (!response.ok) {
|
|
728
|
+
const error = await response.json().catch(() => ({}));
|
|
729
|
+
throw new Error(error.error?.message || response.statusText);
|
|
730
|
+
}
|
|
731
|
+
const json = await response.json();
|
|
688
732
|
const data = this.handleResponse(json);
|
|
689
733
|
return convertOrderBook(data);
|
|
690
734
|
} catch (error) {
|
|
691
|
-
|
|
692
|
-
throw new PmxtError(`Failed to fetchOrderBook: ${error}`);
|
|
735
|
+
throw new Error(`Failed to fetchOrderBook: ${error}`);
|
|
693
736
|
}
|
|
694
737
|
}
|
|
695
738
|
|
|
739
|
+
async submitOrder(built: BuiltOrder): Promise<Order> {
|
|
740
|
+
await this.initPromise;
|
|
741
|
+
try {
|
|
742
|
+
const args: any[] = [];
|
|
743
|
+
args.push(built);
|
|
744
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/submitOrder`, {
|
|
745
|
+
method: 'POST',
|
|
746
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
747
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
748
|
+
});
|
|
749
|
+
if (!response.ok) {
|
|
750
|
+
const error = await response.json().catch(() => ({}));
|
|
751
|
+
throw new Error(error.error?.message || response.statusText);
|
|
752
|
+
}
|
|
753
|
+
const json = await response.json();
|
|
754
|
+
const data = this.handleResponse(json);
|
|
755
|
+
return convertOrder(data);
|
|
756
|
+
} catch (error) {
|
|
757
|
+
throw new Error(`Failed to submitOrder: ${error}`);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
696
760
|
|
|
697
761
|
async cancelOrder(orderId: string): Promise<Order> {
|
|
698
762
|
await this.initPromise;
|
|
@@ -705,116 +769,210 @@ export abstract class Exchange {
|
|
|
705
769
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
706
770
|
});
|
|
707
771
|
if (!response.ok) {
|
|
708
|
-
const
|
|
709
|
-
|
|
710
|
-
throw fromServerError(body.error);
|
|
711
|
-
}
|
|
712
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
772
|
+
const error = await response.json().catch(() => ({}));
|
|
773
|
+
throw new Error(error.error?.message || response.statusText);
|
|
713
774
|
}
|
|
714
775
|
const json = await response.json();
|
|
715
776
|
const data = this.handleResponse(json);
|
|
716
777
|
return convertOrder(data);
|
|
717
778
|
} catch (error) {
|
|
718
|
-
|
|
719
|
-
throw new PmxtError(`Failed to cancelOrder: ${error}`);
|
|
779
|
+
throw new Error(`Failed to cancelOrder: ${error}`);
|
|
720
780
|
}
|
|
721
781
|
}
|
|
722
782
|
|
|
723
783
|
async fetchOrder(orderId: string): Promise<Order> {
|
|
724
784
|
await this.initPromise;
|
|
725
785
|
try {
|
|
726
|
-
const args: any[] = [
|
|
727
|
-
|
|
728
|
-
const
|
|
786
|
+
const args: any[] = [];
|
|
787
|
+
args.push(orderId);
|
|
788
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrder`, {
|
|
789
|
+
method: 'POST',
|
|
790
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
791
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
792
|
+
});
|
|
793
|
+
if (!response.ok) {
|
|
794
|
+
const error = await response.json().catch(() => ({}));
|
|
795
|
+
throw new Error(error.error?.message || response.statusText);
|
|
796
|
+
}
|
|
797
|
+
const json = await response.json();
|
|
729
798
|
const data = this.handleResponse(json);
|
|
730
799
|
return convertOrder(data);
|
|
731
800
|
} catch (error) {
|
|
732
|
-
|
|
733
|
-
throw new PmxtError(`Failed to fetchOrder: ${error}`);
|
|
801
|
+
throw new Error(`Failed to fetchOrder: ${error}`);
|
|
734
802
|
}
|
|
735
803
|
}
|
|
736
804
|
|
|
737
805
|
async fetchOpenOrders(marketId?: string): Promise<Order[]> {
|
|
738
806
|
await this.initPromise;
|
|
739
807
|
try {
|
|
740
|
-
const args =
|
|
741
|
-
|
|
742
|
-
const
|
|
808
|
+
const args: any[] = [];
|
|
809
|
+
if (marketId !== undefined) args.push(marketId);
|
|
810
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOpenOrders`, {
|
|
811
|
+
method: 'POST',
|
|
812
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
813
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
814
|
+
});
|
|
815
|
+
if (!response.ok) {
|
|
816
|
+
const error = await response.json().catch(() => ({}));
|
|
817
|
+
throw new Error(error.error?.message || response.statusText);
|
|
818
|
+
}
|
|
819
|
+
const json = await response.json();
|
|
743
820
|
const data = this.handleResponse(json);
|
|
744
821
|
return data.map(convertOrder);
|
|
745
822
|
} catch (error) {
|
|
746
|
-
|
|
747
|
-
throw new PmxtError(`Failed to fetchOpenOrders: ${error}`);
|
|
823
|
+
throw new Error(`Failed to fetchOpenOrders: ${error}`);
|
|
748
824
|
}
|
|
749
825
|
}
|
|
750
826
|
|
|
751
827
|
async fetchMyTrades(params?: any): Promise<UserTrade[]> {
|
|
752
828
|
await this.initPromise;
|
|
753
829
|
try {
|
|
754
|
-
const args =
|
|
755
|
-
|
|
756
|
-
const
|
|
830
|
+
const args: any[] = [];
|
|
831
|
+
if (params !== undefined) args.push(params);
|
|
832
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMyTrades`, {
|
|
833
|
+
method: 'POST',
|
|
834
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
835
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
836
|
+
});
|
|
837
|
+
if (!response.ok) {
|
|
838
|
+
const error = await response.json().catch(() => ({}));
|
|
839
|
+
throw new Error(error.error?.message || response.statusText);
|
|
840
|
+
}
|
|
841
|
+
const json = await response.json();
|
|
757
842
|
const data = this.handleResponse(json);
|
|
758
843
|
return data.map(convertUserTrade);
|
|
759
844
|
} catch (error) {
|
|
760
|
-
|
|
761
|
-
throw new PmxtError(`Failed to fetchMyTrades: ${error}`);
|
|
845
|
+
throw new Error(`Failed to fetchMyTrades: ${error}`);
|
|
762
846
|
}
|
|
763
847
|
}
|
|
764
848
|
|
|
765
849
|
async fetchClosedOrders(params?: any): Promise<Order[]> {
|
|
766
850
|
await this.initPromise;
|
|
767
851
|
try {
|
|
768
|
-
const args =
|
|
769
|
-
|
|
770
|
-
const
|
|
852
|
+
const args: any[] = [];
|
|
853
|
+
if (params !== undefined) args.push(params);
|
|
854
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchClosedOrders`, {
|
|
855
|
+
method: 'POST',
|
|
856
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
857
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
858
|
+
});
|
|
859
|
+
if (!response.ok) {
|
|
860
|
+
const error = await response.json().catch(() => ({}));
|
|
861
|
+
throw new Error(error.error?.message || response.statusText);
|
|
862
|
+
}
|
|
863
|
+
const json = await response.json();
|
|
771
864
|
const data = this.handleResponse(json);
|
|
772
865
|
return data.map(convertOrder);
|
|
773
866
|
} catch (error) {
|
|
774
|
-
|
|
775
|
-
throw new PmxtError(`Failed to fetchClosedOrders: ${error}`);
|
|
867
|
+
throw new Error(`Failed to fetchClosedOrders: ${error}`);
|
|
776
868
|
}
|
|
777
869
|
}
|
|
778
870
|
|
|
779
871
|
async fetchAllOrders(params?: any): Promise<Order[]> {
|
|
780
872
|
await this.initPromise;
|
|
781
873
|
try {
|
|
782
|
-
const args =
|
|
783
|
-
|
|
784
|
-
const
|
|
874
|
+
const args: any[] = [];
|
|
875
|
+
if (params !== undefined) args.push(params);
|
|
876
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchAllOrders`, {
|
|
877
|
+
method: 'POST',
|
|
878
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
879
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
880
|
+
});
|
|
881
|
+
if (!response.ok) {
|
|
882
|
+
const error = await response.json().catch(() => ({}));
|
|
883
|
+
throw new Error(error.error?.message || response.statusText);
|
|
884
|
+
}
|
|
885
|
+
const json = await response.json();
|
|
785
886
|
const data = this.handleResponse(json);
|
|
786
887
|
return data.map(convertOrder);
|
|
787
888
|
} catch (error) {
|
|
788
|
-
|
|
789
|
-
throw new PmxtError(`Failed to fetchAllOrders: ${error}`);
|
|
889
|
+
throw new Error(`Failed to fetchAllOrders: ${error}`);
|
|
790
890
|
}
|
|
791
891
|
}
|
|
792
892
|
|
|
793
893
|
async fetchPositions(address?: string): Promise<Position[]> {
|
|
794
894
|
await this.initPromise;
|
|
795
895
|
try {
|
|
796
|
-
const args: any[] =
|
|
797
|
-
|
|
798
|
-
const
|
|
896
|
+
const args: any[] = [];
|
|
897
|
+
if (address !== undefined) args.push(address);
|
|
898
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchPositions`, {
|
|
899
|
+
method: 'POST',
|
|
900
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
901
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
902
|
+
});
|
|
903
|
+
if (!response.ok) {
|
|
904
|
+
const error = await response.json().catch(() => ({}));
|
|
905
|
+
throw new Error(error.error?.message || response.statusText);
|
|
906
|
+
}
|
|
907
|
+
const json = await response.json();
|
|
799
908
|
const data = this.handleResponse(json);
|
|
800
909
|
return data.map(convertPosition);
|
|
801
910
|
} catch (error) {
|
|
802
|
-
|
|
803
|
-
throw new PmxtError(`Failed to fetchPositions: ${error}`);
|
|
911
|
+
throw new Error(`Failed to fetchPositions: ${error}`);
|
|
804
912
|
}
|
|
805
913
|
}
|
|
806
914
|
|
|
807
915
|
async fetchBalance(address?: string): Promise<Balance[]> {
|
|
808
916
|
await this.initPromise;
|
|
809
917
|
try {
|
|
810
|
-
const args: any[] =
|
|
811
|
-
|
|
812
|
-
const
|
|
918
|
+
const args: any[] = [];
|
|
919
|
+
if (address !== undefined) args.push(address);
|
|
920
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchBalance`, {
|
|
921
|
+
method: 'POST',
|
|
922
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
923
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
924
|
+
});
|
|
925
|
+
if (!response.ok) {
|
|
926
|
+
const error = await response.json().catch(() => ({}));
|
|
927
|
+
throw new Error(error.error?.message || response.statusText);
|
|
928
|
+
}
|
|
929
|
+
const json = await response.json();
|
|
813
930
|
const data = this.handleResponse(json);
|
|
814
931
|
return data.map(convertBalance);
|
|
815
932
|
} catch (error) {
|
|
816
|
-
|
|
817
|
-
|
|
933
|
+
throw new Error(`Failed to fetchBalance: ${error}`);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
async unwatchOrderBook(id: string): Promise<void> {
|
|
938
|
+
await this.initPromise;
|
|
939
|
+
try {
|
|
940
|
+
const args: any[] = [];
|
|
941
|
+
args.push(id);
|
|
942
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/unwatchOrderBook`, {
|
|
943
|
+
method: 'POST',
|
|
944
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
945
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
946
|
+
});
|
|
947
|
+
if (!response.ok) {
|
|
948
|
+
const error = await response.json().catch(() => ({}));
|
|
949
|
+
throw new Error(error.error?.message || response.statusText);
|
|
950
|
+
}
|
|
951
|
+
const json = await response.json();
|
|
952
|
+
this.handleResponse(json);
|
|
953
|
+
} catch (error) {
|
|
954
|
+
throw new Error(`Failed to unwatchOrderBook: ${error}`);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
async unwatchAddress(address: string): Promise<void> {
|
|
959
|
+
await this.initPromise;
|
|
960
|
+
try {
|
|
961
|
+
const args: any[] = [];
|
|
962
|
+
args.push(address);
|
|
963
|
+
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/unwatchAddress`, {
|
|
964
|
+
method: 'POST',
|
|
965
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
966
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
967
|
+
});
|
|
968
|
+
if (!response.ok) {
|
|
969
|
+
const error = await response.json().catch(() => ({}));
|
|
970
|
+
throw new Error(error.error?.message || response.statusText);
|
|
971
|
+
}
|
|
972
|
+
const json = await response.json();
|
|
973
|
+
this.handleResponse(json);
|
|
974
|
+
} catch (error) {
|
|
975
|
+
throw new Error(`Failed to unwatchAddress: ${error}`);
|
|
818
976
|
}
|
|
819
977
|
}
|
|
820
978
|
|
|
@@ -828,17 +986,13 @@ export abstract class Exchange {
|
|
|
828
986
|
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
829
987
|
});
|
|
830
988
|
if (!response.ok) {
|
|
831
|
-
const
|
|
832
|
-
|
|
833
|
-
throw fromServerError(body.error);
|
|
834
|
-
}
|
|
835
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
989
|
+
const error = await response.json().catch(() => ({}));
|
|
990
|
+
throw new Error(error.error?.message || response.statusText);
|
|
836
991
|
}
|
|
837
992
|
const json = await response.json();
|
|
838
993
|
this.handleResponse(json);
|
|
839
994
|
} catch (error) {
|
|
840
|
-
|
|
841
|
-
throw new PmxtError(`Failed to close: ${error}`);
|
|
995
|
+
throw new Error(`Failed to close: ${error}`);
|
|
842
996
|
}
|
|
843
997
|
}
|
|
844
998
|
|
|
@@ -974,37 +1128,6 @@ export abstract class Exchange {
|
|
|
974
1128
|
}
|
|
975
1129
|
}
|
|
976
1130
|
|
|
977
|
-
/**
|
|
978
|
-
* Unsubscribe from a previously watched order book stream.
|
|
979
|
-
*
|
|
980
|
-
* @param outcomeId - Outcome ID to stop watching
|
|
981
|
-
*/
|
|
982
|
-
async unwatchOrderBook(outcomeId: string | MarketOutcome): Promise<void> {
|
|
983
|
-
await this.initPromise;
|
|
984
|
-
const resolvedOutcomeId = resolveOutcomeId(outcomeId);
|
|
985
|
-
try {
|
|
986
|
-
const args: any[] = [resolvedOutcomeId];
|
|
987
|
-
|
|
988
|
-
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/unwatchOrderBook`, {
|
|
989
|
-
method: 'POST',
|
|
990
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
991
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
992
|
-
});
|
|
993
|
-
if (!response.ok) {
|
|
994
|
-
const body = await response.json().catch(() => ({}));
|
|
995
|
-
if (body.error && typeof body.error === "object") {
|
|
996
|
-
throw fromServerError(body.error);
|
|
997
|
-
}
|
|
998
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
999
|
-
}
|
|
1000
|
-
const json = await response.json();
|
|
1001
|
-
this.handleResponse(json);
|
|
1002
|
-
} catch (error) {
|
|
1003
|
-
if (error instanceof PmxtError) throw error;
|
|
1004
|
-
throw new PmxtError(`Failed to unwatch order book: ${error}`);
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
1131
|
/**
|
|
1009
1132
|
* Watch real-time trade updates via WebSocket.
|
|
1010
1133
|
*
|
|
@@ -1121,39 +1244,6 @@ export abstract class Exchange {
|
|
|
1121
1244
|
}
|
|
1122
1245
|
}
|
|
1123
1246
|
|
|
1124
|
-
/**
|
|
1125
|
-
* Stop watching a previously registered wallet address and release its resource updates.
|
|
1126
|
-
*
|
|
1127
|
-
* @param address - Public wallet to be watched
|
|
1128
|
-
* @returns
|
|
1129
|
-
*/
|
|
1130
|
-
async unwatchAddress(
|
|
1131
|
-
address: string,
|
|
1132
|
-
): Promise<Trade[]> {
|
|
1133
|
-
await this.initPromise;
|
|
1134
|
-
try {
|
|
1135
|
-
const args: any[] = [address];
|
|
1136
|
-
|
|
1137
|
-
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/unwatchAddress`, {
|
|
1138
|
-
method: 'POST',
|
|
1139
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
1140
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
1141
|
-
});
|
|
1142
|
-
if (!response.ok) {
|
|
1143
|
-
const body = await response.json().catch(() => ({}));
|
|
1144
|
-
if (body.error && typeof body.error === "object") {
|
|
1145
|
-
throw fromServerError(body.error);
|
|
1146
|
-
}
|
|
1147
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
1148
|
-
}
|
|
1149
|
-
const json = await response.json();
|
|
1150
|
-
return this.handleResponse(json);
|
|
1151
|
-
} catch (error) {
|
|
1152
|
-
if (error instanceof PmxtError) throw error;
|
|
1153
|
-
throw new PmxtError(`Failed to unwatch address: ${error}`);
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
1247
|
// Trading Methods (require authentication)
|
|
1158
1248
|
|
|
1159
1249
|
/**
|
|
@@ -1249,49 +1339,6 @@ export abstract class Exchange {
|
|
|
1249
1339
|
}
|
|
1250
1340
|
}
|
|
1251
1341
|
|
|
1252
|
-
/**
|
|
1253
|
-
* Submit a pre-built order returned by {@link buildOrder}.
|
|
1254
|
-
*
|
|
1255
|
-
* @param built - The BuiltOrder payload from buildOrder()
|
|
1256
|
-
* @returns The submitted order
|
|
1257
|
-
*
|
|
1258
|
-
* @example
|
|
1259
|
-
* ```typescript
|
|
1260
|
-
* const built = await exchange.buildOrder({
|
|
1261
|
-
* outcome: market.yes,
|
|
1262
|
-
* side: "buy",
|
|
1263
|
-
* type: "limit",
|
|
1264
|
-
* amount: 10,
|
|
1265
|
-
* price: 0.55
|
|
1266
|
-
* });
|
|
1267
|
-
* const order = await exchange.submitOrder(built);
|
|
1268
|
-
* console.log(order.id, order.status);
|
|
1269
|
-
* ```
|
|
1270
|
-
*/
|
|
1271
|
-
async submitOrder(built: BuiltOrder): Promise<Order> {
|
|
1272
|
-
await this.initPromise;
|
|
1273
|
-
try {
|
|
1274
|
-
const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/submitOrder`, {
|
|
1275
|
-
method: 'POST',
|
|
1276
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
1277
|
-
body: JSON.stringify({ args: [built as any], credentials: this.getCredentials() }),
|
|
1278
|
-
});
|
|
1279
|
-
if (!response.ok) {
|
|
1280
|
-
const body = await response.json().catch(() => ({}));
|
|
1281
|
-
if (body.error && typeof body.error === "object") {
|
|
1282
|
-
throw fromServerError(body.error);
|
|
1283
|
-
}
|
|
1284
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
1285
|
-
}
|
|
1286
|
-
const json = await response.json();
|
|
1287
|
-
const data = this.handleResponse(json);
|
|
1288
|
-
return convertOrder(data);
|
|
1289
|
-
} catch (error) {
|
|
1290
|
-
if (error instanceof PmxtError) throw error;
|
|
1291
|
-
throw new PmxtError(`Failed to submit order: ${error}`);
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
1342
|
/**
|
|
1296
1343
|
* Create a new order.
|
|
1297
1344
|
*
|