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