pmxtjs 2.26.2 → 2.27.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.
Files changed (138) hide show
  1. package/dist/esm/generated/src/apis/DefaultApi.d.ts +266 -106
  2. package/dist/esm/generated/src/apis/DefaultApi.js +346 -61
  3. package/dist/esm/generated/src/models/index.d.ts +0 -19
  4. package/dist/esm/generated/src/models/index.js +0 -19
  5. package/dist/esm/pmxt/client.d.ts +59 -4
  6. package/dist/esm/pmxt/client.js +181 -195
  7. package/dist/esm/pmxt/constants.d.ts +53 -0
  8. package/dist/esm/pmxt/constants.js +60 -0
  9. package/dist/generated/src/apis/DefaultApi.d.ts +266 -106
  10. package/dist/generated/src/apis/DefaultApi.js +346 -61
  11. package/dist/generated/src/models/index.d.ts +0 -19
  12. package/dist/generated/src/models/index.js +0 -19
  13. package/dist/pmxt/client.d.ts +59 -4
  14. package/dist/pmxt/client.js +181 -195
  15. package/dist/pmxt/constants.d.ts +53 -0
  16. package/dist/pmxt/constants.js +64 -0
  17. package/generated/.openapi-generator/FILES +0 -38
  18. package/generated/docs/DefaultApi.md +276 -120
  19. package/generated/package.json +1 -1
  20. package/generated/src/apis/DefaultApi.ts +590 -210
  21. package/generated/src/models/index.ts +0 -19
  22. package/package.json +2 -2
  23. package/pmxt/client.ts +223 -208
  24. package/pmxt/constants.ts +67 -0
  25. package/dist/esm/generated/src/models/FetchAllOrdersRequest.d.ts +0 -40
  26. package/dist/esm/generated/src/models/FetchAllOrdersRequest.js +0 -45
  27. package/dist/esm/generated/src/models/FetchBalanceRequest.d.ts +0 -39
  28. package/dist/esm/generated/src/models/FetchBalanceRequest.js +0 -44
  29. package/dist/esm/generated/src/models/FetchClosedOrdersRequest.d.ts +0 -40
  30. package/dist/esm/generated/src/models/FetchClosedOrdersRequest.js +0 -45
  31. package/dist/esm/generated/src/models/FetchEventRequest.d.ts +0 -40
  32. package/dist/esm/generated/src/models/FetchEventRequest.js +0 -45
  33. package/dist/esm/generated/src/models/FetchEventsRequest.d.ts +0 -40
  34. package/dist/esm/generated/src/models/FetchEventsRequest.js +0 -45
  35. package/dist/esm/generated/src/models/FetchMarketRequest.d.ts +0 -40
  36. package/dist/esm/generated/src/models/FetchMarketRequest.js +0 -45
  37. package/dist/esm/generated/src/models/FetchMarketsPaginatedRequest.d.ts +0 -40
  38. package/dist/esm/generated/src/models/FetchMarketsPaginatedRequest.js +0 -45
  39. package/dist/esm/generated/src/models/FetchMarketsPaginatedRequestArgsInner.d.ts +0 -38
  40. package/dist/esm/generated/src/models/FetchMarketsPaginatedRequestArgsInner.js +0 -43
  41. package/dist/esm/generated/src/models/FetchMarketsRequest.d.ts +0 -40
  42. package/dist/esm/generated/src/models/FetchMarketsRequest.js +0 -45
  43. package/dist/esm/generated/src/models/FetchMyTradesRequest.d.ts +0 -40
  44. package/dist/esm/generated/src/models/FetchMyTradesRequest.js +0 -45
  45. package/dist/esm/generated/src/models/FetchOHLCVRequest.d.ts +0 -40
  46. package/dist/esm/generated/src/models/FetchOHLCVRequest.js +0 -47
  47. package/dist/esm/generated/src/models/FetchOHLCVRequestArgsInner.d.ts +0 -22
  48. package/dist/esm/generated/src/models/FetchOHLCVRequestArgsInner.js +0 -50
  49. package/dist/esm/generated/src/models/FetchOpenOrdersRequest.d.ts +0 -39
  50. package/dist/esm/generated/src/models/FetchOpenOrdersRequest.js +0 -44
  51. package/dist/esm/generated/src/models/FetchOrderBookRequest.d.ts +0 -39
  52. package/dist/esm/generated/src/models/FetchOrderBookRequest.js +0 -46
  53. package/dist/esm/generated/src/models/FetchOrderRequest.d.ts +0 -39
  54. package/dist/esm/generated/src/models/FetchOrderRequest.js +0 -46
  55. package/dist/esm/generated/src/models/FetchPositionsRequest.d.ts +0 -39
  56. package/dist/esm/generated/src/models/FetchPositionsRequest.js +0 -44
  57. package/dist/esm/generated/src/models/FetchTradesRequest.d.ts +0 -40
  58. package/dist/esm/generated/src/models/FetchTradesRequest.js +0 -47
  59. package/dist/esm/generated/src/models/FetchTradesRequestArgsInner.d.ts +0 -22
  60. package/dist/esm/generated/src/models/FetchTradesRequestArgsInner.js +0 -50
  61. package/dist/esm/generated/src/models/FetchTradesRequestArgsInnerOneOf.d.ts +0 -24
  62. package/dist/esm/generated/src/models/FetchTradesRequestArgsInnerOneOf.js +0 -54
  63. package/dist/generated/src/models/FetchAllOrdersRequest.d.ts +0 -40
  64. package/dist/generated/src/models/FetchAllOrdersRequest.js +0 -52
  65. package/dist/generated/src/models/FetchBalanceRequest.d.ts +0 -39
  66. package/dist/generated/src/models/FetchBalanceRequest.js +0 -51
  67. package/dist/generated/src/models/FetchClosedOrdersRequest.d.ts +0 -40
  68. package/dist/generated/src/models/FetchClosedOrdersRequest.js +0 -52
  69. package/dist/generated/src/models/FetchEventRequest.d.ts +0 -40
  70. package/dist/generated/src/models/FetchEventRequest.js +0 -52
  71. package/dist/generated/src/models/FetchEventsRequest.d.ts +0 -40
  72. package/dist/generated/src/models/FetchEventsRequest.js +0 -52
  73. package/dist/generated/src/models/FetchMarketRequest.d.ts +0 -40
  74. package/dist/generated/src/models/FetchMarketRequest.js +0 -52
  75. package/dist/generated/src/models/FetchMarketsPaginatedRequest.d.ts +0 -40
  76. package/dist/generated/src/models/FetchMarketsPaginatedRequest.js +0 -52
  77. package/dist/generated/src/models/FetchMarketsPaginatedRequestArgsInner.d.ts +0 -38
  78. package/dist/generated/src/models/FetchMarketsPaginatedRequestArgsInner.js +0 -50
  79. package/dist/generated/src/models/FetchMarketsRequest.d.ts +0 -40
  80. package/dist/generated/src/models/FetchMarketsRequest.js +0 -52
  81. package/dist/generated/src/models/FetchMyTradesRequest.d.ts +0 -40
  82. package/dist/generated/src/models/FetchMyTradesRequest.js +0 -52
  83. package/dist/generated/src/models/FetchOHLCVRequest.d.ts +0 -40
  84. package/dist/generated/src/models/FetchOHLCVRequest.js +0 -54
  85. package/dist/generated/src/models/FetchOHLCVRequestArgsInner.d.ts +0 -22
  86. package/dist/generated/src/models/FetchOHLCVRequestArgsInner.js +0 -56
  87. package/dist/generated/src/models/FetchOpenOrdersRequest.d.ts +0 -39
  88. package/dist/generated/src/models/FetchOpenOrdersRequest.js +0 -51
  89. package/dist/generated/src/models/FetchOrderBookRequest.d.ts +0 -39
  90. package/dist/generated/src/models/FetchOrderBookRequest.js +0 -53
  91. package/dist/generated/src/models/FetchOrderRequest.d.ts +0 -39
  92. package/dist/generated/src/models/FetchOrderRequest.js +0 -53
  93. package/dist/generated/src/models/FetchPositionsRequest.d.ts +0 -39
  94. package/dist/generated/src/models/FetchPositionsRequest.js +0 -51
  95. package/dist/generated/src/models/FetchTradesRequest.d.ts +0 -40
  96. package/dist/generated/src/models/FetchTradesRequest.js +0 -54
  97. package/dist/generated/src/models/FetchTradesRequestArgsInner.d.ts +0 -22
  98. package/dist/generated/src/models/FetchTradesRequestArgsInner.js +0 -56
  99. package/dist/generated/src/models/FetchTradesRequestArgsInnerOneOf.d.ts +0 -24
  100. package/dist/generated/src/models/FetchTradesRequestArgsInnerOneOf.js +0 -61
  101. package/generated/docs/FetchAllOrdersRequest.md +0 -36
  102. package/generated/docs/FetchBalanceRequest.md +0 -36
  103. package/generated/docs/FetchClosedOrdersRequest.md +0 -36
  104. package/generated/docs/FetchEventRequest.md +0 -36
  105. package/generated/docs/FetchEventsRequest.md +0 -36
  106. package/generated/docs/FetchMarketRequest.md +0 -36
  107. package/generated/docs/FetchMarketsPaginatedRequest.md +0 -36
  108. package/generated/docs/FetchMarketsPaginatedRequestArgsInner.md +0 -36
  109. package/generated/docs/FetchMarketsRequest.md +0 -36
  110. package/generated/docs/FetchMyTradesRequest.md +0 -36
  111. package/generated/docs/FetchOHLCVRequest.md +0 -36
  112. package/generated/docs/FetchOHLCVRequestArgsInner.md +0 -40
  113. package/generated/docs/FetchOpenOrdersRequest.md +0 -36
  114. package/generated/docs/FetchOrderBookRequest.md +0 -36
  115. package/generated/docs/FetchOrderRequest.md +0 -36
  116. package/generated/docs/FetchPositionsRequest.md +0 -36
  117. package/generated/docs/FetchTradesRequest.md +0 -36
  118. package/generated/docs/FetchTradesRequestArgsInner.md +0 -40
  119. package/generated/docs/FetchTradesRequestArgsInnerOneOf.md +0 -40
  120. package/generated/src/models/FetchAllOrdersRequest.ts +0 -88
  121. package/generated/src/models/FetchBalanceRequest.ts +0 -81
  122. package/generated/src/models/FetchClosedOrdersRequest.ts +0 -88
  123. package/generated/src/models/FetchEventRequest.ts +0 -88
  124. package/generated/src/models/FetchEventsRequest.ts +0 -88
  125. package/generated/src/models/FetchMarketRequest.ts +0 -88
  126. package/generated/src/models/FetchMarketsPaginatedRequest.ts +0 -88
  127. package/generated/src/models/FetchMarketsPaginatedRequestArgsInner.ts +0 -73
  128. package/generated/src/models/FetchMarketsRequest.ts +0 -88
  129. package/generated/src/models/FetchMyTradesRequest.ts +0 -88
  130. package/generated/src/models/FetchOHLCVRequest.ts +0 -89
  131. package/generated/src/models/FetchOHLCVRequestArgsInner.ts +0 -69
  132. package/generated/src/models/FetchOpenOrdersRequest.ts +0 -81
  133. package/generated/src/models/FetchOrderBookRequest.ts +0 -82
  134. package/generated/src/models/FetchOrderRequest.ts +0 -82
  135. package/generated/src/models/FetchPositionsRequest.ts +0 -81
  136. package/generated/src/models/FetchTradesRequest.ts +0 -89
  137. package/generated/src/models/FetchTradesRequestArgsInner.ts +0 -69
  138. package/generated/src/models/FetchTradesRequestArgsInnerOneOf.ts +0 -80
