@stxapp/stx-typescript 0.11.0 → 0.12.0
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 +7 -0
- package/README.md +1 -1
- package/dist/{chunk-BSX65XEA.cjs → chunk-B3JQFXMJ.cjs} +46 -136
- package/dist/chunk-B3JQFXMJ.cjs.map +1 -0
- package/dist/{chunk-2PYJI3JS.js → chunk-JJRK3Z27.js} +17 -107
- package/dist/chunk-JJRK3Z27.js.map +1 -0
- package/dist/{client-DxY8eJ58.d.ts → client-CwshT5D4.d.cts} +11 -11
- package/dist/{client-DxY8eJ58.d.cts → client-CwshT5D4.d.ts} +11 -11
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.12.0 (2026-11-18)
|
|
4
|
+
|
|
5
|
+
Breaking for anyone reading `orders.post_only` or `orders.fill_or_kill` from `capabilities()`:
|
|
6
|
+
|
|
7
|
+
- Post-only and fill-or-kill orders are sent straight to the exchange, which accepts or rejects them. The client no longer asks `GET /api_version` first. Where a mode is not enabled, the exchange rejects the order and the call throws `STXNotAvailableException` (`feature` `orders.post_only` or `orders.fill_or_kill`), as before. An exchange on a release from before fill modes places the order as a normal limit order. See https://docs.stxapp.io/concepts/order-types/
|
|
8
|
+
- `capabilities()` no longer reports `orders.post_only` or `orders.fill_or_kill`.
|
|
9
|
+
|
|
3
10
|
## 0.11.0 (2026-11-17)
|
|
4
11
|
|
|
5
12
|
Post-only and fill-or-kill orders:
|
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ Every field is described in the [API reference](https://docs.stxapp.io/sdks/type
|
|
|
72
72
|
|
|
73
73
|
</details>
|
|
74
74
|
|
|
75
|
-
`placeOrder(marketId, "buy", "limit", { price, quantity, fillMode: "post_only" })` places a limit order that only rests on the book, and `fillMode: "fill_or_kill"` one that fills in full or not at all.
|
|
75
|
+
`placeOrder(marketId, "buy", "limit", { price, quantity, fillMode: "post_only" })` places a limit order that only rests on the book, and `fillMode: "fill_or_kill"` one that fills in full or not at all. Where the exchange has not enabled a fill mode, it rejects the order and the call throws `STXNotAvailableException`. See [Trading](https://docs.stxapp.io/sdks/typescript/trading/).
|
|
76
76
|
|
|
77
77
|
## For apps: STX accounts and markets
|
|
78
78
|
|
|
@@ -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
|
|
|
@@ -311,22 +311,8 @@ var FEATURES = [
|
|
|
311
311
|
"event_players",
|
|
312
312
|
"leaderboard",
|
|
313
313
|
"loyalty",
|
|
314
|
-
"combos"
|
|
315
|
-
"orders.post_only",
|
|
316
|
-
"orders.fill_or_kill"
|
|
314
|
+
"combos"
|
|
317
315
|
];
|
|
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
316
|
var MEMBER_SCOPES = [
|
|
331
317
|
"profile.read",
|
|
332
318
|
"balance.read",
|
|
@@ -415,9 +401,7 @@ async function discoverCapabilities(probes) {
|
|
|
415
401
|
swallow(probes.signedGet("/api/v1/portfolio/loyalty?limit=1")),
|
|
416
402
|
swallow(probes.joinReason(`rfq:${NOBODY}`))
|
|
417
403
|
]);
|
|
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;
|
|
404
|
+
const apiVersion = _optionalChain([version, 'optionalAccess', _5 => _5.status]) === 200 ? _optionalChain([json, 'call', _6 => _6(version), 'optionalAccess', _7 => _7.api_version]) : null;
|
|
421
405
|
const meta = oauthMetadataFrom(discovery);
|
|
422
406
|
const scopes = meta ? strings(meta.scopes_supported) : [];
|
|
423
407
|
const grants = meta ? strings(meta.grant_types_supported) : [];
|
|
@@ -439,9 +423,7 @@ async function discoverCapabilities(probes) {
|
|
|
439
423
|
leaderboard: board === null ? null : board.status >= 200 && board.status < 300 ? true : board.status === 404 ? false : null,
|
|
440
424
|
// Switched off answers 404 ("Loyalty program is not enabled").
|
|
441
425
|
loyalty: loyalty === null ? null : loyalty.status >= 200 && loyalty.status < 300 ? true : loyalty.status === 404 ? false : null,
|
|
442
|
-
combos: combos === null ? null : combos !== "unmatched topic"
|
|
443
|
-
"orders.post_only": listed(API_FEATURES["orders.post_only"]),
|
|
444
|
-
"orders.fill_or_kill": listed(API_FEATURES["orders.fill_or_kill"])
|
|
426
|
+
combos: combos === null ? null : combos !== "unmatched topic"
|
|
445
427
|
};
|
|
446
428
|
return new Capabilities({
|
|
447
429
|
host: probes.host,
|
|
@@ -1100,7 +1082,7 @@ function readProfile(profileName, path) {
|
|
|
1100
1082
|
}
|
|
1101
1083
|
function processEnv() {
|
|
1102
1084
|
const p = globalThis.process;
|
|
1103
|
-
return _nullishCoalesce(_optionalChain([p, 'optionalAccess',
|
|
1085
|
+
return _nullishCoalesce(_optionalChain([p, 'optionalAccess', _8 => _8.env]), () => ( {}));
|
|
1104
1086
|
}
|
|
1105
1087
|
function resolveSettings(input = {}) {
|
|
1106
1088
|
const environ = _nullishCoalesce(input.environ, () => ( processEnv()));
|
|
@@ -1274,7 +1256,7 @@ function credentialsFromSettings(keyId, privateKey, signer) {
|
|
|
1274
1256
|
}
|
|
1275
1257
|
|
|
1276
1258
|
// src/version.ts
|
|
1277
|
-
var VERSION = "0.
|
|
1259
|
+
var VERSION = "0.12.0";
|
|
1278
1260
|
var USER_AGENT = `stx-typescript/${VERSION}`;
|
|
1279
1261
|
var ASYNC_DISPOSE = _nullishCoalesce(Symbol.asyncDispose, () => ( /* @__PURE__ */ Symbol.for("Symbol.asyncDispose")));
|
|
1280
1262
|
|
|
@@ -1406,7 +1388,7 @@ var AccountView = (_class3 = class {
|
|
|
1406
1388
|
case "all_orders":
|
|
1407
1389
|
this.seeds.orders = (_nullishCoalesce(this.seeds.orders, () => ( 0))) + 1;
|
|
1408
1390
|
this.#orders.clear();
|
|
1409
|
-
for (const o of _nullishCoalesce(_optionalChain([payload, 'optionalAccess',
|
|
1391
|
+
for (const o of _nullishCoalesce(_optionalChain([payload, 'optionalAccess', _9 => _9.orders]), () => ( []))) this.#upsertOrder(o);
|
|
1410
1392
|
return change("orders", true);
|
|
1411
1393
|
case "new_open_order":
|
|
1412
1394
|
this.#upsertOrder(payload);
|
|
@@ -1414,7 +1396,7 @@ var AccountView = (_class3 = class {
|
|
|
1414
1396
|
case "all_trades":
|
|
1415
1397
|
this.seeds.fills = (_nullishCoalesce(this.seeds.fills, () => ( 0))) + 1;
|
|
1416
1398
|
this.#fills.clear();
|
|
1417
|
-
for (const t of _nullishCoalesce(_optionalChain([payload, 'optionalAccess',
|
|
1399
|
+
for (const t of _nullishCoalesce(_optionalChain([payload, 'optionalAccess', _10 => _10.trades]), () => ( []))) this.#upsertFill(t);
|
|
1418
1400
|
return change("fills", true);
|
|
1419
1401
|
case "trade":
|
|
1420
1402
|
this.#upsertFill(payload);
|
|
@@ -1422,22 +1404,22 @@ var AccountView = (_class3 = class {
|
|
|
1422
1404
|
case "all_positions":
|
|
1423
1405
|
this.seeds.positions = (_nullishCoalesce(this.seeds.positions, () => ( 0))) + 1;
|
|
1424
1406
|
this.#positions.clear();
|
|
1425
|
-
for (const p of _nullishCoalesce(_optionalChain([payload, 'optionalAccess',
|
|
1407
|
+
for (const p of _nullishCoalesce(_optionalChain([payload, 'optionalAccess', _11 => _11.positions]), () => ( []))) this.#upsertPosition(p);
|
|
1426
1408
|
return change("positions", true);
|
|
1427
1409
|
case "updated_positions":
|
|
1428
|
-
for (const p of _nullishCoalesce(_optionalChain([payload, 'optionalAccess',
|
|
1410
|
+
for (const p of _nullishCoalesce(_optionalChain([payload, 'optionalAccess', _12 => _12.positions]), () => ( []))) this.#upsertPosition(p);
|
|
1429
1411
|
return change("positions", false);
|
|
1430
1412
|
default:
|
|
1431
1413
|
return void 0;
|
|
1432
1414
|
}
|
|
1433
1415
|
}
|
|
1434
1416
|
#upsertOrder(order) {
|
|
1435
|
-
if (!_optionalChain([order, 'optionalAccess',
|
|
1417
|
+
if (!_optionalChain([order, 'optionalAccess', _13 => _13.id])) return;
|
|
1436
1418
|
if (TERMINAL_ORDER_STATUSES.has(String(order.status))) this.#orders.delete(order.id);
|
|
1437
1419
|
else this.#orders.set(order.id, order);
|
|
1438
1420
|
}
|
|
1439
1421
|
#upsertFill(fill) {
|
|
1440
|
-
if (!_optionalChain([fill, 'optionalAccess',
|
|
1422
|
+
if (!_optionalChain([fill, 'optionalAccess', _14 => _14.id])) return;
|
|
1441
1423
|
this.#fills.delete(fill.id);
|
|
1442
1424
|
this.#fills.set(fill.id, fill);
|
|
1443
1425
|
if (this.#fills.size > this.#maxFills) {
|
|
@@ -1446,7 +1428,7 @@ var AccountView = (_class3 = class {
|
|
|
1446
1428
|
}
|
|
1447
1429
|
}
|
|
1448
1430
|
#upsertPosition(position) {
|
|
1449
|
-
const key = _nullishCoalesce(_optionalChain([position, 'optionalAccess',
|
|
1431
|
+
const key = _nullishCoalesce(_optionalChain([position, 'optionalAccess', _15 => _15.market_id]), () => ( _optionalChain([position, 'optionalAccess', _16 => _16.id])));
|
|
1450
1432
|
if (!key) return;
|
|
1451
1433
|
if (!this.#keepFlat && isZero(position.position)) this.#positions.delete(key);
|
|
1452
1434
|
else this.#positions.set(key, position);
|
|
@@ -1885,7 +1867,7 @@ function buildRequest(operationId, args = {}) {
|
|
|
1885
1867
|
const op = OPERATIONS[operationId];
|
|
1886
1868
|
let path = op.path;
|
|
1887
1869
|
for (const name of op.pathParams) {
|
|
1888
|
-
const value = _optionalChain([args, 'access',
|
|
1870
|
+
const value = _optionalChain([args, 'access', _17 => _17.pathParams, 'optionalAccess', _18 => _18[name]]);
|
|
1889
1871
|
if (!value) throw new TypeError(`${name} is required`);
|
|
1890
1872
|
path = path.replace(`{${name}}`, quote(String(value)));
|
|
1891
1873
|
}
|
|
@@ -1941,7 +1923,7 @@ function toBatchOrderResult(raw) {
|
|
|
1941
1923
|
const obj = raw && typeof raw === "object" ? raw : {};
|
|
1942
1924
|
const order = _nullishCoalesce(obj.order, () => ( null));
|
|
1943
1925
|
const errors = Array.isArray(obj.errors) ? obj.errors : null;
|
|
1944
|
-
return { ...obj, order, errors, ok: order !== null && !_optionalChain([errors, 'optionalAccess',
|
|
1926
|
+
return { ...obj, order, errors, ok: order !== null && !_optionalChain([errors, 'optionalAccess', _19 => _19.length]) };
|
|
1945
1927
|
}
|
|
1946
1928
|
|
|
1947
1929
|
// src/client.ts
|
|
@@ -2046,7 +2028,6 @@ var STX = (_class4 = class _STX {
|
|
|
2046
2028
|
#fetch;
|
|
2047
2029
|
#me;
|
|
2048
2030
|
#capabilities;
|
|
2049
|
-
#apiVersion;
|
|
2050
2031
|
/** Test hook: how retries wait. */
|
|
2051
2032
|
__init5() {this._sleep = sleep}
|
|
2052
2033
|
constructor(opts = {}) {;_class4.prototype.__init5.call(this);
|
|
@@ -2097,7 +2078,7 @@ var STX = (_class4 = class _STX {
|
|
|
2097
2078
|
this.#fetch = fetchImpl;
|
|
2098
2079
|
}
|
|
2099
2080
|
toString() {
|
|
2100
|
-
return `STX(baseUrl=${JSON.stringify(this.baseUrl)}, keyId=${JSON.stringify(_nullishCoalesce(_optionalChain([this, 'access',
|
|
2081
|
+
return `STX(baseUrl=${JSON.stringify(this.baseUrl)}, keyId=${JSON.stringify(_nullishCoalesce(_optionalChain([this, 'access', _20 => _20.credentials, 'optionalAccess', _21 => _21.keyId]), () => ( null)))})`;
|
|
2101
2082
|
}
|
|
2102
2083
|
/** The exchange host, e.g. `"demo.stxapp.io"`: the name `STXNotAvailableException` and `capabilities()` report. */
|
|
2103
2084
|
get host() {
|
|
@@ -2108,7 +2089,7 @@ var STX = (_class4 = class _STX {
|
|
|
2108
2089
|
// ------------------------------------------------------------------
|
|
2109
2090
|
/**
|
|
2110
2091
|
* Which features this exchange has, from what it publishes: its OAuth
|
|
2111
|
-
* discovery document,
|
|
2092
|
+
* discovery document, a signed GET of the routes that not
|
|
2112
2093
|
* every exchange has yet, and a join of a combos topic nobody owns. Nothing
|
|
2113
2094
|
* is created or changed. Checked once per client and cached; pass
|
|
2114
2095
|
* `{ refresh: true }` to check again.
|
|
@@ -2150,81 +2131,12 @@ var STX = (_class4 = class _STX {
|
|
|
2150
2131
|
clearTimeout(timer);
|
|
2151
2132
|
}
|
|
2152
2133
|
}
|
|
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
2134
|
// A typed error for the exchange's refusals of a fill mode, else undefined.
|
|
2218
|
-
|
|
2135
|
+
#fillModeError(err, mode) {
|
|
2219
2136
|
if (!(err instanceof STXValidationException || err instanceof STXRejectedException)) return void 0;
|
|
2220
2137
|
const base = { statusCode: err.statusCode, body: err.body, method: err.method, path: err.path, cause: err };
|
|
2221
2138
|
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
|
-
}
|
|
2139
|
+
if (off) return new STXNotAvailableException(`orders.${_nullishCoalesce(off[1], () => ( off[2]))}`, this.host, base);
|
|
2228
2140
|
if (!(err instanceof STXRejectedException)) return void 0;
|
|
2229
2141
|
const notAccepted = NOT_ACCEPTED.exec(err.message);
|
|
2230
2142
|
if (notAccepted) return new STXFillModeNotAllowedException(err.message, { ...base, fillMode: notAccepted[1] });
|
|
@@ -2283,7 +2195,7 @@ var STX = (_class4 = class _STX {
|
|
|
2283
2195
|
status,
|
|
2284
2196
|
attempt,
|
|
2285
2197
|
durationMs: Date.now() - started,
|
|
2286
|
-
authKind: _optionalChain([this, 'access',
|
|
2198
|
+
authKind: _optionalChain([this, 'access', _22 => _22.auth, 'optionalAccess', _23 => _23.kind]),
|
|
2287
2199
|
requestBody: request.body,
|
|
2288
2200
|
responseBody
|
|
2289
2201
|
});
|
|
@@ -2315,7 +2227,7 @@ var STX = (_class4 = class _STX {
|
|
|
2315
2227
|
});
|
|
2316
2228
|
}
|
|
2317
2229
|
throw new STXTransportException(
|
|
2318
|
-
`${request.method} ${request.path} failed: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess',
|
|
2230
|
+
`${request.method} ${request.path} failed: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess', _24 => _24.message]), () => ( String(err)))}`,
|
|
2319
2231
|
{ method: request.method, path: request.path, cause: err }
|
|
2320
2232
|
);
|
|
2321
2233
|
} finally {
|
|
@@ -2339,7 +2251,7 @@ var STX = (_class4 = class _STX {
|
|
|
2339
2251
|
return await this.#sendOnce(request, sent);
|
|
2340
2252
|
} catch (err) {
|
|
2341
2253
|
if (!(err instanceof STXException)) throw err;
|
|
2342
|
-
if (err.statusCode === 401 && !reauthenticated && _optionalChain([this, 'access',
|
|
2254
|
+
if (err.statusCode === 401 && !reauthenticated && _optionalChain([this, 'access', _25 => _25.auth, 'optionalAccess', _26 => _26.onUnauthorized])) {
|
|
2343
2255
|
reauthenticated = true;
|
|
2344
2256
|
if (await this.auth.onUnauthorized()) continue;
|
|
2345
2257
|
}
|
|
@@ -2354,7 +2266,7 @@ var STX = (_class4 = class _STX {
|
|
|
2354
2266
|
return await this.#send(buildRequest(operationId, args));
|
|
2355
2267
|
} catch (err) {
|
|
2356
2268
|
const feature = GATED_OPERATIONS[operationId];
|
|
2357
|
-
const off = feature !== void 0 && err instanceof STXNotFoundException && SWITCHED_OFF[feature] !== void 0 && _optionalChain([err, 'access',
|
|
2269
|
+
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
2270
|
if (feature && (isMissingRoute(err) || off)) {
|
|
2359
2271
|
throw new STXNotAvailableException(feature, this.host, {
|
|
2360
2272
|
statusCode: err.statusCode,
|
|
@@ -2407,7 +2319,7 @@ var STX = (_class4 = class _STX {
|
|
|
2407
2319
|
* `user_id`.
|
|
2408
2320
|
*/
|
|
2409
2321
|
async userId() {
|
|
2410
|
-
if (_optionalChain([this, 'access',
|
|
2322
|
+
if (_optionalChain([this, 'access', _29 => _29.#me, 'optionalAccess', _30 => _30.user_id])) return this.#me.user_id;
|
|
2411
2323
|
try {
|
|
2412
2324
|
await this.me();
|
|
2413
2325
|
} catch (err) {
|
|
@@ -2418,7 +2330,7 @@ var STX = (_class4 = class _STX {
|
|
|
2418
2330
|
if (!balance.user_id) throw err;
|
|
2419
2331
|
this.#me = { ..._nullishCoalesce(this.#me, () => ( {})), user_id: balance.user_id };
|
|
2420
2332
|
}
|
|
2421
|
-
if (!_optionalChain([this, 'access',
|
|
2333
|
+
if (!_optionalChain([this, 'access', _31 => _31.#me, 'optionalAccess', _32 => _32.user_id])) throw new STXException("GET /api/v1/me returned no user_id");
|
|
2422
2334
|
return this.#me.user_id;
|
|
2423
2335
|
}
|
|
2424
2336
|
// ------------------------------------------------------------------
|
|
@@ -2591,10 +2503,11 @@ var STX = (_class4 = class _STX {
|
|
|
2591
2503
|
* comes back `accepted` (or `delayed` in play); follow it on the `orders`
|
|
2592
2504
|
* channel or with `order()` to see it `filled` or `cancelled`.
|
|
2593
2505
|
*
|
|
2594
|
-
*
|
|
2595
|
-
* it
|
|
2596
|
-
* (`orders.post_only`, `orders.fill_or_kill`)
|
|
2597
|
-
*
|
|
2506
|
+
* The exchange decides whether it takes either mode. Where a mode is not
|
|
2507
|
+
* enabled it rejects the order and this throws `STXNotAvailableException`
|
|
2508
|
+
* (`orders.post_only`, `orders.fill_or_kill`). An exchange on a release from
|
|
2509
|
+
* before fill modes places the order as a normal limit order. A combination
|
|
2510
|
+
* market throws `STXFillModeNotAllowedException`.
|
|
2598
2511
|
*
|
|
2599
2512
|
* The exchange validates the order: a bad price step or a fractional
|
|
2600
2513
|
* quantity throws `STXValidationException` (400) or `STXRejectedException`
|
|
@@ -2608,12 +2521,11 @@ var STX = (_class4 = class _STX {
|
|
|
2608
2521
|
const body = orderBody(marketId, action, orderType, _nullishCoalesce(opts, () => ( {})));
|
|
2609
2522
|
const mode = body.fill_mode;
|
|
2610
2523
|
if (mode === void 0) return this.#one("orders_post", { body });
|
|
2611
|
-
await this.#requireFillModes([mode]);
|
|
2612
2524
|
let order;
|
|
2613
2525
|
try {
|
|
2614
2526
|
order = await this.#one("orders_post", { body });
|
|
2615
2527
|
} catch (err) {
|
|
2616
|
-
throw
|
|
2528
|
+
throw _nullishCoalesce(this.#fillModeError(err, mode), () => ( err));
|
|
2617
2529
|
}
|
|
2618
2530
|
if (mode === "post_only" && order.status === "cancelled" && order.cancellation_reason === "auto_matching") {
|
|
2619
2531
|
throw new STXPostOnlyWouldMatchException(
|
|
@@ -2630,19 +2542,17 @@ var STX = (_class4 = class _STX {
|
|
|
2630
2542
|
* matched comes back as its order, `cancelled` with `cancellation_reason`
|
|
2631
2543
|
* `auto_matching`.
|
|
2632
2544
|
*
|
|
2633
|
-
* When
|
|
2634
|
-
*
|
|
2635
|
-
* thrown with nothing sent.
|
|
2545
|
+
* When the exchange rejects the call because a `fillMode` is not enabled
|
|
2546
|
+
* there, this throws `STXNotAvailableException`, as `placeOrder()` does.
|
|
2636
2547
|
*/
|
|
2637
2548
|
async placeOrders(orders) {
|
|
2638
2549
|
const body = { orders: orders.map(normalizeOrder) };
|
|
2639
2550
|
const modes = body.orders.map((o) => o.fill_mode).filter((m) => typeof m === "string");
|
|
2640
|
-
if (modes.length) await this.#requireFillModes(modes);
|
|
2641
2551
|
let raw;
|
|
2642
2552
|
try {
|
|
2643
2553
|
raw = await this.#list("orders_batched_post", { body });
|
|
2644
2554
|
} catch (err) {
|
|
2645
|
-
throw
|
|
2555
|
+
throw _nullishCoalesce((modes.length ? this.#fillModeError(err, void 0) : void 0), () => ( err));
|
|
2646
2556
|
}
|
|
2647
2557
|
return raw.map(toBatchOrderResult);
|
|
2648
2558
|
}
|
|
@@ -3135,7 +3045,7 @@ var Channel = (_class5 = class {
|
|
|
3135
3045
|
_startPinger() {
|
|
3136
3046
|
this._stopPinger();
|
|
3137
3047
|
let interval = this.pingIntervalMs;
|
|
3138
|
-
const granted = _optionalChain([this, 'access',
|
|
3048
|
+
const granted = _optionalChain([this, 'access', _33 => _33.reply, 'optionalAccess', _34 => _34.ping_timeout]);
|
|
3139
3049
|
if (typeof granted === "number" && this.joinPayload.cancel_on_disconnect) {
|
|
3140
3050
|
const cod = granted / 3;
|
|
3141
3051
|
interval = interval === null ? cod : Math.min(interval, cod);
|
|
@@ -3149,7 +3059,7 @@ var Channel = (_class5 = class {
|
|
|
3149
3059
|
(err) => this.#ws.logger.warn(`${this.topic} ping failed: ${err.message}`)
|
|
3150
3060
|
);
|
|
3151
3061
|
}, every);
|
|
3152
|
-
_optionalChain([this, 'access',
|
|
3062
|
+
_optionalChain([this, 'access', _35 => _35.#pingTimer, 'access', _36 => _36.unref, 'optionalCall', _37 => _37()]);
|
|
3153
3063
|
}
|
|
3154
3064
|
}
|
|
3155
3065
|
/** @internal */
|
|
@@ -3361,7 +3271,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3361
3271
|
*/
|
|
3362
3272
|
async marketUpdates(opts = {}) {
|
|
3363
3273
|
const channel = await this.join("market_updates", {}, opts.onMessage);
|
|
3364
|
-
if (_optionalChain([opts, 'access',
|
|
3274
|
+
if (_optionalChain([opts, 'access', _38 => _38.watch, 'optionalAccess', _39 => _39.length])) await channel.watch(opts.watch);
|
|
3365
3275
|
return channel;
|
|
3366
3276
|
}
|
|
3367
3277
|
/**
|
|
@@ -3610,12 +3520,12 @@ var STXWebSocket = (_class6 = class {
|
|
|
3610
3520
|
if (!(err instanceof STXTransportException)) return false;
|
|
3611
3521
|
if (err.statusCode !== 401 && err.statusCode !== 403) return false;
|
|
3612
3522
|
const auth = this.rest.auth;
|
|
3613
|
-
if (!_optionalChain([auth, 'optionalAccess',
|
|
3523
|
+
if (!_optionalChain([auth, 'optionalAccess', _40 => _40.onUnauthorized])) return false;
|
|
3614
3524
|
return auth.onUnauthorized();
|
|
3615
3525
|
}
|
|
3616
3526
|
async #open(reconnect = false) {
|
|
3617
3527
|
const headers = { "User-Agent": USER_AGENT };
|
|
3618
|
-
if (_optionalChain([this, 'access',
|
|
3528
|
+
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
3529
|
const conn = new (0, _ws2.default)(this.url, {
|
|
3620
3530
|
headers,
|
|
3621
3531
|
rejectUnauthorized: this.rest.verifyTls,
|
|
@@ -3631,7 +3541,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3631
3541
|
conn.on("error", () => {
|
|
3632
3542
|
});
|
|
3633
3543
|
conn.terminate();
|
|
3634
|
-
const reason = _optionalChain([res, 'access',
|
|
3544
|
+
const reason = _optionalChain([res, 'access', _44 => _44.headers, 'optionalAccess', _45 => _45["x-stx-error"]]);
|
|
3635
3545
|
reject(
|
|
3636
3546
|
new STXTransportException(
|
|
3637
3547
|
`Could not open ${this.url}: HTTP ${res.statusCode}${reason ? ` (${String(reason)})` : ""}`,
|
|
@@ -3746,7 +3656,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3746
3656
|
if (!channel.joined) {
|
|
3747
3657
|
channel._endedJoin = { joinRef: String(joinRef), event };
|
|
3748
3658
|
const pending = this.#pending.get(String(joinRef));
|
|
3749
|
-
if (_optionalChain([pending, 'optionalAccess',
|
|
3659
|
+
if (_optionalChain([pending, 'optionalAccess', _46 => _46.event]) === "phx_join") pending.reject(joinInterrupted(channel, event));
|
|
3750
3660
|
if (event === "phx_close" && channel.name === "market") this.#finishMarket(channel);
|
|
3751
3661
|
return;
|
|
3752
3662
|
}
|
|
@@ -3799,7 +3709,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3799
3709
|
} catch (err) {
|
|
3800
3710
|
this.logger.error(`rejoin ${channel.topic} failed: ${err.message}`);
|
|
3801
3711
|
const reply = err instanceof STXChannelException ? err.reply : void 0;
|
|
3802
|
-
if (_optionalChain([reply, 'optionalAccess',
|
|
3712
|
+
if (_optionalChain([reply, 'optionalAccess', _47 => _47.reason]) === "unauthorized" || _optionalChain([reply, 'optionalAccess', _48 => _48.reason]) === COMBOS_UNAVAILABLE_REASON && COMBO_CHANNELS.has(channel.name)) {
|
|
3803
3713
|
channel._close();
|
|
3804
3714
|
return;
|
|
3805
3715
|
}
|
|
@@ -3813,7 +3723,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3813
3723
|
if (!this.connected) return;
|
|
3814
3724
|
if (this.#pendingHeartbeat !== null) {
|
|
3815
3725
|
this.logger.warn("heartbeat unanswered; reconnecting");
|
|
3816
|
-
_optionalChain([this, 'access',
|
|
3726
|
+
_optionalChain([this, 'access', _49 => _49.#conn, 'optionalAccess', _50 => _50.terminate, 'call', _51 => _51()]);
|
|
3817
3727
|
return;
|
|
3818
3728
|
}
|
|
3819
3729
|
const ref = this.#nextRef();
|
|
@@ -3821,7 +3731,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3821
3731
|
try {
|
|
3822
3732
|
this.#send([null, ref, PHOENIX_TOPIC, "heartbeat", {}]);
|
|
3823
3733
|
} catch (e13) {
|
|
3824
|
-
_optionalChain([this, 'access',
|
|
3734
|
+
_optionalChain([this, 'access', _52 => _52.#conn, 'optionalAccess', _53 => _53.terminate, 'call', _54 => _54()]);
|
|
3825
3735
|
}
|
|
3826
3736
|
}, this.heartbeatIntervalMs);
|
|
3827
3737
|
}
|
|
@@ -3908,7 +3818,7 @@ var STXWebSocket = (_class6 = class {
|
|
|
3908
3818
|
this.error = err;
|
|
3909
3819
|
this.#shutdownAfterDrop();
|
|
3910
3820
|
try {
|
|
3911
|
-
_optionalChain([this, 'access',
|
|
3821
|
+
_optionalChain([this, 'access', _55 => _55.onAuthError, 'optionalCall', _56 => _56(err)]);
|
|
3912
3822
|
} catch (hookErr) {
|
|
3913
3823
|
this.logger.error("onAuthError threw", hookErr);
|
|
3914
3824
|
}
|
|
@@ -4015,4 +3925,4 @@ function dropUndefined(payload) {
|
|
|
4015
3925
|
|
|
4016
3926
|
|
|
4017
3927
|
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-
|
|
3928
|
+
//# sourceMappingURL=chunk-B3JQFXMJ.cjs.map
|