@stxapp/stx-typescript 0.8.1 → 0.8.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.
@@ -650,17 +650,22 @@ function isValidLine(line) {
650
650
  return typeof line === "number" && Number.isFinite(line) && line > 0 && line * 2 % 2 === 1;
651
651
  }
652
652
  function marketEntry(m) {
653
- return {
654
- stat_detail: { player_id: m.playerId, stat: m.stat, prop_type: m.propType ?? "ou", line: m.line }
655
- };
653
+ return { rule: m.rule ?? "player_stat_line", player_id: m.playerId, stat: m.stat, line: m.line };
656
654
  }
657
- function toCreateMarketResult(raw) {
658
- const market = raw.market ?? raw.stat_detail ?? {};
659
- return { ...raw, market };
655
+ function toCreateMarketResult(raw, m, index) {
656
+ const market = marketEntry(m);
657
+ switch (raw.status) {
658
+ case "created":
659
+ case "exists":
660
+ return { index, status: raw.status, market_id: String(raw.market_id), reason: null, market };
661
+ case "valid":
662
+ return { index, status: "valid", market_id: null, reason: null, market };
663
+ default:
664
+ return rejected(m, index, raw.reason ?? "not_created");
665
+ }
660
666
  }
661
- function rejected(m, reason) {
662
- const market = marketEntry(m).stat_detail;
663
- return { status: "rejected", reason, market };
667
+ function rejected(m, index, reason) {
668
+ return { index, status: "rejected", market_id: null, reason, market: marketEntry(m) };
664
669
  }
665
670
  function checkMarket(m, players) {
666
671
  if (!isValidLine(m.line)) return { reason: "invalid_line" };
@@ -981,7 +986,7 @@ function credentialsFromSettings(keyId, privateKey, signer) {
981
986
  }
982
987
 
983
988
  // src/version.ts
984
- var VERSION = "0.8.1";
989
+ var VERSION = "0.8.3";
985
990
  var USER_AGENT = `stx-typescript/${VERSION}`;
986
991
  var ASYNC_DISPOSE = Symbol.asyncDispose ?? /* @__PURE__ */ Symbol.for("Symbol.asyncDispose");
987
992
 
@@ -2015,14 +2020,17 @@ var STX = class _STX {
2015
2020
  * `markets.write`, which STX grants, from the client's IP allow-list.
2016
2021
  *
2017
2022
  * Returns one result per market, in order: `created` or `exists` (both with
2018
- * `market_id`), or `rejected` with a `reason`. A rejected market is a
2023
+ * `market_id`), `valid` with `dryRun`, or `rejected` with a `reason`. Each
2024
+ * result's `index` is its position in `markets`, and `market` is that market
2025
+ * as requested. A rejected market is a
2019
2026
  * result, not an error, and resending is safe: a market that is already
2020
2027
  * listed comes back `exists`. A refused request throws (`403` without
2021
2028
  * `markets.write`, `404` unknown event, `422` event not open).
2022
2029
  *
2023
2030
  * Each `line` must be a positive number ending in `.5`, e.g. `18.5`. More
2024
2031
  * than `MAX_MARKETS_PER_REQUEST` markets throws `TypeError` before any
2025
- * request. `validate` also needs the `events` scope.
2032
+ * request. `dryRun` runs every check and creates nothing. `validate` also
2033
+ * needs the `events` scope.
2026
2034
  */
2027
2035
  async createMarkets(eventId, markets, opts = {}) {
2028
2036
  if (markets.length < 1 || markets.length > MAX_MARKETS_PER_REQUEST) {
@@ -2035,19 +2043,20 @@ var STX = class _STX {
2035
2043
  send = send.flatMap(({ m, i }) => {
2036
2044
  const checked = checkMarket(m, players);
2037
2045
  if ("market" in checked) return [{ m: checked.market, i }];
2038
- results[i] = rejected(m, checked.reason);
2046
+ results[i] = rejected(m, i, checked.reason);
2039
2047
  return [];
2040
2048
  });
2041
2049
  }
2042
2050
  if (send.length) {
2043
2051
  const body = { event_id: eventId, markets: send.map(({ m }) => marketEntry(m)) };
2052
+ if (opts.dryRun) body.dry_run = true;
2044
2053
  const raw = await this.#one("markets_post", { body });
2045
2054
  (raw.markets ?? []).forEach((r, k) => {
2046
- const slot = send[k];
2047
- if (slot) results[slot.i] = toCreateMarketResult(r);
2055
+ const slot = send[typeof r.index === "number" ? r.index : k];
2056
+ if (slot) results[slot.i] = toCreateMarketResult(r, slot.m, slot.i);
2048
2057
  });
2049
2058
  }
2050
- return results.map((r, i) => r ?? rejected(markets[i], "not_created"));
2059
+ return results.map((r, i) => r ?? rejected(markets[i], i, "not_created"));
2051
2060
  }
2052
2061
  // ------------------------------------------------------------------
2053
2062
  // Orders
@@ -2079,7 +2088,7 @@ var STX = class _STX {
2079
2088
  *
2080
2089
  * `action` is `"buy"` or `"sell"`; `orderType` is `"limit"` or `"market"`.
2081
2090
  * `price` (dollars, required for a limit order) and `quantity` (contracts)
2082
- * are decimal strings, e.g. `{ price: "0.56", quantity: "2" }`. Numbers are
2091
+ * are decimal strings, e.g. `{ price: "0.58", quantity: "100" }`. Numbers are
2083
2092
  * refused client-side.
2084
2093
  *
2085
2094
  * The exchange validates the order: a bad price step or a fractional
@@ -2866,13 +2875,13 @@ var STXWebSocket = class {
2866
2875
  return this.#joinAccount("user_info", {}, opts.onMessage);
2867
2876
  }
2868
2877
  // ------------------------------------------------------------------
2869
- // Combos (preview)
2878
+ // Combos
2870
2879
  // ------------------------------------------------------------------
2871
2880
  /**
2872
2881
  * Join `rfq:{user_id}` and return a `ComboPlayer`: request quotes on a
2873
2882
  * combination, cash one out, accept, cancel and read a request.
2874
2883
  *
2875
- * Preview: available on US demo; may change before general availability.
2884
+ * Available on US demo.
2876
2885
  * Where combos are not available, rejects with
2877
2886
  * `STXCombosUnavailableException`. Other join refusals (a read-only key, an
2878
2887
  * account that may not trade) reject with `STXComboRefusedException`.
@@ -2892,7 +2901,7 @@ var STXWebSocket = class {
2892
2901
  * Join `combo_quote:{user_id}` and return a `ComboMaker`: receive every
2893
2902
  * request opened from now on (`rfq_opened`), quote and withdraw quotes.
2894
2903
  *
2895
- * Preview: available on US demo; may change before general availability.
2904
+ * Available on US demo.
2896
2905
  * Where combos are not available, rejects with
2897
2906
  * `STXCombosUnavailableException`.
2898
2907
  */
@@ -3356,4 +3365,4 @@ export {
3356
3365
  orderBody,
3357
3366
  STX
3358
3367
  };
3359
- //# sourceMappingURL=chunk-GLUTQFBV.js.map
3368
+ //# sourceMappingURL=chunk-SIYERAKK.js.map