pmxtjs 2.34.2 → 2.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/esm/generated/src/apis/DefaultApi.d.ts +35 -1
  2. package/dist/esm/generated/src/apis/DefaultApi.js +55 -1
  3. package/dist/esm/generated/src/models/FetchEventsPaginated200Response.d.ts +46 -0
  4. package/dist/esm/generated/src/models/FetchEventsPaginated200Response.js +47 -0
  5. package/dist/esm/generated/src/models/PaginatedEventsResult.d.ts +45 -0
  6. package/dist/esm/generated/src/models/PaginatedEventsResult.js +50 -0
  7. package/dist/esm/generated/src/models/index.d.ts +2 -0
  8. package/dist/esm/generated/src/models/index.js +2 -0
  9. package/dist/esm/pmxt/client.d.ts +24 -1
  10. package/dist/esm/pmxt/client.js +418 -88
  11. package/dist/esm/pmxt/models.d.ts +11 -0
  12. package/dist/esm/pmxt/server-manager.js +16 -2
  13. package/dist/generated/src/apis/DefaultApi.d.ts +35 -1
  14. package/dist/generated/src/apis/DefaultApi.js +56 -2
  15. package/dist/generated/src/models/FetchEventsPaginated200Response.d.ts +46 -0
  16. package/dist/generated/src/models/FetchEventsPaginated200Response.js +54 -0
  17. package/dist/generated/src/models/PaginatedEventsResult.d.ts +45 -0
  18. package/dist/generated/src/models/PaginatedEventsResult.js +57 -0
  19. package/dist/generated/src/models/index.d.ts +2 -0
  20. package/dist/generated/src/models/index.js +2 -0
  21. package/dist/pmxt/client.d.ts +24 -1
  22. package/dist/pmxt/client.js +418 -88
  23. package/dist/pmxt/models.d.ts +11 -0
  24. package/dist/pmxt/server-manager.js +16 -2
  25. package/generated/.openapi-generator/FILES +4 -0
  26. package/generated/docs/DefaultApi.md +77 -0
  27. package/generated/docs/FetchEventsPaginated200Response.md +38 -0
  28. package/generated/docs/PaginatedEventsResult.md +39 -0
  29. package/generated/package.json +1 -1
  30. package/generated/src/apis/DefaultApi.ts +79 -0
  31. package/generated/src/models/FetchEventsPaginated200Response.ts +96 -0
  32. package/generated/src/models/PaginatedEventsResult.ts +91 -0
  33. package/generated/src/models/index.ts +2 -0
  34. package/package.json +2 -2
  35. package/pmxt/client.ts +394 -88
  36. package/pmxt/models.ts +14 -0
  37. package/pmxt/server-manager.ts +15 -2
@@ -338,6 +338,51 @@ class Exchange {
338
338
  }
339
339
  return headers;
340
340
  }
341
+ /**
342
+ * Resolve the current sidecar base URL.
343
+ *
344
+ * For hosted mode the configured basePath is returned as-is.
345
+ * For local mode the port is re-read from the lock file on every
346
+ * call so we pick up sidecar restarts that land on a different port.
347
+ */
348
+ resolveBaseUrl() {
349
+ if (this.isHosted)
350
+ return this.config.basePath;
351
+ const port = this.serverManager.getRunningPort();
352
+ return `http://localhost:${port}`;
353
+ }
354
+ /**
355
+ * Execute a fetch with retry on connection failures.
356
+ *
357
+ * Only retries on connection-level errors (ECONNREFUSED, ECONNRESET) —
358
+ * never on HTTP responses (4xx, 5xx). On first connection failure,
359
+ * attempts to restart the sidecar.
360
+ */
361
+ async fetchWithRetry(input, init) {
362
+ const delays = [200, 500, 1000];
363
+ let lastError;
364
+ for (let attempt = 0; attempt <= delays.length; attempt++) {
365
+ try {
366
+ return await fetch(input, init);
367
+ }
368
+ catch (error) {
369
+ lastError = error;
370
+ if (attempt >= delays.length)
371
+ break;
372
+ // Connection failed — try to restart the sidecar on first failure
373
+ if (attempt === 0 && !this.isHosted) {
374
+ try {
375
+ await this.serverManager.ensureServerRunning();
376
+ }
377
+ catch {
378
+ // Restart failed — continue retrying anyway
379
+ }
380
+ }
381
+ await new Promise(resolve => setTimeout(resolve, delays[attempt]));
382
+ }
383
+ }
384
+ throw lastError;
385
+ }
341
386
  // Low-Level API Access
