# What you can do

> Every feature of the Go SDK, the calls that use it, and which STX exchange has it today.

Source: https://docs.stxapp.io/sdks/go/capabilities/

One SDK works against every STX exchange. Not every exchange has every feature yet: OAuth apps are on US demo first, for example. A call that needs a feature the exchange does not have returns an error matching `stx.ErrNotAvailable`, and `client.Capabilities` tells you up front, so the same code runs against Ontario production today and picks up new features as each exchange gets them.

## Features and their calls

| Feature | Id | SDK calls | Guide |
|---|---|---|---|
| Markets, events and prices | | `Markets.List`, `Markets.All`, `Markets.Get`, `Events.List`, `Events.All`; market data channels | [Markets](/sdks/go/markets/), [WebSockets](/sdks/go/websockets/) |
| Trading | | `Orders.Place`, `Orders.PlaceBatch`, `Orders.Cancel`, `Orders.CancelBatch`, `Orders.CancelAll`, `Orders.Get`, `Orders.List` | [Trading](/sdks/go/trading/) |
| Your account | | `Account.Me`, `Account.Balance`, `Account.Positions`, `Portfolio.*`; `stream.AccountView` and the account channels | [Portfolio](/sdks/go/portfolio/) |
| Event players | `event_players` | `Events.Players`, `stx.KnownStats` | [Create markets](/sdks/go/create-markets/) |
| Leaderboard and public profile | `leaderboard` | `Leaderboard.Get`, `Leaderboard.Me`, `Account.UpdateProfile` | [Leaderboard](/concepts/leaderboard/) |
| Combos | `combos` | `Combos.Player`, `Combos.Maker`, `Combos.Available`, or `ComboPlayer` and `ComboMaker` on a stream | [Combos](/sdks/go/combos/) |
| OAuth | `oauth` | `oauth.Discover`, `oauth.DiscoverMetadata` | [Apps](/sdks/go/apps/) |
| Members connect their STX account | `oauth.member` | `Begin`, `Complete`, `MemberClient`, `Refresh`, `Unlink` on an `*oauth.Client` | [Apps](/sdks/go/apps#connect-a-members-account) |
| App tokens | `oauth.app` | `AppClient`, `AppToken`, `ClientCredentials` on an `*oauth.Client` | [Apps](/sdks/go/apps#act-as-your-app) |
| Sign in with STX | `connect` | `oauth.NewSignIn`: `Start`, `Finish`, `Refresh`, `UserInfo`, `Disconnect` | [Sign in with STX](/sdks/go/sign-in-with-stx/) |
| Terms accepted on an STX page | `terms.stx_page` | `APIError.TermsURL` on `stx.ErrTermsRequired`, `oauth.TermsURLWithReturn`, `SessionOptions.OnTermsRequired` | [Apps](/sdks/go/apps#when-stx-has-new-terms-for-the-member) |
| Creating markets | `markets.create` | `Markets.Create`, as an app holding `markets.write` | [Create markets](/sdks/go/create-markets/) |
| Market types | `market_types` | `Markets.Types` | [Create markets](/sdks/go/create-markets#market-types) |

Features without an id are on every exchange.

## Where each feature is available

Which exchange has which feature is listed on [Environments](/environments/) and on each feature's page. Exchanges gain features with their releases, so ask the exchange rather than a table when your code needs to know.

## Ask the exchange

```go
caps, err := client.Capabilities(ctx, false)
if err != nil {
	log.Fatal(err)
}
fmt.Println(caps.Host, caps.APIVersion)
fmt.Println("combos:", caps.Has("combos"), "oauth:", caps.Has("oauth"))
```

On Ontario demo:

```text
demo.stxapp.ca 3.3.194-5
combos: true oauth: false
```

- `caps.Features` maps each id to `true`, `false`, or nil when it could not be checked (a check that needs credentials on a client without them, or an exchange that did not answer).
- `caps.Has("combos")` is true only when the exchange is known to have it.
- `caps.Require("combos")` returns a `*stx.NotAvailableError` when the exchange is known not to have it.

The answer is cached on the client; pass `true` to check again. A missing feature never makes `Capabilities` or `stx.New` fail, and the calls you already make are unaffected: only a call that needs the missing feature returns the error.

### How each feature is decided

Every check reads what the exchange publishes. Nothing is created, changed or canceled.

| Id | Available when |
|---|---|
| `oauth` | `GET /.well-known/oauth-authorization-server` returns the discovery document. |
| `oauth.member` | OAuth is on, `grant_types_supported` lists `authorization_code`, and `scopes_supported` lists a member scope such as `orders.read`. |
| `oauth.app` | OAuth is on and `grant_types_supported` lists `client_credentials`. |
| `connect` | OAuth is on and `scopes_supported` lists `openid`. |
| `terms.stx_page` | Members can connect and `scopes_supported` does not list `terms.write`. |
| `markets.create` | App tokens are on and `scopes_supported` lists `markets.write`. |
| `market_types` | A signed `GET /api/v1/types` answers. |
| `event_players` | A signed `GET /api/v1/events/{event_id}/players` route exists. |
| `leaderboard` | A signed `GET /api/v1/leaderboard?limit=1` answers. |
| `combos` | The exchange has the combo topics. |
| `orders.post_only`, `orders.fill_or_kill` | Deprecated. Always nil (unknown): the exchange does not publish which fill modes it takes. Send the order and handle the answer; see [Post-only and fill-or-kill](/sdks/go/trading#post-only-and-fill-or-kill). |

The OAuth discovery document and its fields are described in [OAuth](/oauth/), and the combo topics in [Combo negotiation](/websockets/channels/combo-negotiation/).

## When a feature is not available

The error is a `*stx.NotAvailableError`. It matches `stx.ErrNotAvailable`, and it unwraps to the answer it was decided from, so a 404 still matches `stx.ErrNotFound`. It carries:

- `Feature`: the id from the tables above, `orders.post_only` or `orders.fill_or_kill` when the exchange rejects an order because that fill mode is not enabled there (see [Post-only and fill-or-kill](/sdks/go/trading#post-only-and-fill-or-kill)), or `scope:<name>` for a scope the exchange does not offer.
- `Host`: the exchange that answered.

```go
types, err := client.Markets.Types(ctx)
var na *stx.NotAvailableError
if errors.As(err, &na) {
	fmt.Println(err)
	// Market types are not available on demo.stxapp.ca yet.
	fmt.Println(na.Feature, na.Host) // market_types demo.stxapp.ca
} else if err != nil {
	log.Fatal(err)
} else {
	fmt.Println(len(types), "market types")
}
```
