@stxapp/stx-typescript 0.10.0 → 0.11.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 +14 -0
- package/README.md +2 -0
- package/dist/{chunk-FTZCBXT7.js → chunk-2PYJI3JS.js} +260 -18
- package/dist/chunk-2PYJI3JS.js.map +1 -0
- package/dist/{chunk-42OCIF3G.cjs → chunk-BSX65XEA.cjs} +290 -48
- package/dist/chunk-BSX65XEA.cjs.map +1 -0
- package/dist/{client-DJr0UUvB.d.cts → client-DxY8eJ58.d.cts} +211 -36
- package/dist/{client-DJr0UUvB.d.ts → client-DxY8eJ58.d.ts} +211 -36
- package/dist/index.cjs +12 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -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-42OCIF3G.cjs.map +0 -1
- package/dist/chunk-FTZCBXT7.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.0 (2026-11-17)
|
|
4
|
+
|
|
5
|
+
Post-only and fill-or-kill orders:
|
|
6
|
+
|
|
7
|
+
- `placeOrder()` and each `placeOrders()` order take `fillMode`: `"normal"` (the default), `"post_only"` or `"fill_or_kill"`, for limit orders. See https://docs.stxapp.io/sdks/typescript/trading/
|
|
8
|
+
- Before sending a post-only or fill-or-kill order, the client asks the exchange once (`GET /api_version`, cached on the client) whether it offers that mode. When it does not, the call throws `STXNotAvailableException` (`feature` `orders.post_only` or `orders.fill_or_kill`, with `apiVersion`) and sends nothing, so an exchange that does not know the mode never places a normal order instead. `capabilities()` reports both features.
|
|
9
|
+
- A post-only order that would have matched throws `STXPostOnlyWouldMatchException` (`reason` `auto_matching` with the cancelled `order`, or `match_with_self`). A fill mode on a combination market throws `STXFillModeNotAllowedException`. Both extend `STXRejectedException`.
|
|
10
|
+
- `Order` has `fill_mode`, `Market` has `rules_version` and `market_rules_pdf_url`, and `accountMarketStats()` takes `unsettledOnly`.
|
|
11
|
+
|
|
12
|
+
Blocked requests:
|
|
13
|
+
|
|
14
|
+
- A request blocked before it reaches the exchange throws `STXBlockedException` (a 403 `STXForbiddenException`) with `reason` and `reference` (the request id from the `x-amz-cf-id` response header, to quote to STX support), or its subclasses `STXRestrictedJurisdictionException` and `STXUnusualNetworkException`. A 403 that carries no reason says that requests need a `User-Agent` header. Blocked requests are never retried.
|
|
15
|
+
- A 429 from the same place is `STXRateLimitException` with `reference` as well as `retryAfter`. `Retry-After` given as an HTTP date is read too, and when it asks for longer than `RetryPolicy.maxBackoffMs` the exception is thrown at once instead of retrying early.
|
|
16
|
+
|
|
3
17
|
## 0.10.0 (2026-11-11)
|
|
4
18
|
|
|
5
19
|
Breaking for anyone passing a geolocation option or using the location check: API key requests are now located from your connection, so the SDK no longer sends or reads geolocation data and no longer has its own location check.
|
package/README.md
CHANGED
|
@@ -72,6 +72,8 @@ 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. On an exchange that does not offer a fill mode, the call throws `STXNotAvailableException` and sends nothing. See [Trading](https://docs.stxapp.io/sdks/typescript/trading/).
|
|
76
|
+
|
|
75
77
|
## For apps: STX accounts and markets
|
|
76
78
|
|
|
77
79
|
An app registered with STX can bring its members' STX accounts in, and can act as itself. This runs on your server; the client secret and the tokens never go to a browser or a mobile app. OAuth is on in US demo today; on an exchange without it these calls throw `STXNotAvailableException`, and `await stx.capabilities()` says which features an exchange has. There are two ways to bring a member's STX account in.
|
|
@@ -43,15 +43,46 @@ var STXTermsRequiredException = class extends STXForbiddenException {
|
|
|
43
43
|
};
|
|
44
44
|
var STXIPNotAllowedException = class extends STXForbiddenException {
|
|
45
45
|
};
|
|
46
|
+
var STXBlockedException = class extends STXForbiddenException {
|
|
47
|
+
reason;
|
|
48
|
+
reference;
|
|
49
|
+
constructor(message, opts = {}) {
|
|
50
|
+
super(message, opts);
|
|
51
|
+
this.reason = opts.reason ?? "blocked";
|
|
52
|
+
this.reference = opts.reference;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var STXRestrictedJurisdictionException = class extends STXBlockedException {
|
|
56
|
+
};
|
|
57
|
+
var STXUnusualNetworkException = class extends STXBlockedException {
|
|
58
|
+
};
|
|
46
59
|
var STXNotFoundException = class extends STXAPIException {
|
|
47
60
|
};
|
|
48
61
|
var STXRejectedException = class extends STXAPIException {
|
|
49
62
|
};
|
|
63
|
+
var STXFillModeNotAllowedException = class extends STXRejectedException {
|
|
64
|
+
fillMode;
|
|
65
|
+
constructor(message, opts) {
|
|
66
|
+
super(message, opts);
|
|
67
|
+
this.fillMode = opts.fillMode;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var STXPostOnlyWouldMatchException = class extends STXRejectedException {
|
|
71
|
+
reason;
|
|
72
|
+
order;
|
|
73
|
+
constructor(message, opts) {
|
|
74
|
+
super(message, opts);
|
|
75
|
+
this.reason = opts.reason;
|
|
76
|
+
this.order = opts.order;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
50
79
|
var STXRateLimitException = class extends STXAPIException {
|
|
51
80
|
retryAfter;
|
|
81
|
+
reference;
|
|
52
82
|
constructor(message, opts = {}) {
|
|
53
83
|
super(message, opts);
|
|
54
84
|
this.retryAfter = opts.retryAfter;
|
|
85
|
+
this.reference = opts.reference;
|
|
55
86
|
}
|
|
56
87
|
};
|
|
57
88
|
var STXServerException = class extends STXAPIException {
|
|
@@ -92,21 +123,27 @@ var FEATURE_PHRASES = {
|
|
|
92
123
|
event_players: "Event players are",
|
|
93
124
|
leaderboard: "The leaderboard is",
|
|
94
125
|
loyalty: "The loyalty program is",
|
|
95
|
-
combos: "Combos are"
|
|
126
|
+
combos: "Combos are",
|
|
127
|
+
"orders.post_only": "Post-only orders are",
|
|
128
|
+
"orders.fill_or_kill": "Fill-or-kill orders are"
|
|
96
129
|
};
|
|
97
|
-
function notAvailableMessage(feature, host) {
|
|
130
|
+
function notAvailableMessage(feature, host, apiVersion) {
|
|
98
131
|
const phrase = feature.startsWith("scope:") ? `The ${feature.slice("scope:".length)} scope is` : FEATURE_PHRASES[feature] ?? `${feature} is`;
|
|
99
|
-
|
|
132
|
+
const where = apiVersion ? `${host} (version ${apiVersion})` : host;
|
|
133
|
+
return `${phrase} not available on ${where} yet.`;
|
|
100
134
|
}
|
|
101
135
|
var STXNotAvailableException = class _STXNotAvailableException extends STXAPIException {
|
|
102
136
|
/** The feature id, e.g. `"combos"`. */
|
|
103
137
|
feature;
|
|
104
138
|
/** The exchange host that lacks it, e.g. `"demo.stxapp.ca"`. */
|
|
105
139
|
host;
|
|
140
|
+
/** The exchange build, e.g. `"3.4.24"`, when known. */
|
|
141
|
+
apiVersion;
|
|
106
142
|
constructor(feature, host, opts = {}) {
|
|
107
|
-
super(opts.message ?? notAvailableMessage(feature, host), opts);
|
|
143
|
+
super(opts.message ?? notAvailableMessage(feature, host, opts.apiVersion), opts);
|
|
108
144
|
this.feature = feature;
|
|
109
145
|
this.host = host;
|
|
146
|
+
this.apiVersion = opts.apiVersion ?? void 0;
|
|
110
147
|
markNotAvailable(this);
|
|
111
148
|
}
|
|
112
149
|
// `this` is the class on the right of `instanceof`: a subclass keeps the
|
|
@@ -172,6 +209,18 @@ function errorForStatus(statusCode, body, opts) {
|
|
|
172
209
|
message = `HTTP ${statusCode}`;
|
|
173
210
|
}
|
|
174
211
|
const base = { statusCode, body, method: opts.method, path: opts.path };
|
|
212
|
+
const edge = edgeBlock(statusCode, body, opts.stxError, opts.cfId);
|
|
213
|
+
if (edge) {
|
|
214
|
+
if (statusCode === 429) {
|
|
215
|
+
return new STXRateLimitException(edge.message, {
|
|
216
|
+
...base,
|
|
217
|
+
retryAfter: parseRetryAfter(opts.retryAfter),
|
|
218
|
+
reference: edge.reference
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
const cls = edge.reason === "restricted_jurisdiction" ? STXRestrictedJurisdictionException : edge.reason === "unusual_network" ? STXUnusualNetworkException : STXBlockedException;
|
|
222
|
+
return new cls(edge.message, { ...base, reason: edge.reason, reference: edge.reference });
|
|
223
|
+
}
|
|
175
224
|
switch (statusCode) {
|
|
176
225
|
case 400:
|
|
177
226
|
return new STXValidationException(message, base);
|
|
@@ -206,10 +255,36 @@ function errorForStatus(statusCode, body, opts) {
|
|
|
206
255
|
return statusCode >= 500 ? new STXServerException(message, base) : new STXAPIException(message, base);
|
|
207
256
|
}
|
|
208
257
|
}
|
|
258
|
+
var NO_USER_AGENT_HINT = "Request blocked (HTTP 403) before it reached the exchange. Every request needs a User-Agent header; if you replaced or removed the SDK's, set one that names your application. If it persists, contact STX support.";
|
|
259
|
+
var EDGE_REASONS = {
|
|
260
|
+
403: ["restricted_jurisdiction", "unusual_network"],
|
|
261
|
+
429: ["rate_limited"]
|
|
262
|
+
};
|
|
263
|
+
var REFERENCE_PLACEHOLDER = "x-amz-cf-id response header";
|
|
264
|
+
function edgeBlock(status, body, stxError, cfId) {
|
|
265
|
+
const reasons = EDGE_REASONS[status];
|
|
266
|
+
if (!reasons || stxError) return void 0;
|
|
267
|
+
let reference = cfId || void 0;
|
|
268
|
+
if (body && typeof body === "object") {
|
|
269
|
+
const fields = body;
|
|
270
|
+
if (typeof fields.error !== "string" || !reasons.includes(fields.error)) return void 0;
|
|
271
|
+
if (reference === void 0 && typeof fields.reference === "string" && fields.reference) {
|
|
272
|
+
reference = fields.reference === REFERENCE_PLACEHOLDER ? void 0 : fields.reference;
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
reason: fields.error,
|
|
276
|
+
message: typeof fields.message === "string" && fields.message ? fields.message : fields.error,
|
|
277
|
+
reference
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
return status === 403 ? { reason: "blocked", message: NO_USER_AGENT_HINT, reference } : void 0;
|
|
281
|
+
}
|
|
209
282
|
function parseRetryAfter(value) {
|
|
210
283
|
if (value === null || value === void 0 || value.trim() === "") return void 0;
|
|
211
284
|
const n = Number(value);
|
|
212
|
-
|
|
285
|
+
if (Number.isFinite(n)) return Math.max(0, n);
|
|
286
|
+
const at = Date.parse(value);
|
|
287
|
+
return Number.isNaN(at) ? void 0 : Math.max(0, (at - Date.now()) / 1e3);
|
|
213
288
|
}
|
|
214
289
|
function bearerError(header) {
|
|
215
290
|
if (!header || !/^\s*Bearer\b/i.test(header)) return void 0;
|
|
@@ -236,8 +311,22 @@ var FEATURES = [
|
|
|
236
311
|
"event_players",
|
|
237
312
|
"leaderboard",
|
|
238
313
|
"loyalty",
|
|
239
|
-
"combos"
|
|
314
|
+
"combos",
|
|
315
|
+
"orders.post_only",
|
|
316
|
+
"orders.fill_or_kill"
|
|
240
317
|
];
|
|
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
|
+
}
|
|
241
330
|
var MEMBER_SCOPES = [
|
|
242
331
|
"profile.read",
|
|
243
332
|
"balance.read",
|
|
@@ -326,7 +415,9 @@ async function discoverCapabilities(probes) {
|
|
|
326
415
|
swallow(probes.signedGet("/api/v1/portfolio/loyalty?limit=1")),
|
|
327
416
|
swallow(probes.joinReason(`rfq:${NOBODY}`))
|
|
328
417
|
]);
|
|
329
|
-
const
|
|
418
|
+
const info = version ? apiVersionFrom(version.status === 200 ? json(version) : null) : null;
|
|
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;
|
|
330
421
|
const meta = oauthMetadataFrom(discovery);
|
|
331
422
|
const scopes = meta ? strings(meta.scopes_supported) : [];
|
|
332
423
|
const grants = meta ? strings(meta.grant_types_supported) : [];
|
|
@@ -348,7 +439,9 @@ async function discoverCapabilities(probes) {
|
|
|
348
439
|
leaderboard: board === null ? null : board.status >= 200 && board.status < 300 ? true : board.status === 404 ? false : null,
|
|
349
440
|
// Switched off answers 404 ("Loyalty program is not enabled").
|
|
350
441
|
loyalty: loyalty === null ? null : loyalty.status >= 200 && loyalty.status < 300 ? true : loyalty.status === 404 ? false : null,
|
|
351
|
-
combos: combos === null ? null : combos !== "unmatched topic"
|
|
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"])
|
|
352
445
|
};
|
|
353
446
|
return new Capabilities({
|
|
354
447
|
host: probes.host,
|
|
@@ -481,7 +574,7 @@ var OPERATIONS = {
|
|
|
481
574
|
account_market_stats_get: {
|
|
482
575
|
method: "GET",
|
|
483
576
|
path: "/api/v1/account/market_stats",
|
|
484
|
-
query: ["market_ids", "event_ids", "exclude_zero_settlements", "from_time", "to_time", "sports", "competitions", "limit", "cursor"],
|
|
577
|
+
query: ["market_ids", "event_ids", "exclude_zero_settlements", "unsettled_only", "from_time", "to_time", "sports", "competitions", "limit", "cursor"],
|
|
485
578
|
pathParams: [],
|
|
486
579
|
hasBody: false,
|
|
487
580
|
responseKey: "market_stats",
|
|
@@ -917,6 +1010,9 @@ var RetryPolicy = class {
|
|
|
917
1010
|
shouldRetry(exc, attempt, idempotent) {
|
|
918
1011
|
if (attempt >= this.maxAttempts) return false;
|
|
919
1012
|
if (!this.retryableExceptions.some((cls) => exc instanceof cls)) return false;
|
|
1013
|
+
if (exc instanceof STXRateLimitException && exc.retryAfter !== void 0 && exc.retryAfter * 1e3 > this.maxBackoffMs) {
|
|
1014
|
+
return false;
|
|
1015
|
+
}
|
|
920
1016
|
return idempotent || exc instanceof STXRateLimitException;
|
|
921
1017
|
}
|
|
922
1018
|
/** Milliseconds to wait after attempt `attempt` (1-based) failed. */
|
|
@@ -1178,7 +1274,7 @@ function credentialsFromSettings(keyId, privateKey, signer) {
|
|
|
1178
1274
|
}
|
|
1179
1275
|
|
|
1180
1276
|
// src/version.ts
|
|
1181
|
-
var VERSION = "0.
|
|
1277
|
+
var VERSION = "0.11.0";
|
|
1182
1278
|
var USER_AGENT = `stx-typescript/${VERSION}`;
|
|
1183
1279
|
var ASYNC_DISPOSE = Symbol.asyncDispose ?? /* @__PURE__ */ Symbol.for("Symbol.asyncDispose");
|
|
1184
1280
|
|
|
@@ -1828,7 +1924,9 @@ function decodeResponse(request, status, text, headers = {}) {
|
|
|
1828
1924
|
method: request.method,
|
|
1829
1925
|
path: request.path,
|
|
1830
1926
|
retryAfter: headers.retryAfter,
|
|
1831
|
-
wwwAuthenticate: headers.wwwAuthenticate
|
|
1927
|
+
wwwAuthenticate: headers.wwwAuthenticate,
|
|
1928
|
+
stxError: headers.stxError,
|
|
1929
|
+
cfId: headers.cfId
|
|
1832
1930
|
});
|
|
1833
1931
|
}
|
|
1834
1932
|
function splitPage(operationId, body) {
|
|
@@ -1847,6 +1945,10 @@ function toBatchOrderResult(raw) {
|
|
|
1847
1945
|
}
|
|
1848
1946
|
|
|
1849
1947
|
// src/client.ts
|
|
1948
|
+
var FILL_MODES = ["normal", "post_only", "fill_or_kill"];
|
|
1949
|
+
var NOT_ENABLED = /fill_mode (post_only|fill_or_kill) is not enabled|The (post_only|fill_or_kill) fill mode is not enabled/;
|
|
1950
|
+
var NOT_ACCEPTED = /does not accept the (post_only|fill_or_kill) fill mode/;
|
|
1951
|
+
var MATCH_WITH_SELF = "would match with your other order";
|
|
1850
1952
|
var NEW_ORDER_FIELDS = {
|
|
1851
1953
|
marketId: "market_id",
|
|
1852
1954
|
action: "action",
|
|
@@ -1857,7 +1959,8 @@ var NEW_ORDER_FIELDS = {
|
|
|
1857
1959
|
expiration: "expiration",
|
|
1858
1960
|
expirationTime: "expiration_time",
|
|
1859
1961
|
cancelOnDisconnect: "cancel_on_disconnect",
|
|
1860
|
-
deviceId: "device_id"
|
|
1962
|
+
deviceId: "device_id",
|
|
1963
|
+
fillMode: "fill_mode"
|
|
1861
1964
|
};
|
|
1862
1965
|
function amount(name, value, required) {
|
|
1863
1966
|
if (value === void 0 || value === null) {
|
|
@@ -1872,6 +1975,13 @@ function amount(name, value, required) {
|
|
|
1872
1975
|
return value;
|
|
1873
1976
|
}
|
|
1874
1977
|
function orderBody(marketId, action, orderType, opts) {
|
|
1978
|
+
const mode = opts.fillMode;
|
|
1979
|
+
if (mode !== void 0 && mode !== null && !FILL_MODES.includes(mode)) {
|
|
1980
|
+
throw new TypeError(`fillMode must be one of ${JSON.stringify(FILL_MODES)}, got ${JSON.stringify(mode)}`);
|
|
1981
|
+
}
|
|
1982
|
+
if ((mode === "post_only" || mode === "fill_or_kill") && orderType !== "limit") {
|
|
1983
|
+
throw new TypeError(`fillMode "${mode}" is for limit orders only`);
|
|
1984
|
+
}
|
|
1875
1985
|
const body = {
|
|
1876
1986
|
market_id: marketId,
|
|
1877
1987
|
action,
|
|
@@ -1884,7 +1994,8 @@ function orderBody(marketId, action, orderType, opts) {
|
|
|
1884
1994
|
expiration: opts.expiration,
|
|
1885
1995
|
expiration_time: opts.expirationTime,
|
|
1886
1996
|
cancel_on_disconnect: opts.cancelOnDisconnect,
|
|
1887
|
-
device_id: opts.deviceId
|
|
1997
|
+
device_id: opts.deviceId,
|
|
1998
|
+
fill_mode: mode === "normal" ? void 0 : mode
|
|
1888
1999
|
};
|
|
1889
2000
|
for (const [k, v] of Object.entries(optional)) if (v !== void 0 && v !== null) body[k] = v;
|
|
1890
2001
|
return body;
|
|
@@ -1935,6 +2046,7 @@ var STX = class _STX {
|
|
|
1935
2046
|
#fetch;
|
|
1936
2047
|
#me;
|
|
1937
2048
|
#capabilities;
|
|
2049
|
+
#apiVersion;
|
|
1938
2050
|
/** Test hook: how retries wait. */
|
|
1939
2051
|
_sleep = sleep;
|
|
1940
2052
|
constructor(opts = {}) {
|
|
@@ -2038,6 +2150,89 @@ var STX = class _STX {
|
|
|
2038
2150
|
clearTimeout(timer);
|
|
2039
2151
|
}
|
|
2040
2152
|
}
|
|
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
|
+
// A typed error for the exchange's refusals of a fill mode, else undefined.
|
|
2218
|
+
async #fillModeError(err, mode) {
|
|
2219
|
+
if (!(err instanceof STXValidationException || err instanceof STXRejectedException)) return void 0;
|
|
2220
|
+
const base = { statusCode: err.statusCode, body: err.body, method: err.method, path: err.path, cause: err };
|
|
2221
|
+
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
|
+
}
|
|
2228
|
+
if (!(err instanceof STXRejectedException)) return void 0;
|
|
2229
|
+
const notAccepted = NOT_ACCEPTED.exec(err.message);
|
|
2230
|
+
if (notAccepted) return new STXFillModeNotAllowedException(err.message, { ...base, fillMode: notAccepted[1] });
|
|
2231
|
+
if (mode === "post_only" && err.message.includes(MATCH_WITH_SELF)) {
|
|
2232
|
+
return new STXPostOnlyWouldMatchException(err.message, { ...base, reason: "match_with_self" });
|
|
2233
|
+
}
|
|
2234
|
+
return void 0;
|
|
2235
|
+
}
|
|
2041
2236
|
async #joinReason(topic) {
|
|
2042
2237
|
if (!this.auth) return null;
|
|
2043
2238
|
const ws = this.websocket({ reconnect: false, joinTimeoutMs: 8e3 });
|
|
@@ -2129,7 +2324,9 @@ var STX = class _STX {
|
|
|
2129
2324
|
this.#report(request, response.status, attempt, started, text);
|
|
2130
2325
|
return decodeResponse(request, response.status, text, {
|
|
2131
2326
|
retryAfter: response.headers.get("Retry-After"),
|
|
2132
|
-
wwwAuthenticate: response.headers.get("WWW-Authenticate")
|
|
2327
|
+
wwwAuthenticate: response.headers.get("WWW-Authenticate"),
|
|
2328
|
+
stxError: response.headers.get("x-stx-error"),
|
|
2329
|
+
cfId: response.headers.get("x-amz-cf-id")
|
|
2133
2330
|
});
|
|
2134
2331
|
}
|
|
2135
2332
|
async #send(request) {
|
|
@@ -2388,6 +2585,17 @@ var STX = class _STX {
|
|
|
2388
2585
|
* are decimal strings, e.g. `{ price: "0.58", quantity: "100" }`. Numbers are
|
|
2389
2586
|
* refused client-side.
|
|
2390
2587
|
*
|
|
2588
|
+
* `fillMode` (limit orders only) is `"normal"` (the default), `"post_only"`
|
|
2589
|
+
* or `"fill_or_kill"`. A post-only order that would match on arrival is not
|
|
2590
|
+
* placed: this throws `STXPostOnlyWouldMatchException`. A fill-or-kill order
|
|
2591
|
+
* comes back `accepted` (or `delayed` in play); follow it on the `orders`
|
|
2592
|
+
* channel or with `order()` to see it `filled` or `cancelled`.
|
|
2593
|
+
*
|
|
2594
|
+
* Before sending either mode, the client checks once that the exchange offers
|
|
2595
|
+
* it (`GET /api_version`, cached) and throws `STXNotAvailableException`
|
|
2596
|
+
* (`orders.post_only`, `orders.fill_or_kill`) without sending the order when
|
|
2597
|
+
* it does not. A combination market throws `STXFillModeNotAllowedException`.
|
|
2598
|
+
*
|
|
2391
2599
|
* The exchange validates the order: a bad price step or a fractional
|
|
2392
2600
|
* quantity throws `STXValidationException` (400) or `STXRejectedException`
|
|
2393
2601
|
* (422) with the API's message. An order from outside the region is also
|
|
@@ -2398,16 +2606,44 @@ var STX = class _STX {
|
|
|
2398
2606
|
*/
|
|
2399
2607
|
async placeOrder(marketId, action, orderType, opts) {
|
|
2400
2608
|
const body = orderBody(marketId, action, orderType, opts ?? {});
|
|
2401
|
-
|
|
2609
|
+
const mode = body.fill_mode;
|
|
2610
|
+
if (mode === void 0) return this.#one("orders_post", { body });
|
|
2611
|
+
await this.#requireFillModes([mode]);
|
|
2612
|
+
let order;
|
|
2613
|
+
try {
|
|
2614
|
+
order = await this.#one("orders_post", { body });
|
|
2615
|
+
} catch (err) {
|
|
2616
|
+
throw await this.#fillModeError(err, mode) ?? err;
|
|
2617
|
+
}
|
|
2618
|
+
if (mode === "post_only" && order.status === "cancelled" && order.cancellation_reason === "auto_matching") {
|
|
2619
|
+
throw new STXPostOnlyWouldMatchException(
|
|
2620
|
+
"The post-only order would have matched on arrival, so it was cancelled.",
|
|
2621
|
+
{ reason: "auto_matching", order, statusCode: 200, method: "POST", path: OPERATIONS.orders_post.path }
|
|
2622
|
+
);
|
|
2623
|
+
}
|
|
2624
|
+
return order;
|
|
2402
2625
|
}
|
|
2403
2626
|
/**
|
|
2404
2627
|
* `POST /api/v1/orders/batched`: place several orders in one call. Returns
|
|
2405
2628
|
* one result per order, in order; a rejected order has `errors` instead of
|
|
2406
|
-
* `order` and does not stop the others.
|
|
2629
|
+
* `order` and does not stop the others. A post-only order that would have
|
|
2630
|
+
* matched comes back as its order, `cancelled` with `cancellation_reason`
|
|
2631
|
+
* `auto_matching`.
|
|
2632
|
+
*
|
|
2633
|
+
* When any order has a `fillMode` other than `"normal"`, the exchange is
|
|
2634
|
+
* checked first as in `placeOrder()`, and `STXNotAvailableException` is
|
|
2635
|
+
* thrown with nothing sent.
|
|
2407
2636
|
*/
|
|
2408
2637
|
async placeOrders(orders) {
|
|
2409
2638
|
const body = { orders: orders.map(normalizeOrder) };
|
|
2410
|
-
const
|
|
2639
|
+
const modes = body.orders.map((o) => o.fill_mode).filter((m) => typeof m === "string");
|
|
2640
|
+
if (modes.length) await this.#requireFillModes(modes);
|
|
2641
|
+
let raw;
|
|
2642
|
+
try {
|
|
2643
|
+
raw = await this.#list("orders_batched_post", { body });
|
|
2644
|
+
} catch (err) {
|
|
2645
|
+
throw (modes.length ? await this.#fillModeError(err, void 0) : void 0) ?? err;
|
|
2646
|
+
}
|
|
2411
2647
|
return raw.map(toBatchOrderResult);
|
|
2412
2648
|
}
|
|
2413
2649
|
/**
|
|
@@ -2466,6 +2702,7 @@ var STX = class _STX {
|
|
|
2466
2702
|
market_ids: ids(q.marketIds),
|
|
2467
2703
|
event_ids: ids(q.eventIds),
|
|
2468
2704
|
exclude_zero_settlements: q.excludeZeroSettlements,
|
|
2705
|
+
unsettled_only: q.unsettledOnly,
|
|
2469
2706
|
from_time: q.fromTime,
|
|
2470
2707
|
to_time: q.toTime,
|
|
2471
2708
|
sports: ids(q.sports),
|
|
@@ -3711,8 +3948,13 @@ export {
|
|
|
3711
3948
|
STXInsufficientScopeException,
|
|
3712
3949
|
STXTermsRequiredException,
|
|
3713
3950
|
STXIPNotAllowedException,
|
|
3951
|
+
STXBlockedException,
|
|
3952
|
+
STXRestrictedJurisdictionException,
|
|
3953
|
+
STXUnusualNetworkException,
|
|
3714
3954
|
STXNotFoundException,
|
|
3715
3955
|
STXRejectedException,
|
|
3956
|
+
STXFillModeNotAllowedException,
|
|
3957
|
+
STXPostOnlyWouldMatchException,
|
|
3716
3958
|
STXRateLimitException,
|
|
3717
3959
|
STXServerException,
|
|
3718
3960
|
STXTransportException,
|
|
@@ -3773,4 +4015,4 @@ export {
|
|
|
3773
4015
|
orderBody,
|
|
3774
4016
|
STX
|
|
3775
4017
|
};
|
|
3776
|
-
//# sourceMappingURL=chunk-
|
|
4018
|
+
//# sourceMappingURL=chunk-2PYJI3JS.js.map
|