Skip to content

Markets

Describes github.com/stxapp/stx-go v0.3.1, the current release.

package main
import (
"context"
"fmt"
"log"
stx "github.com/stxapp/stx-go"
)
func main() {
ctx := context.Background()
client, err := stx.New()
if err != nil {
log.Fatal(err)
}
page, err := client.Markets.List(ctx, &stx.MarketsQuery{Status: []string{"open"}, Limit: 5})
if err != nil {
log.Fatal(err)
}
for _, m := range page.Items {
bid, offer := "-", "-"
if len(m.Bids) > 0 {
bid = m.Bids[0].Price.String()
}
if len(m.Offers) > 0 {
offer = m.Offers[len(m.Offers)-1].Price.String()
}
fmt.Println(m.Symbol, "last", m.LastTradedPrice, "bid", bid, "offer", offer)
}
fmt.Println("more pages:", page.HasMore())
}

Sample output (two of the five markets):

STXNHL-26OCT101600EDMSJ-GAMEEDM last 0.5800 bid 0.5800 offer 0.6100
STXNHL-26OCT101600EDMSJ-SOGSJCMCDAVID209555-3.5 last 0.5200 bid 0.4900 offer 0.5400
more pages: true

stx.MarketsQuery fields:

Field Meaning
MarketIDs, EventIDs One id or several
Status One or several, lowercase, e.g. "open"; see Market status
Trading stx.Bool(true) for only the markets accepting orders now, stx.Bool(false) for only those that are not; nil for both
Sports, Competitions One or several
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. A nil query lists every market. client.Markets.Get(ctx, marketID) fetches one market and returns an error matching stx.ErrNotFound when there is none.

A list method returns one *stx.Page[T]: page.Items, page.Cursor (empty on the last page) and page.HasMore(). To walk every page, use the All twin, which follows the cursor for you and stops when you break out of the loop:

var market stx.Market
for m, err := range client.Markets.All(ctx, &stx.MarketsQuery{
Status: []string{"open"},
Trading: stx.Bool(true),
SortBy: "event_start",
SortDirection: "desc",
}) {
if err != nil {
log.Fatal(err)
}
if m.EventStatus == "scheduled" {
market = m
break
}
}
fmt.Println(market.MarketID, market.Symbol, market.MaxPrice)
// e00651a3-10cb-4bc1-9e1f-c5ea1796c83b STXNHL-26OCT101600EDMSJ-GAMEEDM 1.0000

Status: []string{"open"} with Trading: stx.Bool(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. Read the price ceiling from MaxPrice rather than assuming one.

Or page by hand:

q := &stx.MarketsQuery{Status: []string{"open"}, Limit: 100}
for {
page, err := client.Markets.List(ctx, q)
if err != nil {
log.Fatal(err)
}
for _, m := range page.Items {
fmt.Println(m.Symbol)
}
if !page.HasMore() {
break
}
q.Cursor = page.Cursor
}
events, err := client.Events.List(ctx, &stx.EventsQuery{Limit: 10})
if err != nil {
log.Fatal(err)
}
for _, e := range events.Items {
fmt.Println(e.EventID, 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 e, err := range client.Events.All(ctx, &stx.EventsQuery{Promoted: stx.Bool(true)}) {
if err != nil {
log.Fatal(err)
}
fmt.Println(e.Title)
}

stx.EventsQuery filters on EventIDs, Sports, Competitions, EventTypes, Title, Status and Promoted, and sorts with SortBy and SortDirection.

Bids and Offers are a snapshot of the top of the book. To follow prices as they move, stream them; see WebSockets. An app can also create markets on scheduled events; see Create markets.

STX is operated by XV Exchange, LLC, a Designated Contract Market regulated by the U.S. Commodity Futures Trading Commission (CFTC). Contracts traded on STX are cleared by XV Clearing, LLC, a CFTC-registered Derivatives Clearing Organization. Trading involves substantial risk of loss and may not be appropriate for everyone. Members risk losing the cost to enter any transaction, including fees. Consider whether trading is appropriate for you in light of your experience and financial resources. Nothing on this site is investment advice or a recommendation to trade. Past performance is not indicative of future results.

© 2026 STX. All rights reserved.llms.txtllms-full.txtView as Markdown
Docs version v1.10.5