@stxapp/stx-typescript 0.6.2 → 0.6.3
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 +4 -0
- package/dist/{chunk-WGIYEJBI.cjs → chunk-CSHPFQ2V.cjs} +65 -10
- package/dist/chunk-CSHPFQ2V.cjs.map +1 -0
- package/dist/{chunk-X7B7WXJ3.js → chunk-PZUVKPHZ.js} +65 -10
- package/dist/{chunk-X7B7WXJ3.js.map → chunk-PZUVKPHZ.js.map} +1 -1
- package/dist/{client-C0G5lsiP.d.cts → client-Dkd5vesS.d.cts} +2 -2
- package/dist/{client-C0G5lsiP.d.ts → client-Dkd5vesS.d.ts} +2 -2
- 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 +17 -17
- 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-WGIYEJBI.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.3 (2026-09-28)
|
|
4
|
+
|
|
5
|
+
- `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.
|
|
6
|
+
|
|
3
7
|
## 0.6.2 (2026-09-28)
|
|
4
8
|
|
|
5
9
|
- `balance()`, `positions()` and `placeOrders()` now work on every STX exchange, with the same results everywhere.
|
|
@@ -809,7 +809,7 @@ function credentialsFromSettings(keyId, privateKey, signer) {
|
|
|
809
809
|
}
|
|
810
810
|
|
|
811
811
|
// src/version.ts
|
|
812
|
-
var VERSION = "0.6.
|
|
812
|
+
var VERSION = "0.6.3";
|
|
813
813
|
var USER_AGENT = `stx-typescript/${VERSION}`;
|
|
814
814
|
var ASYNC_DISPOSE = _nullishCoalesce(Symbol.asyncDispose, () => ( /* @__PURE__ */ Symbol.for("Symbol.asyncDispose")));
|
|
815
815
|
|
|
@@ -1251,15 +1251,70 @@ async function positionsFromChannel(client, query = {}) {
|
|
|
1251
1251
|
if (!rows) throw new STXException("The positions channel sent no positions", { path: "/api/v1/positions" });
|
|
1252
1252
|
return filter ? rows.filter((p) => filter.has(String(p.market_id).toLowerCase())) : rows;
|
|
1253
1253
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
}
|
|
1254
|
+
var MAX_BATCH_ORDERS = 100;
|
|
1255
|
+
var ORDER_TYPES = ["limit", "market"];
|
|
1256
|
+
var ACTIONS = ["buy", "sell"];
|
|
1257
|
+
var EXPIRATIONS = ["good_till_start", "good_till_time"];
|
|
1258
|
+
function batchRefusal(message) {
|
|
1259
|
+
return new STXValidationException(message, {
|
|
1260
|
+
statusCode: 400,
|
|
1261
|
+
body: { error: message },
|
|
1262
|
+
method: "POST",
|
|
1263
|
+
path: "/api/v1/orders/batched"
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
function enumError(field, value, allowed, required) {
|
|
1267
|
+
if (value === void 0 || value === null) return required ? `${field} is required` : void 0;
|
|
1268
|
+
if (typeof value !== "string") return `${field} is invalid`;
|
|
1269
|
+
return allowed.includes(value) ? void 0 : `${field} has invalid value: ${value}`;
|
|
1270
|
+
}
|
|
1271
|
+
function parseDecimal(text) {
|
|
1272
|
+
if (/^[+-]?(inf|infinity|nan)$/i.test(text)) return { special: true };
|
|
1273
|
+
const m = /^([+-]?)(?:(\d+)\.?(\d*)|\.(\d+))(?:[eE]([+-]?\d+))?$/.exec(text);
|
|
1274
|
+
if (!m) return void 0;
|
|
1275
|
+
const int = _nullishCoalesce(m[2], () => ( ""));
|
|
1276
|
+
const frac = _nullishCoalesce(_nullishCoalesce(m[3], () => ( m[4])), () => ( ""));
|
|
1277
|
+
return { special: false, sign: m[1] === "-" ? -1 : 1, digits: int + frac, exp: Number(_nullishCoalesce(m[5], () => ( 0))) - frac.length };
|
|
1278
|
+
}
|
|
1279
|
+
var scaleOf = (exp) => Math.max(0, -exp);
|
|
1280
|
+
function priceError(value) {
|
|
1281
|
+
if (value === void 0 || value === null) return void 0;
|
|
1282
|
+
const format2 = 'price must be a dollar amount as a string, e.g. "30.00"';
|
|
1283
|
+
if (typeof value !== "string") return format2;
|
|
1284
|
+
const d = parseDecimal(value);
|
|
1285
|
+
if (!d || d.special) return format2;
|
|
1286
|
+
if (scaleOf(d.exp) > 7) return "price supports at most 7 decimal places";
|
|
1287
|
+
const trailingZeros = /0*$/.exec(d.digits)[0].length;
|
|
1288
|
+
const significant = /^0*$/.test(d.digits) ? 0 : scaleOf(d.exp + trailingZeros);
|
|
1289
|
+
if (significant > 2) {
|
|
1290
|
+
return `price must be a whole number of cents \u2014 at most 2 decimal places, not counting trailing zeros (got ${JSON.stringify(value)})`;
|
|
1291
|
+
}
|
|
1292
|
+
if (d.sign < 0 || /^0*$/.test(d.digits)) return "price must be greater than 0";
|
|
1293
|
+
return void 0;
|
|
1294
|
+
}
|
|
1295
|
+
function marketIdError(value) {
|
|
1296
|
+
if (value === void 0 || value === null) return "market_id is required";
|
|
1297
|
+
return typeof value === "string" && UUID.test(value) ? void 0 : "market_id is not a valid UUID";
|
|
1298
|
+
}
|
|
1299
|
+
function quantityError(value) {
|
|
1300
|
+
if (value === void 0 || value === null) return "quantity is required";
|
|
1301
|
+
const d = typeof value === "string" ? parseDecimal(value) : void 0;
|
|
1302
|
+
return d && !d.special ? void 0 : 'quantity must be a decimal string, e.g. "10" or "10.00"';
|
|
1303
|
+
}
|
|
1304
|
+
function validateBatch(orders) {
|
|
1305
|
+
if (orders.length === 0) throw batchRefusal("orders must not be empty");
|
|
1306
|
+
if (orders.length > MAX_BATCH_ORDERS) {
|
|
1307
|
+
throw batchRefusal(`orders may contain at most ${MAX_BATCH_ORDERS} orders per batch`);
|
|
1262
1308
|
}
|
|
1309
|
+
for (const order of orders) {
|
|
1310
|
+
const { marketId, action, orderType, ...fields } = order;
|
|
1311
|
+
const body = orderBody(marketId, action, orderType, fields);
|
|
1312
|
+
const message = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(marketIdError(body.market_id), () => ( enumError("order_type", body.order_type, ORDER_TYPES, true))), () => ( enumError("action", body.action, ACTIONS, true))), () => ( priceError(body.price))), () => ( quantityError(body.quantity))), () => ( enumError("expiration", body.expiration, EXPIRATIONS, false))), () => ( (body.expiration !== void 0 && body.order_type !== "limit" ? "Order expiration is only supported for limit orders." : void 0)));
|
|
1313
|
+
if (message) throw batchRefusal(message);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
async function placeOrdersOneByOne(client, orders, opts) {
|
|
1317
|
+
validateBatch(orders);
|
|
1263
1318
|
const packet = _optionalChain([opts, 'optionalAccess', _17 => _17.geoLocation]) !== void 0 ? opts.geoLocation : await _asyncNullishCoalesce(await resolveGeoLocation(client.geoLocation), async () => ( null));
|
|
1264
1319
|
const results = [];
|
|
1265
1320
|
let placed = 0;
|
|
@@ -2902,4 +2957,4 @@ function dropUndefined(payload) {
|
|
|
2902
2957
|
|
|
2903
2958
|
|
|
2904
2959
|
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-
|
|
2960
|
+
//# sourceMappingURL=chunk-CSHPFQ2V.cjs.map
|