Create markets
Describes github.com/stxapp/stx-go v0.3.1, the current release.
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. Creating markets covers the setup and the full list of outcomes; this page shows the SDK calls. Where the exchange does not offer it yet, Markets.Create, Markets.Types and Events.Players return an error matching stx.ErrNotAvailable; see What you can do.
The calls run as your app, on an app token from the oauth package:
package main
import ( "context" "fmt" "log" "os"
stx "github.com/stxapp/stx-go" "github.com/stxapp/stx-go/oauth")
func main() { ctx := context.Background() app, err := oauth.New(oauth.Config{ BaseURL: "demo.stxapp.io", ClientID: os.Getenv("STX_OAUTH_CLIENT_ID"), ClientSecret: os.Getenv("STX_OAUTH_CLIENT_SECRET"), }) if err != nil { log.Fatal(err) } client, err := app.AppClient([]string{oauth.ScopeEvents, oauth.ScopeMarketsWrite}) if err != nil { log.Fatal(err) }
eventID := "24636b3d-f566-4dd3-8c8b-c1a6c2747789" roster, err := client.Events.Players(ctx, eventID) if err != nil { log.Fatal(err) } player := roster.Teams[0].Players[0] fmt.Println(player.PlayerID, player.Name, player.Jersey, player.Position) // 3895074 Connor McDavid 97 C
markets := []stx.NewMarket{{PlayerID: player.PlayerID, Stat: "GOAL_SO", Line: 3.5}}
// Check first: every check runs on STX and nothing is created. checked, err := client.Markets.Create(ctx, eventID, markets, &stx.CreateMarketsOptions{DryRun: true}) if err != nil { log.Fatal(err) } for _, r := range checked { if r.Status != stx.MarketValid && r.Status != stx.MarketExists { log.Fatalf("market %d: %s", r.Index, r.Reason) } }
results, err := client.Markets.Create(ctx, eventID, markets, nil) if err != nil { log.Fatal(err) } for _, r := range results { fmt.Println(r.Status, r.MarketID) } // created 2a473aeb-10de-47e4-a7ce-dbb771094d84}- Lines must be positive and end in
.5:3.5is accepted;3,3.25and0come backrejectedwithinvalid_line(stx.RejectInvalidLine). - Stats: an event accepts the stats
Events.Playerslists inStats. - Results come back one per market, in order:
stx.MarketCreated,stx.MarketExists(already listed, sameMarketID),stx.MarketValid(withDryRun) orstx.MarketRejectedwith aReason.Indexis the market’s position in your list, andMarketis the market as you asked for it. Resending is safe. DryRun: trueruns every check on STX and creates nothing.Validate: truechecks players, stats and lines before sending, and returns failures as rejected without a request. It reads the event’s players, so the token also needsevents.- Up to
stx.MaxMarketsPerRequest(25) markets per call.
Market types
Section titled “Market types”Markets.Types lists every market type the exchange has, keyed by rule. A type with PartnerCreate set can be created with Markets.Create, 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.
types, err := client.Markets.Types(ctx)if err != nil { log.Fatal(err)}psl := types[stx.RulePlayerStatLine]fmt.Println(len(types), psl.PartnerCreate, len(psl.EventTypes))// 57 true 4
