Describes @stxapp/stx-typescript 0.12.1, the current release.
Markets
Section titled “Markets”import { STX } from "@stxapp/stx-typescript";
const client = new STX();const page = await client.markets({ status: "open", limit: 5 });for (const market of page) { console.log(market.symbol, "last", market.last_traded_price, "bid", market.bids?.[0]?.price);}console.log("more pages:", page.hasMore);Sample output (two of the five markets):
STXNHL-26OCT101600EDMSJ-GAMEEDM last 0.5800 bid 0.5800STXNHL-26OCT101600EDMSJ-SOGSJCMCDAVID209555-3.5 last 0.5200 bid 0.4900more pages: true| Option | Meaning |
|---|---|
marketIds, eventIds |
One id or a list |
status |
One or a list, lowercase, e.g. "open"; see Market status |
trading |
true for only the markets accepting orders now, false for only those that are not |
sports, competitions |
One or a list |
sortBy, sortDirection |
e.g. sortBy: "event_start", sortDirection: "desc" |
limit, cursor |
Page size and the cursor from the previous page |
Filters combine with AND; a list filter matches any of its values. client.market(id) fetches one market and throws STXNotFoundException when there is none.
Pagination
Section titled “Pagination”A list method returns one Page: page.items, page.cursor (null on the last page), page.hasMore and page.length. A Page is iterable. To walk every page, use the iter* twin, which follows the cursor for you:
import { STX } from "@stxapp/stx-typescript";
const client = new STX();
let market;for await (const m of client.iterMarkets({ status: "open", trading: true, sortBy: "event_start", sortDirection: "desc" })) { if (m.event_status === "scheduled") { market = m; break; }}console.log(market?.market_id, market?.symbol, market?.max_price);// e00651a3-10cb-4bc1-9e1f-c5ea1796c83b STXNHL-26OCT101600EDMSJ-GAMEEDM 1.0000status: "open" with trading: true returns only the markets that are open and accept orders now. A pre_open market also accepts limit orders, but they wait at accepted and do not reach the book until it opens.
Or page by hand:
let page = await client.markets({ status: "open", limit: 100 });while (true) { for (const m of page) console.log(m.symbol); if (!page.hasMore) break; page = await client.markets({ status: "open", limit: 100, cursor: page.cursor! });}Events
Section titled “Events”const events = await client.events({ limit: 10 });for (const e of events) console.log(e.event_id, e.title, e.status);// 24636b3d-f566-4dd3-8c8b-c1a6c2747789 Edmonton Oilers at San Jose Sharks scheduled// a80f6a9d-fcc6-4a02-82d7-82a55e90db1c Seattle Kraken at Detroit Red Wings completed
for await (const e of client.iterEvents({ promoted: true })) console.log(e.title);events() filters on eventIds, sports, competitions, eventTypes, title, status and promoted, and sorts with sortBy and sortDirection.
Creating markets
Section titled “Creating markets”An app that STX has granted the markets.write scope can create player-prop markets on scheduled events, from an address on its IP allow-list. See Creating markets for the setup and the full list of outcomes. Where the exchange does not offer it yet, createMarkets(), marketTypes() and asking for markets.write throw STXNotAvailableException; see What you can do.
import { AppScopes, OAuthClient } from "@stxapp/stx-typescript/oauth";import { Stats } from "@stxapp/stx-typescript";
const oauth = new OAuthClient({ clientId, clientSecret });const stx = oauth.appClient([AppScopes.EVENTS, AppScopes.MARKETS_WRITE]);
const roster = await stx.eventPlayers(eventId);const player = roster.teams[0].players[0]; // { player_id: "3895074", name: "Connor McDavid", jersey: "97", position: "C" }
const markets = [ { playerId: player.player_id, stat: Stats.Hockey.GOAL_SO, line: 3.5 },];
// Check first: every check runs on STX and nothing is created.const checked = await stx.createMarkets(eventId, markets, { dryRun: true });if (checked.every((r) => r.status === "valid" || r.status === "exists")) { const results = await stx.createMarkets(eventId, markets); for (const r of results) console.log(r.status, r.status === "rejected" ? r.reason : r.market_id);}// created 2a473aeb-10de-47e4-a7ce-dbb771094d84- Lines must be positive and end in
.5:3.5is accepted;3,3.25,0and"3.5"come backrejectedwithinvalid_line. - Stats: an event accepts the stats
eventPlayers()(orstatsFor(event)) returns for it.Statslists them by sport for autocomplete. - Results come back one per market, in order:
created,exists(already listed, samemarket_id),valid(withdryRun) orrejectedwith areason. Each result hasindex(its position in your list),market_id,reasonandmarket, the market as you requested it. Resending is safe. dryRun: trueruns every check on STX and creates nothing.validate: truechecks players, stats and lines before sending, and returns failures asrejectedwithout a request. It reads the event’s players, so the token also needsevents.- Up to
MAX_MARKETS_PER_REQUEST(25) markets per call; more throwsTypeErrorbefore sending.
Market types
Section titled “Market types”marketTypes() lists every market type the exchange has, keyed by rule. A type with partner_create: true can be created with createMarkets(), and lists the fields an entry takes and the stats each event type offers. It changes only when STX adds a rule or a stat, so read it once.
const types = await stx.marketTypes();const psl = types.player_stat_line;console.log(psl.partner_create, Object.keys(psl.event_types));// true [ "baseball_game", "basketball_game", "football_game", "hockey_game" ]console.log(psl.fields.line);// { type: "number", description: "A positive half line, e.g. 19.5." }console.log(psl.event_types.basketball_game.stats[1]);// { name: "Points", stat: "POINTS" }Captured on US demo, which listed 57 types; player_stat_line is the one an app can create today.
Live prices
Section titled “Live prices”bids and offers are a snapshot of the top of the book. To follow prices as they move, stream them; see WebSockets.

