What you can do
Describes github.com/stxapp/stx-go v0.3.1, the current release.
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
Section titled “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, WebSockets | |
| Trading | Orders.Place, Orders.PlaceBatch, Orders.Cancel, Orders.CancelBatch, Orders.CancelAll, Orders.Get, Orders.List |
Trading | |
| Your account | Account.Me, Account.Balance, Account.Positions, Portfolio.*; stream.AccountView and the account channels |
Portfolio | |
| Event players | event_players |
Events.Players, stx.KnownStats |
Create markets |
| Leaderboard and public profile | leaderboard |
Leaderboard.Get, Leaderboard.Me, Account.UpdateProfile |
Leaderboard |
| Combos | combos |
Combos.Player, Combos.Maker, Combos.Available, or ComboPlayer and ComboMaker on a stream |
Combos |
| OAuth | oauth |
oauth.Discover, oauth.DiscoverMetadata |
Apps |
| Members connect their STX account | oauth.member |
Begin, Complete, MemberClient, Refresh, Unlink on an *oauth.Client |
Apps |
| App tokens | oauth.app |
AppClient, AppToken, ClientCredentials on an *oauth.Client |
Apps |
| Sign in with STX | connect |
oauth.NewSignIn: Start, Finish, Refresh, UserInfo, Disconnect |
Sign in with STX |
| Terms accepted on an STX page | terms.stx_page |
APIError.TermsURL on stx.ErrTermsRequired, oauth.TermsURLWithReturn, SessionOptions.OnTermsRequired |
Apps |
| Creating markets | markets.create |
Markets.Create, as an app holding markets.write |
Create markets |
| Market types | market_types |
Markets.Types |
Create markets |
Features without an id are on every exchange.
Where each feature is available
Section titled “Where each feature is available”Which exchange has which feature is listed on 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
Section titled “Ask the exchange”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:
demo.stxapp.ca 3.3.194-5combos: true oauth: falsecaps.Featuresmaps each id totrue,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.NotAvailableErrorwhen 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
Section titled “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. |
The OAuth discovery document and its fields are described in OAuth, and the combo topics in Combo negotiation.
When a feature is not available
Section titled “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_onlyororders.fill_or_killwhen the exchange rejects an order because that fill mode is not enabled there (see Post-only and fill-or-kill), orscope:<name>for a scope the exchange does not offer.Host: the exchange that answered.
types, err := client.Markets.Types(ctx)var na *stx.NotAvailableErrorif 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")}
