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