@@ -18,37 +18,18 @@ export * from './EventFetchParams';
18
18
  export * from './ExchangeCredentials';
19
19
  export * from './ExchangeCredentialsSignatureType';
20
20
  export * from './ExecutionPriceResult';
21
- export * from './FetchAllOrdersRequest';
22
21
  export * from './FetchBalance200Response';
23
- export * from './FetchBalanceRequest';
24
- export * from './FetchClosedOrdersRequest';
25
22
  export * from './FetchEvent200Response';
26
- export * from './FetchEventRequest';
27
23
  export * from './FetchEvents200Response';
28
- export * from './FetchEventsRequest';
29
24
  export * from './FetchMarket200Response';
30
- export * from './FetchMarketRequest';
31
25
  export * from './FetchMarkets200Response';
32
26
  export * from './FetchMarketsPaginated200Response';
33
- export * from './FetchMarketsPaginatedRequest';
34
- export * from './FetchMarketsPaginatedRequestArgsInner';
35
- export * from './FetchMarketsRequest';
36
27
  export * from './FetchMyTrades200Response';
37
- export * from './FetchMyTradesRequest';
38
28
  export * from './FetchOHLCV200Response';
39
- export * from './FetchOHLCVRequest';
40
- export * from './FetchOHLCVRequestArgsInner';
41
29
  export * from './FetchOpenOrders200Response';
