@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.
@@ -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: false,
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: false,
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: _nullishCoalesce(m.propType, () => ( "ou")), line: m.line }
635
+ };
636
+ }
637
+ function toCreateMarketResult(raw) {
638
+ const market = _nullishCoalesce(_nullishCoalesce(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
 
@@ -809,7 +961,7 @@ function credentialsFromSettings(keyId, privateKey, signer) {
809
961
  }
810
962
 
811
963
  // src/version.ts
812
- var VERSION = "0.7.0";
964
+ var VERSION = "0.8.0";
813
965
  var USER_AGENT = `stx-typescript/${VERSION}`;
814
966
  var ASYNC_DISPOSE = _nullishCoalesce(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 body = op.hasBody || args.body !== void 0 ? JSON.stringify(_nullishCoalesce(args.body, () => ( {}))) : void 0;
1295
+ const declared = op.hasBody && op.method !== "DELETE";
1296
+ const body = declared || args.body !== void 0 ? JSON.stringify(_nullishCoalesce(args.body, () => ( {}))) : void 0;
1144
1297
  return {
1145
1298
  operationId,
1146
1299
  method: op.method,
@@ -1533,6 +1686,63 @@ var STX = (_class3 = 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
+ (_nullishCoalesce(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) => _nullishCoalesce(r, () => ( rejected(markets[i], "not_created"))));
1744
+ }
1745
+ // ------------------------------------------------------------------
1536
1746
  // Orders
1537
1747
  // ------------------------------------------------------------------
1538
1748
  static #ordersQuery(q) {
@@ -2770,5 +2980,8 @@ function dropUndefined(payload) {
2770
2980
 
2771
2981
 
2772
2982
 
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;
2774
- //# sourceMappingURL=chunk-ASOLCDBG.cjs.map
2983
+
2984
+
2985
+
2986
+ 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.Stats = Stats; exports.MAX_MARKETS_PER_REQUEST = MAX_MARKETS_PER_REQUEST; exports.isValidLine = isValidLine; 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;
2987
+ //# sourceMappingURL=chunk-L2DEU7R6.cjs.map