@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.12.1 (2026-11-18)
|
|
4
|
+
|
|
5
|
+
- `capabilities()` reports `orders.post_only` and `orders.fill_or_kill` again, so code written for 0.11 that reads them compiles and runs unchanged. Both are deprecated and always `null` (unknown): the exchange no longer publishes whether it takes fill modes, so the SDK does not guess. `caps.has()` is `false` for them and `caps.require()` does not throw. Send the order with `fillMode` and handle `STXNotAvailableException` instead.
|
|
6
|
+
- On an exchange that does not have fill modes, a post-only or fill-or-kill order may be placed as a normal limit order, without an error. Check `fill_mode` on the order you get back. See https://docs.stxapp.io/sdks/typescript/trading/#post-only-and-fill-or-kill
|
|
7
|
+
|
|
8
|
+
## 0.12.0 (2026-11-18)
|
|
9
|
+
|
|
10
|
+
Breaking for anyone reading `orders.post_only` or `orders.fill_or_kill` from `capabilities()`:
|
|
11
|
+
|
|
12
|
+
- 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/
|
|
13
|
+
- `capabilities()` no longer reports `orders.post_only` or `orders.fill_or_kill`.
|
|
14
|
+
|
|
3
15
|
## 0.11.0 (2026-11-17)
|
|
4
16
|
|
|
5
17
|
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`. An exchange without fill modes may instead place it as a normal limit order, so check `fill_mode` on the order you get back. See [Trading](https://docs.stxapp.io/sdks/typescript/trading/).
|
|
76
76
|
|
|
77
77
|
## For apps: STX accounts and markets
|
|
78
78
|
|
|
@@ -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 = body?.api_version;
|
|
324
|
-
const features = body?.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 = info?.apiVersion;
|
|
420
|
-
const listed = (name) => version === null ? null : version.status === 200 || version.status === 404 || version.status === 403 && json(version) === null ? !!info?.features?.includes(name) : null;
|
|
419
|
+
const apiVersion = version?.status === 200 ? json(version)?.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,
|
|
@@ -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 = Symbol.asyncDispose ?? /* @__PURE__ */ Symbol.for("Symbol.asyncDispose");
|
|
1280
1280
|
|
|
@@ -2046,7 +2046,6 @@ var STX = class _STX {
|
|
|
2046
2046
|
#fetch;
|
|
2047
2047
|
#me;
|
|
2048
2048
|
#capabilities;
|
|
2049
|
-
#apiVersion;
|
|
2050
2049
|
/** Test hook: how retries wait. */
|
|
2051
2050
|
_sleep = sleep;
|
|
2052
2051
|
constructor(opts = {}) {
|
|
@@ -2108,7 +2107,7 @@ var STX = 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 = 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: ${err?.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 (!info.features?.includes(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 cached.catch(() => null))?.apiVersion : void 0;
|
|
2226
|
-
return new STXNotAvailableException(`orders.${off[1] ?? off[2]}`, this.host, { ...base, apiVersion });
|
|
2227
|
-
}
|
|
2157
|
+
if (off) return new STXNotAvailableException(`orders.${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] });
|
|
@@ -2591,10 +2521,11 @@ var STX = 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 = class _STX {
|
|
|
2608
2539
|
const body = orderBody(marketId, action, orderType, 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 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 = 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 (modes.length ?
|
|
2573
|
+
throw (modes.length ? this.#fillModeError(err, void 0) : void 0) ?? err;
|
|
2646
2574
|
}
|
|
2647
2575
|
return raw.map(toBatchOrderResult);
|
|
2648
2576
|
}
|
|
@@ -4015,4 +3943,4 @@ export {
|
|
|
4015
3943
|
orderBody,
|
|
4016
3944
|
STX
|
|
4017
3945
|
};
|
|
4018
|
-
//# sourceMappingURL=chunk-
|
|
3946
|
+
//# sourceMappingURL=chunk-NYUIPUZH.js.map
|