42
- export * from './FetchOpenOrdersRequest';
43
30
  export * from './FetchOrderBook200Response';
44
- export * from './FetchOrderBookRequest';
45
- export * from './FetchOrderRequest';
46
31
  export * from './FetchPositions200Response';
47
- export * from './FetchPositionsRequest';
48
32
  export * from './FetchTrades200Response';
49
- export * from './FetchTradesRequest';
50
- export * from './FetchTradesRequestArgsInner';
51
- export * from './FetchTradesRequestArgsInnerOneOf';
52
33
  export * from './FilterEventsRequest';
53
34
  export * from './FilterEventsRequestArgsInner';
54
35
  export * from './FilterMarketsRequest';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxtjs",
3
- "version": "2.26.2",
3
+ "version": "2.27.1",
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.26.2"
46
+ "pmxt-core": "2.27.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/jest": "^30.0.0",
package/pmxt/client.ts CHANGED
@@ -10,8 +10,6 @@ import {
10
10
  CreateOrderRequest,
11
11
  DefaultApi,
12
12
  ExchangeCredentials,
13
- FetchOHLCVRequest,
14
- FetchTradesRequest,
15
13
  BuildOrderRequest,
16
14
  SubmitOrderRequest,
17
15
  } from "../generated/src/index.js";
