@stxapp/stx-typescript 0.11.0 → 0.12.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/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/{chunk-2PYJI3JS.js → chunk-NYUIPUZH.js} +31 -103
- package/dist/chunk-NYUIPUZH.js.map +1 -0
- package/dist/{chunk-BSX65XEA.cjs → chunk-WTKAZNEP.cjs} +60 -132
- package/dist/chunk-WTKAZNEP.cjs.map +1 -0
- package/dist/{client-DxY8eJ58.d.ts → client-CjXFrcQR.d.cts} +10 -10
- package/dist/{client-DxY8eJ58.d.cts → client-CjXFrcQR.d.ts} +10 -10
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/oauth.cjs +30 -30
- package/dist/oauth.d.cts +2 -2
- package/dist/oauth.d.ts +2 -2
- package/dist/oauth.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-2PYJI3JS.js.map +0 -1
- package/dist/chunk-BSX65XEA.cjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6;// src/exceptions.ts
|
|
2
2
|
var STXException = class extends Error {
|
|
3
3
|
|
|
4
4
|
|
|
@@ -312,21 +312,22 @@ var FEATURES = [
|
|
|
312
312
|
"leaderboard",
|
|
313
313
|
"loyalty",
|
|
314
314
|
"combos",
|
|
315
|
+
/**
|
|
316
|
+
* @deprecated The exchange no longer publishes whether it takes post-only
|
|
317
|
+
* orders, so this is always `null` (unknown). Send the order with
|
|
318
|
+
* `fillMode: "post_only"` and handle `STXNotAvailableException`. An exchange
|
|
319
|
+
* on a release from before fill modes may place it as a normal limit order.
|
|
320
|
+
*/
|
|
315
321
|
"orders.post_only",
|
|
322
|
+
/**
|
|
323
|
+
* @deprecated The exchange no longer publishes whether it takes fill-or-kill
|
|
324
|
+
* orders, so this is always `null` (unknown). Send the order with
|
|
325
|
+
* `fillMode: "fill_or_kill"` and handle `STXNotAvailableException`. An
|
|
326
|
+
* exchange on a release from before fill modes may place it as a normal
|
|
327
|
+
* limit order.
|
|
328
|
+
*/
|
|
316
329
|
"orders.fill_or_kill"
|
|
317
330
|
];
|
|
318
|
-
var API_FEATURES = {
|
|
319
|
-
"orders.post_only": "order_post_only",
|
|
320
|
-
"orders.fill_or_kill": "order_fill_or_kill"
|
|
321
|
-
};
|
|
322
|
-
function apiVersionFrom(body) {
|
|
323
|
-
const version = _optionalChain([body, 'optionalAccess', _5 => _5.api_version]);
|
|
324
|
-
const features = _optionalChain([body, 'optionalAccess', _6 => _6.features]);
|
|
325
|
-
return {
|
|
326
|
-
apiVersion: typeof version === "string" ? version : null,
|
|
327
|
-
features: Array.isArray(features) ? features.filter((f) => typeof f === "string") : null
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
331
|
var MEMBER_SCOPES = [
|
|
331
332
|
"profile.read",
|
|
332
333
|
"balance.read",
|
|
@@ -415,9 +416,7 @@ async function discoverCapabilities(probes) {
|
|
|
415
416
|
swallow(probes.signedGet("/api/v1/portfolio/loyalty?limit=1")),
|
|
416
417
|
swallow(probes.joinReason(`rfq:${NOBODY}`))
|
|
417
418
|
]);
|
|
418
|
-
const
|
|
419
|
-
const apiVersion = _optionalChain([info, 'optionalAccess', _7 => _7.apiVersion]);
|
|
420
|
-
const listed = (name) => version === null ? null : version.status === 200 || version.status === 404 || version.status === 403 && json(version) === null ? !!_optionalChain([info, 'optionalAccess', _8 => _8.features, 'optionalAccess', _9 => _9.includes, 'call', _10 => _10(name)]) : null;
|
|
419
|
+
const apiVersion = _optionalChain([version, 'optionalAccess', _5 => _5.status]) === 200 ? _optionalChain([json, 'call', _6 => _6(version), 'optionalAccess', _7 => _7.api_version]) : null;
|
|
421
420
|
const meta = oauthMetadataFrom(discovery);
|
|
422
421
|
const scopes = meta ? strings(meta.scopes_supported) : [];
|
|
423
422
|
const grants = meta ? strings(meta.grant_types_supported) : [];
|
|
@@ -440,8 +439,9 @@ async function discoverCapabilities(probes) {
|
|
|
440
439
|
// Switched off answers 404 ("Loyalty program is not enabled").
|
|
441
440
|
loyalty: loyalty === null ? null : loyalty.status >= 200 && loyalty.status < 300 ? true : loyalty.status === 404 ? false : null,
|
|
442
441
|
combos: combos === null ? null : combos !== "unmatched topic",
|
|
443
|
-
|
|
444
|
-
"orders.
|
|
442
|
+
// Kept so code written for 0.11 still compiles; the exchange publishes no answer.
|
|
443
|
+
"orders.post_only": null,
|
|
444
|
+
"orders.fill_or_kill": null
|
|
445
445
|
};
|
|
446
446
|
return new Capabilities({
|
|
447
447
|
host: probes.host,
|
|
@@ -1100,7 +1100,7 @@ function readProfile(profileName, path) {
|
|
|
1100
1100
|
}
|
|
1101
1101
|
function processEnv() {
|
|
1102
1102
|
const p = globalThis.process;
|
|
1103
|
-
return _nullishCoalesce(_optionalChain([p, 'optionalAccess',
|
|
1103
|
+
return _nullishCoalesce(_optionalChain([p, 'optionalAccess', _8 => _8.env]), () => ( {}));
|
|
1104
1104
|
}
|
|
1105
1105
|
function resolveSettings(input = {}) {
|
|
1106
1106
|
const environ = _nullishCoalesce(input.environ, () => ( processEnv()));
|
|
@@ -1274,7 +1274,7 @@ function credentialsFromSettings(keyId, privateKey, signer) {
|
|
|
1274
1274
|
}
|
|
1275
1275
|
|
|
1276
1276
|
// src/version.ts
|
|
1277
|
-
var VERSION = "0.
|
|
1277
|
+
var VERSION = "0.12.1";
|
|
1278
1278
|
var USER_AGENT = `stx-typescript/${VERSION}`;
|
|
1279
1279
|
var ASYNC_DISPOSE = _nullishCoalesce(Symbol.asyncDispose, () => ( /* @__PURE__ */ Symbol.for("Symbol.asyncDispose")));
|
|
1280
1280
|
|
|
@@ -1406,7 +1406,7 @@ var AccountView = (_class3 = class {
|
|
|
1406
1406
|
case "all_orders":
|
|
1407
1407
|
this.seeds.orders = (_nullishCoalesce(this.seeds.orders, () => ( 0))) + 1;
|
|
1408
1408
|
this.#orders.clear();
|
|
1409
|
-
for (const o of _nullishCoalesce(_optionalChain([payload, 'optionalAccess',
|
|
1409
|
+
for (const o of _nullishCoalesce(_optionalChain([payload, 'optionalAccess', _9 => _9.orders]), () => ( []))) this.#upsertOrder(o);
|
|
1410
1410
|
return change("orders", true);
|
|
1411
1411
|
case "new_open_order":
|
|
1412
1412
|
this.#upsertOrder(payload);
|
|
@@ -1414,7 +1414,7 @@ var AccountView = (_class3 = class {
|
|
|
1414
1414
|
case "all_trades":
|
|
1415
1415
|
this.seeds.fills = (_nullishCoalesce(this.seeds.fills, () => ( 0))) + 1;
|
|
1416
1416
|
this.#fills.clear();
|
|
1417
|
-
for (const t of _nullishCoalesce(_optionalChain([payload, 'optionalAccess',
|
|
1417
|
+
for (const t of _nullishCoalesce(_optionalChain([payload, 'optionalAccess', _10 => _10.trades]), () => ( []))) this.#upsertFill(t);
|
|
1418
1418
|
return change("fills", true);
|
|
1419
1419
|
case "trade":
|
|
1420
1420
|
this.#upsertFill(payload);
|
|
@@ -1422,22 +1422,22 @@ var AccountView = (_class3 = class {
|
|
|
1422
1422
|
case "all_positions":
|
|
1423
1423
|
this.seeds.positions = (_nullishCoalesce(this.seeds.positions, () => ( 0))) + 1;
|
|
1424
1424
|
this.#positions.clear();
|
|
1425
|
-
for (const p of _nullishCoalesce(_optionalChain([payload, 'optionalAccess',
|
|
1425
|
+
for (const p of _nullishCoalesce(_optionalChain([payload, 'optionalAccess', _11 => _11.positions]), () => ( []))) this.#upsertPosition(p);
|
|
1426
1426
|
return change("positions", true);
|
|
1427
1427
|
case "updated_positions":
|
|
1428
|
-
for (const p of _nullishCoalesce(_optionalChain([payload, 'optionalAccess',
|
|
1428
|
+
for (const p of _nullishCoalesce(_optionalChain([payload, 'optionalAccess', _12 => _12.positions]), () => ( []))) this.#upsertPosition(p);
|
|
1429
1429
|
return change("positions", false);
|
|
1430
1430
|
default:
|
|
1431
1431
|
return void 0;
|
|
1432
1432
|
}
|
|
1433
1433
|
}
|
|
1434
1434
|
#upsertOrder(order) {
|
|
1435
|
-
if (!_optionalChain([order, 'optionalAccess',
|
|
1435
|
+
if (!_optionalChain([order, 'optionalAccess', _13 => _13.id])) return;
|
|
1436
1436
|
if (TERMINAL_ORDER_STATUSES.has(String(order.status))) this.#orders.delete(order.id);
|
|
1437
1437
|
else this.#orders.set(order.id, order);
|
|
1438
1438
|
}
|
|
1439
1439
|
#upsertFill(fill) {
|
|
1440
|
-
if (!_optionalChain([fill, 'optionalAccess',
|
|
1440
|
+
if (!_optionalChain([fill, 'optionalAccess', _14 => _14.id])) return;
|
|
1441
1441
|
this.#fills.delete(fill.id);
|
|
1442
1442
|
this.#fills.set(fill.id, fill);
|
|
1443
1443
|
if (this.#fills.size > this.#maxFills) {
|
|
@@ -1446,7 +1446,7 @@ var AccountView = (_class3 = class {
|
|
|
1446
1446
|
}
|
|
1447
1447
|
}
|
|
1448
1448
|
#upsertPosition(position) {
|
|
1449
|
-
const key = _nullishCoalesce(_optionalChain([position, 'optionalAccess',
|
|
1449
|
+
const key = _nullishCoalesce(_optionalChain([position, 'optionalAccess', _15 => _15.market_id]), () => ( _optionalChain([position, 'optionalAccess', _16 => _16.id])));
|
|
1450
1450
|
if (!key) return;
|
|
1451
1451
|
if (!this.#keepFlat && isZero(position.position)) this.#positions.delete(key);
|
|
1452
1452
|
else this.#positions.set(key, position);
|
|
@@ -1885,7 +1885,7 @@ function buildRequest(operationId, args = {}) {
|
|
|
1885
1885
|
const op = OPERATIONS[operationId];
|
|
1886
1886
|
let path = op.path;
|
|
1887
1887
|
for (const name of op.pathParams) {
|
|
1888
|
-
const value = _optionalChain([args, 'access',
|
|
1888
|
+
const value = _optionalChain([args, 'access', _17 => _17.pathParams, 'optionalAccess', _18 => _18[name]]);
|
|
1889
1889
|
if (!value) throw new TypeError(`${name} is required`);
|
|
1890
1890
|
path = path.replace(`{${name}}`, quote(String(value)));
|
|
1891
1891
|
}
|
|
@@ -1941,7 +1941,7 @@ function toBatchOrderResult(raw) {
|
|
|
1941
1941
|
const obj = raw && typeof raw === "object" ? raw : {};
|
|
1942
1942
|
const order = _nullishCoalesce(obj.order, () => ( null));
|
|
1943
1943
|
const errors = Array.isArray(obj.errors) ? obj.errors : null;
|
|
1944
|
-
return { ...obj, order, errors, ok: order !== null && !_optionalChain([errors, 'optionalAccess',
|
|
1944
|
+
return { ...obj, order, errors, ok: order !== null && !_optionalChain([errors, 'optionalAccess', _19 => _19.length]) };
|
|
1945
1945
|
}
|
|
1946
1946
|
|
|
1947
1947
|
// src/client.ts
|
|
@@ -2046,7 +2046,6 @@ var STX = (_class4 = class _STX {
|
|
|
2046
2046
|
#fetch;
|
|
2047
2047
|
#me;
|
|
2048
2048
|
#capabilities;
|
|
2049
|
-
#apiVersion;
|
|
2050
2049
|
/** Test hook: how retries wait. */
|
|
2051
2050
|
__init5() {this._sleep = sleep}
|
|
2052
2051
|
constructor(opts = {}) {;_class4.prototype.__init5.call(this);
|
|
@@ -2097,7 +2096,7 @@ var STX = (_class4 = class _STX {
|
|
|
2097
2096
|
this.#fetch = fetchImpl;
|
|
2098
2097
|
}
|
|
2099
2098
|
toString() {
|
|
2100
|
-
return `STX(baseUrl=${JSON.stringify(this.baseUrl)}, keyId=${JSON.stringify(_nullishCoalesce(_optionalChain([this, 'access',
|
|
2099
|
+
return `STX(baseUrl=${JSON.stringify(this.baseUrl)}, keyId=${JSON.stringify(_nullishCoalesce(_optionalChain([this, 'access', _20 => _20.credentials, 'optionalAccess', _21 => _21.keyId]), () => ( null)))})`;
|
|
2101
2100
|
}
|
|
2102
2101
|
/** The exchange host, e.g. `"demo.stxapp.io"`: the name `STXNotAvailableException` and `capabilities()` report. */
|
|
2103
2102
|
get host() {
|
|
@@ -2108,7 +2107,7 @@ var STX = (_class4 = class _STX {
|
|
|
2108
2107
|
// ------------------------------------------------------------------
|
|
2109
2108
|
/**
|
|
2110
2109
|
* Which features this exchange has, from what it publishes: its OAuth
|
|
2111
|
-
* discovery document,
|
|
2110
|
+
* discovery document, a signed GET of the routes that not
|
|
2112
2111
|
* every exchange has yet, and a join of a combos topic nobody owns. Nothing
|
|
2113
2112
|
* is created or changed. Checked once per client and cached; pass
|
|
2114
2113
|
* `{ refresh: true }` to check again.
|
|
@@ -2150,81 +2149,12 @@ var STX = (_class4 = class _STX {
|
|
|
2150
2149
|
clearTimeout(timer);
|
|
2151
2150
|
}
|
|
2152
2151
|
}
|
|
2153
|
-
// GET /api_version, cached on the client. A 404 is an answer (no feature
|
|
2154
|
-
// list), and so is a bare 403 from the edge (not JSON, no x-stx-error), which
|
|
2155
|
-
// some exchanges send for this path while serving the API. Any other failure
|
|
2156
|
-
// throws, so an outage or a block with a reason is never read as "absent".
|
|
2157
|
-
#apiVersionInfo() {
|
|
2158
|
-
if (!this.#apiVersion) {
|
|
2159
|
-
const run = this.#fetchApiVersion();
|
|
2160
|
-
this.#apiVersion = run;
|
|
2161
|
-
run.catch(() => {
|
|
2162
|
-
if (this.#apiVersion === run) this.#apiVersion = void 0;
|
|
2163
|
-
});
|
|
2164
|
-
}
|
|
2165
|
-
return this.#apiVersion;
|
|
2166
|
-
}
|
|
2167
|
-
async #fetchApiVersion() {
|
|
2168
|
-
const request = {
|
|
2169
|
-
operationId: "api_version",
|
|
2170
|
-
method: "GET",
|
|
2171
|
-
path: "/api_version",
|
|
2172
|
-
body: void 0,
|
|
2173
|
-
idempotent: true
|
|
2174
|
-
};
|
|
2175
|
-
const controller = new AbortController();
|
|
2176
|
-
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
2177
|
-
let res;
|
|
2178
|
-
let text;
|
|
2179
|
-
try {
|
|
2180
|
-
res = await this.#fetch(this.baseUrl + request.path, {
|
|
2181
|
-
method: "GET",
|
|
2182
|
-
headers: { "User-Agent": USER_AGENT, Accept: "application/json" },
|
|
2183
|
-
signal: controller.signal
|
|
2184
|
-
});
|
|
2185
|
-
text = await res.text();
|
|
2186
|
-
} catch (err) {
|
|
2187
|
-
throw new STXTransportException(`GET /api_version failed: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess', _25 => _25.message]), () => ( String(err)))}`, {
|
|
2188
|
-
method: "GET",
|
|
2189
|
-
path: request.path,
|
|
2190
|
-
cause: err
|
|
2191
|
-
});
|
|
2192
|
-
} finally {
|
|
2193
|
-
clearTimeout(timer);
|
|
2194
|
-
}
|
|
2195
|
-
if (res.status === 404 || res.status === 403 && !res.headers.get("x-stx-error") && isEdgeBlock(403, text)) {
|
|
2196
|
-
return { apiVersion: null, features: null };
|
|
2197
|
-
}
|
|
2198
|
-
return apiVersionFrom(
|
|
2199
|
-
decodeResponse(request, res.status, text, {
|
|
2200
|
-
retryAfter: res.headers.get("Retry-After"),
|
|
2201
|
-
stxError: res.headers.get("x-stx-error"),
|
|
2202
|
-
cfId: res.headers.get("x-amz-cf-id")
|
|
2203
|
-
})
|
|
2204
|
-
);
|
|
2205
|
-
}
|
|
2206
|
-
// Older builds ignore a fill_mode they do not know and would place a normal
|
|
2207
|
-
// order, so nothing is sent unless the exchange lists the mode.
|
|
2208
|
-
async #requireFillModes(modes) {
|
|
2209
|
-
for (const mode of [...new Set(modes)].sort()) {
|
|
2210
|
-
const feature = `orders.${mode}`;
|
|
2211
|
-
const info = await this.#apiVersionInfo();
|
|
2212
|
-
if (!_optionalChain([info, 'access', _26 => _26.features, 'optionalAccess', _27 => _27.includes, 'call', _28 => _28(API_FEATURES[feature])])) {
|
|
2213
|
-
throw new STXNotAvailableException(feature, this.host, { apiVersion: info.apiVersion });
|
|
2214
|
-
}
|
|
2215
|
-
}
|
|
2216
|
-
}
|
|
2217
2152
|
// A typed error for the exchange's refusals of a fill mode, else undefined.
|
|
2218
|
-
|
|
2153
|
+
#fillModeError(err, mode) {
|
|
2219
2154
|
if (!(err instanceof STXValidationException || err instanceof STXRejectedException)) return void 0;
|
|
2220
2155
|
const base = { statusCode: err.statusCode, body: err.body, method: err.method, path: err.path, cause: err };
|
|
2221
2156
|
const off = NOT_ENABLED.exec(err.message);
|
|
2222
|
-
if (off) {
|
|
2223
|
-
const cached = this.#apiVersion;
|
|
2224
|
-
this.#apiVersion = void 0;
|
|
2225
|
-
const apiVersion = cached ? await _asyncOptionalChain([(await cached.catch(() => null)), 'optionalAccess', async _29 => _29.apiVersion]) : void 0;
|
|
2226
|
-
return new STXNotAvailableException(`orders.${_nullishCoalesce(off[1], () => ( off[2]))}`, this.host, { ...base, apiVersion });
|
|
2227
|
-
}
|
|
2157
|
+
if (off) return new STXNotAvailableException(`orders.${_nullishCoalesce(off[1], () => ( off[2]))}`, this.host, base);
|
|
2228
2158
|
if (!(err instanceof STXRejectedException)) return void 0;
|
|
2229
2159
|
const notAccepted = NOT_ACCEPTED.exec(err.message);
|
|
2230
2160
|
if (notAccepted) return new STXFillModeNotAllowedException(err.message, { ...base, fillMode: notAccepted[1] });
|
|
@@ -2283,7 +2213,7 @@ var STX = (_class4 = class _STX {
|
|
|
2283
2213
|
status,
|
|
2284
2214
|
attempt,
|
|
2285
2215
|
durationMs: Date.now() - started,
|
|
2286
|
-
authKind: _optionalChain([this, 'access',
|
|
2216
|
+
authKind: _optionalChain([this, 'access', _22 => _22.auth, 'optionalAccess', _23 => _23.kind]),
|
|
2287
2217
|
requestBody: request.body,
|
|
2288
2218
|
responseBody
|
|
2289
2219
|
});
|
|
@@ -2315,7 +2245,7 @@ var STX = (_class4 = class _STX {
|
|
|
2315
2245
|
});
|
|
2316
2246
|
}
|
|
2317
2247
|
throw new STXTransportException(
|
|
2318
|
-
`${request.method} ${request.path} failed: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess',
|
|
2248
|
+
`${request.method} ${request.path} failed: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess', _24 => _24.message]), () => ( String(err)))}`,
|
|
2319
2249
|
{ method: request.method, path: request.path, cause: err }
|
|
2320
2250
|
);
|
|
2321
2251
|
} finally {
|
|
@@ -2339,7 +2269,7 @@ var STX = (_class4 = class _STX {
|
|
|
2339
2269
|
return await this.#sendOnce(request, sent);
|
|
2340
2270
|
} catch (err) {
|
|
2341
2271
|
if (!(err instanceof STXException)) throw err;
|
|
2342
|
-
if (err.statusCode === 401 && !reauthenticated && _optionalChain([this, 'access',
|
|
2272
|
+
if (err.statusCode === 401 && !reauthenticated && _optionalChain([this, 'access', _25 => _25.auth, 'optionalAccess', _26 => _26.onUnauthorized])) {
|
|
2343
2273
|
reauthenticated = true;
|
|
2344
2274
|
if (await this.auth.onUnauthorized()) continue;
|
|
2345
2275
|
}
|
|
@@ -2354,7 +2284,7 @@ var STX = (_class4 = class _STX {
|
|
|
2354
2284
|
return await this.#send(buildRequest(operationId, args));
|
|
2355
2285
|
} catch (err) {
|
|
2356
2286
|
const feature = GATED_OPERATIONS[operationId];
|
|
2357
|
-
const off = feature !== void 0 && err instanceof STXNotFoundException && SWITCHED_OFF[feature] !== void 0 && _optionalChain([err, 'access',
|
|
2287
|
+
const off = feature !== void 0 && err instanceof STXNotFoundException && SWITCHED_OFF[feature] !== void 0 && _optionalChain([err, 'access', _27 => _27.body, 'optionalAccess', _28 => _28.error]) === SWITCHED_OFF[feature];
|
|
2358
2288
|
if (feature && (isMissingRoute(err) || off)) {
|
|
2359
2289
|
throw new STXNotAvailableException(feature, this.host, {
|
|
2360
2290
|
statusCode: err.statusCode,
|
|
@@ -2407,7 +2337,7 @@ var STX = (_class4 = class _STX {
|
|
|
2407
2337
|
* `user_id`.
|
|
2408
2338
|
*/
|
|
2409
2339
|
async userId() {
|
|
2410
|
-
if (_optionalChain([this, 'access',
|
|
2340
|
+
if (_optionalChain([this, 'access', _29 => _29.#me, 'optionalAccess', _30 => _30.user_id])) return this.#me.user_id;
|
|
2411
2341
|
try {
|
|
2412
2342
|
await this.me();
|
|
2413
2343
|
} catch (err) {
|
|
@@ -2418,7 +2348,7 @@ var STX = (_class4 = class _STX {
|
|
|
2418
2348
|
if (!balance.user_id) throw err;
|
|
2419
2349
|
this.#me = { ..._nullishCoalesce(this.#me, () => ( {})), user_id: balance.user_id };
|
|
2420
2350
|
}
|
|
2421
|
-
if (!_optionalChain([this, 'access',
|
|
2351
|
+
if (!_optionalChain([this, 'access', _31 => _31.#me, 'optionalAccess', _32 => _32.user_id])) throw new STXException("GET /api/v1/me returned no user_id");
|
|
2422
2352
|
return this.#me.user_id;
|
|
2423
2353
|
}
|
|
2424
2354
|
// ------------------------------------------------------------------
|
|
@@ -2591,10 +2521,11 @@ var STX = (_class4 = class _STX {
|
|
|
2591
2521
|
* comes back `accepted` (or `delayed` in play); follow it on the `orders`
|
|
2592
2522
|
* channel or with `order()` to see it `filled` or `cancelled`.
|
|
2593
2523
|
*
|
|
2594
|
-
*
|
|
2595
|
-
* it
|
|
2596
|
-
* (`orders.post_only`, `orders.fill_or_kill`)
|
|
2597
|
-
*
|
|
2524
|
+
* The exchange decides whether it takes either mode. Where a mode is not
|
|
2525
|
+
* enabled it rejects the order and this throws `STXNotAvailableException`
|
|
2526
|
+
* (`orders.post_only`, `orders.fill_or_kill`). An exchange on a release from
|
|
2527
|
+
* before fill modes places the order as a normal limit order. A combination
|
|
2528
|
+
* market throws `STXFillModeNotAllowedException`.
|
|
2598
2529
|
*
|
|
2599
2530
|
* The exchange validates the order: a bad price step or a fractional
|
|
2600
2531
|
* quantity throws `STXValidationException` (400) or `STXRejectedException`
|
|
@@ -2608,12 +2539,11 @@ var STX = (_class4 = class _STX {
|
|
|
2608
2539
|
const body = orderBody(marketId, action, orderType, _nullishCoalesce(opts, () => ( {})));
|
|
2609
2540
|
const mode = body.fill_mode;
|
|
2610
2541
|
if (mode === void 0) return this.#one("orders_post", { body });
|
|
2611
|
-
await this.#requireFillModes([mode]);
|
|
2612
2542
|
let order;
|
|
2613
2543
|
try {
|
|
2614
2544
|
order = await this.#one("orders_post", { body });
|
|
2615
2545
|
} catch (err) {
|
|
2616
|
-
throw
|
|
2546
|
+
throw _nullishCoalesce(this.#fillModeError(err, mode), () => ( err));
|
|
2617
2547
|
}
|
|
2618
2548
|
if (mode === "post_only" && order.status === "cancelled" && order.cancellation_reason === "auto_matching") {
|
|
2619
2549
|
throw new STXPostOnlyWouldMatchException(
|
|
@@ -2630,19 +2560,17 @@ var STX = (_class4 = class _STX {
|
|
|
2630
2560
|
* matched comes back as its order, `cancelled` with `cancellation_reason`
|
|
2631
2561
|
* `auto_matching`.
|
|
2632
2562
|
*
|
|
2633
|
-
* When
|
|
2634
|
-
*
|
|
2635
|
-
* thrown with nothing sent.
|
|
2563
|
+
* When the exchange rejects the call because a `fillMode` is not enabled
|
|
2564
|
+
* there, this throws `STXNotAvailableException`, as `placeOrder()` does.
|
|
2636
2565
|
*/
|
|
2637
2566
|
async placeOrders(orders) {
|
|
2638
2567
|
const body = { orders: orders.map(normalizeOrder) };
|
|
2639
2568
|
const modes = body.orders.map((o) => o.fill_mode).filter((m) => typeof m === "string");
|
|
2640
|
-
if (modes.length) await this.#requireFillModes(modes);
|
|
2641
2569
|
let raw;
|
|
2642
2570
|
try {
|
|
2643
2571
|
raw = await this.#list("orders_batched_post", { body });
|
|
2644
2572
|
} catch (err) {
|
|
2645
|
-
throw
|
|
2573
|
+
throw _nullishCoalesce((modes.length ? this.#fillModeError(err, void 0) : void 0), () => ( err));
|
|
2646
2574
|
}
|
|
2647
2575
|
return raw.map(toBatchOrderResult);
|
|
2648
2576
|
}
|
|
@@ -3135,7 +3063,7 @@ var Channel = (_class5 = class {
|
|
|
3135
3063
|
_startPinger() {
|
|
3136
3064
|
this._stopPinger();
|
|
3137
3065
|
let interval = this.pingIntervalMs;
|
|
3138
|
-
const granted = _optionalChain([this, 'access',
|
|
3066
|
+
const granted = _optionalChain([this, 'access', _33 => _33.reply, 'optionalAccess', _34 => _34.ping_timeout]);
|
|
3139
3067
|
if (typeof granted === "number" && this.joinPayload.cancel_on_disconnect) {
|
|
3140
3068
|
const cod = granted / 3;
|
|
3141
3069
|
interval = interval === null ? cod : Math.min(interval, cod);
|
|
@@ -3149,7 +3077,7 @@ var Channel = (_class5 = class {
|
|
|
3149
3077
|
(err) => this.#ws.logger.warn(`${this.topic} ping failed: ${err.message}`)
|
|
3150
3078
|
);
|
|
3151
3079
|
}, every);
|
|
3152
|
-
_optionalChain([this, 'access',
|
|
3080
|
+
_optionalChain([this, 'access', _35 => _35.#pingTimer, 'access', _36 => _36.unref, 'optionalCall', _37 => _37()]);
|
|
3153
3081
|
}
|
|
3154
3082
|
}
|
|
3155
3083
|
/** @internal */
|
|
@@ -3361,7 +3289,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3361
3289
|
*/
|
|
3362
3290
|
async marketUpdates(opts = {}) {
|
|
3363
3291
|
const channel = await this.join("market_updates", {}, opts.onMessage);
|
|
3364
|
-
if (_optionalChain([opts, 'access',
|
|
3292
|
+
if (_optionalChain([opts, 'access', _38 => _38.watch, 'optionalAccess', _39 => _39.length])) await channel.watch(opts.watch);
|
|
3365
3293
|
return channel;
|
|
3366
3294
|
}
|
|
3367
3295
|
/**
|
|
@@ -3610,12 +3538,12 @@ var STXWebSocket = (_class6 = class {
|
|
|
3610
3538
|
if (!(err instanceof STXTransportException)) return false;
|
|
3611
3539
|
if (err.statusCode !== 401 && err.statusCode !== 403) return false;
|
|
3612
3540
|
const auth = this.rest.auth;
|
|
3613
|
-
if (!_optionalChain([auth, 'optionalAccess',
|
|
3541
|
+
if (!_optionalChain([auth, 'optionalAccess', _40 => _40.onUnauthorized])) return false;
|
|
3614
3542
|
return auth.onUnauthorized();
|
|
3615
3543
|
}
|
|
3616
3544
|
async #open(reconnect = false) {
|
|
3617
3545
|
const headers = { "User-Agent": USER_AGENT };
|
|
3618
|
-
if (_optionalChain([this, 'access',
|
|
3546
|
+
if (_optionalChain([this, 'access', _41 => _41.rest, 'access', _42 => _42.auth, 'optionalAccess', _43 => _43.websocketHeaders])) Object.assign(headers, await this.rest.auth.websocketHeaders({ reconnect }));
|
|
3619
3547
|
const conn = new (0, _ws2.default)(this.url, {
|
|
3620
3548
|
headers,
|
|
3621
3549
|
rejectUnauthorized: this.rest.verifyTls,
|
|
@@ -3631,7 +3559,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3631
3559
|
conn.on("error", () => {
|
|
3632
3560
|
});
|
|
3633
3561
|
conn.terminate();
|
|
3634
|
-
const reason = _optionalChain([res, 'access',
|
|
3562
|
+
const reason = _optionalChain([res, 'access', _44 => _44.headers, 'optionalAccess', _45 => _45["x-stx-error"]]);
|
|
3635
3563
|
reject(
|
|
3636
3564
|
new STXTransportException(
|
|
3637
3565
|
`Could not open ${this.url}: HTTP ${res.statusCode}${reason ? ` (${String(reason)})` : ""}`,
|
|
@@ -3746,7 +3674,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3746
3674
|
if (!channel.joined) {
|
|
3747
3675
|
channel._endedJoin = { joinRef: String(joinRef), event };
|
|
3748
3676
|
const pending = this.#pending.get(String(joinRef));
|
|
3749
|
-
if (_optionalChain([pending, 'optionalAccess',
|
|
3677
|
+
if (_optionalChain([pending, 'optionalAccess', _46 => _46.event]) === "phx_join") pending.reject(joinInterrupted(channel, event));
|
|
3750
3678
|
if (event === "phx_close" && channel.name === "market") this.#finishMarket(channel);
|
|
3751
3679
|
return;
|
|
3752
3680
|
}
|
|
@@ -3799,7 +3727,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3799
3727
|
} catch (err) {
|
|
3800
3728
|
this.logger.error(`rejoin ${channel.topic} failed: ${err.message}`);
|
|
3801
3729
|
const reply = err instanceof STXChannelException ? err.reply : void 0;
|
|
3802
|
-
if (_optionalChain([reply, 'optionalAccess',
|
|
3730
|
+
if (_optionalChain([reply, 'optionalAccess', _47 => _47.reason]) === "unauthorized" || _optionalChain([reply, 'optionalAccess', _48 => _48.reason]) === COMBOS_UNAVAILABLE_REASON && COMBO_CHANNELS.has(channel.name)) {
|
|
3803
3731
|
channel._close();
|
|
3804
3732
|
return;
|
|
3805
3733
|
}
|
|
@@ -3813,7 +3741,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3813
3741
|
if (!this.connected) return;
|
|
3814
3742
|
if (this.#pendingHeartbeat !== null) {
|
|
3815
3743
|
this.logger.warn("heartbeat unanswered; reconnecting");
|
|
3816
|
-
_optionalChain([this, 'access',
|
|
3744
|
+
_optionalChain([this, 'access', _49 => _49.#conn, 'optionalAccess', _50 => _50.terminate, 'call', _51 => _51()]);
|
|
3817
3745
|
return;
|
|
3818
3746
|
}
|
|
3819
3747
|
const ref = this.#nextRef();
|
|
@@ -3821,7 +3749,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3821
3749
|
try {
|
|
3822
3750
|
this.#send([null, ref, PHOENIX_TOPIC, "heartbeat", {}]);
|
|
3823
3751
|
} catch (e13) {
|
|
3824
|
-
_optionalChain([this, 'access',
|
|
3752
|
+
_optionalChain([this, 'access', _52 => _52.#conn, 'optionalAccess', _53 => _53.terminate, 'call', _54 => _54()]);
|
|
3825
3753
|
}
|
|
3826
3754
|
}, this.heartbeatIntervalMs);
|
|
3827
3755
|
}
|
|
@@ -3908,7 +3836,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3908
3836
|
this.error = err;
|
|
3909
3837
|
this.#shutdownAfterDrop();
|
|
3910
3838
|
try {
|
|
3911
|
-
_optionalChain([this, 'access',
|
|
3839
|
+
_optionalChain([this, 'access', _55 => _55.onAuthError, 'optionalCall', _56 => _56(err)]);
|
|
3912
3840
|
} catch (hookErr) {
|
|
3913
3841
|
this.logger.error("onAuthError threw", hookErr);
|
|
3914
3842
|
}
|
|
@@ -4015,4 +3943,4 @@ function dropUndefined(payload) {
|
|
|
4015
3943
|
|
|
4016
3944
|
|
|
4017
3945
|
exports.STXException = STXException; exports.STXConfigException = STXConfigException; exports.STXAPIException = STXAPIException; exports.STXValidationException = STXValidationException; exports.STXAuthenticationException = STXAuthenticationException; exports.STXForbiddenException = STXForbiddenException; exports.STXInvalidTokenException = STXInvalidTokenException; exports.STXInsufficientScopeException = STXInsufficientScopeException; exports.STXTermsRequiredException = STXTermsRequiredException; exports.STXIPNotAllowedException = STXIPNotAllowedException; exports.STXBlockedException = STXBlockedException; exports.STXRestrictedJurisdictionException = STXRestrictedJurisdictionException; exports.STXUnusualNetworkException = STXUnusualNetworkException; exports.STXNotFoundException = STXNotFoundException; exports.STXRejectedException = STXRejectedException; exports.STXFillModeNotAllowedException = STXFillModeNotAllowedException; exports.STXPostOnlyWouldMatchException = STXPostOnlyWouldMatchException; exports.STXRateLimitException = STXRateLimitException; exports.STXServerException = STXServerException; exports.STXTransportException = STXTransportException; exports.STXChannelException = STXChannelException; exports.STXTimeoutException = STXTimeoutException; exports.notAvailableMessage = notAvailableMessage; exports.STXNotAvailableException = STXNotAvailableException; exports.STXCombosUnavailableException = STXCombosUnavailableException; exports.isEdgeBlock = isEdgeBlock; exports.STXComboRefusedException = STXComboRefusedException; exports.STXComboPriceMovedException = STXComboPriceMovedException; exports.errorForStatus = errorForStatus; exports.FEATURES = FEATURES; exports.Capabilities = Capabilities; exports.Region = Region; exports.Environment = Environment; exports.Environments = Environments; exports.HOSTS = HOSTS; exports.environmentNamed = environmentNamed; exports.resolveHost = resolveHost; exports.baseUrlFor = baseUrlFor; exports.socketUrlFor = socketUrlFor; exports.OPERATIONS = OPERATIONS; exports.Stats = Stats; exports.MAX_MARKETS_PER_REQUEST = MAX_MARKETS_PER_REQUEST; exports.isValidLine = isValidLine; exports.Page = Page; exports.RetryPolicy = RetryPolicy; exports.NO_RETRY = NO_RETRY; exports.resolveSettings = resolveSettings; exports.KEY_HEADER = KEY_HEADER; exports.TIMESTAMP_HEADER = TIMESTAMP_HEADER; exports.SIGNATURE_HEADER = SIGNATURE_HEADER; exports.buildMessage = buildMessage; exports.requestPath = requestPath; exports.handshakePath = handshakePath; exports.loadPrivateKey = loadPrivateKey; exports.signerFromPrivateKey = signerFromPrivateKey; exports.ApiKeyCredentials = ApiKeyCredentials; exports.VERSION = VERSION; exports.USER_AGENT = USER_AGENT; exports.TERMINAL_ORDER_STATUSES = TERMINAL_ORDER_STATUSES; exports.AccountView = AccountView; exports.ComboPlayer = ComboPlayer; exports.ComboMaker = ComboMaker; exports.centsToDollars = centsToDollars; exports.toDollarString = toDollarString; exports.toQuantity = toQuantity; exports.convertMarketPayload = convertMarketPayload; exports.convertMarketsFrame = convertMarketsFrame; exports.convertBook = convertBook; exports.convertMarketChannelPayload = convertMarketChannelPayload; exports.SNAPSHOT_EVENTS = SNAPSHOT_EVENTS; exports.ChannelMessage = ChannelMessage; exports.ReconnectPolicy = ReconnectPolicy; exports.Channel = Channel; exports.STXWebSocket = STXWebSocket; exports.orderBody = orderBody; exports.STX = STX;
|
|
4018
|
-
//# sourceMappingURL=chunk-
|
|
3946
|
+
//# sourceMappingURL=chunk-WTKAZNEP.cjs.map
|