# Create markets

> Create player-prop markets on scheduled events, as an app holding markets.write.

Source: https://docs.stxapp.io/sdks/go/create-markets/

> **Availability.** Available on US demo now. See [Environments](https://docs.stxapp.io/environments/).

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](/apps/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](/sdks/go/capabilities/).

The calls run as your app, on an app token from the [oauth package](/sdks/go/apps#act-as-your-app):

```go
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.5` is accepted; `3`, `3.25` and `0` come back `rejected` with `invalid_line` (`stx.RejectInvalidLine`).
- **Stats**: an event accepts the stats `Events.Players` lists in `Stats`.
- **Results** come back one per market, in order: `stx.MarketCreated`, `stx.MarketExists` (already listed, same `MarketID`), `stx.MarketValid` (with `DryRun`) or `stx.MarketRejected` with a `Reason`. `Index` is the market's position in your list, and `Market` is the market as you asked for it. Resending is safe.
- **`DryRun: true`** runs every check on STX and creates nothing.
- **`Validate: true`** checks players, stats and lines before sending, and returns failures as rejected without a request. It reads the event's players, so the token also needs `events`.
- Up to `stx.MaxMarketsPerRequest` (25) markets per call.

## 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.

```go
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
```