@@ -44,6 +42,7 @@ import {
44
42
  import { ServerManager } from "./server-manager.js";
45
43
  import { buildArgsWithOptionalOptions } from "./args.js";
46
44
  import { PmxtError, fromServerError } from "./errors.js";
45
+ import { LOCAL_URL, resolvePmxtBaseUrl } from "./constants.js";
47
46
 
48
47
  /**
49
48
  * Resolve a MarketOutcome shorthand to a plain outcome ID string.
@@ -54,6 +53,47 @@ function resolveOutcomeId(input: string | MarketOutcome): string {
54
53
  return input.outcomeId;
55
54
  }
56
55
 
56
+ /**
57
+ * Build a URL-encoded query string from a plain record.
58
+ *
59
+ * - `undefined` / `null` values are skipped (they shouldn't appear in the URL).
60
+ * - Arrays are serialised as repeated `key=v1&key=v2` pairs.
61
+ * - Nested objects are skipped here; callers should route such queries through
62
+ * POST instead (see `queryHasNestedObject`).
63
+ */
64
+ function buildSidecarQueryString(query: Record<string, unknown>): string {
65
+ const parts: string[] = [];
66
+ for (const [key, value] of Object.entries(query)) {
67
+ if (value === undefined || value === null) continue;
68
+ if (Array.isArray(value)) {
69
+ for (const v of value) {
70
+ if (v === undefined || v === null) continue;
71
+ parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(v))}`);
72
+ }
73
+ } else if (typeof value === 'object') {
74
+ // Nested objects don't round-trip through query strings. Caller
75
+ // should have detected this and POSTed instead.
76
+ continue;
77
+ } else {
78
+ parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
79
+ }
80
+ }
81
+ return parts.join('&');
82
+ }
83
+
84
+ /**
85
+ * True if any top-level value in the query is a nested object (not an array).
86
+ * Such queries can't be safely expressed in a query string, so we fall back
87
+ * to POST to preserve the original argument shape.
88
+ */
89
+ function queryHasNestedObject(query: Record<string, unknown>): boolean {
90
+ for (const value of Object.values(query)) {
91
+ if (value === undefined || value === null) continue;
92
+ if (typeof value === 'object' && !Array.isArray(value)) return true;
93
+ }
94
+ return false;
95
+ }
96
+
57
97
  // Converter functions
58
98
  function convertMarket(raw: any): UnifiedMarket {
59
99
  const outcomes: MarketOutcome[] = (raw.outcomes || []).map((o: any) => ({
@@ -232,16 +272,43 @@ function convertSubscriptionSnapshot(raw: any): SubscribedAddressSnapshot {
232
272
  * Base exchange client options.
233
273
  */
234
274
  export interface ExchangeOptions {
235
- /** API key for authentication (optional) */
275
+ /** Venue-specific API key (e.g. Polymarket CLOB key). Optional. */
236
276
  apiKey?: string;
237
277
 
238
- /** Private key for authentication (optional) */
278
+ /** Venue-specific private key. Optional. */
239
279
  privateKey?: string;
240
280
 
241
- /** Base URL of the PMXT sidecar server */
281
+ /**
282
+ * Hosted pmxt API key.
283
+ *
284
+ * When set (either as this kwarg or via the `PMXT_API_KEY` env
285
+ * variable), and no explicit `baseUrl` / `PMXT_BASE_URL` is set,
286
+ * the Exchange will default to the hosted pmxt endpoint
287
+ * (`https://api.pmxt.dev`) instead of the local sidecar, and send
288
+ * `Authorization: Bearer <pmxtApiKey>` on every request.
289
+ *
290
+ * The local sidecar ignores this header, so it is safe to set in
291
+ * both local and hosted modes.
292
+ */
293
+ pmxtApiKey?: string;
294
+
295
+ /**
296
+ * Base URL of the pmxt server.
297
+ *
298
+ * Resolution precedence:
299
+ * 1. Explicit `baseUrl` kwarg.
300
+ * 2. `PMXT_BASE_URL` environment variable.
301
+ * 3. `HOSTED_URL` when `pmxtApiKey` (kwarg or env) is present.
302
+ * 4. Local sidecar (`http://localhost:3847`).
303
+ */
242
304
  baseUrl?: string;
243
305
 
244
- /** Automatically start server if not running (default: true) */
306
+ /**
307
+ * Automatically start the local sidecar if it is not running.
308
+ *
309
+ * Default: `true` when the resolved base URL is the local sidecar,
310
+ * `false` otherwise. Explicit `true` / `false` always wins.
311
+ */
245
312
  autoStartServer?: boolean;
246
313
 
247
314
  /** Optional Polymarket Proxy/Smart Wallet address */
@@ -261,12 +328,22 @@ export abstract class Exchange {
261
328
  protected exchangeName: string;
262
329
  protected apiKey?: string;
263
330
  protected privateKey?: string;
331
+ protected pmxtApiKey?: string;
264
332
  protected proxyAddress?: string;
265
333
  protected signatureType?: number;
266
334
  protected api: DefaultApi;
267
335
  protected config: Configuration;
268
336
  protected serverManager: ServerManager;
269
337
  protected initPromise: Promise<void>;
338
+ protected isHosted: boolean;
339
+
340
+ /**
341
+ * Sticky flag: set to `true` the first time a GET read is rejected by
342
+ * the sidecar with 404/405 (i.e. an older pmxt-core that only supports
343
+ * POST). While false, read methods try GET first; once flipped they
344
+ * POST directly and skip the GET probe for the lifetime of this client.
345
+ */
346
+ private _getReadsUnsupported: boolean = false;
270
347
 
271
348
  constructor(exchangeName: string, options: ExchangeOptions = {}) {
272
349
  this.exchangeName = exchangeName.toLowerCase();
@@ -275,13 +352,29 @@ export abstract class Exchange {
275
352
  this.proxyAddress = options.proxyAddress;
276
353
  this.signatureType = options.signatureType;
277
354
 
278
- let baseUrl = options.baseUrl || "http://localhost:3847";
279
- const autoStartServer = options.autoStartServer !== false;
280
-
281
- // Initialize server manager
355
+ // Resolve base URL + hosted API key via the shared precedence
356
+ // rules. See constants.ts for the full resolution table.
357
+ const resolved = resolvePmxtBaseUrl({
358
+ baseUrl: options.baseUrl,
359
+ pmxtApiKey: options.pmxtApiKey,
360
+ });
361
+ const baseUrl = resolved.baseUrl;
362
+ this.pmxtApiKey = resolved.pmxtApiKey;
363
+ this.isHosted = resolved.isHosted;
364
+
365
+ // auto_start_server defaults: true for local, false for hosted.
366
+ // An explicit value in the options always wins.
367
+ const autoStartServer = options.autoStartServer !== undefined
368
+ ? options.autoStartServer
369
+ : !this.isHosted;
370
+
371
+ // Initialize server manager (no network calls happen here — the
372
+ // constructor just stores config).
282
373
  this.serverManager = new ServerManager({ baseUrl });
283
374
 
284
- // Configure the API client with the initial base URL (will be updated if port changes)
375
+ // Configure the API client with the initial base URL (will be
376
+ // updated to the actual listen port if the local sidecar gets
377
+ // bumped off the default).
285
378
  this.config = new Configuration({ basePath: baseUrl });
286
379
  this.api = new DefaultApi(this.config);
287
380
 
@@ -339,10 +432,22 @@ export abstract class Exchange {
339
432
 
340
433
  protected getAuthHeaders(): Record<string, string> {
341
434
  const headers: Record<string, string> = { ...(this.config.headers as Record<string, string>) };
435
+
436
+ // Local sidecar access token (read from the lock file). Only
437
+ // meaningful when talking to a local sidecar we spawned
438
+ // ourselves; harmless elsewhere.
342
439
  const accessToken = this.serverManager.getAccessToken();
343
440
  if (accessToken) {
344
441
  headers['x-pmxt-access-token'] = accessToken;
345
442
  }
443
+
444
+ // Hosted pmxt bearer token. The hosted service requires this;
445
+ // the local sidecar ignores it. Safe to attach unconditionally
446
+ // whenever a pmxtApiKey has been resolved.
447
+ if (this.pmxtApiKey) {
448
+ headers['Authorization'] = `Bearer ${this.pmxtApiKey}`;
449
+ }
450
+
346
451
  return headers;
347
452
  }
348
453
 
@@ -398,6 +503,75 @@ export abstract class Exchange {
398
503
  }
399
504
  }
400
505
 
506
+ /**
507
+ * Dispatch a sidecar read method, preferring GET but transparently
508
+ * falling back to POST for full backward compatibility.
509
+ *
510
+ * GET is used when:
511
+ * - the client has no per-instance credentials (the sidecar's GET
512
+ * handler intentionally drops credentials to avoid leaking them
513
+ * through query strings and access logs), and
514
+ * - the sidecar hasn't already returned 404/405 for a previous GET
515
+ * in this client's lifetime (`_getReadsUnsupported`), and
516
+ * - the query has no nested objects (query strings can't round-trip
517
+ * arbitrary JSON).
518
+ *
519
+ * Otherwise (or if the GET attempt is rejected with 404/405) the call
520
+ * is sent as POST with the original `{args, credentials}` body so that
521
+ * SDK users talking to an older pmxt-core continue to work unchanged.
522
+ *
523
+ * @internal — shared transport used by every generated read method.
524
+ */
525
+ protected async sidecarReadRequest(
526
+ methodName: string,
527
+ query: Record<string, unknown>,
528
+ args: unknown[],
529
+ ): Promise<any> {
530
+ const baseUrl = `${this.config.basePath}/api/${this.exchangeName}/${methodName}`;
531
+ const hasCredentials = this.getCredentials() !== undefined;
532
+
533
+ if (!hasCredentials && !this._getReadsUnsupported && !queryHasNestedObject(query)) {
534
+ const qs = buildSidecarQueryString(query);
535
+ const getUrl = qs ? `${baseUrl}?${qs}` : baseUrl;
536
+ const response = await fetch(getUrl, {
537
+ method: 'GET',
538
+ headers: this.getAuthHeaders(),
539
+ });
540
+
541
+ // 404 / 405 => older sidecar without GET dispatch. Remember
542
+ // the downgrade so future calls skip the probe, and fall
543
+ // through to POST below.
544
+ if (response.status === 404 || response.status === 405) {
545
+ await response.text().catch(() => undefined);
546
+ this._getReadsUnsupported = true;
547
+ } else {
548
+ if (!response.ok) {
549
+ const body = await response.json().catch(() => ({}));
550
+ if (body.error && typeof body.error === "object") {
551
+ throw fromServerError(body.error);
552
+ }
553
+ throw new PmxtError(body.error?.message || response.statusText);
554
+ }
555
+ return response.json();
556
+ }
557
+ }
558
+
559
+ // POST fallback — identical to the original per-method template.
560
+ const response = await fetch(baseUrl, {
561
+ method: 'POST',
562
+ headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
563
+ body: JSON.stringify({ args, credentials: this.getCredentials() }),
564
+ });
565
+ if (!response.ok) {
566
+ const body = await response.json().catch(() => ({}));
567
+ if (body.error && typeof body.error === "object") {
568
+ throw fromServerError(body.error);
569
+ }
570
+ throw new PmxtError(body.error?.message || response.statusText);
571
+ }
572
+ return response.json();
573
+ }
574
+
401
575
  // BEGIN GENERATED METHODS
402
576
 
403
577
  async loadMarkets(reload: boolean = false): Promise<Record<string, UnifiedMarket>> {
@@ -434,19 +608,8 @@ export abstract class Exchange {
434
608
  await this.initPromise;
435
609
  try {
436
610
  const args = buildArgsWithOptionalOptions(params);
437
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarkets`, {
438
- method: 'POST',
439
- headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
440
- body: JSON.stringify({ args, credentials: this.getCredentials() }),
441
- });
442
- if (!response.ok) {
443
- const body = await response.json().catch(() => ({}));
444
- if (body.error && typeof body.error === "object") {
445
- throw fromServerError(body.error);
446
- }
447
- throw new PmxtError(body.error?.message || response.statusText);
448
- }
449
- const json = await response.json();
611
+ const query = { ...(params || {}) };
612
+ const json = await this.sidecarReadRequest('fetchMarkets', query, args);
450
613
  const data = this.handleResponse(json);
451
614
  return data.map(convertMarket);
452
615
  } catch (error) {
@@ -459,19 +622,8 @@ export abstract class Exchange {
459
622
  await this.initPromise;
460
623
  try {
461
624
  const args = buildArgsWithOptionalOptions(params);
462
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarketsPaginated`, {
463
- method: 'POST',
464
- headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
465
- body: JSON.stringify({ args, credentials: this.getCredentials() }),
466
- });
467
- if (!response.ok) {
468
- const body = await response.json().catch(() => ({}));
469
- if (body.error && typeof body.error === "object") {
470
- throw fromServerError(body.error);
471
- }
472
- throw new PmxtError(body.error?.message || response.statusText);
473
- }
474
- const json = await response.json();
625
+ const query = { ...(params || {}) };
626
+ const json = await this.sidecarReadRequest('fetchMarketsPaginated', query, args);
475
627
  const data = this.handleResponse(json);
476
628
  return {
477
629
  data: (data.data || []).map(convertMarket),
@@ -488,19 +640,8 @@ export abstract class Exchange {
488
640
  await this.initPromise;
489
641
  try {
490
642
  const args = buildArgsWithOptionalOptions(params);
491
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvents`, {
492
- method: 'POST',
493
- headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
494
- body: JSON.stringify({ args, credentials: this.getCredentials() }),
495
- });
496
- if (!response.ok) {
497
- const body = await response.json().catch(() => ({}));
498
- if (body.error && typeof body.error === "object") {
499
- throw fromServerError(body.error);
500
- }
501
- throw new PmxtError(body.error?.message || response.statusText);
502
- }
503
- const json = await response.json();
643
+ const query = { ...(params || {}) };
644
+ const json = await this.sidecarReadRequest('fetchEvents', query, args);
504
645
  const data = this.handleResponse(json);
505
646
  return data.map(convertEvent);
506
647
  } catch (error) {
@@ -513,19 +654,8 @@ export abstract class Exchange {
513
654
  await this.initPromise;
514
655
  try {
515
656
  const args = buildArgsWithOptionalOptions(params);
516
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMarket`, {
517
- method: 'POST',
518
- headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
519
- body: JSON.stringify({ args, credentials: this.getCredentials() }),
520
- });
521
- if (!response.ok) {
522
- const body = await response.json().catch(() => ({}));
523
- if (body.error && typeof body.error === "object") {
524
- throw fromServerError(body.error);
525
- }
526
- throw new PmxtError(body.error?.message || response.statusText);
527
- }
528
- const json = await response.json();
657
+ const query = { ...(params || {}) };
658
+ const json = await this.sidecarReadRequest('fetchMarket', query, args);
529
659
  const data = this.handleResponse(json);
530
660
  return convertMarket(data);
531
661
  } catch (error) {
@@ -538,19 +668,8 @@ export abstract class Exchange {
538
668
  await this.initPromise;
539
669
  try {
540
670
  const args = buildArgsWithOptionalOptions(params);
541
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchEvent`, {
542
- method: 'POST',
543
- headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
544
- body: JSON.stringify({ args, credentials: this.getCredentials() }),
545
- });
546
- if (!response.ok) {
547
- const body = await response.json().catch(() => ({}));
548
- if (body.error && typeof body.error === "object") {
549
- throw fromServerError(body.error);
550
- }
551
- throw new PmxtError(body.error?.message || response.statusText);
552
- }
553
- const json = await response.json();
671
+ const query = { ...(params || {}) };
672
+ const json = await this.sidecarReadRequest('fetchEvent', query, args);
554
673
  const data = this.handleResponse(json);
555
674
  return convertEvent(data);
556
675
  } catch (error) {
@@ -563,21 +682,9 @@ export abstract class Exchange {
563
682
  await this.initPromise;
564
683
  const resolvedId = resolveOutcomeId(id);
565
684
  try {
566
- const args: any[] = [];
567
- args.push(resolvedId);
568
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrderBook`, {
569
- method: 'POST',
570
- headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
571
- body: JSON.stringify({ args, credentials: this.getCredentials() }),
572
- });
573
- if (!response.ok) {
574
- const body = await response.json().catch(() => ({}));
575
- if (body.error && typeof body.error === "object") {
576
- throw fromServerError(body.error);
577
- }
578
- throw new PmxtError(body.error?.message || response.statusText);
579
- }
580
- const json = await response.json();
685
+ const args: any[] = [resolvedId];
686
+ const query = { id: resolvedId };
687
+ const json = await this.sidecarReadRequest('fetchOrderBook', query, args);
581
688
  const data = this.handleResponse(json);
582
689
  return convertOrderBook(data);
583
690
  } catch (error) {
@@ -616,21 +723,9 @@ export abstract class Exchange {
616
723
  async fetchOrder(orderId: string): Promise<Order> {
617
724
  await this.initPromise;
618
725
  try {
619
- const args: any[] = [];
620
- args.push(orderId);
621
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOrder`, {
622
- method: 'POST',
623
- headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
624
- body: JSON.stringify({ args, credentials: this.getCredentials() }),
625
- });
626
- if (!response.ok) {
627
- const body = await response.json().catch(() => ({}));
628
- if (body.error && typeof body.error === "object") {
629
- throw fromServerError(body.error);
630
- }
631
- throw new PmxtError(body.error?.message || response.statusText);
632
- }
633
- const json = await response.json();
726
+ const args: any[] = [orderId];
727
+ const query = { orderId };
728
+ const json = await this.sidecarReadRequest('fetchOrder', query, args);
634
729
  const data = this.handleResponse(json);
635
730
  return convertOrder(data);
636
731
  } catch (error) {
@@ -643,19 +738,8 @@ export abstract class Exchange {
643
738
  await this.initPromise;
644
739
  try {
645
740
  const args = buildArgsWithOptionalOptions(marketId);
646
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchOpenOrders`, {
647
- method: 'POST',
648
- headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
649
- body: JSON.stringify({ args, credentials: this.getCredentials() }),
650
- });
651
- if (!response.ok) {
652
- const body = await response.json().catch(() => ({}));
653
- if (body.error && typeof body.error === "object") {
654
- throw fromServerError(body.error);
655
- }
656
- throw new PmxtError(body.error?.message || response.statusText);
657
- }
658
- const json = await response.json();
741
+ const query = { marketId };
742
+ const json = await this.sidecarReadRequest('fetchOpenOrders', query, args);
659
743
  const data = this.handleResponse(json);
660
744
  return data.map(convertOrder);
661
745
  } catch (error) {
@@ -668,19 +752,8 @@ export abstract class Exchange {
668
752
  await this.initPromise;
669
753
  try {
670
754
  const args = buildArgsWithOptionalOptions(params);
671
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchMyTrades`, {
672
- method: 'POST',
673
- headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
674
- body: JSON.stringify({ args, credentials: this.getCredentials() }),
675
- });
676
- if (!response.ok) {
677
- const body = await response.json().catch(() => ({}));
678
- if (body.error && typeof body.error === "object") {
679
- throw fromServerError(body.error);
680
- }
681
- throw new PmxtError(body.error?.message || response.statusText);
682
- }
683
- const json = await response.json();
755
+ const query = { ...(params || {}) };
756
+ const json = await this.sidecarReadRequest('fetchMyTrades', query, args);
684
757
  const data = this.handleResponse(json);
685
758
  return data.map(convertUserTrade);
686
759
  } catch (error) {
@@ -693,19 +766,8 @@ export abstract class Exchange {
693
766
  await this.initPromise;
694
767
  try {
695
768
  const args = buildArgsWithOptionalOptions(params);
696
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchClosedOrders`, {
697
- method: 'POST',
698
- headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
699
- body: JSON.stringify({ args, credentials: this.getCredentials() }),
700
- });
701
- if (!response.ok) {
702
- const body = await response.json().catch(() => ({}));
703
- if (body.error && typeof body.error === "object") {
704
- throw fromServerError(body.error);
705
- }
706
- throw new PmxtError(body.error?.message || response.statusText);
707
- }
708
- const json = await response.json();
769
+ const query = { ...(params || {}) };
770
+ const json = await this.sidecarReadRequest('fetchClosedOrders', query, args);
709
771
  const data = this.handleResponse(json);
710
772
  return data.map(convertOrder);
711
773
  } catch (error) {
@@ -718,19 +780,8 @@ export abstract class Exchange {
718
780
  await this.initPromise;
719
781
  try {
720
782
  const args = buildArgsWithOptionalOptions(params);
721
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchAllOrders`, {
722
- method: 'POST',
723
- headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
724
- body: JSON.stringify({ args, credentials: this.getCredentials() }),
725
- });
726
- if (!response.ok) {
727
- const body = await response.json().catch(() => ({}));
728
- if (body.error && typeof body.error === "object") {
729
- throw fromServerError(body.error);
730
- }
731
- throw new PmxtError(body.error?.message || response.statusText);
732
- }
733
- const json = await response.json();
783
+ const query = { ...(params || {}) };
784
+ const json = await this.sidecarReadRequest('fetchAllOrders', query, args);
734
785
  const data = this.handleResponse(json);
735
786
  return data.map(convertOrder);
736
787
  } catch (error) {
@@ -742,20 +793,9 @@ export abstract class Exchange {
742
793
  async fetchPositions(address?: string): Promise<Position[]> {
743
794
  await this.initPromise;
744
795
  try {
745
- const args: any[] = address? [address] : [];
746
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchPositions`, {
747
- method: 'POST',
748
- headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
749
- body: JSON.stringify({ args, credentials: this.getCredentials() }),
750
- });
751
- if (!response.ok) {
752
- const body = await response.json().catch(() => ({}));
753
- if (body.error && typeof body.error === "object") {
754
- throw fromServerError(body.error);
755
- }
756
- throw new PmxtError(body.error?.message || response.statusText);
757
- }
758
- const json = await response.json();
796
+ const args: any[] = address ? [address] : [];
797
+ const query = { address };
798
+ const json = await this.sidecarReadRequest('fetchPositions', query, args);
759
799
  const data = this.handleResponse(json);
760
800
  return data.map(convertPosition);
761
801
  } catch (error) {
@@ -767,20 +807,9 @@ export abstract class Exchange {
767
807
  async fetchBalance(address?: string): Promise<Balance[]> {
768
808
  await this.initPromise;
769
809
  try {
770
- const args: any[] = address? [address] : [];
771
- const response = await fetch(`${this.config.basePath}/api/${this.exchangeName}/fetchBalance`, {
772
- method: 'POST',
773
- headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
774
- body: JSON.stringify({ args, credentials: this.getCredentials() }),
775
- });
776
- if (!response.ok) {
777
- const body = await response.json().catch(() => ({}));
778
- if (body.error && typeof body.error === "object") {
779
- throw fromServerError(body.error);
780
- }
781
- throw new PmxtError(body.error?.message || response.statusText);
782
- }
783
- const json = await response.json();
810
+ const args: any[] = address ? [address] : [];
811
+ const query = { address };
812
+ const json = await this.sidecarReadRequest('fetchBalance', query, args);
784
813
  const data = this.handleResponse(json);
785
814
  return data.map(convertBalance);
786
815
  } catch (error) {
@@ -850,17 +879,10 @@ export abstract class Exchange {
850
879
  paramsDict.limit = params.limit;
851
880
  }
852
881
 
853
- const requestBody: FetchOHLCVRequest = {
854
- args: [resolvedOutcomeId, paramsDict],
855
- credentials: this.getCredentials()
856
- };
857
-
858
- const response = await this.api.fetchOHLCV({
859
- exchange: this.exchangeName as any,
860
- fetchOHLCVRequest: requestBody,
861
- }, { headers: this.getAuthHeaders() });
862
-
863
- const data = this.handleResponse(response);
882
+ const args = [resolvedOutcomeId, paramsDict];
883
+ const query = { id: resolvedOutcomeId, ...paramsDict };
884
+ const json = await this.sidecarReadRequest('fetchOHLCV', query, args);
885
+ const data = this.handleResponse(json);
864
886
  return data.map(convertCandle);
865
887
  } catch (error) {
866
888
  if (error instanceof PmxtError) throw error;
@@ -889,17 +911,10 @@ export abstract class Exchange {
889
911
  paramsDict.limit = params.limit;
890
912
  }
891
913
 
892
- const requestBody: FetchTradesRequest = {
893
- args: [resolvedOutcomeId, paramsDict],
894
- credentials: this.getCredentials()
895
- };
896
-
897
- const response = await this.api.fetchTrades({
898
- exchange: this.exchangeName as any,
899
- fetchTradesRequest: requestBody,
900
- }, { headers: this.getAuthHeaders() });
901
-
902
- const data = this.handleResponse(response);
914
+ const args = [resolvedOutcomeId, paramsDict];
915
+ const query = { id: resolvedOutcomeId, ...paramsDict };
916
+ const json = await this.sidecarReadRequest('fetchTrades', query, args);
917
+ const data = this.handleResponse(json);
903
918
  return data.map(convertTrade);
904
919
  } catch (error) {
905
920
  if (error instanceof PmxtError) throw error;