Skip to content

MarketsService

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

type MarketsService struct {
// contains filtered or unexported fields
}

MarketsService lists markets and market types, and creates markets. Use it through Client.Markets.

func (s *MarketsService) All(ctx context.Context, q *MarketsQuery) iter.Seq2[Market, error]

All returns every market matching q, following the cursor. q.Cursor is ignored.

Example

List open markets with their best bid and offer.

ctx := context.Background()
client, err := stx.New()
if err != nil {
log.Fatal(err)
}
for market, err := range client.Markets.All(ctx, &stx.MarketsQuery{Status: []string{"open"}, Trading: stx.Bool(true)}) {
if err != nil {
log.Fatal(err)
}
var bid, offer stx.Decimal
if len(market.Bids) > 0 {
bid = market.Bids[0].Price
}
if len(market.Offers) > 0 {
offer = market.Offers[len(market.Offers)-1].Price // sorted highest first
}
fmt.Printf("%s bid %s offer %s\n", market.Symbol, bid, offer)
}
func (s *MarketsService) Create(ctx context.Context, eventID string, markets []NewMarket, opts *CreateMarketsOptions) ([]CreateMarketResult, error)

Create creates markets on a scheduled event (POST /api/v1/markets), 1 to MaxMarketsPerRequest per call. It needs an app token with markets.write, which STX grants, sent from an address on the app’s IP allow-list. See https://docs.stxapp.io/apps/creating-markets/.

It returns one result per market, in order. A rejected market is a result, not an error, and resending is safe: a market already listed comes back MarketExists. A refused request is an error: a 403 without markets.write, ErrNotFound for an unknown event, ErrRejected for an event that is not open. Where the exchange cannot create markets the error matches ErrNotAvailable.

func (s *MarketsService) Get(ctx context.Context, marketID string) (*Market, error)

Get returns one market by id. It returns an error matching ErrNotFound when there is none.

func (s *MarketsService) List(ctx context.Context, q *MarketsQuery) (*Page[Market], error)

List returns one page of markets (GET /api/v1/markets).

func (s *MarketsService) Types(ctx context.Context) (MarketTypes, error)

Types returns the market types (GET /api/v1/types). It changes only when STX adds a rule or a stat, so read it once and keep it. It needs an API key or an OAuth app token with the events scope, and returns an error matching ErrNotAvailable where the exchange does not have it.

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