@stxapp/stx-typescript 0.7.0 → 0.8.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 +6 -0
- package/dist/{chunk-CDXZOW53.js → chunk-H7XZDE2U.js} +218 -5
- package/dist/chunk-H7XZDE2U.js.map +1 -0
- package/dist/{chunk-ASOLCDBG.cjs → chunk-L2DEU7R6.cjs} +219 -6
- package/dist/chunk-L2DEU7R6.cjs.map +1 -0
- package/dist/{client-CA1d-osT.d.cts → client-E5Lg6k8d.d.cts} +583 -109
- package/dist/{client-CA1d-osT.d.ts → client-E5Lg6k8d.d.ts} +583 -109
- package/dist/index.cjs +8 -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 +7 -1
- package/dist/oauth.cjs +21 -19
- package/dist/oauth.cjs.map +1 -1
- package/dist/oauth.d.cts +8 -4
- package/dist/oauth.d.ts +8 -4
- package/dist/oauth.js +5 -3
- package/dist/oauth.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-ASOLCDBG.cjs.map +0 -1
- package/dist/chunk-CDXZOW53.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.8.0 (2026-10-06)
|
|
4
|
+
|
|
5
|
+
- Create player-prop markets as an app with the `markets.write` scope: `eventPlayers()`, `statsFor()` and `createMarkets()`, with `Stats` constants by sport and an opt-in `validate` check. Lines must be positive and end in `.5`; up to 25 markets per call.
|
|
6
|
+
- `AppScopes.MARKETS_WRITE`.
|
|
7
|
+
- Request and response types follow the current exchange REST spec.
|
|
8
|
+
|
|
3
9
|
## 0.7.0 (2026-10-03)
|
|
4
10
|
|
|
5
11
|
- `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.
|
|
@@ -299,6 +299,17 @@ var OPERATIONS = {
|
|
|
299
299
|
isList: true,
|
|
300
300
|
paginated: true
|
|
301
301
|
},
|
|
302
|
+
events__id_players_get: {
|
|
303
|
+
method: "GET",
|
|
304
|
+
path: "/api/v1/events/{event_id}/players",
|
|
305
|
+
query: [],
|
|
306
|
+
pathParams: ["event_id"],
|
|
307
|
+
hasBody: false,
|
|
308
|
+
responseKey: "",
|
|
309
|
+
model: "",
|
|
310
|
+
isList: false,
|
|
311
|
+
paginated: false
|
|
312
|
+
},
|
|
302
313
|
fills_get: {
|
|
303
314
|
method: "GET",
|
|
304
315
|
path: "/api/v1/fills",
|
|
@@ -310,6 +321,28 @@ var OPERATIONS = {
|
|
|
310
321
|
isList: true,
|
|
311
322
|
paginated: true
|
|
312
323
|
},
|
|
324
|
+
leaderboard_get: {
|
|
325
|
+
method: "GET",
|
|
326
|
+
path: "/api/v1/leaderboard",
|
|
327
|
+
query: ["period", "category", "metric", "limit"],
|
|
328
|
+
pathParams: [],
|
|
329
|
+
hasBody: false,
|
|
330
|
+
responseKey: "",
|
|
331
|
+
model: "",
|
|
332
|
+
isList: false,
|
|
333
|
+
paginated: false
|
|
334
|
+
},
|
|
335
|
+
leaderboard_me_get: {
|
|
336
|
+
method: "GET",
|
|
337
|
+
path: "/api/v1/leaderboard/me",
|
|
338
|
+
query: ["period", "category"],
|
|
339
|
+
pathParams: [],
|
|
340
|
+
hasBody: false,
|
|
341
|
+
responseKey: "",
|
|
342
|
+
model: "",
|
|
343
|
+
isList: false,
|
|
344
|
+
paginated: false
|
|
345
|
+
},
|
|
313
346
|
markets_get: {
|
|
314
347
|
method: "GET",
|
|
315
348
|
path: "/api/v1/markets",
|
|
@@ -321,6 +354,17 @@ var OPERATIONS = {
|
|
|
321
354
|
isList: true,
|
|
322
355
|
paginated: true
|
|
323
356
|
},
|
|
357
|
+
markets_post: {
|
|
358
|
+
method: "POST",
|
|
359
|
+
path: "/api/v1/markets",
|
|
360
|
+
query: [],
|
|
361
|
+
pathParams: [],
|
|
362
|
+
hasBody: true,
|
|
363
|
+
responseKey: "",
|
|
364
|
+
model: "",
|
|
365
|
+
isList: false,
|
|
366
|
+
paginated: false
|
|
367
|
+
},
|
|
324
368
|
me_get: {
|
|
325
369
|
method: "GET",
|
|
326
370
|
path: "/api/v1/me",
|
|
@@ -332,6 +376,17 @@ var OPERATIONS = {
|
|
|
332
376
|
isList: false,
|
|
333
377
|
paginated: false
|
|
334
378
|
},
|
|
379
|
+
me_profile_patch: {
|
|
380
|
+
method: "PATCH",
|
|
381
|
+
path: "/api/v1/me/profile",
|
|
382
|
+
query: [],
|
|
383
|
+
pathParams: [],
|
|
384
|
+
hasBody: true,
|
|
385
|
+
responseKey: "me",
|
|
386
|
+
model: "Me",
|
|
387
|
+
isList: false,
|
|
388
|
+
paginated: false
|
|
389
|
+
},
|
|
335
390
|
orders_get: {
|
|
336
391
|
method: "GET",
|
|
337
392
|
path: "/api/v1/orders",
|
|
@@ -359,7 +414,7 @@ var OPERATIONS = {
|
|
|
359
414
|
path: "/api/v1/orders/all",
|
|
360
415
|
query: [],
|
|
361
416
|
pathParams: [],
|
|
362
|
-
hasBody:
|
|
417
|
+
hasBody: true,
|
|
363
418
|
responseKey: "cancellations",
|
|
364
419
|
model: "Cancellation",
|
|
365
420
|
isList: true,
|
|
@@ -392,7 +447,7 @@ var OPERATIONS = {
|
|
|
392
447
|
path: "/api/v1/orders/{order_id}",
|
|
393
448
|
query: [],
|
|
394
449
|
pathParams: ["order_id"],
|
|
395
|
-
hasBody:
|
|
450
|
+
hasBody: true,
|
|
396
451
|
responseKey: "",
|
|
397
452
|
model: "",
|
|
398
453
|
isList: false,
|
|
@@ -499,6 +554,103 @@ var OPERATIONS = {
|
|
|
499
554
|
}
|
|
500
555
|
};
|
|
501
556
|
|
|
557
|
+
// src/markets.ts
|
|
558
|
+
var Stats = {
|
|
559
|
+
Baseball: {
|
|
560
|
+
BASES: "BASES",
|
|
561
|
+
BK: "BK",
|
|
562
|
+
DOUBLES: "DOUBLES",
|
|
563
|
+
HITS: "HITS",
|
|
564
|
+
HIT_RUN_RBI: "HIT_RUN_RBI",
|
|
565
|
+
HOMERUN: "HOMERUN",
|
|
566
|
+
PERA: "PERA",
|
|
567
|
+
PHITA: "PHITA",
|
|
568
|
+
PK: "PK",
|
|
569
|
+
POUTS: "POUTS",
|
|
570
|
+
PRUNSALOWED: "PRUNSALOWED",
|
|
571
|
+
PWALKSA: "PWALKSA",
|
|
572
|
+
RBI: "RBI",
|
|
573
|
+
RUNS: "RUNS",
|
|
574
|
+
SINGLES: "SINGLES",
|
|
575
|
+
STOLENBASES: "STOLENBASES",
|
|
576
|
+
TRIPLES: "TRIPLES",
|
|
577
|
+
WALKS: "WALKS"
|
|
578
|
+
},
|
|
579
|
+
Basketball: {
|
|
580
|
+
ASSISTS: "ASSISTS",
|
|
581
|
+
BLOCKS: "BLOCKS",
|
|
582
|
+
POINTS: "POINTS",
|
|
583
|
+
POINTS_ASSISTS: "POINTS_ASSISTS",
|
|
584
|
+
POINTS_REBOUNDS: "POINTS_REBOUNDS",
|
|
585
|
+
POINTS_REBOUNDS_ASSISTS: "POINTS_REBOUNDS_ASSISTS",
|
|
586
|
+
REBOUNDS: "REBOUNDS",
|
|
587
|
+
REBOUNDS_ASSISTS: "REBOUNDS_ASSISTS",
|
|
588
|
+
STEALS: "STEALS",
|
|
589
|
+
STEALS_BLOCKS: "STEALS_BLOCKS",
|
|
590
|
+
THREE_POINTS: "THREE_POINTS",
|
|
591
|
+
TURNOVERS: "TURNOVERS"
|
|
592
|
+
},
|
|
593
|
+
Football: {
|
|
594
|
+
DEF_INTERCEPT: "DEF_INTERCEPT",
|
|
595
|
+
DEF_TD: "DEF_TD",
|
|
596
|
+
FG_MADE: "FG_MADE",
|
|
597
|
+
INTERCEPT: "INTERCEPT",
|
|
598
|
+
PASS_ATT: "PASS_ATT",
|
|
599
|
+
PASS_CMP: "PASS_CMP",
|
|
600
|
+
PASS_RUSH_YDS: "PASS_RUSH_YDS",
|
|
601
|
+
PASS_SACKS: "PASS_SACKS",
|
|
602
|
+
PASS_TD: "PASS_TD",
|
|
603
|
+
PASS_YDS: "PASS_YDS",
|
|
604
|
+
REC: "REC",
|
|
605
|
+
RECV_LONG: "RECV_LONG",
|
|
606
|
+
RECV_TD: "RECV_TD",
|
|
607
|
+
RECV_YDS: "RECV_YDS",
|
|
608
|
+
RUSH_ATT: "RUSH_ATT",
|
|
609
|
+
RUSH_LONG: "RUSH_LONG",
|
|
610
|
+
RUSH_REC_YDS: "RUSH_REC_YDS",
|
|
611
|
+
RUSH_TD: "RUSH_TD",
|
|
612
|
+
RUSH_YDS: "RUSH_YDS",
|
|
613
|
+
SACKS: "SACKS",
|
|
614
|
+
TACKLES_ASSIST: "TACKLES_ASSIST",
|
|
615
|
+
TACKLES_SOLO: "TACKLES_SOLO",
|
|
616
|
+
TACKLES_TOTAL: "TACKLES_TOTAL",
|
|
617
|
+
TD_SCORE: "TD_SCORE"
|
|
618
|
+
},
|
|
619
|
+
Hockey: {
|
|
620
|
+
ASSISTS: "ASSISTS",
|
|
621
|
+
GOALS: "GOALS",
|
|
622
|
+
GOAL_AG: "GOAL_AG",
|
|
623
|
+
GOAL_SO: "GOAL_SO",
|
|
624
|
+
POINTS: "POINTS",
|
|
625
|
+
SAVES: "SAVES"
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
var MAX_MARKETS_PER_REQUEST = 25;
|
|
629
|
+
function isValidLine(line) {
|
|
630
|
+
return typeof line === "number" && Number.isFinite(line) && line > 0 && line * 2 % 2 === 1;
|
|
631
|
+
}
|
|
632
|
+
function marketEntry(m) {
|
|
633
|
+
return {
|
|
634
|
+
stat_detail: { player_id: m.playerId, stat: m.stat, prop_type: m.propType ?? "ou", line: m.line }
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
function toCreateMarketResult(raw) {
|
|
638
|
+
const market = raw.market ?? raw.stat_detail ?? {};
|
|
639
|
+
return { ...raw, market };
|
|
640
|
+
}
|
|
641
|
+
function rejected(m, reason) {
|
|
642
|
+
const market = marketEntry(m).stat_detail;
|
|
643
|
+
return { status: "rejected", reason, market };
|
|
644
|
+
}
|
|
645
|
+
function checkMarket(m, players) {
|
|
646
|
+
if (!isValidLine(m.line)) return { reason: "invalid_line" };
|
|
647
|
+
const stat = players.stats.find((s) => String(s.stat).toUpperCase() === String(m.stat).toUpperCase());
|
|
648
|
+
if (!stat) return { reason: "unsupported_stat" };
|
|
649
|
+
const ids2 = new Set(players.teams.flatMap((t) => t.players.map((p) => p.player_id)));
|
|
650
|
+
if (!ids2.has(m.playerId)) return { reason: "unknown_player" };
|
|
651
|
+
return { market: { ...m, stat: stat.stat } };
|
|
652
|
+
}
|
|
653
|
+
|
|
502
654
|
// src/paging.ts
|
|
503
655
|
var Page = class {
|
|
504
656
|
items;
|
|
@@ -809,7 +961,7 @@ function credentialsFromSettings(keyId, privateKey, signer) {
|
|
|
809
961
|
}
|
|
810
962
|
|
|
811
963
|
// src/version.ts
|
|
812
|
-
var VERSION = "0.
|
|
964
|
+
var VERSION = "0.8.0";
|
|
813
965
|
var USER_AGENT = `stx-typescript/${VERSION}`;
|
|
814
966
|
var ASYNC_DISPOSE = Symbol.asyncDispose ?? /* @__PURE__ */ Symbol.for("Symbol.asyncDispose");
|
|
815
967
|
|
|
@@ -1140,7 +1292,8 @@ function buildRequest(operationId, args = {}) {
|
|
|
1140
1292
|
if (unknown.length) throw new TypeError(`${operationId} does not take ${unknown.sort().join(", ")}`);
|
|
1141
1293
|
const qs = encodeQuery(query);
|
|
1142
1294
|
if (qs) path = `${path}?${qs}`;
|
|
1143
|
-
const
|
|
1295
|
+
const declared = op.hasBody && op.method !== "DELETE";
|
|
1296
|
+
const body = declared || args.body !== void 0 ? JSON.stringify(args.body ?? {}) : void 0;
|
|
1144
1297
|
return {
|
|
1145
1298
|
operationId,
|
|
1146
1299
|
method: op.method,
|
|
@@ -1533,6 +1686,63 @@ var STX = class _STX {
|
|
|
1533
1686
|
return this.#iterate("events_get", _STX.#eventsQuery({ ...query, cursor: void 0 }));
|
|
1534
1687
|
}
|
|
1535
1688
|
// ------------------------------------------------------------------
|
|
1689
|
+
// Creating markets
|
|
1690
|
+
// ------------------------------------------------------------------
|
|
1691
|
+
/**
|
|
1692
|
+
* `GET /api/v1/events/{event_id}/players`: the event's team rosters and the
|
|
1693
|
+
* stats a market on it can use. `teams` is empty until the rosters are
|
|
1694
|
+
* published. Needs an OAuth app token with `events`, or an API key.
|
|
1695
|
+
*/
|
|
1696
|
+
eventPlayers(eventId) {
|
|
1697
|
+
return this.#one("events__id_players_get", { pathParams: { event_id: eventId } });
|
|
1698
|
+
}
|
|
1699
|
+
/** The stats `event` accepts for new markets. */
|
|
1700
|
+
async statsFor(event) {
|
|
1701
|
+
const eventId = typeof event === "string" ? event : event.event_id;
|
|
1702
|
+
if (!eventId) throw new TypeError("statsFor needs an event id");
|
|
1703
|
+
return (await this.eventPlayers(eventId)).stats;
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* `POST /api/v1/markets`: create player-prop markets on a scheduled event,
|
|
1707
|
+
* up to `MAX_MARKETS_PER_REQUEST` per call. Needs an OAuth app token with
|
|
1708
|
+
* `markets.write`, which STX grants, from the client's IP allow-list.
|
|
1709
|
+
*
|
|
1710
|
+
* Returns one result per market, in order: `created` or `exists` (both with
|
|
1711
|
+
* `market_id`), or `rejected` with a `reason`. A rejected market is a
|
|
1712
|
+
* result, not an error, and resending is safe: a market that is already
|
|
1713
|
+
* listed comes back `exists`. A refused request throws (`403` without
|
|
1714
|
+
* `markets.write`, `404` unknown event, `422` event not open).
|
|
1715
|
+
*
|
|
1716
|
+
* Each `line` must be a positive number ending in `.5`, e.g. `18.5`. More
|
|
1717
|
+
* than `MAX_MARKETS_PER_REQUEST` markets throws `TypeError` before any
|
|
1718
|
+
* request. `validate` also needs the `events` scope.
|
|
1719
|
+
*/
|
|
1720
|
+
async createMarkets(eventId, markets, opts = {}) {
|
|
1721
|
+
if (markets.length < 1 || markets.length > MAX_MARKETS_PER_REQUEST) {
|
|
1722
|
+
throw new TypeError(`createMarkets takes 1 to ${MAX_MARKETS_PER_REQUEST} markets; got ${markets.length}`);
|
|
1723
|
+
}
|
|
1724
|
+
const results = new Array(markets.length);
|
|
1725
|
+
let send = markets.map((m, i) => ({ m, i }));
|
|
1726
|
+
if (opts.validate) {
|
|
1727
|
+
const players = await this.eventPlayers(eventId);
|
|
1728
|
+
send = send.flatMap(({ m, i }) => {
|
|
1729
|
+
const checked = checkMarket(m, players);
|
|
1730
|
+
if ("market" in checked) return [{ m: checked.market, i }];
|
|
1731
|
+
results[i] = rejected(m, checked.reason);
|
|
1732
|
+
return [];
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1735
|
+
if (send.length) {
|
|
1736
|
+
const body = { event_id: eventId, markets: send.map(({ m }) => marketEntry(m)) };
|
|
1737
|
+
const raw = await this.#one("markets_post", { body });
|
|
1738
|
+
(raw.markets ?? []).forEach((r, k) => {
|
|
1739
|
+
const slot = send[k];
|
|
1740
|
+
if (slot) results[slot.i] = toCreateMarketResult(r);
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1743
|
+
return results.map((r, i) => r ?? rejected(markets[i], "not_created"));
|
|
1744
|
+
}
|
|
1745
|
+
// ------------------------------------------------------------------
|
|
1536
1746
|
// Orders
|
|
1537
1747
|
// ------------------------------------------------------------------
|
|
1538
1748
|
static #ordersQuery(q) {
|
|
@@ -2739,6 +2949,9 @@ export {
|
|
|
2739
2949
|
baseUrlFor,
|
|
2740
2950
|
socketUrlFor,
|
|
2741
2951
|
OPERATIONS,
|
|
2952
|
+
Stats,
|
|
2953
|
+
MAX_MARKETS_PER_REQUEST,
|
|
2954
|
+
isValidLine,
|
|
2742
2955
|
Page,
|
|
2743
2956
|
RetryPolicy,
|
|
2744
2957
|
NO_RETRY,
|
|
@@ -2771,4 +2984,4 @@ export {
|
|
|
2771
2984
|
orderBody,
|
|
2772
2985
|
STX
|
|
2773
2986
|
};
|
|
2774
|
-
//# sourceMappingURL=chunk-
|
|
2987
|
+
//# sourceMappingURL=chunk-H7XZDE2U.js.map
|