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.
- package/dist/esm/generated/src/apis/DefaultApi.d.ts +266 -106
- package/dist/esm/generated/src/apis/DefaultApi.js +346 -61
- package/dist/esm/generated/src/models/index.d.ts +0 -19
- package/dist/esm/generated/src/models/index.js +0 -19
- package/dist/esm/pmxt/client.d.ts +59 -4
- package/dist/esm/pmxt/client.js +181 -195
- package/dist/esm/pmxt/constants.d.ts +53 -0
- package/dist/esm/pmxt/constants.js +60 -0
- package/dist/generated/src/apis/DefaultApi.d.ts +266 -106
- package/dist/generated/src/apis/DefaultApi.js +346 -61
- package/dist/generated/src/models/index.d.ts +0 -19
- package/dist/generated/src/models/index.js +0 -19
- package/dist/pmxt/client.d.ts +59 -4
- package/dist/pmxt/client.js +181 -195
- package/dist/pmxt/constants.d.ts +53 -0
- package/dist/pmxt/constants.js +64 -0
- package/generated/.openapi-generator/FILES +0 -38
- package/generated/docs/DefaultApi.md +276 -120
- package/generated/package.json +1 -1
- package/generated/src/apis/DefaultApi.ts +590 -210
- package/generated/src/models/index.ts +0 -19
- package/package.json +2 -2
- package/pmxt/client.ts +223 -208
- package/pmxt/constants.ts +67 -0
- package/dist/esm/generated/src/models/FetchAllOrdersRequest.d.ts +0 -40
- package/dist/esm/generated/src/models/FetchAllOrdersRequest.js +0 -45
- package/dist/esm/generated/src/models/FetchBalanceRequest.d.ts +0 -39
- package/dist/esm/generated/src/models/FetchBalanceRequest.js +0 -44
- package/dist/esm/generated/src/models/FetchClosedOrdersRequest.d.ts +0 -40
- package/dist/esm/generated/src/models/FetchClosedOrdersRequest.js +0 -45
- package/dist/esm/generated/src/models/FetchEventRequest.d.ts +0 -40
- package/dist/esm/generated/src/models/FetchEventRequest.js +0 -45
- package/dist/esm/generated/src/models/FetchEventsRequest.d.ts +0 -40
- package/dist/esm/generated/src/models/FetchEventsRequest.js +0 -45
- package/dist/esm/generated/src/models/FetchMarketRequest.d.ts +0 -40
- package/dist/esm/generated/src/models/FetchMarketRequest.js +0 -45
- package/dist/esm/generated/src/models/FetchMarketsPaginatedRequest.d.ts +0 -40
- package/dist/esm/generated/src/models/FetchMarketsPaginatedRequest.js +0 -45
- package/dist/esm/generated/src/models/FetchMarketsPaginatedRequestArgsInner.d.ts +0 -38
- package/dist/esm/generated/src/models/FetchMarketsPaginatedRequestArgsInner.js +0 -43
- package/dist/esm/generated/src/models/FetchMarketsRequest.d.ts +0 -40
- package/dist/esm/generated/src/models/FetchMarketsRequest.js +0 -45
- package/dist/esm/generated/src/models/FetchMyTradesRequest.d.ts +0 -40
- package/dist/esm/generated/src/models/FetchMyTradesRequest.js +0 -45
- package/dist/esm/generated/src/models/FetchOHLCVRequest.d.ts +0 -40
- package/dist/esm/generated/src/models/FetchOHLCVRequest.js +0 -47
- package/dist/esm/generated/src/models/FetchOHLCVRequestArgsInner.d.ts +0 -22
- package/dist/esm/generated/src/models/FetchOHLCVRequestArgsInner.js +0 -50
- package/dist/esm/generated/src/models/FetchOpenOrdersRequest.d.ts +0 -39
- package/dist/esm/generated/src/models/FetchOpenOrdersRequest.js +0 -44
- package/dist/esm/generated/src/models/FetchOrderBookRequest.d.ts +0 -39
- package/dist/esm/generated/src/models/FetchOrderBookRequest.js +0 -46
- package/dist/esm/generated/src/models/FetchOrderRequest.d.ts +0 -39
- package/dist/esm/generated/src/models/FetchOrderRequest.js +0 -46
- package/dist/esm/generated/src/models/FetchPositionsRequest.d.ts +0 -39
- package/dist/esm/generated/src/models/FetchPositionsRequest.js +0 -44
- package/dist/esm/generated/src/models/FetchTradesRequest.d.ts +0 -40
- package/dist/esm/generated/src/models/FetchTradesRequest.js +0 -47
- package/dist/esm/generated/src/models/FetchTradesRequestArgsInner.d.ts +0 -22
- package/dist/esm/generated/src/models/FetchTradesRequestArgsInner.js +0 -50
- package/dist/esm/generated/src/models/FetchTradesRequestArgsInnerOneOf.d.ts +0 -24
- package/dist/esm/generated/src/models/FetchTradesRequestArgsInnerOneOf.js +0 -54
- package/dist/generated/src/models/FetchAllOrdersRequest.d.ts +0 -40
- package/dist/generated/src/models/FetchAllOrdersRequest.js +0 -52
- package/dist/generated/src/models/FetchBalanceRequest.d.ts +0 -39
- package/dist/generated/src/models/FetchBalanceRequest.js +0 -51
- package/dist/generated/src/models/FetchClosedOrdersRequest.d.ts +0 -40
- package/dist/generated/src/models/FetchClosedOrdersRequest.js +0 -52
- package/dist/generated/src/models/FetchEventRequest.d.ts +0 -40
- package/dist/generated/src/models/FetchEventRequest.js +0 -52
- package/dist/generated/src/models/FetchEventsRequest.d.ts +0 -40
- package/dist/generated/src/models/FetchEventsRequest.js +0 -52
- package/dist/generated/src/models/FetchMarketRequest.d.ts +0 -40
- package/dist/generated/src/models/FetchMarketRequest.js +0 -52
- package/dist/generated/src/models/FetchMarketsPaginatedRequest.d.ts +0 -40
- package/dist/generated/src/models/FetchMarketsPaginatedRequest.js +0 -52
- package/dist/generated/src/models/FetchMarketsPaginatedRequestArgsInner.d.ts +0 -38
- package/dist/generated/src/models/FetchMarketsPaginatedRequestArgsInner.js +0 -50
- package/dist/generated/src/models/FetchMarketsRequest.d.ts +0 -40
- package/dist/generated/src/models/FetchMarketsRequest.js +0 -52
- package/dist/generated/src/models/FetchMyTradesRequest.d.ts +0 -40
- package/dist/generated/src/models/FetchMyTradesRequest.js +0 -52
- package/dist/generated/src/models/FetchOHLCVRequest.d.ts +0 -40
- package/dist/generated/src/models/FetchOHLCVRequest.js +0 -54
- package/dist/generated/src/models/FetchOHLCVRequestArgsInner.d.ts +0 -22
- package/dist/generated/src/models/FetchOHLCVRequestArgsInner.js +0 -56
- package/dist/generated/src/models/FetchOpenOrdersRequest.d.ts +0 -39
- package/dist/generated/src/models/FetchOpenOrdersRequest.js +0 -51
- package/dist/generated/src/models/FetchOrderBookRequest.d.ts +0 -39
- package/dist/generated/src/models/FetchOrderBookRequest.js +0 -53
- package/dist/generated/src/models/FetchOrderRequest.d.ts +0 -39
- package/dist/generated/src/models/FetchOrderRequest.js +0 -53
- package/dist/generated/src/models/FetchPositionsRequest.d.ts +0 -39
- package/dist/generated/src/models/FetchPositionsRequest.js +0 -51
- package/dist/generated/src/models/FetchTradesRequest.d.ts +0 -40
- package/dist/generated/src/models/FetchTradesRequest.js +0 -54
- package/dist/generated/src/models/FetchTradesRequestArgsInner.d.ts +0 -22
- package/dist/generated/src/models/FetchTradesRequestArgsInner.js +0 -56
- package/dist/generated/src/models/FetchTradesRequestArgsInnerOneOf.d.ts +0 -24
- package/dist/generated/src/models/FetchTradesRequestArgsInnerOneOf.js +0 -61
- package/generated/docs/FetchAllOrdersRequest.md +0 -36
- package/generated/docs/FetchBalanceRequest.md +0 -36
- package/generated/docs/FetchClosedOrdersRequest.md +0 -36
- package/generated/docs/FetchEventRequest.md +0 -36
- package/generated/docs/FetchEventsRequest.md +0 -36
- package/generated/docs/FetchMarketRequest.md +0 -36
- package/generated/docs/FetchMarketsPaginatedRequest.md +0 -36
- package/generated/docs/FetchMarketsPaginatedRequestArgsInner.md +0 -36
- package/generated/docs/FetchMarketsRequest.md +0 -36
- package/generated/docs/FetchMyTradesRequest.md +0 -36
- package/generated/docs/FetchOHLCVRequest.md +0 -36
- package/generated/docs/FetchOHLCVRequestArgsInner.md +0 -40
- package/generated/docs/FetchOpenOrdersRequest.md +0 -36
- package/generated/docs/FetchOrderBookRequest.md +0 -36
- package/generated/docs/FetchOrderRequest.md +0 -36
- package/generated/docs/FetchPositionsRequest.md +0 -36
- package/generated/docs/FetchTradesRequest.md +0 -36
- package/generated/docs/FetchTradesRequestArgsInner.md +0 -40
- package/generated/docs/FetchTradesRequestArgsInnerOneOf.md +0 -40
- package/generated/src/models/FetchAllOrdersRequest.ts +0 -88
- package/generated/src/models/FetchBalanceRequest.ts +0 -81
- package/generated/src/models/FetchClosedOrdersRequest.ts +0 -88
- package/generated/src/models/FetchEventRequest.ts +0 -88
- package/generated/src/models/FetchEventsRequest.ts +0 -88
- package/generated/src/models/FetchMarketRequest.ts +0 -88
- package/generated/src/models/FetchMarketsPaginatedRequest.ts +0 -88
- package/generated/src/models/FetchMarketsPaginatedRequestArgsInner.ts +0 -73
- package/generated/src/models/FetchMarketsRequest.ts +0 -88
- package/generated/src/models/FetchMyTradesRequest.ts +0 -88
- package/generated/src/models/FetchOHLCVRequest.ts +0 -89
- package/generated/src/models/FetchOHLCVRequestArgsInner.ts +0 -69
- package/generated/src/models/FetchOpenOrdersRequest.ts +0 -81
- package/generated/src/models/FetchOrderBookRequest.ts +0 -82
- package/generated/src/models/FetchOrderRequest.ts +0 -82
- package/generated/src/models/FetchPositionsRequest.ts +0 -81
- package/generated/src/models/FetchTradesRequest.ts +0 -89
- package/generated/src/models/FetchTradesRequestArgsInner.ts +0 -69
- package/generated/src/models/FetchTradesRequestArgsInnerOneOf.ts +0 -80
package/dist/esm/pmxt/client.js
CHANGED
|
@@ -9,6 +9,7 @@ import { MarketList, } from "./models.js";
|
|
|
9
9
|
import { ServerManager } from "./server-manager.js";
|
|
10
10
|
import { buildArgsWithOptionalOptions } from "./args.js";
|
|
11
11
|
import { PmxtError, fromServerError } from "./errors.js";
|
|
12
|
+
import { resolvePmxtBaseUrl } from "./constants.js";
|
|
12
13
|
/**
|
|
13
14
|
* Resolve a MarketOutcome shorthand to a plain outcome ID string.
|
|
14
15
|
* Accepts either a raw string ID or a MarketOutcome object.
|
|
@@ -18,6 +19,51 @@ function resolveOutcomeId(input) {
|
|
|
18
19
|
return input;
|
|
19
20
|
return input.outcomeId;
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Build a URL-encoded query string from a plain record.
|
|
24
|
+
*
|
|
25
|
+
* - `undefined` / `null` values are skipped (they shouldn't appear in the URL).
|
|
26
|
+
* - Arrays are serialised as repeated `key=v1&key=v2` pairs.
|
|
27
|
+
* - Nested objects are skipped here; callers should route such queries through
|
|
28
|
+
* POST instead (see `queryHasNestedObject`).
|
|
29
|
+
*/
|
|
30
|
+
function buildSidecarQueryString(query) {
|
|
31
|
+
const parts = [];
|
|
32
|
+
for (const [key, value] of Object.entries(query)) {
|
|
33
|
+
if (value === undefined || value === null)
|
|
34
|
+
continue;
|
|
35
|
+
if (Array.isArray(value)) {
|
|
36
|
+
for (const v of value) {
|
|
37
|
+
if (v === undefined || v === null)
|
|
38
|
+
continue;
|
|
39
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(v))}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (typeof value === 'object') {
|
|
43
|
+
// Nested objects don't round-trip through query strings. Caller
|
|
44
|
+
// should have detected this and POSTed instead.
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return parts.join('&');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* True if any top-level value in the query is a nested object (not an array).
|
|
55
|
+
* Such queries can't be safely expressed in a query string, so we fall back
|
|
56
|
+
* to POST to preserve the original argument shape.
|
|
57
|
+
*/
|
|
58
|
+
function queryHasNestedObject(query) {
|
|
59
|
+
for (const value of Object.values(query)) {
|
|
60
|
+
if (value === undefined || value === null)
|
|
61
|
+
continue;
|
|
62
|
+
if (typeof value === 'object' && !Array.isArray(value))
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
21
67
|
// Converter functions
|
|
22
68
|
function convertMarket(raw) {
|
|
23
69
|
const outcomes = (raw.outcomes || []).map((o) => ({
|
|
@@ -183,23 +229,47 @@ export class Exchange {
|
|
|
183
229
|
exchangeName;
|
|
184
230
|
apiKey;
|
|
185
231
|
privateKey;
|
|
232
|
+
pmxtApiKey;
|
|
186
233
|
proxyAddress;
|
|
187
234
|
signatureType;
|
|
188
235
|
api;
|
|
189
236
|
config;
|
|
190
237
|
serverManager;
|
|
191
238
|
initPromise;
|
|
239
|
+
isHosted;
|
|
240
|
+
/**
|
|
241
|
+
* Sticky flag: set to `true` the first time a GET read is rejected by
|
|
242
|
+
* the sidecar with 404/405 (i.e. an older pmxt-core that only supports
|
|
243
|
+
* POST). While false, read methods try GET first; once flipped they
|
|
244
|
+
* POST directly and skip the GET probe for the lifetime of this client.
|
|
245
|
+
*/
|
|
246
|
+
_getReadsUnsupported = false;
|
|
192
247
|
constructor(exchangeName, options = {}) {
|
|
193
248
|
this.exchangeName = exchangeName.toLowerCase();
|
|
194
249
|
this.apiKey = options.apiKey;
|
|
195
250
|
this.privateKey = options.privateKey;
|
|
196
251
|
this.proxyAddress = options.proxyAddress;
|
|
197
252
|
this.signatureType = options.signatureType;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
253
|
+
// Resolve base URL + hosted API key via the shared precedence
|
|
254
|
+
// rules. See constants.ts for the full resolution table.
|
|
255
|
+
const resolved = resolvePmxtBaseUrl({
|
|
256
|
+
baseUrl: options.baseUrl,
|
|
257
|
+
pmxtApiKey: options.pmxtApiKey,
|
|
258
|
+
});
|
|
259
|
+
const baseUrl = resolved.baseUrl;
|
|
260
|
+
this.pmxtApiKey = resolved.pmxtApiKey;
|
|
261
|
+
this.isHosted = resolved.isHosted;
|
|
262
|
+
// auto_start_server defaults: true for local, false for hosted.
|
|
263
|
+
// An explicit value in the options always wins.
|
|
264
|
+
const autoStartServer = options.autoStartServer !== undefined
|
|
265
|
+
? options.autoStartServer
|
|
266
|
+
: !this.isHosted;
|
|
267
|
+
// Initialize server manager (no network calls happen here — the
|
|
268
|
+
// constructor just stores config).
|
|
201
269
|
this.serverManager = new ServerManager({ baseUrl });
|
|
202
|
-
// Configure the API client with the initial base URL (will be
|
|
270
|
+
// Configure the API client with the initial base URL (will be
|
|
271
|
+
// updated to the actual listen port if the local sidecar gets
|
|
272
|
+
// bumped off the default).
|
|
203
273
|
this.config = new Configuration({ basePath: baseUrl });
|
|
204
274
|
this.api = new DefaultApi(this.config);
|
|
205
275
|
// Initialize the server connection asynchronously
|
|
@@ -249,10 +319,19 @@ export class Exchange {
|
|
|
249
319
|
}
|
|
250
320
|
getAuthHeaders() {
|
|
251
321
|
const headers = { ...this.config.headers };
|
|
322
|
+
// Local sidecar access token (read from the lock file). Only
|
|
323
|
+
// meaningful when talking to a local sidecar we spawned
|
|
324
|
+
// ourselves; harmless elsewhere.
|
|
252
325
|
const accessToken = this.serverManager.getAccessToken();
|
|
253
326
|
if (accessToken) {
|
|
254
327
|
headers['x-pmxt-access-token'] = accessToken;
|
|
255
328
|
}
|
|
329
|
+
// Hosted pmxt bearer token. The hosted service requires this;
|
|
330
|
+
// the local sidecar ignores it. Safe to attach unconditionally
|
|
331
|
+
// whenever a pmxtApiKey has been resolved.
|
|
332
|
+
if (this.pmxtApiKey) {
|
|
333
|
+
headers['Authorization'] = `Bearer ${this.pmxtApiKey}`;
|
|
334
|
+
}
|
|
256
335
|
return headers;
|
|
257
336
|
}
|
|
258
337
|
// Low-Level API Access
|
|
@@ -303,6 +382,68 @@ export class Exchange {
|
|
|
303
382
|
throw new PmxtError(`Failed to call API '${operationId}': ${error}`);
|
|
304
383
|
}
|
|
305
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Dispatch a sidecar read method, preferring GET but transparently
|
|
387
|
+
* falling back to POST for full backward compatibility.
|
|
388
|
+
*
|
|
389
|
+
* GET is used when:
|
|
390
|
+
* - the client has no per-instance credentials (the sidecar's GET
|
|
391
|
+
* handler intentionally drops credentials to avoid leaking them
|
|
392
|
+
* through query strings and access logs), and
|
|
393
|
+
* - the sidecar hasn't already returned 404/405 for a previous GET
|
|
394
|
+
* in this client's lifetime (`_getReadsUnsupported`), and
|
|
395
|
+
* - the query has no nested objects (query strings can't round-trip
|
|
396
|
+
* arbitrary JSON).
|
|
397
|
+
*
|
|
398
|
+
* Otherwise (or if the GET attempt is rejected with 404/405) the call
|
|
399
|
+
* is sent as POST with the original `{args, credentials}` body so that
|
|
400
|
+
* SDK users talking to an older pmxt-core continue to work unchanged.
|
|
401
|
+
*
|
|
402
|
+
* @internal — shared transport used by every generated read method.
|
|
403
|
+
*/
|
|
404
|
+
async sidecarReadRequest(methodName, query, args) {
|
|
405
|
+
const baseUrl = `${this.config.basePath}/api/${this.exchangeName}/${methodName}`;
|
|
406
|
+
const hasCredentials = this.getCredentials() !== undefined;
|
|
407
|
+
if (!hasCredentials && !this._getReadsUnsupported && !queryHasNestedObject(query)) {
|
|
408
|
+
const qs = buildSidecarQueryString(query);
|
|
409
|
+
const getUrl = qs ? `${baseUrl}?${qs}` : baseUrl;
|
|
410
|
+
const response = await fetch(getUrl, {
|
|
411
|
+
method: 'GET',
|
|
412
|
+
headers: this.getAuthHeaders(),
|
|
413
|
+
});
|
|
414
|
+
// 404 / 405 => older sidecar without GET dispatch. Remember
|
|
415
|
+
// the downgrade so future calls skip the probe, and fall
|
|
416
|
+
// through to POST below.
|
|
417
|
+
if (response.status === 404 || response.status === 405) {
|
|
418
|
+
await response.text().catch(() => undefined);
|
|
419
|
+
this._getReadsUnsupported = true;
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
if (!response.ok) {
|
|
423
|
+
const body = await response.json().catch(() => ({}));
|
|
424
|
+
if (body.error && typeof body.error === "object") {
|
|
425
|
+
throw fromServerError(body.error);
|
|
426
|
+
}
|
|
427
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
428
|
+
}
|
|
429
|
+
return response.json();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
// POST fallback — identical to the original per-method template.
|
|
433
|
+
const response = await fetch(baseUrl, {
|
|
434
|
+
method: 'POST',
|
|
435
|
+
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
436
|
+
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
437
|
+
});
|
|
438
|
+
if (!response.ok) {
|
|
439
|
+
const body = await response.json().catch(() => ({}));
|
|
440
|
+
if (body.error && typeof body.error === "object") {
|
|
441
|
+
throw fromServerError(body.error);
|
|
442
|
+
}
|
|
443
|
+
throw new PmxtError(body.error?.message || response.statusText);
|
|
444
|
+
}
|
|
445
|
+
return response.json();
|
|
446
|
+
}
|
|
306
447
|
// BEGIN GENERATED METHODS
|
|
307
448
|
async loadMarkets(reload = false) {
|
|
308
449
|
await this.initPromise;
|
|
@@ -339,19 +480,8 @@ export class Exchange {
|
|
|
339
480
|
await this.initPromise;
|
|
340
481
|
try {
|
|
341
482
|
const args = buildArgsWithOptionalOptions(params);
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
345
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
346
|
-
});
|
|
347
|
-
if (!response.ok) {
|
|
348
|
-
const body = await response.json().catch(() => ({}));
|
|
349
|
-
if (body.error && typeof body.error === "object") {
|
|
350
|
-
throw fromServerError(body.error);
|
|
351
|
-
}
|
|
352
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
353
|
-
}
|
|
354
|
-
const json = await response.json();
|
|
483
|
+
const query = { ...(params || {}) };
|
|
484
|
+
const json = await this.sidecarReadRequest('fetchMarkets', query, args);
|
|
355
485
|
const data = this.handleResponse(json);
|
|
356
486
|
return data.map(convertMarket);
|
|
357
487
|
}
|
|
@@ -365,19 +495,8 @@ export class Exchange {
|
|
|
365
495
|
await this.initPromise;
|
|
366
496
|
try {
|
|
367
497
|
const args = buildArgsWithOptionalOptions(params);
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
371
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
372
|
-
});
|
|
373
|
-
if (!response.ok) {
|
|
374
|
-
const body = await response.json().catch(() => ({}));
|
|
375
|
-
if (body.error && typeof body.error === "object") {
|
|
376
|
-
throw fromServerError(body.error);
|
|
377
|
-
}
|
|
378
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
379
|
-
}
|
|
380
|
-
const json = await response.json();
|
|
498
|
+
const query = { ...(params || {}) };
|
|
499
|
+
const json = await this.sidecarReadRequest('fetchMarketsPaginated', query, args);
|
|
381
500
|
const data = this.handleResponse(json);
|
|
382
501
|
return {
|
|
383
502
|
data: (data.data || []).map(convertMarket),
|
|
@@ -395,19 +514,8 @@ export class Exchange {
|
|
|
395
514
|
await this.initPromise;
|
|
396
515
|
try {
|
|
397
516
|
const args = buildArgsWithOptionalOptions(params);
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
401
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
402
|
-
});
|
|
403
|
-
if (!response.ok) {
|
|
404
|
-
const body = await response.json().catch(() => ({}));
|
|
405
|
-
if (body.error && typeof body.error === "object") {
|
|
406
|
-
throw fromServerError(body.error);
|
|
407
|
-
}
|
|
408
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
409
|
-
}
|
|
410
|
-
const json = await response.json();
|
|
517
|
+
const query = { ...(params || {}) };
|
|
518
|
+
const json = await this.sidecarReadRequest('fetchEvents', query, args);
|
|
411
519
|
const data = this.handleResponse(json);
|
|
412
520
|
return data.map(convertEvent);
|
|
413
521
|
}
|
|
@@ -421,19 +529,8 @@ export class Exchange {
|
|
|
421
529
|
await this.initPromise;
|
|
422
530
|
try {
|
|
423
531
|
const args = buildArgsWithOptionalOptions(params);
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
427
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
428
|
-
});
|
|
429
|
-
if (!response.ok) {
|
|
430
|
-
const body = await response.json().catch(() => ({}));
|
|
431
|
-
if (body.error && typeof body.error === "object") {
|
|
432
|
-
throw fromServerError(body.error);
|
|
433
|
-
}
|
|
434
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
435
|
-
}
|
|
436
|
-
const json = await response.json();
|
|
532
|
+
const query = { ...(params || {}) };
|
|
533
|
+
const json = await this.sidecarReadRequest('fetchMarket', query, args);
|
|
437
534
|
const data = this.handleResponse(json);
|
|
438
535
|
return convertMarket(data);
|
|
439
536
|
}
|
|
@@ -447,19 +544,8 @@ export class Exchange {
|
|
|
447
544
|
await this.initPromise;
|
|
448
545
|
try {
|
|
449
546
|
const args = buildArgsWithOptionalOptions(params);
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
453
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
454
|
-
});
|
|
455
|
-
if (!response.ok) {
|
|
456
|
-
const body = await response.json().catch(() => ({}));
|
|
457
|
-
if (body.error && typeof body.error === "object") {
|
|
458
|
-
throw fromServerError(body.error);
|
|
459
|
-
}
|
|
460
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
461
|
-
}
|
|
462
|
-
const json = await response.json();
|
|
547
|
+
const query = { ...(params || {}) };
|
|
548
|
+
const json = await this.sidecarReadRequest('fetchEvent', query, args);
|
|
463
549
|
const data = this.handleResponse(json);
|
|
464
550
|
return convertEvent(data);
|
|
465
551
|
}
|
|
@@ -473,21 +559,9 @@ export class Exchange {
|
|
|
473
559
|
await this.initPromise;
|
|
474
560
|
const resolvedId = resolveOutcomeId(id);
|
|
475
561
|
try {
|
|
476
|
-
const args = [];
|
|
477
|
-
|
|
478
|
-
const
|
|
479
|
-
method: 'POST',
|
|
480
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
481
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
482
|
-
});
|
|
483
|
-
if (!response.ok) {
|
|
484
|
-
const body = await response.json().catch(() => ({}));
|
|
485
|
-
if (body.error && typeof body.error === "object") {
|
|
486
|
-
throw fromServerError(body.error);
|
|
487
|
-
}
|
|
488
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
489
|
-
}
|
|
490
|
-
const json = await response.json();
|
|
562
|
+
const args = [resolvedId];
|
|
563
|
+
const query = { id: resolvedId };
|
|
564
|
+
const json = await this.sidecarReadRequest('fetchOrderBook', query, args);
|
|
491
565
|
const data = this.handleResponse(json);
|
|
492
566
|
return convertOrderBook(data);
|
|
493
567
|
}
|
|
@@ -527,21 +601,9 @@ export class Exchange {
|
|
|
527
601
|
async fetchOrder(orderId) {
|
|
528
602
|
await this.initPromise;
|
|
529
603
|
try {
|
|
530
|
-
const args = [];
|
|
531
|
-
|
|
532
|
-
const
|
|
533
|
-
method: 'POST',
|
|
534
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
535
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
536
|
-
});
|
|
537
|
-
if (!response.ok) {
|
|
538
|
-
const body = await response.json().catch(() => ({}));
|
|
539
|
-
if (body.error && typeof body.error === "object") {
|
|
540
|
-
throw fromServerError(body.error);
|
|
541
|
-
}
|
|
542
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
543
|
-
}
|
|
544
|
-
const json = await response.json();
|
|
604
|
+
const args = [orderId];
|
|
605
|
+
const query = { orderId };
|
|
606
|
+
const json = await this.sidecarReadRequest('fetchOrder', query, args);
|
|
545
607
|
const data = this.handleResponse(json);
|
|
546
608
|
return convertOrder(data);
|
|
547
609
|
}
|
|
@@ -555,19 +617,8 @@ export class Exchange {
|
|
|
555
617
|
await this.initPromise;
|
|
556
618
|
try {
|
|
557
619
|
const args = buildArgsWithOptionalOptions(marketId);
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
561
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
562
|
-
});
|
|
563
|
-
if (!response.ok) {
|
|
564
|
-
const body = await response.json().catch(() => ({}));
|
|
565
|
-
if (body.error && typeof body.error === "object") {
|
|
566
|
-
throw fromServerError(body.error);
|
|
567
|
-
}
|
|
568
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
569
|
-
}
|
|
570
|
-
const json = await response.json();
|
|
620
|
+
const query = { marketId };
|
|
621
|
+
const json = await this.sidecarReadRequest('fetchOpenOrders', query, args);
|
|
571
622
|
const data = this.handleResponse(json);
|
|
572
623
|
return data.map(convertOrder);
|
|
573
624
|
}
|
|
@@ -581,19 +632,8 @@ export class Exchange {
|
|
|
581
632
|
await this.initPromise;
|
|
582
633
|
try {
|
|
583
634
|
const args = buildArgsWithOptionalOptions(params);
|
|
584
|
-
const
|
|
585
|
-
|
|
586
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
587
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
588
|
-
});
|
|
589
|
-
if (!response.ok) {
|
|
590
|
-
const body = await response.json().catch(() => ({}));
|
|
591
|
-
if (body.error && typeof body.error === "object") {
|
|
592
|
-
throw fromServerError(body.error);
|
|
593
|
-
}
|
|
594
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
595
|
-
}
|
|
596
|
-
const json = await response.json();
|
|
635
|
+
const query = { ...(params || {}) };
|
|
636
|
+
const json = await this.sidecarReadRequest('fetchMyTrades', query, args);
|
|
597
637
|
const data = this.handleResponse(json);
|
|
598
638
|
return data.map(convertUserTrade);
|
|
599
639
|
}
|
|
@@ -607,19 +647,8 @@ export class Exchange {
|
|
|
607
647
|
await this.initPromise;
|
|
608
648
|
try {
|
|
609
649
|
const args = buildArgsWithOptionalOptions(params);
|
|
610
|
-
const
|
|
611
|
-
|
|
612
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
613
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
614
|
-
});
|
|
615
|
-
if (!response.ok) {
|
|
616
|
-
const body = await response.json().catch(() => ({}));
|
|
617
|
-
if (body.error && typeof body.error === "object") {
|
|
618
|
-
throw fromServerError(body.error);
|
|
619
|
-
}
|
|
620
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
621
|
-
}
|
|
622
|
-
const json = await response.json();
|
|
650
|
+
const query = { ...(params || {}) };
|
|
651
|
+
const json = await this.sidecarReadRequest('fetchClosedOrders', query, args);
|
|
623
652
|
const data = this.handleResponse(json);
|
|
624
653
|
return data.map(convertOrder);
|
|
625
654
|
}
|
|
@@ -633,19 +662,8 @@ export class Exchange {
|
|
|
633
662
|
await this.initPromise;
|
|
634
663
|
try {
|
|
635
664
|
const args = buildArgsWithOptionalOptions(params);
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
639
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
640
|
-
});
|
|
641
|
-
if (!response.ok) {
|
|
642
|
-
const body = await response.json().catch(() => ({}));
|
|
643
|
-
if (body.error && typeof body.error === "object") {
|
|
644
|
-
throw fromServerError(body.error);
|
|
645
|
-
}
|
|
646
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
647
|
-
}
|
|
648
|
-
const json = await response.json();
|
|
665
|
+
const query = { ...(params || {}) };
|
|
666
|
+
const json = await this.sidecarReadRequest('fetchAllOrders', query, args);
|
|
649
667
|
const data = this.handleResponse(json);
|
|
650
668
|
return data.map(convertOrder);
|
|
651
669
|
}
|
|
@@ -659,19 +677,8 @@ export class Exchange {
|
|
|
659
677
|
await this.initPromise;
|
|
660
678
|
try {
|
|
661
679
|
const args = address ? [address] : [];
|
|
662
|
-
const
|
|
663
|
-
|
|
664
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
665
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
666
|
-
});
|
|
667
|
-
if (!response.ok) {
|
|
668
|
-
const body = await response.json().catch(() => ({}));
|
|
669
|
-
if (body.error && typeof body.error === "object") {
|
|
670
|
-
throw fromServerError(body.error);
|
|
671
|
-
}
|
|
672
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
673
|
-
}
|
|
674
|
-
const json = await response.json();
|
|
680
|
+
const query = { address };
|
|
681
|
+
const json = await this.sidecarReadRequest('fetchPositions', query, args);
|
|
675
682
|
const data = this.handleResponse(json);
|
|
676
683
|
return data.map(convertPosition);
|
|
677
684
|
}
|
|
@@ -685,19 +692,8 @@ export class Exchange {
|
|
|
685
692
|
await this.initPromise;
|
|
686
693
|
try {
|
|
687
694
|
const args = address ? [address] : [];
|
|
688
|
-
const
|
|
689
|
-
|
|
690
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
691
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
692
|
-
});
|
|
693
|
-
if (!response.ok) {
|
|
694
|
-
const body = await response.json().catch(() => ({}));
|
|
695
|
-
if (body.error && typeof body.error === "object") {
|
|
696
|
-
throw fromServerError(body.error);
|
|
697
|
-
}
|
|
698
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
699
|
-
}
|
|
700
|
-
const json = await response.json();
|
|
695
|
+
const query = { address };
|
|
696
|
+
const json = await this.sidecarReadRequest('fetchBalance', query, args);
|
|
701
697
|
const data = this.handleResponse(json);
|
|
702
698
|
return data.map(convertBalance);
|
|
703
699
|
}
|
|
@@ -764,15 +760,10 @@ export class Exchange {
|
|
|
764
760
|
if (params.limit) {
|
|
765
761
|
paramsDict.limit = params.limit;
|
|
766
762
|
}
|
|
767
|
-
const
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
const response = await this.api.fetchOHLCV({
|
|
772
|
-
exchange: this.exchangeName,
|
|
773
|
-
fetchOHLCVRequest: requestBody,
|
|
774
|
-
}, { headers: this.getAuthHeaders() });
|
|
775
|
-
const data = this.handleResponse(response);
|
|
763
|
+
const args = [resolvedOutcomeId, paramsDict];
|
|
764
|
+
const query = { id: resolvedOutcomeId, ...paramsDict };
|
|
765
|
+
const json = await this.sidecarReadRequest('fetchOHLCV', query, args);
|
|
766
|
+
const data = this.handleResponse(json);
|
|
776
767
|
return data.map(convertCandle);
|
|
777
768
|
}
|
|
778
769
|
catch (error) {
|
|
@@ -798,15 +789,10 @@ export class Exchange {
|
|
|
798
789
|
if (params.limit) {
|
|
799
790
|
paramsDict.limit = params.limit;
|
|
800
791
|
}
|
|
801
|
-
const
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
const response = await this.api.fetchTrades({
|
|
806
|
-
exchange: this.exchangeName,
|
|
807
|
-
fetchTradesRequest: requestBody,
|
|
808
|
-
}, { headers: this.getAuthHeaders() });
|
|
809
|
-
const data = this.handleResponse(response);
|
|
792
|
+
const args = [resolvedOutcomeId, paramsDict];
|
|
793
|
+
const query = { id: resolvedOutcomeId, ...paramsDict };
|
|
794
|
+
const json = await this.sidecarReadRequest('fetchTrades', query, args);
|
|
795
|
+
const data = this.handleResponse(json);
|
|
810
796
|
return data.map(convertTrade);
|
|
811
797
|
}
|
|
812
798
|
catch (error) {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared URL and environment-variable constants for the pmxt SDK.
|
|
3
|
+
*
|
|
4
|
+
* These are deliberately plain exports (no runtime logic) so that they
|
|
5
|
+
* can be imported from any module without creating import cycles.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The hosted pmxt production endpoint.
|
|
9
|
+
*
|
|
10
|
+
* Exchange classes and `Router` default to this URL whenever a hosted
|
|
11
|
+
* pmxt API key is supplied (via `pmxtApiKey` kwarg or the
|
|
12
|
+
* `PMXT_API_KEY` environment variable) AND no explicit `baseUrl` /
|
|
13
|
+
* `PMXT_BASE_URL` is configured.
|
|
14
|
+
*/
|
|
15
|
+
export declare const HOSTED_URL = "https://api.pmxt.dev";
|
|
16
|
+
/**
|
|
17
|
+
* The local sidecar default.
|
|
18
|
+
*
|
|
19
|
+
* This is the URL the SDK uses when no hosted key and no explicit
|
|
20
|
+
* override are present. It matches the port that the pmxt-core
|
|
21
|
+
* sidecar listens on by default.
|
|
22
|
+
*/
|
|
23
|
+
export declare const LOCAL_URL = "http://localhost:3847";
|
|
24
|
+
/**
|
|
25
|
+
* Environment variable names. Centralised so tests and docs can
|
|
26
|
+
* reference a single source of truth.
|
|
27
|
+
*/
|
|
28
|
+
export declare const ENV: {
|
|
29
|
+
readonly BASE_URL: "PMXT_BASE_URL";
|
|
30
|
+
readonly API_KEY: "PMXT_API_KEY";
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Resolve the effective base URL for an SDK client, following the
|
|
34
|
+
* documented precedence rules:
|
|
35
|
+
*
|
|
36
|
+
* 1. Explicit `baseUrl` argument wins.
|
|
37
|
+
* 2. `PMXT_BASE_URL` environment variable.
|
|
38
|
+
* 3. If a hosted API key is present (argument or `PMXT_API_KEY` env),
|
|
39
|
+
* default to {@link HOSTED_URL}.
|
|
40
|
+
* 4. Otherwise, default to {@link LOCAL_URL}.
|
|
41
|
+
*
|
|
42
|
+
* Returns both the resolved URL and an `isHosted` flag (true iff the
|
|
43
|
+
* resolved URL is anything other than the local sidecar default).
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolvePmxtBaseUrl(args: {
|
|
46
|
+
baseUrl?: string;
|
|
47
|
+
pmxtApiKey?: string;
|
|
48
|
+
env?: NodeJS.ProcessEnv;
|
|
49
|
+
}): {
|
|
50
|
+
baseUrl: string;
|
|
51
|
+
pmxtApiKey?: string;
|
|
52
|
+
isHosted: boolean;
|
|
53
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared URL and environment-variable constants for the pmxt SDK.
|
|
3
|
+
*
|
|
4
|
+
* These are deliberately plain exports (no runtime logic) so that they
|
|
5
|
+
* can be imported from any module without creating import cycles.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The hosted pmxt production endpoint.
|
|
9
|
+
*
|
|
10
|
+
* Exchange classes and `Router` default to this URL whenever a hosted
|
|
11
|
+
* pmxt API key is supplied (via `pmxtApiKey` kwarg or the
|
|
12
|
+
* `PMXT_API_KEY` environment variable) AND no explicit `baseUrl` /
|
|
13
|
+
* `PMXT_BASE_URL` is configured.
|
|
14
|
+
*/
|
|
15
|
+
export const HOSTED_URL = "https://api.pmxt.dev";
|
|
16
|
+
/**
|
|
17
|
+
* The local sidecar default.
|
|
18
|
+
*
|
|
19
|
+
* This is the URL the SDK uses when no hosted key and no explicit
|
|
20
|
+
* override are present. It matches the port that the pmxt-core
|
|
21
|
+
* sidecar listens on by default.
|
|
22
|
+
*/
|
|
23
|
+
export const LOCAL_URL = "http://localhost:3847";
|
|
24
|
+
/**
|
|
25
|
+
* Environment variable names. Centralised so tests and docs can
|
|
26
|
+
* reference a single source of truth.
|
|
27
|
+
*/
|
|
28
|
+
export const ENV = {
|
|
29
|
+
BASE_URL: "PMXT_BASE_URL",
|
|
30
|
+
API_KEY: "PMXT_API_KEY",
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Resolve the effective base URL for an SDK client, following the
|
|
34
|
+
* documented precedence rules:
|
|
35
|
+
*
|
|
36
|
+
* 1. Explicit `baseUrl` argument wins.
|
|
37
|
+
* 2. `PMXT_BASE_URL` environment variable.
|
|
38
|
+
* 3. If a hosted API key is present (argument or `PMXT_API_KEY` env),
|
|
39
|
+
* default to {@link HOSTED_URL}.
|
|
40
|
+
* 4. Otherwise, default to {@link LOCAL_URL}.
|
|
41
|
+
*
|
|
42
|
+
* Returns both the resolved URL and an `isHosted` flag (true iff the
|
|
43
|
+
* resolved URL is anything other than the local sidecar default).
|
|
44
|
+
*/
|
|
45
|
+
export function resolvePmxtBaseUrl(args) {
|
|
46
|
+
const env = args.env ?? (typeof process !== "undefined" ? process.env : {});
|
|
47
|
+
const pmxtApiKey = args.pmxtApiKey ?? env[ENV.API_KEY] ?? undefined;
|
|
48
|
+
const pick = (url) => ({
|
|
49
|
+
baseUrl: url,
|
|
50
|
+
pmxtApiKey,
|
|
51
|
+
isHosted: url !== LOCAL_URL,
|
|
52
|
+
});
|
|
53
|
+
if (args.baseUrl)
|
|
54
|
+
return pick(args.baseUrl);
|
|
55
|
+
if (env[ENV.BASE_URL])
|
|
56
|
+
return pick(env[ENV.BASE_URL]);
|
|
57
|
+
if (pmxtApiKey)
|
|
58
|
+
return pick(HOSTED_URL);
|
|
59
|
+
return pick(LOCAL_URL);
|
|
60
|
+
}
|