342
387
  /**
343
388
  * Call an exchange-specific REST endpoint by its operationId.
@@ -357,12 +402,12 @@ class Exchange {
357
402
  async callApi(operationId, params) {
358
403
  await this.initPromise;
359
404
  try {
360
- const url = `${this.config.basePath}/api/${this.exchangeName}/callApi`;
405
+ const url = `${this.resolveBaseUrl()}/api/${this.exchangeName}/callApi`;
361
406
  const requestBody = {
362
407
  args: [operationId, params],
363
408
  credentials: this.getCredentials()
364
409
  };
365
- const response = await fetch(url, {
410
+ const response = await this.fetchWithRetry(url, {
366
411
  method: 'POST',
367
412
  headers: {
368
413
  'Content-Type': 'application/json',
@@ -406,12 +451,13 @@ class Exchange {
406
451
  * @internal — shared transport used by every generated read method.
407
452
  */
408
453
  async sidecarReadRequest(methodName, query, args) {
409
- const baseUrl = `${this.config.basePath}/api/${this.exchangeName}/${methodName}`;
454
+ const resolvedBase = this.resolveBaseUrl();
455
+ const baseUrl = `${resolvedBase}/api/${this.exchangeName}/${methodName}`;
410
456
  const hasCredentials = this.getCredentials() !== undefined;
411
457
  if (!hasCredentials && !this._getReadsUnsupported && !queryHasNestedObject(query)) {
412
458
  const qs = buildSidecarQueryString(query);
413
459
  const getUrl = qs ? `${baseUrl}?${qs}` : baseUrl;
414
- const response = await fetch(getUrl, {
460
+ const response = await this.fetchWithRetry(getUrl, {
415
461
  method: 'GET',
416
462
  headers: this.getAuthHeaders(),
417
463
  });
@@ -434,7 +480,7 @@ class Exchange {
434
480
  }
435
481
  }
436
482
  // POST fallback — identical to the original per-method template.
437
- const response = await fetch(baseUrl, {
483
+ const response = await this.fetchWithRetry(baseUrl, {
438
484
  method: 'POST',
439
485
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
440
486
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
@@ -454,14 +500,17 @@ class Exchange {
454
500
  try {
455
501
  const args = [];
456
502
  args.push(reload);
457
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/loadMarkets`, {
503
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/loadMarkets`, {
458
504
  method: 'POST',
459
505
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
460
506
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
461
507
  });
462
508
  if (!response.ok) {
463
- const error = await response.json().catch(() => ({}));
464
- throw new Error(error.error?.message || response.statusText);
509
+ const body = await response.json().catch(() => ({}));
510
+ if (body.error && typeof body.error === "object") {
511
+ throw (0, errors_js_1.fromServerError)(body.error);
512
+ }
513
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
465
514
  }
466
515
  const json = await response.json();
467
516
  const data = this.handleResponse(json);
@@ -472,7 +521,9 @@ class Exchange {
472
521
  return result;
473
522
  }
474
523
  catch (error) {
475
- throw new Error(`Failed to loadMarkets: ${error}`);
524
+ if (error instanceof errors_js_1.PmxtError)
525
+ throw error;
526
+ throw new errors_js_1.PmxtError(`Failed to loadMarkets: ${error}`);
476
527
  }
477
528
  }
478
529
  async fetchMarkets(params) {
@@ -481,21 +532,26 @@ class Exchange {
481
532
  const args = [];
482
533
  if (params !== undefined)
483
534
  args.push(params);
484
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarkets`, {
535
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchMarkets`, {
485
536
  method: 'POST',
486
537
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
487
538
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
488
539
  });
489
540
  if (!response.ok) {
490
- const error = await response.json().catch(() => ({}));
491
- throw new Error(error.error?.message || response.statusText);
541
+ const body = await response.json().catch(() => ({}));
542
+ if (body.error && typeof body.error === "object") {
543
+ throw (0, errors_js_1.fromServerError)(body.error);
544
+ }
545
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
492
546
  }
493
547
  const json = await response.json();
494
548
  const data = this.handleResponse(json);
495
549
  return data.map(convertMarket);
496
550
  }
497
551
  catch (error) {
498
- throw new Error(`Failed to fetchMarkets: ${error}`);
552
+ if (error instanceof errors_js_1.PmxtError)
553
+ throw error;
554
+ throw new errors_js_1.PmxtError(`Failed to fetchMarkets: ${error}`);
499
555
  }
500
556
  }
501
557
  async fetchMarketsPaginated(params) {
@@ -504,14 +560,17 @@ class Exchange {
504
560
  const args = [];
505
561
  if (params !== undefined)
506
562
  args.push(params);
507
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarketsPaginated`, {
563
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchMarketsPaginated`, {
508
564
  method: 'POST',
509
565
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
510
566
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
511
567
  });
512
568
  if (!response.ok) {
513
- const error = await response.json().catch(() => ({}));
514
- throw new Error(error.error?.message || response.statusText);
569
+ const body = await response.json().catch(() => ({}));
570
+ if (body.error && typeof body.error === "object") {
571
+ throw (0, errors_js_1.fromServerError)(body.error);
572
+ }
573
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
515
574
  }
516
575
  const json = await response.json();
517
576
  const data = this.handleResponse(json);
@@ -522,7 +581,9 @@ class Exchange {
522
581
  };
523
582
  }
524
583
  catch (error) {
525
- throw new Error(`Failed to fetchMarketsPaginated: ${error}`);
584
+ if (error instanceof errors_js_1.PmxtError)
585
+ throw error;
586
+ throw new errors_js_1.PmxtError(`Failed to fetchMarketsPaginated: ${error}`);
526
587
  }
527
588
  }
528
589
  async fetchEvents(params) {
@@ -531,21 +592,58 @@ class Exchange {
531
592
  const args = [];
532
593
  if (params !== undefined)
533
594
  args.push(params);
534
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvents`, {
595
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchEvents`, {
535
596
  method: 'POST',
536
597
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
537
598
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
538
599
  });
539
600
  if (!response.ok) {
540
- const error = await response.json().catch(() => ({}));
541
- throw new Error(error.error?.message || response.statusText);
601
+ const body = await response.json().catch(() => ({}));
602
+ if (body.error && typeof body.error === "object") {
603
+ throw (0, errors_js_1.fromServerError)(body.error);
604
+ }
605
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
542
606
  }
543
607
  const json = await response.json();
544
608
  const data = this.handleResponse(json);
545
609
  return data.map(convertEvent);
546
610
  }
547
611
  catch (error) {
548
- throw new Error(`Failed to fetchEvents: ${error}`);
612
+ if (error instanceof errors_js_1.PmxtError)
613
+ throw error;
614
+ throw new errors_js_1.PmxtError(`Failed to fetchEvents: ${error}`);
615
+ }
616
+ }
617
+ async fetchEventsPaginated(params) {
618
+ await this.initPromise;
619
+ try {
620
+ const args = [];
621
+ if (params !== undefined)
622
+ args.push(params);
623
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchEventsPaginated`, {
624
+ method: 'POST',
625
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
626
+ body: JSON.stringify({ args, credentials: this.getCredentials() }),
627
+ });
628
+ if (!response.ok) {
629
+ const body = await response.json().catch(() => ({}));
630
+ if (body.error && typeof body.error === "object") {
631
+ throw (0, errors_js_1.fromServerError)(body.error);
632
+ }
633
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
634
+ }
635
+ const json = await response.json();
636
+ const data = this.handleResponse(json);
637
+ return {
638
+ data: (data.data || []).map(convertEvent),
639
+ total: data.total,
640
+ nextCursor: data.nextCursor,
641
+ };
642
+ }
643
+ catch (error) {
644
+ if (error instanceof errors_js_1.PmxtError)
645
+ throw error;
646
+ throw new errors_js_1.PmxtError(`Failed to fetchEventsPaginated: ${error}`);
549
647
  }
550
648
  }
551
649
  async fetchMarket(params) {
@@ -554,21 +652,26 @@ class Exchange {
554
652
  const args = [];
555
653
  if (params !== undefined)
556
654
  args.push(params);
557
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarket`, {
655
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchMarket`, {
558
656
  method: 'POST',
559
657
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
560
658
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
561
659
  });
562
660
  if (!response.ok) {
563
- const error = await response.json().catch(() => ({}));
564
- throw new Error(error.error?.message || response.statusText);
661
+ const body = await response.json().catch(() => ({}));
662
+ if (body.error && typeof body.error === "object") {
663
+ throw (0, errors_js_1.fromServerError)(body.error);
664
+ }
665
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
565
666
  }
566
667
  const json = await response.json();
567
668
  const data = this.handleResponse(json);
568
669
  return convertMarket(data);
569
670
  }
570
671
  catch (error) {
571
- throw new Error(`Failed to fetchMarket: ${error}`);
672
+ if (error instanceof errors_js_1.PmxtError)
673
+ throw error;
674
+ throw new errors_js_1.PmxtError(`Failed to fetchMarket: ${error}`);
572
675
  }
573
676
  }
574
677
  async fetchEvent(params) {
@@ -577,21 +680,26 @@ class Exchange {
577
680
  const args = [];
578
681
  if (params !== undefined)
579
682
  args.push(params);
580
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvent`, {
683
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchEvent`, {
581
684
  method: 'POST',
582
685
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
583
686
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
584
687
  });
585
688
  if (!response.ok) {
586
- const error = await response.json().catch(() => ({}));
587
- throw new Error(error.error?.message || response.statusText);
689
+ const body = await response.json().catch(() => ({}));
690
+ if (body.error && typeof body.error === "object") {
691
+ throw (0, errors_js_1.fromServerError)(body.error);
692
+ }
693
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
588
694
  }
589
695
  const json = await response.json();
590
696
  const data = this.handleResponse(json);
591
697
  return convertEvent(data);
592
698
  }
593
699
  catch (error) {
594
- throw new Error(`Failed to fetchEvent: ${error}`);
700
+ if (error instanceof errors_js_1.PmxtError)
701
+ throw error;
702
+ throw new errors_js_1.PmxtError(`Failed to fetchEvent: ${error}`);
595
703
  }
596
704
  }
597
705
  async fetchOrderBook(id) {
@@ -599,21 +707,26 @@ class Exchange {
599
707
  try {
600
708
  const args = [];
601
709
  args.push(id);
602
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrderBook`, {
710
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchOrderBook`, {
603
711
  method: 'POST',
604
712
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
605
713
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
606
714
  });
607
715
  if (!response.ok) {
608
- const error = await response.json().catch(() => ({}));
609
- throw new Error(error.error?.message || response.statusText);
716
+ const body = await response.json().catch(() => ({}));
717
+ if (body.error && typeof body.error === "object") {
718
+ throw (0, errors_js_1.fromServerError)(body.error);
719
+ }
720
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
610
721
  }
611
722
  const json = await response.json();
612
723
  const data = this.handleResponse(json);
613
724
  return convertOrderBook(data);
614
725
  }
615
726
  catch (error) {
616
- throw new Error(`Failed to fetchOrderBook: ${error}`);
727
+ if (error instanceof errors_js_1.PmxtError)
728
+ throw error;
729
+ throw new errors_js_1.PmxtError(`Failed to fetchOrderBook: ${error}`);
617
730
  }
618
731
  }
619
732
  async submitOrder(built) {
@@ -621,21 +734,26 @@ class Exchange {
621
734
  try {
622
735
  const args = [];
623
736
  args.push(built);
624
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/submitOrder`, {
737
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/submitOrder`, {
625
738
  method: 'POST',
626
739
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
627
740
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
628
741
  });
629
742
  if (!response.ok) {
630
- const error = await response.json().catch(() => ({}));
631
- throw new Error(error.error?.message || response.statusText);
743
+ const body = await response.json().catch(() => ({}));
744
+ if (body.error && typeof body.error === "object") {
745
+ throw (0, errors_js_1.fromServerError)(body.error);
746
+ }
747
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
632
748
  }
633
749
  const json = await response.json();
634
750
  const data = this.handleResponse(json);
635
751
  return convertOrder(data);
636
752
  }
637
753
  catch (error) {
638
- throw new Error(`Failed to submitOrder: ${error}`);
754
+ if (error instanceof errors_js_1.PmxtError)
755
+ throw error;
756
+ throw new errors_js_1.PmxtError(`Failed to submitOrder: ${error}`);
639
757
  }
640
758
  }
641
759
  async cancelOrder(orderId) {
@@ -643,21 +761,26 @@ class Exchange {
643
761
  try {
644
762
  const args = [];
645
763
  args.push(orderId);
646
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/cancelOrder`, {
764
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/cancelOrder`, {
647
765
  method: 'POST',
648
766
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
649
767
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
650
768
  });
651
769
  if (!response.ok) {
652
- const error = await response.json().catch(() => ({}));
653
- throw new Error(error.error?.message || response.statusText);
770
+ const body = await response.json().catch(() => ({}));
771
+ if (body.error && typeof body.error === "object") {
772
+ throw (0, errors_js_1.fromServerError)(body.error);
773
+ }
774
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
654
775
  }
655
776
  const json = await response.json();
656
777
  const data = this.handleResponse(json);
657
778
  return convertOrder(data);
658
779
  }
659
780
  catch (error) {
660
- throw new Error(`Failed to cancelOrder: ${error}`);
781
+ if (error instanceof errors_js_1.PmxtError)
782
+ throw error;
783
+ throw new errors_js_1.PmxtError(`Failed to cancelOrder: ${error}`);
661
784
  }
662
785
  }
663
786
  async fetchOrder(orderId) {
@@ -665,21 +788,26 @@ class Exchange {
665
788
  try {
666
789
  const args = [];
667
790
  args.push(orderId);
668
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrder`, {
791
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchOrder`, {
669
792
  method: 'POST',
670
793
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
671
794
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
672
795
  });
673
796
  if (!response.ok) {
674
- const error = await response.json().catch(() => ({}));
675
- throw new Error(error.error?.message || response.statusText);
797
+ const body = await response.json().catch(() => ({}));
798
+ if (body.error && typeof body.error === "object") {
799
+ throw (0, errors_js_1.fromServerError)(body.error);
800
+ }
801
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
676
802
  }
677
803
  const json = await response.json();
678
804
  const data = this.handleResponse(json);
679
805
  return convertOrder(data);
680
806
  }
681
807
  catch (error) {
682
- throw new Error(`Failed to fetchOrder: ${error}`);
808
+ if (error instanceof errors_js_1.PmxtError)
809
+ throw error;
810
+ throw new errors_js_1.PmxtError(`Failed to fetchOrder: ${error}`);
683
811
  }
684
812
  }
685
813
  async fetchOpenOrders(marketId) {
@@ -688,21 +816,26 @@ class Exchange {
688
816
  const args = [];
689
817
  if (marketId !== undefined)
690
818
  args.push(marketId);
691
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOpenOrders`, {
819
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchOpenOrders`, {
692
820
  method: 'POST',
693
821
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
694
822
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
695
823
  });
696
824
  if (!response.ok) {
697
- const error = await response.json().catch(() => ({}));
698
- throw new Error(error.error?.message || response.statusText);
825
+ const body = await response.json().catch(() => ({}));
826
+ if (body.error && typeof body.error === "object") {
827
+ throw (0, errors_js_1.fromServerError)(body.error);
828
+ }
829
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
699
830
  }
700
831
  const json = await response.json();
701
832
  const data = this.handleResponse(json);
702
833
  return data.map(convertOrder);
703
834
  }
704
835
  catch (error) {
705
- throw new Error(`Failed to fetchOpenOrders: ${error}`);
836
+ if (error instanceof errors_js_1.PmxtError)
837
+ throw error;
838
+ throw new errors_js_1.PmxtError(`Failed to fetchOpenOrders: ${error}`);
706
839
  }
707
840
  }
708
841
  async fetchMyTrades(params) {
@@ -711,21 +844,26 @@ class Exchange {
711
844
  const args = [];
712
845
  if (params !== undefined)
713
846
  args.push(params);
714
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMyTrades`, {
847
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchMyTrades`, {
715
848
  method: 'POST',
716
849
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
717
850
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
718
851
  });
719
852
  if (!response.ok) {
720
- const error = await response.json().catch(() => ({}));
721
- throw new Error(error.error?.message || response.statusText);
853
+ const body = await response.json().catch(() => ({}));
854
+ if (body.error && typeof body.error === "object") {
855
+ throw (0, errors_js_1.fromServerError)(body.error);
856
+ }
857
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
722
858
  }
723
859
  const json = await response.json();
724
860
  const data = this.handleResponse(json);
725
861
  return data.map(convertUserTrade);
726
862
  }
727
863
  catch (error) {
728
- throw new Error(`Failed to fetchMyTrades: ${error}`);
864
+ if (error instanceof errors_js_1.PmxtError)
865
+ throw error;
866
+ throw new errors_js_1.PmxtError(`Failed to fetchMyTrades: ${error}`);
729
867
  }
730
868
  }
731
869
  async fetchClosedOrders(params) {
@@ -734,21 +872,26 @@ class Exchange {
734
872
  const args = [];
735
873
  if (params !== undefined)
736
874
  args.push(params);
737
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchClosedOrders`, {
875
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchClosedOrders`, {
738
876
  method: 'POST',
739
877
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
740
878
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
741
879
  });
742
880
  if (!response.ok) {
743
- const error = await response.json().catch(() => ({}));
744
- throw new Error(error.error?.message || response.statusText);
881
+ const body = await response.json().catch(() => ({}));
882
+ if (body.error && typeof body.error === "object") {
883
+ throw (0, errors_js_1.fromServerError)(body.error);
884
+ }
885
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
745
886
  }
746
887
  const json = await response.json();
747
888
  const data = this.handleResponse(json);
748
889
  return data.map(convertOrder);
749
890
  }
750
891
  catch (error) {
751
- throw new Error(`Failed to fetchClosedOrders: ${error}`);
892
+ if (error instanceof errors_js_1.PmxtError)
893
+ throw error;
894
+ throw new errors_js_1.PmxtError(`Failed to fetchClosedOrders: ${error}`);
752
895
  }
753
896
  }
754
897
  async fetchAllOrders(params) {
@@ -757,21 +900,26 @@ class Exchange {
757
900
  const args = [];
758
901
  if (params !== undefined)
759
902
  args.push(params);
760
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchAllOrders`, {
903
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchAllOrders`, {
761
904
  method: 'POST',
762
905
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
763
906
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
764
907
  });
765
908
  if (!response.ok) {
766
- const error = await response.json().catch(() => ({}));
767
- throw new Error(error.error?.message || response.statusText);
909
+ const body = await response.json().catch(() => ({}));
910
+ if (body.error && typeof body.error === "object") {
911
+ throw (0, errors_js_1.fromServerError)(body.error);
912
+ }
913
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
768
914
  }
769
915
  const json = await response.json();
770
916
  const data = this.handleResponse(json);
771
917
  return data.map(convertOrder);
772
918
  }
773
919
  catch (error) {
774
- throw new Error(`Failed to fetchAllOrders: ${error}`);
920
+ if (error instanceof errors_js_1.PmxtError)
921
+ throw error;
922
+ throw new errors_js_1.PmxtError(`Failed to fetchAllOrders: ${error}`);
775
923
  }
776
924
  }
777
925
  async fetchPositions(address) {
@@ -780,21 +928,26 @@ class Exchange {
780
928
  const args = [];
781
929
  if (address !== undefined)
782
930
  args.push(address);
783
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchPositions`, {
931
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchPositions`, {
784
932
  method: 'POST',
785
933
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
786
934
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
787
935
  });
788
936
  if (!response.ok) {
789
- const error = await response.json().catch(() => ({}));
790
- throw new Error(error.error?.message || response.statusText);
937
+ const body = await response.json().catch(() => ({}));
938
+ if (body.error && typeof body.error === "object") {
939
+ throw (0, errors_js_1.fromServerError)(body.error);
940
+ }
941
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
791
942
  }
792
943
  const json = await response.json();
793
944
  const data = this.handleResponse(json);
794
945
  return data.map(convertPosition);
795
946
  }
796
947
  catch (error) {
797
- throw new Error(`Failed to fetchPositions: ${error}`);
948
+ if (error instanceof errors_js_1.PmxtError)
949
+ throw error;
950
+ throw new errors_js_1.PmxtError(`Failed to fetchPositions: ${error}`);
798
951
  }
799
952
  }
800
953
  async fetchBalance(address) {
@@ -803,21 +956,26 @@ class Exchange {
803
956
  const args = [];
804
957
  if (address !== undefined)
805
958
  args.push(address);
806
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchBalance`, {
959
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchBalance`, {
807
960
  method: 'POST',
808
961
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
809
962
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
810
963
  });
811
964
  if (!response.ok) {
812
- const error = await response.json().catch(() => ({}));
813
- throw new Error(error.error?.message || response.statusText);
965
+ const body = await response.json().catch(() => ({}));
966
+ if (body.error && typeof body.error === "object") {
967
+ throw (0, errors_js_1.fromServerError)(body.error);
968
+ }
969
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
814
970
  }
815
971
  const json = await response.json();
816
972
  const data = this.handleResponse(json);
817
973
  return data.map(convertBalance);
818
974
  }
819
975
  catch (error) {
820
- throw new Error(`Failed to fetchBalance: ${error}`);
976
+ if (error instanceof errors_js_1.PmxtError)
977
+ throw error;
978
+ throw new errors_js_1.PmxtError(`Failed to fetchBalance: ${error}`);
821
979
  }
822
980
  }
823
981
  async unwatchOrderBook(id) {
@@ -825,20 +983,25 @@ class Exchange {
825
983
  try {
826
984
  const args = [];
827
985
  args.push(id);
828
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/unwatchOrderBook`, {
986
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/unwatchOrderBook`, {
829
987
  method: 'POST',
830
988
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
831
989
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
832
990
  });
833
991
  if (!response.ok) {
834
- const error = await response.json().catch(() => ({}));
835
- throw new Error(error.error?.message || response.statusText);
992
+ const body = await response.json().catch(() => ({}));
993
+ if (body.error && typeof body.error === "object") {
994
+ throw (0, errors_js_1.fromServerError)(body.error);
995
+ }
996
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
836
997
  }
837
998
  const json = await response.json();
838
999
  this.handleResponse(json);
839
1000
  }
840
1001
  catch (error) {
841
- throw new Error(`Failed to unwatchOrderBook: ${error}`);
1002
+ if (error instanceof errors_js_1.PmxtError)
1003
+ throw error;
1004
+ throw new errors_js_1.PmxtError(`Failed to unwatchOrderBook: ${error}`);
842
1005
  }
843
1006
  }
844
1007
  async unwatchAddress(address) {
@@ -846,40 +1009,207 @@ class Exchange {
846
1009
  try {
847
1010
  const args = [];
848
1011
  args.push(address);
849
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/unwatchAddress`, {
1012
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/unwatchAddress`, {
850
1013
  method: 'POST',
851
1014
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
852
1015
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
853
1016
  });
854
1017
  if (!response.ok) {
855
- const error = await response.json().catch(() => ({}));
856
- throw new Error(error.error?.message || response.statusText);
1018
+ const body = await response.json().catch(() => ({}));
1019
+ if (body.error && typeof body.error === "object") {
1020
+ throw (0, errors_js_1.fromServerError)(body.error);
1021
+ }
1022
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
857
1023
  }
858
1024
  const json = await response.json();
859
1025
  this.handleResponse(json);
860
1026
  }
861
1027
  catch (error) {
862
- throw new Error(`Failed to unwatchAddress: ${error}`);
1028
+ if (error instanceof errors_js_1.PmxtError)
1029
+ throw error;
1030
+ throw new errors_js_1.PmxtError(`Failed to unwatchAddress: ${error}`);
863
1031
  }
864
1032
  }
865
1033
  async close() {
866
1034
  await this.initPromise;
867
1035
  try {
868
1036
  const args = [];
869
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/close`, {
1037
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/close`, {
870
1038
  method: 'POST',
871
1039
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
872
1040
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
873
1041
  });
874
1042
  if (!response.ok) {
875
- const error = await response.json().catch(() => ({}));
876
- throw new Error(error.error?.message || response.statusText);
1043
+ const body = await response.json().catch(() => ({}));
1044
+ if (body.error && typeof body.error === "object") {
1045
+ throw (0, errors_js_1.fromServerError)(body.error);
1046
+ }
1047
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
877
1048
  }
878
1049
  const json = await response.json();
879
1050
  this.handleResponse(json);
880
1051
  }
881
1052
  catch (error) {
882
- throw new Error(`Failed to close: ${error}`);
1053
+ if (error instanceof errors_js_1.PmxtError)
1054
+ throw error;
1055
+ throw new errors_js_1.PmxtError(`Failed to close: ${error}`);
1056
+ }
1057
+ }
1058
+ async fetchMarketMatches(params) {
1059
+ await this.initPromise;
1060
+ try {
1061
+ const args = [];
1062
+ args.push(params);
1063
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchMarketMatches`, {
1064
+ method: 'POST',
1065
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
1066
+ body: JSON.stringify({ args, credentials: this.getCredentials() }),
1067
+ });
1068
+ if (!response.ok) {
1069
+ const body = await response.json().catch(() => ({}));
1070
+ if (body.error && typeof body.error === "object") {
1071
+ throw (0, errors_js_1.fromServerError)(body.error);
1072
+ }
1073
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
1074
+ }
1075
+ const json = await response.json();
1076
+ return this.handleResponse(json);
1077
+ }
1078
+ catch (error) {
1079
+ if (error instanceof errors_js_1.PmxtError)
1080
+ throw error;
1081
+ throw new errors_js_1.PmxtError(`Failed to fetchMarketMatches: ${error}`);
1082
+ }
1083
+ }
1084
+ async fetchMatches(params) {
1085
+ await this.initPromise;
1086
+ try {
1087
+ const args = [];
1088
+ args.push(params);
1089
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchMatches`, {
1090
+ method: 'POST',
1091
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
1092
+ body: JSON.stringify({ args, credentials: this.getCredentials() }),
1093
+ });
1094
+ if (!response.ok) {
1095
+ const body = await response.json().catch(() => ({}));
1096
+ if (body.error && typeof body.error === "object") {
1097
+ throw (0, errors_js_1.fromServerError)(body.error);
1098
+ }
1099
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
1100
+ }
1101
+ const json = await response.json();
1102
+ return this.handleResponse(json);
1103
+ }
1104
+ catch (error) {
1105
+ if (error instanceof errors_js_1.PmxtError)
1106
+ throw error;
1107
+ throw new errors_js_1.PmxtError(`Failed to fetchMatches: ${error}`);
1108
+ }
1109
+ }
1110
+ async fetchEventMatches(params) {
1111
+ await this.initPromise;
1112
+ try {
1113
+ const args = [];
1114
+ args.push(params);
1115
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchEventMatches`, {
1116
+ method: 'POST',
1117
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
1118
+ body: JSON.stringify({ args, credentials: this.getCredentials() }),
1119
+ });
1120
+ if (!response.ok) {
1121
+ const body = await response.json().catch(() => ({}));
1122
+ if (body.error && typeof body.error === "object") {
1123
+ throw (0, errors_js_1.fromServerError)(body.error);
1124
+ }
1125
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
1126
+ }
1127
+ const json = await response.json();
1128
+ return this.handleResponse(json);
1129
+ }
1130
+ catch (error) {
1131
+ if (error instanceof errors_js_1.PmxtError)
1132
+ throw error;
1133
+ throw new errors_js_1.PmxtError(`Failed to fetchEventMatches: ${error}`);
1134
+ }
1135
+ }
1136
+ async compareMarketPrices(params) {
1137
+ await this.initPromise;
1138
+ try {
1139
+ const args = [];
1140
+ args.push(params);
1141
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/compareMarketPrices`, {
1142
+ method: 'POST',
1143
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
1144
+ body: JSON.stringify({ args, credentials: this.getCredentials() }),
1145
+ });
1146
+ if (!response.ok) {
1147
+ const body = await response.json().catch(() => ({}));
1148
+ if (body.error && typeof body.error === "object") {
1149
+ throw (0, errors_js_1.fromServerError)(body.error);
1150
+ }
1151
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
1152
+ }
1153
+ const json = await response.json();
1154
+ return this.handleResponse(json);
1155
+ }
1156
+ catch (error) {
1157
+ if (error instanceof errors_js_1.PmxtError)
1158
+ throw error;
1159
+ throw new errors_js_1.PmxtError(`Failed to compareMarketPrices: ${error}`);
1160
+ }
1161
+ }
1162
+ async fetchHedges(params) {
1163
+ await this.initPromise;
1164
+ try {
1165
+ const args = [];
1166
+ args.push(params);
1167
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchHedges`, {
1168
+ method: 'POST',
1169
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
1170
+ body: JSON.stringify({ args, credentials: this.getCredentials() }),
1171
+ });
1172
+ if (!response.ok) {
1173
+ const body = await response.json().catch(() => ({}));
1174
+ if (body.error && typeof body.error === "object") {
1175
+ throw (0, errors_js_1.fromServerError)(body.error);
1176
+ }
1177
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
1178
+ }
1179
+ const json = await response.json();
1180
+ return this.handleResponse(json);
1181
+ }
1182
+ catch (error) {
1183
+ if (error instanceof errors_js_1.PmxtError)
1184
+ throw error;
1185
+ throw new errors_js_1.PmxtError(`Failed to fetchHedges: ${error}`);
1186
+ }
1187
+ }
1188
+ async fetchArbitrage(params) {
1189
+ await this.initPromise;
1190
+ try {
1191
+ const args = [];
1192
+ if (params !== undefined)
1193
+ args.push(params);
1194
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/fetchArbitrage`, {
1195
+ method: 'POST',
1196
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
1197
+ body: JSON.stringify({ args, credentials: this.getCredentials() }),
1198
+ });
1199
+ if (!response.ok) {
1200
+ const body = await response.json().catch(() => ({}));
1201
+ if (body.error && typeof body.error === "object") {
1202
+ throw (0, errors_js_1.fromServerError)(body.error);
1203
+ }
1204
+ throw new errors_js_1.PmxtError(body.error?.message || response.statusText);
1205
+ }
1206
+ const json = await response.json();
1207
+ return this.handleResponse(json);
1208
+ }
1209
+ catch (error) {
1210
+ if (error instanceof errors_js_1.PmxtError)
1211
+ throw error;
1212
+ throw new errors_js_1.PmxtError(`Failed to fetchArbitrage: ${error}`);
883
1213
  }
884
1214
  }
885
1215
  // END GENERATED METHODS
@@ -984,7 +1314,7 @@ class Exchange {
984
1314
  if (limit !== undefined) {
985
1315
  args.push(limit);
986
1316
  }
987
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/watchOrderBook`, {
1317
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/watchOrderBook`, {
988
1318
  method: 'POST',
989
1319
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
990
1320
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
@@ -1043,7 +1373,7 @@ class Exchange {
1043
1373
  if (limit !== undefined) {
1044
1374
  args.push(limit);
1045
1375
  }
1046
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/watchTrades`, {
1376
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/watchTrades`, {
1047
1377
  method: 'POST',
1048
1378
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
1049
1379
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
@@ -1093,7 +1423,7 @@ class Exchange {
1093
1423
  if (types !== undefined) {
1094
1424
  args.push(types);
1095
1425
  }
1096
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/watchAddress`, {
1426
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/watchAddress`, {
1097
1427
  method: 'POST',
1098
1428
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
1099
1429
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
@@ -1181,7 +1511,7 @@ class Exchange {
1181
1511
  if (params.fee !== undefined) {
1182
1512
  paramsDict.fee = params.fee;
1183
1513
  }
1184
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/buildOrder`, {
1514
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/buildOrder`, {
1185
1515
  method: 'POST',
1186
1516
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
1187
1517
  body: JSON.stringify({ args: [paramsDict], credentials: this.getCredentials() }),
@@ -1251,7 +1581,7 @@ class Exchange {
1251
1581
  if (params.fee !== undefined) {
1252
1582
  paramsDict.fee = params.fee;
1253
1583
  }
1254
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/createOrder`, {
1584
+ const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/createOrder`, {
1255
1585
  method: 'POST',
1256
1586
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
1257
1587
  body: JSON.stringify({ args: [paramsDict], credentials: this.getCredentials() }),
@@ -1305,8 +1635,8 @@ class Exchange {
1305
1635
  if (credentials) {
1306
1636
  body.credentials = credentials;
1307
1637
  }
1308
- const url = `${this.config.basePath}/api/${this.exchangeName}/getExecutionPriceDetailed`;
1309
- const response = await fetch(url, {
1638
+ const url = `${this.resolveBaseUrl()}/api/${this.exchangeName}/getExecutionPriceDetailed`;
1639
+ const response = await this.fetchWithRetry(url, {
1310
1640
  method: 'POST',
1311
1641
  headers: {
1312
1642
  'Content-Type': 'application/json',