pmxtjs 2.19.4 → 2.19.6

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.
@@ -44,6 +44,7 @@ export declare abstract class Exchange {
44
44
  private initializeServer;
45
45
  protected handleResponse(response: any): any;
46
46
  protected getCredentials(): ExchangeCredentials | undefined;
47
+ protected getAuthHeaders(): Record<string, string>;
47
48
  /**
48
49
  * Call an exchange-specific REST endpoint by its operationId.
49
50
  * This provides direct access to all implicit API methods defined in
@@ -67,6 +68,7 @@ export declare abstract class Exchange {
67
68
  fetchMarket(params?: any): Promise<UnifiedMarket>;
68
69
  fetchEvent(params?: any): Promise<UnifiedEvent>;
69
70
  fetchOrderBook(id: string): Promise<OrderBook>;
71
+ submitOrder(built: any): Promise<Order>;
70
72
  cancelOrder(orderId: string): Promise<Order>;
71
73
  fetchOrder(orderId: string): Promise<Order>;
72
74
  fetchOpenOrders(marketId?: string): Promise<Order[]>;
@@ -183,15 +183,9 @@ export class Exchange {
183
183
  // (may differ from default if default port was busy)
184
184
  const actualPort = this.serverManager.getRunningPort();
185
185
  const newBaseUrl = `http://localhost:${actualPort}`;
186
- const accessToken = this.serverManager.getAccessToken();
187
- const headers = {};
188
- if (accessToken) {
189
- headers['x-pmxt-access-token'] = accessToken;
190
- }
191
186
  // Update API client with actual base URL
192
187
  this.config = new Configuration({
193
188
  basePath: newBaseUrl,
194
- headers
195
189
  });
196
190
  this.api = new DefaultApi(this.config);
197
191
  }
@@ -220,6 +214,14 @@ export class Exchange {
220
214
  signatureType: this.signatureType,
221
215
  };
222
216
  }
217
+ getAuthHeaders() {
218
+ const headers = { ...this.config.headers };
219
+ const accessToken = this.serverManager.getAccessToken();
220
+ if (accessToken) {
221
+ headers['x-pmxt-access-token'] = accessToken;
222
+ }
223
+ return headers;
224
+ }
223
225
  // Low-Level API Access
224
226
  /**
225
227
  * Call an exchange-specific REST endpoint by its operationId.
@@ -248,7 +250,7 @@ export class Exchange {
248
250
  method: 'POST',
249
251
  headers: {
250
252
  'Content-Type': 'application/json',
251
- ...this.config.headers
253
+ ...this.getAuthHeaders()
252
254
  },
253
255
  body: JSON.stringify(requestBody)
254
256
  });
@@ -271,7 +273,7 @@ export class Exchange {
271
273
  args.push(reload);
272
274
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/loadMarkets`, {
273
275
  method: 'POST',
274
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
276
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
275
277
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
276
278
  });
277
279
  if (!response.ok) {
@@ -298,7 +300,7 @@ export class Exchange {
298
300
  args.push(params);
299
301
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarkets`, {
300
302
  method: 'POST',
301
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
303
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
302
304
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
303
305
  });
304
306
  if (!response.ok) {
@@ -321,7 +323,7 @@ export class Exchange {
321
323
  args.push(params);
322
324
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarketsPaginated`, {
323
325
  method: 'POST',
324
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
326
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
325
327
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
326
328
  });
327
329
  if (!response.ok) {
@@ -348,7 +350,7 @@ export class Exchange {
348
350
  args.push(params);
349
351
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvents`, {
350
352
  method: 'POST',
351
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
353
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
352
354
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
353
355
  });
354
356
  if (!response.ok) {
@@ -371,7 +373,7 @@ export class Exchange {
371
373
  args.push(params);
372
374
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarket`, {
373
375
  method: 'POST',
374
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
376
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
375
377
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
376
378
  });
377
379
  if (!response.ok) {
@@ -394,7 +396,7 @@ export class Exchange {
394
396
  args.push(params);
395
397
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvent`, {
396
398
  method: 'POST',
397
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
399
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
398
400
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
399
401
  });
400
402
  if (!response.ok) {
@@ -416,7 +418,7 @@ export class Exchange {
416
418
  args.push(id);
417
419
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrderBook`, {
418
420
  method: 'POST',
419
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
421
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
420
422
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
421
423
  });
422
424
  if (!response.ok) {
@@ -431,6 +433,28 @@ export class Exchange {
431
433
  throw new Error(`Failed to fetchOrderBook: ${error}`);
432
434
  }
433
435
  }
436
+ async submitOrder(built) {
437
+ await this.initPromise;
438
+ try {
439
+ const args = [];
440
+ args.push(built);
441
+ const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/submitOrder`, {
442
+ method: 'POST',
443
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
444
+ body: JSON.stringify({ args, credentials: this.getCredentials() }),
445
+ });
446
+ if (!response.ok) {
447
+ const error = await response.json().catch(() => ({}));
448
+ throw new Error(error.error?.message || response.statusText);
449
+ }
450
+ const json = await response.json();
451
+ const data = this.handleResponse(json);
452
+ return convertOrder(data);
453
+ }
454
+ catch (error) {
455
+ throw new Error(`Failed to submitOrder: ${error}`);
456
+ }
457
+ }
434
458
  async cancelOrder(orderId) {
435
459
  await this.initPromise;
436
460
  try {
@@ -438,7 +462,7 @@ export class Exchange {
438
462
  args.push(orderId);
439
463
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/cancelOrder`, {
440
464
  method: 'POST',
441
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
465
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
442
466
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
443
467
  });
444
468
  if (!response.ok) {
@@ -460,7 +484,7 @@ export class Exchange {
460
484
  args.push(orderId);
461
485
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrder`, {
462
486
  method: 'POST',
463
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
487
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
464
488
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
465
489
  });
466
490
  if (!response.ok) {
@@ -483,7 +507,7 @@ export class Exchange {
483
507
  args.push(marketId);
484
508
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOpenOrders`, {
485
509
  method: 'POST',
486
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
510
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
487
511
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
488
512
  });
489
513
  if (!response.ok) {
@@ -506,7 +530,7 @@ export class Exchange {
506
530
  args.push(params);
507
531
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMyTrades`, {
508
532
  method: 'POST',
509
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
533
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
510
534
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
511
535
  });
512
536
  if (!response.ok) {
@@ -529,7 +553,7 @@ export class Exchange {
529
553
  args.push(params);
530
554
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchClosedOrders`, {
531
555
  method: 'POST',
532
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
556
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
533
557
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
534
558
  });
535
559
  if (!response.ok) {
@@ -552,7 +576,7 @@ export class Exchange {
552
576
  args.push(params);
553
577
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchAllOrders`, {
554
578
  method: 'POST',
555
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
579
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
556
580
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
557
581
  });
558
582
  if (!response.ok) {
@@ -573,7 +597,7 @@ export class Exchange {
573
597
  const args = [];
574
598
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchPositions`, {
575
599
  method: 'POST',
576
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
600
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
577
601
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
578
602
  });
579
603
  if (!response.ok) {
@@ -594,7 +618,7 @@ export class Exchange {
594
618
  const args = [];
595
619
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchBalance`, {
596
620
  method: 'POST',
597
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
621
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
598
622
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
599
623
  });
600
624
  if (!response.ok) {
@@ -615,7 +639,7 @@ export class Exchange {
615
639
  const args = [];
616
640
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/close`, {
617
641
  method: 'POST',
618
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
642
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
619
643
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
620
644
  });
621
645
  if (!response.ok) {
@@ -667,7 +691,7 @@ export class Exchange {
667
691
  const response = await this.api.fetchOHLCV({
668
692
  exchange: this.exchangeName,
669
693
  fetchOHLCVRequest: requestBody,
670
- });
694
+ }, { headers: this.getAuthHeaders() });
671
695
  const data = this.handleResponse(response);
672
696
  return data.map(convertCandle);
673
697
  }
@@ -698,7 +722,7 @@ export class Exchange {
698
722
  const response = await this.api.fetchTrades({
699
723
  exchange: this.exchangeName,
700
724
  fetchTradesRequest: requestBody,
701
- });
725
+ }, { headers: this.getAuthHeaders() });
702
726
  const data = this.handleResponse(response);
703
727
  return data.map(convertTrade);
704
728
  }
@@ -44,6 +44,7 @@ export declare abstract class Exchange {
44
44
  private initializeServer;
45
45
  protected handleResponse(response: any): any;
46
46
  protected getCredentials(): ExchangeCredentials | undefined;
47
+ protected getAuthHeaders(): Record<string, string>;
47
48
  /**
48
49
  * Call an exchange-specific REST endpoint by its operationId.
49
50
  * This provides direct access to all implicit API methods defined in
@@ -67,6 +68,7 @@ export declare abstract class Exchange {
67
68
  fetchMarket(params?: any): Promise<UnifiedMarket>;
68
69
  fetchEvent(params?: any): Promise<UnifiedEvent>;
69
70
  fetchOrderBook(id: string): Promise<OrderBook>;
71
+ submitOrder(built: any): Promise<Order>;
70
72
  cancelOrder(orderId: string): Promise<Order>;
71
73
  fetchOrder(orderId: string): Promise<Order>;
72
74
  fetchOpenOrders(marketId?: string): Promise<Order[]>;
@@ -186,15 +186,9 @@ class Exchange {
186
186
  // (may differ from default if default port was busy)
187
187
  const actualPort = this.serverManager.getRunningPort();
188
188
  const newBaseUrl = `http://localhost:${actualPort}`;
189
- const accessToken = this.serverManager.getAccessToken();
190
- const headers = {};
191
- if (accessToken) {
192
- headers['x-pmxt-access-token'] = accessToken;
193
- }
194
189
  // Update API client with actual base URL
195
190
  this.config = new index_js_1.Configuration({
196
191
  basePath: newBaseUrl,
197
- headers
198
192
  });
199
193
  this.api = new index_js_1.DefaultApi(this.config);
200
194
  }
@@ -223,6 +217,14 @@ class Exchange {
223
217
  signatureType: this.signatureType,
224
218
  };
225
219
  }
220
+ getAuthHeaders() {
221
+ const headers = { ...this.config.headers };
222
+ const accessToken = this.serverManager.getAccessToken();
223
+ if (accessToken) {
224
+ headers['x-pmxt-access-token'] = accessToken;
225
+ }
226
+ return headers;
227
+ }
226
228
  // Low-Level API Access
227
229
  /**
228
230
  * Call an exchange-specific REST endpoint by its operationId.
@@ -251,7 +253,7 @@ class Exchange {
251
253
  method: 'POST',
252
254
  headers: {
253
255
  'Content-Type': 'application/json',
254
- ...this.config.headers
256
+ ...this.getAuthHeaders()
255
257
  },
256
258
  body: JSON.stringify(requestBody)
257
259
  });
@@ -274,7 +276,7 @@ class Exchange {
274
276
  args.push(reload);
275
277
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/loadMarkets`, {
276
278
  method: 'POST',
277
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
279
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
278
280
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
279
281
  });
280
282
  if (!response.ok) {
@@ -301,7 +303,7 @@ class Exchange {
301
303
  args.push(params);
302
304
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarkets`, {
303
305
  method: 'POST',
304
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
306
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
305
307
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
306
308
  });
307
309
  if (!response.ok) {
@@ -324,7 +326,7 @@ class Exchange {
324
326
  args.push(params);
325
327
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarketsPaginated`, {
326
328
  method: 'POST',
327
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
329
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
328
330
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
329
331
  });
330
332
  if (!response.ok) {
@@ -351,7 +353,7 @@ class Exchange {
351
353
  args.push(params);
352
354
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvents`, {
353
355
  method: 'POST',
354
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
356
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
355
357
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
356
358
  });
357
359
  if (!response.ok) {
@@ -374,7 +376,7 @@ class Exchange {
374
376
  args.push(params);
375
377
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarket`, {
376
378
  method: 'POST',
377
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
379
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
378
380
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
379
381
  });
380
382
  if (!response.ok) {
@@ -397,7 +399,7 @@ class Exchange {
397
399
  args.push(params);
398
400
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvent`, {
399
401
  method: 'POST',
400
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
402
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
401
403
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
402
404
  });
403
405
  if (!response.ok) {
@@ -419,7 +421,7 @@ class Exchange {
419
421
  args.push(id);
420
422
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrderBook`, {
421
423
  method: 'POST',
422
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
424
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
423
425
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
424
426
  });
425
427
  if (!response.ok) {
@@ -434,6 +436,28 @@ class Exchange {
434
436
  throw new Error(`Failed to fetchOrderBook: ${error}`);
435
437
  }
436
438
  }
439
+ async submitOrder(built) {
440
+ await this.initPromise;
441
+ try {
442
+ const args = [];
443
+ args.push(built);
444
+ const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/submitOrder`, {
445
+ method: 'POST',
446
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
447
+ body: JSON.stringify({ args, credentials: this.getCredentials() }),
448
+ });
449
+ if (!response.ok) {
450
+ const error = await response.json().catch(() => ({}));
451
+ throw new Error(error.error?.message || response.statusText);
452
+ }
453
+ const json = await response.json();
454
+ const data = this.handleResponse(json);
455
+ return convertOrder(data);
456
+ }
457
+ catch (error) {
458
+ throw new Error(`Failed to submitOrder: ${error}`);
459
+ }
460
+ }
437
461
  async cancelOrder(orderId) {
438
462
  await this.initPromise;
439
463
  try {
@@ -441,7 +465,7 @@ class Exchange {
441
465
  args.push(orderId);
442
466
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/cancelOrder`, {
443
467
  method: 'POST',
444
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
468
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
445
469
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
446
470
  });
447
471
  if (!response.ok) {
@@ -463,7 +487,7 @@ class Exchange {
463
487
  args.push(orderId);
464
488
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrder`, {
465
489
  method: 'POST',
466
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
490
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
467
491
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
468
492
  });
469
493
  if (!response.ok) {
@@ -486,7 +510,7 @@ class Exchange {
486
510
  args.push(marketId);
487
511
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOpenOrders`, {
488
512
  method: 'POST',
489
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
513
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
490
514
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
491
515
  });
492
516
  if (!response.ok) {
@@ -509,7 +533,7 @@ class Exchange {
509
533
  args.push(params);
510
534
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMyTrades`, {
511
535
  method: 'POST',
512
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
536
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
513
537
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
514
538
  });
515
539
  if (!response.ok) {
@@ -532,7 +556,7 @@ class Exchange {
532
556
  args.push(params);
533
557
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchClosedOrders`, {
534
558
  method: 'POST',
535
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
559
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
536
560
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
537
561
  });
538
562
  if (!response.ok) {
@@ -555,7 +579,7 @@ class Exchange {
555
579
  args.push(params);
556
580
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchAllOrders`, {
557
581
  method: 'POST',
558
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
582
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
559
583
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
560
584
  });
561
585
  if (!response.ok) {
@@ -576,7 +600,7 @@ class Exchange {
576
600
  const args = [];
577
601
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchPositions`, {
578
602
  method: 'POST',
579
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
603
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
580
604
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
581
605
  });
582
606
  if (!response.ok) {
@@ -597,7 +621,7 @@ class Exchange {
597
621
  const args = [];
598
622
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchBalance`, {
599
623
  method: 'POST',
600
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
624
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
601
625
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
602
626
  });
603
627
  if (!response.ok) {
@@ -618,7 +642,7 @@ class Exchange {
618
642
  const args = [];
619
643
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/close`, {
620
644
  method: 'POST',
621
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
645
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
622
646
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
623
647
  });
624
648
  if (!response.ok) {
@@ -670,7 +694,7 @@ class Exchange {
670
694
  const response = await this.api.fetchOHLCV({
671
695
  exchange: this.exchangeName,
672
696
  fetchOHLCVRequest: requestBody,
673
- });
697
+ }, { headers: this.getAuthHeaders() });
674
698
  const data = this.handleResponse(response);
675
699
  return data.map(convertCandle);
676
700
  }
@@ -701,7 +725,7 @@ class Exchange {
701
725
  const response = await this.api.fetchTrades({
702
726
  exchange: this.exchangeName,
703
727
  fetchTradesRequest: requestBody,
704
- });
728
+ }, { headers: this.getAuthHeaders() });
705
729
  const data = this.handleResponse(response);
706
730
  return data.map(convertTrade);
707
731
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxtjs",
3
- "version": "2.19.4",
3
+ "version": "2.19.6",
4
4
  "description": "OpenAPI client for pmxtjs",
5
5
  "author": "OpenAPI-Generator",
6
6
  "repository": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxtjs",
3
- "version": "2.19.4",
3
+ "version": "2.19.6",
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.19.4"
46
+ "pmxt-core": "2.19.6"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/jest": "^30.0.0",
package/pmxt/client.ts CHANGED
@@ -261,16 +261,9 @@ export abstract class Exchange {
261
261
  const actualPort = this.serverManager.getRunningPort();
262
262
  const newBaseUrl = `http://localhost:${actualPort}`;
263
263
 
264
- const accessToken = this.serverManager.getAccessToken();
265
- const headers: any = {};
266
- if (accessToken) {
267
- headers['x-pmxt-access-token'] = accessToken;
268
- }
269
-
270
264
  // Update API client with actual base URL
271
265
  this.config = new Configuration({
272
266
  basePath: newBaseUrl,
273
- headers
274
267
  });
275
268
  this.api = new DefaultApi(this.config);
276
269
  } catch (error) {
@@ -303,6 +296,15 @@ export abstract class Exchange {
303
296
  };
304
297
  }
305
298
 
299
+ protected getAuthHeaders(): Record<string, string> {
300
+ const headers: Record<string, string> = { ...(this.config.headers as Record<string, string>) };
301
+ const accessToken = this.serverManager.getAccessToken();
302
+ if (accessToken) {
303
+ headers['x-pmxt-access-token'] = accessToken;
304
+ }
305
+ return headers;
306
+ }
307
+
306
308
  // Low-Level API Access
307
309
 
308
310
  /**
@@ -334,7 +336,7 @@ export abstract class Exchange {
334
336
  method: 'POST',
335
337
  headers: {
336
338
  'Content-Type': 'application/json',
337
- ...this.config.headers
339
+ ...this.getAuthHeaders()
338
340
  },
339
341
  body: JSON.stringify(requestBody)
340
342
  });
@@ -360,7 +362,7 @@ export abstract class Exchange {
360
362
  args.push(reload);
361
363
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/loadMarkets`, {
362
364
  method: 'POST',
363
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
365
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
364
366
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
365
367
  });
366
368
  if (!response.ok) {
@@ -386,7 +388,7 @@ export abstract class Exchange {
386
388
  if (params !== undefined) args.push(params);
387
389
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarkets`, {
388
390
  method: 'POST',
389
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
391
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
390
392
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
391
393
  });
392
394
  if (!response.ok) {
@@ -408,7 +410,7 @@ export abstract class Exchange {
408
410
  if (params !== undefined) args.push(params);
409
411
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarketsPaginated`, {
410
412
  method: 'POST',
411
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
413
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
412
414
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
413
415
  });
414
416
  if (!response.ok) {
@@ -434,7 +436,7 @@ export abstract class Exchange {
434
436
  if (params !== undefined) args.push(params);
435
437
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvents`, {
436
438
  method: 'POST',
437
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
439
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
438
440
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
439
441
  });
440
442
  if (!response.ok) {
@@ -456,7 +458,7 @@ export abstract class Exchange {
456
458
  if (params !== undefined) args.push(params);
457
459
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarket`, {
458
460
  method: 'POST',
459
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
461
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
460
462
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
461
463
  });
462
464
  if (!response.ok) {
@@ -478,7 +480,7 @@ export abstract class Exchange {
478
480
  if (params !== undefined) args.push(params);
479
481
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvent`, {
480
482
  method: 'POST',
481
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
483
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
482
484
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
483
485
  });
484
486
  if (!response.ok) {
@@ -500,7 +502,7 @@ export abstract class Exchange {
500
502
  args.push(id);
501
503
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrderBook`, {
502
504
  method: 'POST',
503
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
505
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
504
506
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
505
507
  });
506
508
  if (!response.ok) {
@@ -515,6 +517,28 @@ export abstract class Exchange {
515
517
  }
516
518
  }
517
519
 
520
+ async submitOrder(built: any): Promise<Order> {
521
+ await this.initPromise;
522
+ try {
523
+ const args: any[] = [];
524
+ args.push(built);
525
+ const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/submitOrder`, {
526
+ method: 'POST',
527
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
528
+ body: JSON.stringify({ args, credentials: this.getCredentials() }),
529
+ });
530
+ if (!response.ok) {
531
+ const error = await response.json().catch(() => ({}));
532
+ throw new Error(error.error?.message || response.statusText);
533
+ }
534
+ const json = await response.json();
535
+ const data = this.handleResponse(json);
536
+ return convertOrder(data);
537
+ } catch (error) {
538
+ throw new Error(`Failed to submitOrder: ${error}`);
539
+ }
540
+ }
541
+
518
542
  async cancelOrder(orderId: string): Promise<Order> {
519
543
  await this.initPromise;
520
544
  try {
@@ -522,7 +546,7 @@ export abstract class Exchange {
522
546
  args.push(orderId);
523
547
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/cancelOrder`, {
524
548
  method: 'POST',
525
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
549
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
526
550
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
527
551
  });
528
552
  if (!response.ok) {
@@ -544,7 +568,7 @@ export abstract class Exchange {
544
568
  args.push(orderId);
545
569
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrder`, {
546
570
  method: 'POST',
547
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
571
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
548
572
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
549
573
  });
550
574
  if (!response.ok) {
@@ -566,7 +590,7 @@ export abstract class Exchange {
566
590
  if (marketId !== undefined) args.push(marketId);
567
591
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOpenOrders`, {
568
592
  method: 'POST',
569
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
593
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
570
594
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
571
595
  });
572
596
  if (!response.ok) {
@@ -588,7 +612,7 @@ export abstract class Exchange {
588
612
  if (params !== undefined) args.push(params);
589
613
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMyTrades`, {
590
614
  method: 'POST',
591
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
615
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
592
616
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
593
617
  });
594
618
  if (!response.ok) {
@@ -610,7 +634,7 @@ export abstract class Exchange {
610
634
  if (params !== undefined) args.push(params);
611
635
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchClosedOrders`, {
612
636
  method: 'POST',
613
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
637
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
614
638
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
615
639
  });
616
640
  if (!response.ok) {
@@ -632,7 +656,7 @@ export abstract class Exchange {
632
656
  if (params !== undefined) args.push(params);
633
657
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchAllOrders`, {
634
658
  method: 'POST',
635
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
659
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
636
660
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
637
661
  });
638
662
  if (!response.ok) {
@@ -653,7 +677,7 @@ export abstract class Exchange {
653
677
  const args: any[] = [];
654
678
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchPositions`, {
655
679
  method: 'POST',
656
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
680
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
657
681
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
658
682
  });
659
683
  if (!response.ok) {
@@ -674,7 +698,7 @@ export abstract class Exchange {
674
698
  const args: any[] = [];
675
699
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchBalance`, {
676
700
  method: 'POST',
677
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
701
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
678
702
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
679
703
  });
680
704
  if (!response.ok) {
@@ -695,7 +719,7 @@ export abstract class Exchange {
695
719
  const args: any[] = [];
696
720
  const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/close`, {
697
721
  method: 'POST',
698
- headers: { 'Content-Type': 'application/json', ...this.config.headers },
722
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
699
723
  body: JSON.stringify({ args, credentials: this.getCredentials() }),
700
724
  });
701
725
  if (!response.ok) {
@@ -753,7 +777,7 @@ export abstract class Exchange {
753
777
  const response = await this.api.fetchOHLCV({
754
778
  exchange: this.exchangeName as any,
755
779
  fetchOHLCVRequest: requestBody,
756
- });
780
+ }, { headers: this.getAuthHeaders() });
757
781
 
758
782
  const data = this.handleResponse(response);
759
783
  return data.map(convertCandle);
@@ -790,7 +814,7 @@ export abstract class Exchange {
790
814
  const response = await this.api.fetchTrades({
791
815
  exchange: this.exchangeName as any,
792
816
  fetchTradesRequest: requestBody,
793
- });
817
+ }, { headers: this.getAuthHeaders() });
794
818
 
795
819
  const data = this.handleResponse(response);
796
820
  return data.map(convertTrade);