Describes @stxapp/stx-typescript 0.12.1, the current release.
The STX client. Configuration comes from the options, then environment variables, then a profile in ~/.stx/credentials:
const client = new STX();const me = await client.me();me.user_id; // "e6528824-b4e0-4ff8-bd70-36e5904738d1"const page = await client.markets({ status: "open", limit: 10 });page.items[0]?.symbol; // "STXNHL-26OCT101600EDMSJ-GAMEEDM"Constructor
Section titled “Constructor”new STX(opts?: STXOptions)| Parameter | Type | Description |
|---|---|---|
opts (optional) |
STXOptions |
|
opts.env (optional) |
string | null |
"production" or "demo" ("prod" and "live" are accepted). |
opts.environment (optional) |
string | STXEnvironment |
A published environment, Environments.OntarioDemo, or its name, "ontario-demo". Instead of region + env; host still wins. |
opts.fetch (optional) |
FetchLike |
Inject a fetch implementation (tests, proxies). |
opts.host (optional) |
string | null |
A hostname or URL, overriding region/env: "demo.stxapp.ca", "http://localhost:4000". |
opts.keyId (optional) |
string | null |
The API key ID. |
opts.onResponse (optional) |
(event: ResponseEvent) => void |
Called once per HTTP attempt, after it completes or fails: an audit or activity log hook. Never throws into the request; an exception here is swallowed. |
opts.privateKey (optional) |
PrivateKeyInput | null |
The Ed25519 private key: PEM text, a path to a PEM file, PEM bytes, or a KeyObject. |
opts.profile (optional) |
string | null |
A section of ~/.stx/credentials to read. |
opts.region (optional) |
string | null |
A known region, e.g. "ontario" or "us". With env, picks the host. |
opts.retry (optional) |
RetryPolicy |
A RetryPolicy; NO_RETRY disables retries. |
opts.signer (optional) |
Signer |
Instead of privateKey: signs message bytes, for keys in an HSM or KMS. |
opts.timeoutMs (optional) |
number |
Milliseconds per HTTP request. Default 30000. |
opts.verifyTls (optional) |
boolean | null |
Set false only for a local server. Honoured by the WebSocket; for HTTP requests, pass a fetch whose dispatcher skips verification (Node’s global fetch has no per-call switch). |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
baseUrl |
string |
|
credentials |
ApiKeyCredentials | undefined |
The API key, when one is configured. |
onResponse |
(event: ResponseEvent) => void | undefined |
|
profile |
string |
|
retry |
RetryPolicy |
|
socketUrl |
string |
|
timeoutMs |
number |
|
verifyTls |
boolean |
|
host |
string |
The exchange host, e.g. "demo.stxapp.io": the name STXNotAvailableException and capabilities() report. |
Methods
Section titled “Methods”acceptTerms()
Section titled “acceptTerms()”acceptTerms(deviceId: string, opts?: AcceptTermsOptions): Promise<string>POST /api/v1/tnc/accept: accept the current terms for your own account,
with your own API key. Resolves to the server’s message.
An app cannot accept the terms for a member: called with a member’s OAuth
access token, the exchange answers 403 terms_not_delegable
(STXForbiddenException). The member accepts on an STX page instead.
| Parameter | Type | Description |
|---|---|---|
deviceId |
string |
|
opts (optional) |
AcceptTermsOptions |
|
opts.acceptHouseRules (optional) |
boolean |
|
opts.acceptPrivacy (optional) |
boolean |
|
opts.acceptTerms (optional) |
boolean |
Returns Promise<string>.
accountMarketStats()
Section titled “accountMarketStats()”accountMarketStats(query?: MarketStatsQuery): Promise<Page<MarketStat>>GET /api/v1/account/market_stats: your exposure and P&L per market.
Not the market_stats WebSocket channel, which carries price history.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
MarketStatsQuery |
|
query.competitions (optional) |
StrList |
|
query.cursor (optional) |
string |
|
query.eventIds (optional) |
StrList |
|
query.excludeZeroSettlements (optional) |
boolean |
|
query.fromTime (optional) |
number |
|
query.limit (optional) |
number |
|
query.marketIds (optional) |
StrList |
|
query.sports (optional) |
StrList |
|
query.toTime (optional) |
number |
|
query.unsettledOnly (optional) |
boolean |
Only markets not yet resulted or voided, ordered by market id so a row keeps its place between pages. Not combinable with fromTime, toTime or excludeZeroSettlements: true. |
Returns Promise<Page<MarketStat>>.
adjustments()
Section titled “adjustments()”adjustments(query?: PageQuery): Promise<Page<PaymentTransaction>>GET /api/v1/portfolio/adjustments: manual balance adjustments.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
PageQuery |
|
query.cursor (optional) |
string |
|
query.limit (optional) |
number |
Returns Promise<Page<PaymentTransaction>>.
balance()
Section titled “balance()”balance(): Promise<Balance>GET /api/v1/account/balance: balance, liabilities and fee schedule.
The same object the balances channel pushes.
Returns Promise<Balance>.
cancelAllOrders()
Section titled “cancelAllOrders()”cancelAllOrders(): Promise<Cancellation[]>DELETE /api/v1/orders/all: cancel everything resting on the account.
Returns Promise<Cancellation[]>.
cancelOrder()
Section titled “cancelOrder()”cancelOrder(orderId: string): Promise<Cancellation>DELETE /api/v1/orders/{order_id}: request a cancel. A cancel is a
request: a fill already in flight can still land.
| Parameter | Type | Description |
|---|---|---|
orderId |
string |
Returns Promise<Cancellation>.
cancelOrders()
Section titled “cancelOrders()”cancelOrders(orderIds: readonly string[]): Promise<Cancellation[]>DELETE /api/v1/orders/batched: cancel the named orders.
| Parameter | Type | Description |
|---|---|---|
orderIds |
readonly string[] |
Returns Promise<Cancellation[]>.
capabilities()
Section titled “capabilities()”capabilities(opts?: { refresh?: boolean }): Promise<Capabilities>Which features this exchange has, from what it publishes: its OAuth
discovery document, a signed GET of the routes that not
every exchange has yet, and a join of a combos topic nobody owns. Nothing
is created or changed. Checked once per client and cached; pass
{ refresh: true } to check again.
const caps = await stx.capabilities();caps.features.combos; // false on demo.stxapp.cacaps.require("combos"); // throws STXNotAvailableException thereEach feature is true, false, or null when it could not be checked
(no credentials for a signed check, or no answer). A missing feature never
throws here; the call that needs it throws STXNotAvailableException.
| Parameter | Type | Description |
|---|---|---|
opts (optional) |
{ refresh?: boolean } |
|
opts.refresh (optional) |
boolean |
Returns Promise<Capabilities>.
close()
Section titled “close()”close(): Promise<void>Nothing to release (fetch pools connections itself); present so await using and explicit cleanup work.
Returns Promise<void>.
createMarkets()
Section titled “createMarkets()”createMarkets(eventId: string, markets: readonly NewMarketInput[], opts?: CreateMarketsOptions): Promise<CreateMarketResult[]>POST /api/v1/markets: create markets on a scheduled event, up to
MAX_MARKETS_PER_REQUEST per call. Each market names its rule and the
fields that rule takes. Needs an OAuth app token with markets.write,
which STX grants, from an address on the client’s IP allow-list (it
applies to every call that client makes).
Returns one result per market, in order: created or exists (both with
market_id), valid with dryRun, or rejected with a reason. Each
result’s index is its position in markets, and market is that market
as requested. A rejected market is a
result, not an error, and resending is safe: a market that is already
listed comes back exists. A refused request throws (403 without
markets.write, 404 unknown event, 422 event not open).
Each line must be a positive number ending in .5, e.g. 18.5. More
than MAX_MARKETS_PER_REQUEST markets throws TypeError before any
request. dryRun runs every check and creates nothing. validate also
needs the events scope.
| Parameter | Type | Description |
|---|---|---|
eventId |
string |
|
markets |
readonly NewMarketInput[] |
|
opts (optional) |
CreateMarketsOptions |
|
opts.dryRun (optional) |
boolean |
Run every check on the exchange and create nothing. A market that would be created, or a repeat of one, comes back valid. |
opts.validate (optional) |
boolean |
Check each market against the event’s players and stats, and the line rule, before sending. Failing markets come back rejected without a request; the rest are sent with the event’s own stat key. The exchange checks every market either way. Reads eventPlayers(), so the token also needs the events scope. |
Returns Promise<CreateMarketResult[]>.
deposits()
Section titled “deposits()”deposits(query?: PageQuery): Promise<Page<PaymentTransaction>>GET /api/v1/portfolio/deposits.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
PageQuery |
|
query.cursor (optional) |
string |
|
query.limit (optional) |
number |
Returns Promise<Page<PaymentTransaction>>.
eventPlayers()
Section titled “eventPlayers()”eventPlayers(eventId: string): Promise<EventPlayers>GET /api/v1/events/{event_id}/players: the event’s team rosters and the
stats a market on it can use. teams is empty until the rosters are
published. Needs an OAuth app token with events, or an API key.
| Parameter | Type | Description |
|---|---|---|
eventId |
string |
Returns Promise<EventPlayers>.
events()
Section titled “events()”events(query?: EventsQuery): Promise<Page<Event>>GET /api/v1/events: one page of events.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
EventsQuery |
|
query.competitions (optional) |
StrList |
|
query.cursor (optional) |
string |
|
query.eventIds (optional) |
StrList |
|
query.eventTypes (optional) |
StrList |
|
query.limit (optional) |
number |
|
query.promoted (optional) |
boolean |
|
query.sortBy (optional) |
string |
"start_time". |
query.sortDirection (optional) |
"asc" | "desc" |
|
query.sports (optional) |
StrList |
|
query.status (optional) |
string |
scheduled, in_progress, completed or cancelled. |
query.title (optional) |
string |
Returns Promise<Page<Event>>.
fees()
Section titled “fees()”fees(query?: PageQuery): Promise<Page<FeeTransaction>>GET /api/v1/portfolio/fees: fee and fee-refund entries.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
PageQuery |
|
query.cursor (optional) |
string |
|
query.limit (optional) |
number |
Returns Promise<Page<FeeTransaction>>.
fills()
Section titled “fills()”fills(query?: FillsQuery): Promise<Page<Fill>>GET /api/v1/fills: one page of your executions.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
FillsQuery |
|
query.cursor (optional) |
string |
|
query.limit (optional) |
number |
|
query.marketIds (optional) |
StrList |
|
query.orderIds (optional) |
StrList |
|
query.status (optional) |
string |
created, open, settled or cancelled. |
Returns Promise<Page<Fill>>.
iterAccountMarketStats()
Section titled “iterAccountMarketStats()”iterAccountMarketStats(query?: WithoutCursor<MarketStatsQuery>): AsyncGenerator<MarketStat, void, undefined>Every per-market stat row, following the cursor.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
WithoutCursor<MarketStatsQuery> |
|
query.competitions (optional) |
StrList |
|
query.eventIds (optional) |
StrList |
|
query.excludeZeroSettlements (optional) |
boolean |
|
query.fromTime (optional) |
number |
|
query.limit (optional) |
number |
|
query.marketIds (optional) |
StrList |
|
query.sports (optional) |
StrList |
|
query.toTime (optional) |
number |
|
query.unsettledOnly (optional) |
boolean |
Only markets not yet resulted or voided, ordered by market id so a row keeps its place between pages. Not combinable with fromTime, toTime or excludeZeroSettlements: true. |
Returns AsyncGenerator<MarketStat, void, undefined>.
iterAdjustments()
Section titled “iterAdjustments()”iterAdjustments(query?: { limit?: number }): AsyncGenerator<PaymentTransaction, void, undefined>Every adjustment, following the cursor.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
{ limit?: number } |
|
query.limit (optional) |
number |
Returns AsyncGenerator<PaymentTransaction, void, undefined>.
iterDeposits()
Section titled “iterDeposits()”iterDeposits(query?: { limit?: number }): AsyncGenerator<PaymentTransaction, void, undefined>Every deposit, following the cursor.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
{ limit?: number } |
|
query.limit (optional) |
number |
Returns AsyncGenerator<PaymentTransaction, void, undefined>.
iterEvents()
Section titled “iterEvents()”iterEvents(query?: WithoutCursor<EventsQuery>): AsyncGenerator<Event, void, undefined>Every event matching the filters, following the cursor.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
WithoutCursor<EventsQuery> |
|
query.competitions (optional) |
StrList |
|
query.eventIds (optional) |
StrList |
|
query.eventTypes (optional) |
StrList |
|
query.limit (optional) |
number |
|
query.promoted (optional) |
boolean |
|
query.sortBy (optional) |
string |
"start_time". |
query.sortDirection (optional) |
"asc" | "desc" |
|
query.sports (optional) |
StrList |
|
query.status (optional) |
string |
scheduled, in_progress, completed or cancelled. |
query.title (optional) |
string |
Returns AsyncGenerator<Event, void, undefined>.
iterFees()
Section titled “iterFees()”iterFees(query?: { limit?: number }): AsyncGenerator<FeeTransaction, void, undefined>Every fee entry, following the cursor.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
{ limit?: number } |
|
query.limit (optional) |
number |
Returns AsyncGenerator<FeeTransaction, void, undefined>.
iterFills()
Section titled “iterFills()”iterFills(query?: WithoutCursor<FillsQuery>): AsyncGenerator<Fill, void, undefined>Every fill matching the filters, following the cursor.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
WithoutCursor<FillsQuery> |
|
query.limit (optional) |
number |
|
query.marketIds (optional) |
StrList |
|
query.orderIds (optional) |
StrList |
|
query.status (optional) |
string |
created, open, settled or cancelled. |
Returns AsyncGenerator<Fill, void, undefined>.
iterLoyalty()
Section titled “iterLoyalty()”iterLoyalty(query?: { limit?: number }): AsyncGenerator<Transaction, void, undefined>Every loyalty entry, following the cursor. Throws like loyalty().
| Parameter | Type | Description |
|---|---|---|
query (optional) |
{ limit?: number } |
|
query.limit (optional) |
number |
Returns AsyncGenerator<Transaction, void, undefined>.
iterMarkets()
Section titled “iterMarkets()”iterMarkets(query?: WithoutCursor<MarketsQuery>): AsyncGenerator<Market, void, undefined>Every market matching the filters, following the cursor.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
WithoutCursor<MarketsQuery> |
|
query.competitions (optional) |
StrList |
|
query.eventIds (optional) |
StrList |
|
query.limit (optional) |
number |
Default 100, maximum 200. |
query.marketIds (optional) |
StrList |
|
query.sortBy (optional) |
string |
"event_start". |
query.sortDirection (optional) |
"asc" | "desc" |
|
query.sports (optional) |
StrList |
|
query.status (optional) |
StrList |
One status or a list, e.g. ["pre_open", "open"]. |
query.trading (optional) |
boolean |
true for only the markets accepting orders now, false for only those that are not. |
Returns AsyncGenerator<Market, void, undefined>.
iterOrders()
Section titled “iterOrders()”iterOrders(query?: WithoutCursor<OrdersQuery>): AsyncGenerator<Order, void, undefined>Every order matching the filters, following the cursor.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
WithoutCursor<OrdersQuery> |
|
query.clientOrderIds (optional) |
StrList |
|
query.limit (optional) |
number |
|
query.marketIds (optional) |
StrList |
|
query.orderIds (optional) |
StrList |
|
query.status (optional) |
StrList |
One status or a list, e.g. ["accepted", "delayed", "open"]. |
Returns AsyncGenerator<Order, void, undefined>.
iterSettlements()
Section titled “iterSettlements()”iterSettlements(query?: WithoutCursor<SettlementsQuery>): AsyncGenerator<Settlement, void, undefined>Every settlement, following the cursor.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
WithoutCursor<SettlementsQuery> |
|
query.limit (optional) |
number |
|
query.marketIds (optional) |
StrList |
|
query.type (optional) |
string |
closed_short, closed_long, expired_short or expired_long. |
Returns AsyncGenerator<Settlement, void, undefined>.
iterWithdrawals()
Section titled “iterWithdrawals()”iterWithdrawals(query?: { limit?: number }): AsyncGenerator<PaymentTransaction, void, undefined>Every withdrawal, following the cursor.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
{ limit?: number } |
|
query.limit (optional) |
number |
Returns AsyncGenerator<PaymentTransaction, void, undefined>.
leaderboard()
Section titled “leaderboard()”leaderboard(query?: LeaderboardQuery): Promise<Leaderboard>GET /api/v1/leaderboard: ranked members for a period, sport and metric.
Rows carry a public handle and avatar, never an account id. Throws
STXNotAvailableException (feature leaderboard) where the exchange does
not have the leaderboard.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
LeaderboardQuery |
|
query.category (optional) |
string |
all or a sport key. |
query.limit (optional) |
number |
|
query.metric (optional) |
string |
volume, profit, predictions, markets, win_rate, biggest_win, return or streak. |
query.period (optional) |
string & { } | "daily" | "weekly" | "monthly" | "yearly" | "all" |
daily, weekly, monthly, yearly or all. |
Returns Promise<Leaderboard>.
leaderboardMe()
Section titled “leaderboardMe()”leaderboardMe(query?: Pick<LeaderboardQuery, "period" | "category">): Promise<LeaderboardStanding>GET /api/v1/leaderboard/me: your own standing, including your rank outside the list.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
Pick<LeaderboardQuery, "period" | "category"> |
Returns Promise<LeaderboardStanding>.
loyalty()
Section titled “loyalty()”loyalty(query?: PageQuery): Promise<Page<Transaction>>GET /api/v1/portfolio/loyalty: loyalty entries. Throws
STXNotAvailableException (feature loyalty) where the exchange has the
loyalty program switched off.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
PageQuery |
|
query.cursor (optional) |
string |
|
query.limit (optional) |
number |
Returns Promise<Page<Transaction>>.
market()
Section titled “market()”market(marketId: string): Promise<Market>One market by id. Throws STXNotFoundException if there is none.
| Parameter | Type | Description |
|---|---|---|
marketId |
string |
Returns Promise<Market>.
markets()
Section titled “markets()”markets(query?: MarketsQuery): Promise<Page<Market>>GET /api/v1/markets: one page of markets. Filters combine with AND;
list filters match any value.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
MarketsQuery |
|
query.competitions (optional) |
StrList |
|
query.cursor (optional) |
string |
|
query.eventIds (optional) |
StrList |
|
query.limit (optional) |
number |
Default 100, maximum 200. |
query.marketIds (optional) |
StrList |
|
query.sortBy (optional) |
string |
"event_start". |
query.sortDirection (optional) |
"asc" | "desc" |
|
query.sports (optional) |
StrList |
|
query.status (optional) |
StrList |
One status or a list, e.g. ["pre_open", "open"]. |
query.trading (optional) |
boolean |
true for only the markets accepting orders now, false for only those that are not. |
Returns Promise<Page<Market>>.
marketTypes()
Section titled “marketTypes()”marketTypes(): Promise<MarketTypes>GET /api/v1/types: the market types, keyed by rule. One with
partner_create: true can be created with createMarkets(), and lists
the fields an entry takes and, per event type, the stats on offer. It
changes only when STX adds a rule or a stat, so read it once and keep it.
Needs an OAuth app token with events, or an API key.
Returns Promise<MarketTypes>.
me(): Promise<Me>GET /api/v1/me: who this key belongs to. Returns the user_id the
account channels are keyed by, the account_id, and the key’s scope
(read_only or read_write).
Returns Promise<Me>.
order()
Section titled “order()”order(orderId: string): Promise<Order>GET /api/v1/orders/{order_id}: one of your orders.
| Parameter | Type | Description |
|---|---|---|
orderId |
string |
Returns Promise<Order>.
orders()
Section titled “orders()”orders(query?: OrdersQuery): Promise<Page<Order>>GET /api/v1/orders: one page of your orders, newest first.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
OrdersQuery |
|
query.clientOrderIds (optional) |
StrList |
|
query.cursor (optional) |
string |
|
query.limit (optional) |
number |
|
query.marketIds (optional) |
StrList |
|
query.orderIds (optional) |
StrList |
|
query.status (optional) |
StrList |
One status or a list, e.g. ["accepted", "delayed", "open"]. |
Returns Promise<Page<Order>>.
placeOrder()
Section titled “placeOrder()”placeOrder(marketId: string, action: string, orderType: string, opts: OrderOptions): Promise<Order>POST /api/v1/orders: place one order.
action is "buy" or "sell"; orderType is "limit" or "market".
price (dollars, required for a limit order) and quantity (contracts)
are decimal strings, e.g. { price: "0.58", quantity: "100" }. Numbers are
refused client-side.
fillMode (limit orders only) is "normal" (the default), "post_only"
or "fill_or_kill". A post-only order that would match on arrival is not
placed: this throws STXPostOnlyWouldMatchException. A fill-or-kill order
comes back accepted (or delayed in play); follow it on the orders
channel or with order() to see it filled or cancelled.
The exchange decides whether it takes either mode. Where a mode is not
enabled it rejects the order and this throws STXNotAvailableException
(orders.post_only, orders.fill_or_kill). An exchange on a release from
before fill modes places the order as a normal limit order. A combination
market throws STXFillModeNotAllowedException.
The exchange validates the order: a bad price step or a fractional
quantity throws STXValidationException (400) or STXRejectedException
(422) with the API’s message. An order from outside the region is also
an STXRejectedException.
A POST is never retried after a 5xx or a dropped connection; pass
clientOrderId so you can look the order up if that happens.
| Parameter | Type | Description |
|---|---|---|
marketId |
string |
|
action |
string |
|
orderType |
string |
|
opts |
OrderOptions |
|
opts.cancelOnDisconnect (optional) |
boolean |
|
opts.clientOrderId (optional) |
string |
|
opts.deviceId (optional) |
string |
|
opts.expiration (optional) |
string |
"good_till_start" or "good_till_time". |
opts.expirationTime (optional) |
number |
Unix microseconds, with expiration: "good_till_time". |
opts.fillMode (optional) |
FillMode |
"normal" (the default), "post_only" (only ever rests on the book as a maker) or "fill_or_kill" (fills in full or not at all). Limit orders only. |
opts.price (optional) |
string |
Dollars, as a decimal string: "0.58". Required for a limit order. |
opts.quantity |
string |
Contracts, as a decimal string: "100". |
Returns Promise<Order>.
placeOrders()
Section titled “placeOrders()”placeOrders(orders: readonly NewOrderInput[]): Promise<BatchOrderResult[]>POST /api/v1/orders/batched: place several orders in one call. Returns
one result per order, in order; a rejected order has errors instead of
order and does not stop the others. A post-only order that would have
matched comes back as its order, cancelled with cancellation_reason
auto_matching.
When the exchange rejects the call because a fillMode is not enabled
there, this throws STXNotAvailableException, as placeOrder() does.
| Parameter | Type | Description |
|---|---|---|
orders |
readonly NewOrderInput[] |
Returns Promise<BatchOrderResult[]>.
positions()
Section titled “positions()”positions(query?: { marketIds?: StrList }): Promise<Position[]>GET /api/v1/positions: your open positions, the same objects the
positions channel sends on join. position is positive when long,
negative when short.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
{ marketIds?: StrList } |
|
query.marketIds (optional) |
StrList |
Returns Promise<Position[]>.
settlements()
Section titled “settlements()”settlements(query?: SettlementsQuery): Promise<Page<Settlement>>GET /api/v1/portfolio/settlements: settlements on your account.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
SettlementsQuery |
|
query.cursor (optional) |
string |
|
query.limit (optional) |
number |
|
query.marketIds (optional) |
StrList |
|
query.type (optional) |
string |
closed_short, closed_long, expired_short or expired_long. |
Returns Promise<Page<Settlement>>.
statsFor()
Section titled “statsFor()”statsFor(event: string | { event_id?: string | null }): Promise<EventStat[]>The stats event accepts for new markets.
| Parameter | Type | Description |
|---|---|---|
event |
string | { event_id?: string | null } |
Returns Promise<EventStat[]>.
updateProfile()
Section titled “updateProfile()”updateProfile(update: ProfileUpdate): Promise<Me>PATCH /api/v1/me/profile: change your public handle, avatar or
leaderboard opt-in. Resolves to the updated me.
| Parameter | Type | Description |
|---|---|---|
update |
ProfileUpdate |
|
update.avatar (optional) |
Record<string, unknown> | null |
A new avatar. Any style/palette pairing renders; the seed selects the pattern. null is refused (400). |
update.handle (optional) |
string | null |
New public handle: 3-24 characters of lowercase letters, digits and inner . or _; case is folded. Must be unused, not a reserved word and not blocked. May be changed once every 30 days; re-sending your current handle is not a change. A blank handle is refused (422). |
update.leaderboard_opt_in (optional) |
boolean | null |
Your consent to appear on public boards. true joins, false leaves; your own standing is unaffected. Each change is recorded with its time. Joining gives you a generated handle and avatar if you have none yet. |
Returns Promise<Me>.
userId()
Section titled “userId()”userId(): Promise<string>The user id from me(), fetched once and cached. If me() is not
permitted, the id comes from balance(), which carries the same
user_id.
Returns Promise<string>.
websocket()
Section titled “websocket()”websocket(opts?: Omit<STXWebSocketOptions, "rest">): STXWebSocketAn STXWebSocket using this client’s host and key. Account channels
need your user id; the socket fetches it through me() on first use.
| Parameter | Type | Description |
|---|---|---|
opts (optional) |
Omit<STXWebSocketOptions, "rest"> |
|
opts.channelPingIntervalMs (optional) |
number | null |
Milliseconds between channel ping frames on every joined topic that answers them; null disables them. orders with cancel-on-disconnect pings faster, from the granted timeout. Default 30000. The market:<id>, rfq: and combo_quote: topics have no ping command and are never pinged; the socket heartbeat keeps them alive. |
opts.env (optional) |
string | null |
"production" or "demo" ("prod" and "live" are accepted). |
opts.environment (optional) |
string | STXEnvironment |
A published environment, Environments.OntarioDemo, or its name, "ontario-demo". Instead of region + env; host still wins. |
opts.heartbeatIntervalMs (optional) |
number |
Milliseconds between socket heartbeats. The server closes a socket silent for 60 s. Default 25000. |
opts.host (optional) |
string | null |
A hostname or URL, overriding region/env: "demo.stxapp.ca", "http://localhost:4000". |
opts.joinTimeoutMs (optional) |
number |
Milliseconds to wait for a join or push reply. Default 10000. |
opts.keyId (optional) |
string | null |
The API key ID. |
opts.logger (optional) |
Logger |
|
opts.onReconnect (optional) |
() => void | Promise<void> |
Called after every successful reconnect and rejoin, and after rejoining a channel the server closed or errored while the socket stayed up: the moment to read open orders and anything else you loaded with STX again. |
opts.privateKey (optional) |
PrivateKeyInput | null |
The Ed25519 private key: PEM text, a path to a PEM file, PEM bytes, or a KeyObject. |
opts.profile (optional) |
string | null |
A section of ~/.stx/credentials to read. |
opts.queueSize (optional) |
number |
Messages buffered per channel for iteration; the oldest is dropped when full. Default 10000. |
opts.reconnect (optional) |
boolean |
Reconnect after a drop. Default true. |
opts.reconnectPolicy (optional) |
ReconnectPolicy |
|
opts.region (optional) |
string | null |
A known region, e.g. "ontario" or "us". With env, picks the host. |
opts.signer (optional) |
Signer |
Instead of privateKey: signs message bytes, for keys in an HSM or KMS. |
opts.userId (optional) |
string |
Your user id, if you already have it (skips GET /me). |
opts.verifyTls (optional) |
boolean | null |
Set false only for a local server. Honoured by the WebSocket; for HTTP requests, pass a fetch whose dispatcher skips verification (Node’s global fetch has no per-call switch). |
Returns STXWebSocket.
withdrawals()
Section titled “withdrawals()”withdrawals(query?: PageQuery): Promise<Page<PaymentTransaction>>GET /api/v1/portfolio/withdrawals.
| Parameter | Type | Description |
|---|---|---|
query (optional) |
PageQuery |
|
query.cursor (optional) |
string |
|
query.limit (optional) |
number |
Returns Promise<Page<PaymentTransaction>>.

