@stxapp/stx-typescript 0.6.2 → 0.7.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 +8 -0
- package/dist/{chunk-WGIYEJBI.cjs → chunk-ASOLCDBG.cjs} +26 -157
- package/dist/chunk-ASOLCDBG.cjs.map +1 -0
- package/dist/{chunk-X7B7WXJ3.js → chunk-CDXZOW53.js} +8 -139
- package/dist/chunk-CDXZOW53.js.map +1 -0
- package/dist/{client-C0G5lsiP.d.cts → client-CA1d-osT.d.cts} +4 -9
- package/dist/{client-C0G5lsiP.d.ts → client-CA1d-osT.d.ts} +4 -9
- 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 +21 -21
- package/dist/oauth.cjs.map +1 -1
- package/dist/oauth.d.cts +8 -8
- package/dist/oauth.d.ts +8 -8
- package/dist/oauth.js +5 -5
- package/dist/oauth.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-WGIYEJBI.cjs.map +0 -1
- package/dist/chunk-X7B7WXJ3.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0 (2026-10-03)
|
|
4
|
+
|
|
5
|
+
- `balance()`, `positions()` and `placeOrders()` call `GET /api/v1/account/balance`, `GET /api/v1/positions` and `POST /api/v1/orders/batched` directly. They require exchange v3.3.172 or later, which every STX environment runs. On an older exchange they now throw `STXNotFoundException` instead of reading the channel snapshots or placing orders one at a time.
|
|
6
|
+
|
|
7
|
+
## 0.6.3 (2026-09-28)
|
|
8
|
+
|
|
9
|
+
- `placeOrders()` checks the whole list before placing any order on every exchange: an over-long list or a malformed order is refused with nothing placed.
|
|
10
|
+
|
|
3
11
|
## 0.6.2 (2026-09-28)
|
|
4
12
|
|
|
5
13
|
- `balance()`, `positions()` and `placeOrders()` now work on every STX exchange, with the same results everywhere.
|
|
@@ -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;// src/enums.ts
|
|
2
2
|
var Region = {
|
|
3
3
|
US: "us",
|
|
4
4
|
ONTARIO: "ontario"
|
|
@@ -185,7 +185,7 @@ var Environments = {
|
|
|
185
185
|
name: "ontario-production",
|
|
186
186
|
region: Region.ONTARIO,
|
|
187
187
|
env: Environment.PRODUCTION,
|
|
188
|
-
host: "stxapp.ca",
|
|
188
|
+
host: "api.on.stxapp.ca",
|
|
189
189
|
realMoney: true
|
|
190
190
|
}
|
|
191
191
|
};
|
|
@@ -809,7 +809,7 @@ function credentialsFromSettings(keyId, privateKey, signer) {
|
|
|
809
809
|
}
|
|
810
810
|
|
|
811
811
|
// src/version.ts
|
|
812
|
-
var VERSION = "0.
|
|
812
|
+
var VERSION = "0.7.0";
|
|
813
813
|
var USER_AGENT = `stx-typescript/${VERSION}`;
|
|
814
814
|
var ASYNC_DISPOSE = _nullishCoalesce(Symbol.asyncDispose, () => ( /* @__PURE__ */ Symbol.for("Symbol.asyncDispose")));
|
|
815
815
|
|
|
@@ -1187,105 +1187,6 @@ function toBatchOrderResult(raw) {
|
|
|
1187
1187
|
return { ...obj, order, errors, ok: order !== null && !_optionalChain([errors, 'optionalAccess', _16 => _16.length]) };
|
|
1188
1188
|
}
|
|
1189
1189
|
|
|
1190
|
-
// src/legacy-routes.ts
|
|
1191
|
-
function isRouteMissing(err) {
|
|
1192
|
-
return err instanceof STXNotFoundException && err.statusCode === 404 && typeof err.body === "string";
|
|
1193
|
-
}
|
|
1194
|
-
var QUIET = { debug() {
|
|
1195
|
-
}, info() {
|
|
1196
|
-
}, warn() {
|
|
1197
|
-
}, error() {
|
|
1198
|
-
} };
|
|
1199
|
-
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1200
|
-
async function channelSnapshot(client, join3, event) {
|
|
1201
|
-
const me = await client._identity();
|
|
1202
|
-
const ws = client.websocket({
|
|
1203
|
-
userId: me.user_id,
|
|
1204
|
-
reconnect: false,
|
|
1205
|
-
channelPingIntervalMs: null,
|
|
1206
|
-
joinTimeoutMs: client.timeoutMs,
|
|
1207
|
-
logger: QUIET
|
|
1208
|
-
});
|
|
1209
|
-
try {
|
|
1210
|
-
const channel = await join3(ws, me);
|
|
1211
|
-
const snapshot = await channel.waitSnapshot(client.timeoutMs);
|
|
1212
|
-
return snapshot[event];
|
|
1213
|
-
} finally {
|
|
1214
|
-
await ws.close();
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
async function balanceFromChannel(client) {
|
|
1218
|
-
const payload = await channelSnapshot(
|
|
1219
|
-
client,
|
|
1220
|
-
(ws, me) => ws.balances(me.account_id ? { accountId: me.account_id } : {}),
|
|
1221
|
-
"balances"
|
|
1222
|
-
);
|
|
1223
|
-
if (!payload || typeof payload !== "object") {
|
|
1224
|
-
throw new STXException("The balances channel sent no balance", { path: "/api/v1/account/balance" });
|
|
1225
|
-
}
|
|
1226
|
-
return payload;
|
|
1227
|
-
}
|
|
1228
|
-
function positionsFilter(marketIds) {
|
|
1229
|
-
if (marketIds === void 0 || marketIds === null) return null;
|
|
1230
|
-
const list = typeof marketIds === "string" ? [marketIds] : [...marketIds];
|
|
1231
|
-
if (list.length === 0) return null;
|
|
1232
|
-
const joined = list.join(",");
|
|
1233
|
-
if (joined === "") return null;
|
|
1234
|
-
const ids2 = joined.split(",").map((s) => s.trim());
|
|
1235
|
-
for (const id of ids2) {
|
|
1236
|
-
if (!UUID.test(id)) {
|
|
1237
|
-
throw new STXValidationException(`${id} is not a valid UUID`, {
|
|
1238
|
-
statusCode: 400,
|
|
1239
|
-
body: { error: `${id} is not a valid UUID` },
|
|
1240
|
-
method: "GET",
|
|
1241
|
-
path: "/api/v1/positions"
|
|
1242
|
-
});
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
return new Set(ids2.map((id) => id.toLowerCase()));
|
|
1246
|
-
}
|
|
1247
|
-
async function positionsFromChannel(client, query = {}) {
|
|
1248
|
-
const filter = positionsFilter(query.marketIds);
|
|
1249
|
-
const payload = await channelSnapshot(client, (ws) => ws.positions(), "all_positions");
|
|
1250
|
-
const rows = payload && Array.isArray(payload.positions) ? payload.positions : null;
|
|
1251
|
-
if (!rows) throw new STXException("The positions channel sent no positions", { path: "/api/v1/positions" });
|
|
1252
|
-
return filter ? rows.filter((p) => filter.has(String(p.market_id).toLowerCase())) : rows;
|
|
1253
|
-
}
|
|
1254
|
-
async function placeOrdersOneByOne(client, orders, opts) {
|
|
1255
|
-
if (orders.length === 0) {
|
|
1256
|
-
throw new STXValidationException("orders must not be empty", {
|
|
1257
|
-
statusCode: 400,
|
|
1258
|
-
body: { error: "orders must not be empty" },
|
|
1259
|
-
method: "POST",
|
|
1260
|
-
path: "/api/v1/orders/batched"
|
|
1261
|
-
});
|
|
1262
|
-
}
|
|
1263
|
-
const packet = _optionalChain([opts, 'optionalAccess', _17 => _17.geoLocation]) !== void 0 ? opts.geoLocation : await _asyncNullishCoalesce(await resolveGeoLocation(client.geoLocation), async () => ( null));
|
|
1264
|
-
const results = [];
|
|
1265
|
-
let placed = 0;
|
|
1266
|
-
for (let i = 0; i < orders.length; i++) {
|
|
1267
|
-
const { marketId, action, orderType, ...fields } = orders[i];
|
|
1268
|
-
try {
|
|
1269
|
-
const order = await client.placeOrder(marketId, action, orderType, { ...fields, geoLocation: packet });
|
|
1270
|
-
results.push(toBatchOrderResult({ order }));
|
|
1271
|
-
placed += 1;
|
|
1272
|
-
} catch (err) {
|
|
1273
|
-
if (!(err instanceof STXException)) throw err;
|
|
1274
|
-
if (err instanceof STXRejectedException && !(err instanceof STXGeoLocationException)) {
|
|
1275
|
-
results.push(toBatchOrderResult({ errors: [err.message] }));
|
|
1276
|
-
continue;
|
|
1277
|
-
}
|
|
1278
|
-
if (err instanceof STXServerException || err instanceof STXTransportException) throw err;
|
|
1279
|
-
if (placed === 0) throw err;
|
|
1280
|
-
results.push(toBatchOrderResult({ errors: [err.message] }));
|
|
1281
|
-
if (err instanceof STXValidationException) continue;
|
|
1282
|
-
for (let j = i + 1; j < orders.length; j++) results.push(toBatchOrderResult({ errors: [err.message] }));
|
|
1283
|
-
break;
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
return results;
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
1190
|
// src/client.ts
|
|
1290
1191
|
var NEW_ORDER_FIELDS = {
|
|
1291
1192
|
marketId: "market_id",
|
|
@@ -1362,8 +1263,6 @@ var STX = (_class3 = class _STX {
|
|
|
1362
1263
|
|
|
1363
1264
|
#fetch;
|
|
1364
1265
|
#me;
|
|
1365
|
-
// Exchanges older than v3.3.172: the routes this exchange turned out not to serve.
|
|
1366
|
-
#missingRoutes = /* @__PURE__ */ new Set();
|
|
1367
1266
|
/** Test hook: how retries wait. */
|
|
1368
1267
|
__init4() {this._sleep = sleep}
|
|
1369
1268
|
constructor(opts = {}) {;_class3.prototype.__init4.call(this);
|
|
@@ -1415,7 +1314,7 @@ var STX = (_class3 = class _STX {
|
|
|
1415
1314
|
this.#fetch = fetchImpl;
|
|
1416
1315
|
}
|
|
1417
1316
|
toString() {
|
|
1418
|
-
return `STX(baseUrl=${JSON.stringify(this.baseUrl)}, keyId=${JSON.stringify(_nullishCoalesce(_optionalChain([this, 'access',
|
|
1317
|
+
return `STX(baseUrl=${JSON.stringify(this.baseUrl)}, keyId=${JSON.stringify(_nullishCoalesce(_optionalChain([this, 'access', _17 => _17.credentials, 'optionalAccess', _18 => _18.keyId]), () => ( null)))})`;
|
|
1419
1318
|
}
|
|
1420
1319
|
/** Nothing to release (fetch pools connections itself); present so `await using` and explicit cleanup work. */
|
|
1421
1320
|
async close() {
|
|
@@ -1450,7 +1349,7 @@ var STX = (_class3 = class _STX {
|
|
|
1450
1349
|
status,
|
|
1451
1350
|
attempt,
|
|
1452
1351
|
durationMs: Date.now() - started,
|
|
1453
|
-
authKind: _optionalChain([this, 'access',
|
|
1352
|
+
authKind: _optionalChain([this, 'access', _19 => _19.auth, 'optionalAccess', _20 => _20.kind]),
|
|
1454
1353
|
requestBody: request.body,
|
|
1455
1354
|
responseBody
|
|
1456
1355
|
});
|
|
@@ -1482,7 +1381,7 @@ var STX = (_class3 = class _STX {
|
|
|
1482
1381
|
});
|
|
1483
1382
|
}
|
|
1484
1383
|
throw new STXTransportException(
|
|
1485
|
-
`${request.method} ${request.path} failed: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess',
|
|
1384
|
+
`${request.method} ${request.path} failed: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess', _21 => _21.message]), () => ( String(err)))}`,
|
|
1486
1385
|
{ method: request.method, path: request.path, cause: err }
|
|
1487
1386
|
);
|
|
1488
1387
|
} finally {
|
|
@@ -1504,7 +1403,7 @@ var STX = (_class3 = class _STX {
|
|
|
1504
1403
|
return await this.#sendOnce(request, sent);
|
|
1505
1404
|
} catch (err) {
|
|
1506
1405
|
if (!(err instanceof STXException)) throw err;
|
|
1507
|
-
if (err.statusCode === 401 && !reauthenticated && _optionalChain([this, 'access',
|
|
1406
|
+
if (err.statusCode === 401 && !reauthenticated && _optionalChain([this, 'access', _22 => _22.auth, 'optionalAccess', _23 => _23.onUnauthorized])) {
|
|
1508
1407
|
reauthenticated = true;
|
|
1509
1408
|
if (await this.auth.onUnauthorized()) continue;
|
|
1510
1409
|
}
|
|
@@ -1540,7 +1439,7 @@ var STX = (_class3 = class _STX {
|
|
|
1540
1439
|
}
|
|
1541
1440
|
}
|
|
1542
1441
|
async #geoBody(body, opts) {
|
|
1543
|
-
const packet = _optionalChain([opts, 'optionalAccess',
|
|
1442
|
+
const packet = _optionalChain([opts, 'optionalAccess', _24 => _24.geoLocation]) !== void 0 ? _nullishCoalesce(opts.geoLocation, () => ( void 0)) : await resolveGeoLocation(this.geoLocation);
|
|
1544
1443
|
return packet === void 0 ? body : { ...body, geo_location: packet };
|
|
1545
1444
|
}
|
|
1546
1445
|
// ------------------------------------------------------------------
|
|
@@ -1555,21 +1454,13 @@ var STX = (_class3 = class _STX {
|
|
|
1555
1454
|
this.#me = await this.#one("me_get");
|
|
1556
1455
|
return this.#me;
|
|
1557
1456
|
}
|
|
1558
|
-
/**
|
|
1559
|
-
* @internal The cached `me()` when it has both ids, else a fresh `me()`.
|
|
1560
|
-
* Never falls back to `balance()`, so the channel fallbacks can use it.
|
|
1561
|
-
*/
|
|
1562
|
-
async _identity() {
|
|
1563
|
-
if (_optionalChain([this, 'access', _26 => _26.#me, 'optionalAccess', _27 => _27.user_id]) && this.#me.account_id) return this.#me;
|
|
1564
|
-
return this.me();
|
|
1565
|
-
}
|
|
1566
1457
|
/**
|
|
1567
1458
|
* The user id from `me()`, fetched once and cached. If `me()` is not
|
|
1568
1459
|
* permitted, the id comes from `balance()`, which carries the same
|
|
1569
1460
|
* `user_id`.
|
|
1570
1461
|
*/
|
|
1571
1462
|
async userId() {
|
|
1572
|
-
if (_optionalChain([this, 'access',
|
|
1463
|
+
if (_optionalChain([this, 'access', _25 => _25.#me, 'optionalAccess', _26 => _26.user_id])) return this.#me.user_id;
|
|
1573
1464
|
try {
|
|
1574
1465
|
await this.me();
|
|
1575
1466
|
} catch (err) {
|
|
@@ -1580,7 +1471,7 @@ var STX = (_class3 = class _STX {
|
|
|
1580
1471
|
if (!balance.user_id) throw err;
|
|
1581
1472
|
this.#me = { ..._nullishCoalesce(this.#me, () => ( {})), user_id: balance.user_id };
|
|
1582
1473
|
}
|
|
1583
|
-
if (!_optionalChain([this, 'access',
|
|
1474
|
+
if (!_optionalChain([this, 'access', _27 => _27.#me, 'optionalAccess', _28 => _28.user_id])) throw new STXException("GET /api/v1/me returned no user_id");
|
|
1584
1475
|
return this.#me.user_id;
|
|
1585
1476
|
}
|
|
1586
1477
|
// ------------------------------------------------------------------
|
|
@@ -1695,15 +1586,7 @@ var STX = (_class3 = class _STX {
|
|
|
1695
1586
|
*/
|
|
1696
1587
|
async placeOrders(orders, opts) {
|
|
1697
1588
|
const body = { orders: orders.map(normalizeOrder) };
|
|
1698
|
-
|
|
1699
|
-
let raw;
|
|
1700
|
-
try {
|
|
1701
|
-
raw = await this.#list("orders_batched_post", { body: await this.#geoBody(body, opts) });
|
|
1702
|
-
} catch (err) {
|
|
1703
|
-
if (!isRouteMissing(err)) throw err;
|
|
1704
|
-
this.#missingRoutes.add("batch");
|
|
1705
|
-
return placeOrdersOneByOne(this, orders, opts);
|
|
1706
|
-
}
|
|
1589
|
+
const raw = await this.#list("orders_batched_post", { body: await this.#geoBody(body, opts) });
|
|
1707
1590
|
return raw.map(toBatchOrderResult);
|
|
1708
1591
|
}
|
|
1709
1592
|
/**
|
|
@@ -1788,28 +1671,14 @@ var STX = (_class3 = class _STX {
|
|
|
1788
1671
|
* negative when short.
|
|
1789
1672
|
*/
|
|
1790
1673
|
async positions(query = {}) {
|
|
1791
|
-
|
|
1792
|
-
try {
|
|
1793
|
-
return await this.#list("positions_get", { query: { market_ids: ids(query.marketIds) } });
|
|
1794
|
-
} catch (err) {
|
|
1795
|
-
if (!isRouteMissing(err)) throw err;
|
|
1796
|
-
this.#missingRoutes.add("positions");
|
|
1797
|
-
return positionsFromChannel(this, query);
|
|
1798
|
-
}
|
|
1674
|
+
return this.#list("positions_get", { query: { market_ids: ids(query.marketIds) } });
|
|
1799
1675
|
}
|
|
1800
1676
|
/**
|
|
1801
1677
|
* `GET /api/v1/account/balance`: balance, liabilities and fee schedule.
|
|
1802
1678
|
* The same object the `balances` channel pushes.
|
|
1803
1679
|
*/
|
|
1804
1680
|
async balance() {
|
|
1805
|
-
|
|
1806
|
-
try {
|
|
1807
|
-
return await this.#one("account_balance_get");
|
|
1808
|
-
} catch (err) {
|
|
1809
|
-
if (!isRouteMissing(err)) throw err;
|
|
1810
|
-
this.#missingRoutes.add("balance");
|
|
1811
|
-
return balanceFromChannel(this);
|
|
1812
|
-
}
|
|
1681
|
+
return this.#one("account_balance_get");
|
|
1813
1682
|
}
|
|
1814
1683
|
static #marketStatsQuery(q) {
|
|
1815
1684
|
return {
|
|
@@ -1826,7 +1695,7 @@ var STX = (_class3 = class _STX {
|
|
|
1826
1695
|
}
|
|
1827
1696
|
/**
|
|
1828
1697
|
* `GET /api/v1/account/market_stats`: your exposure and P&L per market.
|
|
1829
|
-
* Not the
|
|
1698
|
+
* Not the `market_stats` WebSocket channel, which carries price history.
|
|
1830
1699
|
*/
|
|
1831
1700
|
accountMarketStats(query = {}) {
|
|
1832
1701
|
return this.#page("account_market_stats_get", _STX.#marketStatsQuery(query));
|
|
@@ -2192,7 +2061,7 @@ var Channel = (_class4 = class {
|
|
|
2192
2061
|
_startPinger() {
|
|
2193
2062
|
this._stopPinger();
|
|
2194
2063
|
let interval = this.pingIntervalMs;
|
|
2195
|
-
const granted = _optionalChain([this, 'access',
|
|
2064
|
+
const granted = _optionalChain([this, 'access', _29 => _29.reply, 'optionalAccess', _30 => _30.ping_timeout]);
|
|
2196
2065
|
if (typeof granted === "number" && this.joinPayload.cancel_on_disconnect) {
|
|
2197
2066
|
const cod = granted * 0.6;
|
|
2198
2067
|
interval = interval === null ? cod : Math.min(interval, cod);
|
|
@@ -2205,7 +2074,7 @@ var Channel = (_class4 = class {
|
|
|
2205
2074
|
(err) => this.#ws.logger.warn(`${this.topic} ping failed: ${err.message}`)
|
|
2206
2075
|
);
|
|
2207
2076
|
}, every);
|
|
2208
|
-
_optionalChain([this, 'access',
|
|
2077
|
+
_optionalChain([this, 'access', _31 => _31.#pingTimer, 'access', _32 => _32.unref, 'optionalCall', _33 => _33()]);
|
|
2209
2078
|
}
|
|
2210
2079
|
}
|
|
2211
2080
|
/** @internal */
|
|
@@ -2352,7 +2221,7 @@ var STXWebSocket = (_class5 = class {
|
|
|
2352
2221
|
return this.#userId;
|
|
2353
2222
|
}
|
|
2354
2223
|
// ------------------------------------------------------------------
|
|
2355
|
-
//
|
|
2224
|
+
// Market data channels
|
|
2356
2225
|
// ------------------------------------------------------------------
|
|
2357
2226
|
/**
|
|
2358
2227
|
* `orderbook`: the aggregated book, one `book` push per market. Each push
|
|
@@ -2400,7 +2269,7 @@ var STXWebSocket = (_class5 = class {
|
|
|
2400
2269
|
*/
|
|
2401
2270
|
async marketUpdates(opts = {}) {
|
|
2402
2271
|
const channel = await this.join("market_updates", {}, opts.onMessage);
|
|
2403
|
-
if (_optionalChain([opts, 'access',
|
|
2272
|
+
if (_optionalChain([opts, 'access', _34 => _34.watch, 'optionalAccess', _35 => _35.length])) await channel.watch(opts.watch);
|
|
2404
2273
|
return channel;
|
|
2405
2274
|
}
|
|
2406
2275
|
/**
|
|
@@ -2557,12 +2426,12 @@ var STXWebSocket = (_class5 = class {
|
|
|
2557
2426
|
if (!(err instanceof STXTransportException)) return false;
|
|
2558
2427
|
if (err.statusCode !== 401 && err.statusCode !== 403) return false;
|
|
2559
2428
|
const auth = this.rest.auth;
|
|
2560
|
-
if (!_optionalChain([auth, 'optionalAccess',
|
|
2429
|
+
if (!_optionalChain([auth, 'optionalAccess', _36 => _36.onUnauthorized])) return false;
|
|
2561
2430
|
return auth.onUnauthorized();
|
|
2562
2431
|
}
|
|
2563
2432
|
async #open(reconnect = false) {
|
|
2564
2433
|
const headers = { "User-Agent": USER_AGENT };
|
|
2565
|
-
if (_optionalChain([this, 'access',
|
|
2434
|
+
if (_optionalChain([this, 'access', _37 => _37.rest, 'access', _38 => _38.auth, 'optionalAccess', _39 => _39.websocketHeaders])) Object.assign(headers, await this.rest.auth.websocketHeaders({ reconnect }));
|
|
2566
2435
|
const conn = new (0, _ws2.default)(this.url, {
|
|
2567
2436
|
headers,
|
|
2568
2437
|
rejectUnauthorized: this.rest.verifyTls,
|
|
@@ -2576,7 +2445,7 @@ var STXWebSocket = (_class5 = class {
|
|
|
2576
2445
|
const onUnexpected = (_req, res) => {
|
|
2577
2446
|
cleanup();
|
|
2578
2447
|
conn.terminate();
|
|
2579
|
-
const reason = _optionalChain([res, 'access',
|
|
2448
|
+
const reason = _optionalChain([res, 'access', _40 => _40.headers, 'optionalAccess', _41 => _41["x-stx-error"]]);
|
|
2580
2449
|
reject(
|
|
2581
2450
|
new STXTransportException(
|
|
2582
2451
|
`Could not open ${this.url}: HTTP ${res.statusCode}${reason ? ` (${String(reason)})` : ""}`,
|
|
@@ -2721,7 +2590,7 @@ var STXWebSocket = (_class5 = class {
|
|
|
2721
2590
|
} catch (err) {
|
|
2722
2591
|
this.logger.error(`rejoin ${channel.topic} failed: ${err.message}`);
|
|
2723
2592
|
const reply = err instanceof STXChannelException ? err.reply : void 0;
|
|
2724
|
-
if (_optionalChain([reply, 'optionalAccess',
|
|
2593
|
+
if (_optionalChain([reply, 'optionalAccess', _42 => _42.reason]) === "unauthorized") {
|
|
2725
2594
|
channel._close();
|
|
2726
2595
|
return;
|
|
2727
2596
|
}
|
|
@@ -2735,7 +2604,7 @@ var STXWebSocket = (_class5 = class {
|
|
|
2735
2604
|
if (!this.connected) return;
|
|
2736
2605
|
if (this.#pendingHeartbeat !== null) {
|
|
2737
2606
|
this.logger.warn("heartbeat unanswered; reconnecting");
|
|
2738
|
-
_optionalChain([this, 'access',
|
|
2607
|
+
_optionalChain([this, 'access', _43 => _43.#conn, 'optionalAccess', _44 => _44.terminate, 'call', _45 => _45()]);
|
|
2739
2608
|
return;
|
|
2740
2609
|
}
|
|
2741
2610
|
const ref = this.#nextRef();
|
|
@@ -2743,7 +2612,7 @@ var STXWebSocket = (_class5 = class {
|
|
|
2743
2612
|
try {
|
|
2744
2613
|
this.#send([null, ref, PHOENIX_TOPIC, "heartbeat", {}]);
|
|
2745
2614
|
} catch (e10) {
|
|
2746
|
-
_optionalChain([this, 'access',
|
|
2615
|
+
_optionalChain([this, 'access', _46 => _46.#conn, 'optionalAccess', _47 => _47.terminate, 'call', _48 => _48()]);
|
|
2747
2616
|
}
|
|
2748
2617
|
}, this.heartbeatIntervalMs);
|
|
2749
2618
|
}
|
|
@@ -2819,7 +2688,7 @@ var STXWebSocket = (_class5 = class {
|
|
|
2819
2688
|
this.error = err;
|
|
2820
2689
|
this.#shutdownAfterDrop();
|
|
2821
2690
|
try {
|
|
2822
|
-
_optionalChain([this, 'access',
|
|
2691
|
+
_optionalChain([this, 'access', _49 => _49.onAuthError, 'optionalCall', _50 => _50(err)]);
|
|
2823
2692
|
} catch (hookErr) {
|
|
2824
2693
|
this.logger.error("onAuthError threw", hookErr);
|
|
2825
2694
|
}
|
|
@@ -2902,4 +2771,4 @@ function dropUndefined(payload) {
|
|
|
2902
2771
|
|
|
2903
2772
|
|
|
2904
2773
|
exports.Region = Region; exports.Environment = Environment; exports.geoRejection = geoRejection; 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.STXNotFoundException = STXNotFoundException; exports.STXRejectedException = STXRejectedException; exports.STXGeoLocationException = STXGeoLocationException; exports.STXRateLimitException = STXRateLimitException; exports.STXServerException = STXServerException; exports.STXTransportException = STXTransportException; exports.STXChannelException = STXChannelException; exports.STXTimeoutException = STXTimeoutException; exports.errorForStatus = errorForStatus; exports.Environments = Environments; exports.HOSTS = HOSTS; exports.environmentNamed = environmentNamed; exports.resolveHost = resolveHost; exports.baseUrlFor = baseUrlFor; exports.socketUrlFor = socketUrlFor; exports.OPERATIONS = OPERATIONS; 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.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;
|
|
2905
|
-
//# sourceMappingURL=chunk-
|
|
2774
|
+
//# sourceMappingURL=chunk-ASOLCDBG.cjs.map
|