Describes github.com/stxapp/stx-go v0.3.1, the current release.
github.com/stxapp/stx-go is the Go SDK for the STX exchange. Read markets, place and cancel orders, follow your account, and stream the WebSocket channels, with every request signed by your API key. Response fields are described in the API reference.
go get github.com/stxapp/stx-gopackage main
import ( "context" "fmt" "log"
stx "github.com/stxapp/stx-go")
func main() { ctx := context.Background()
// Reads your API key and exchange from STX_* environment variables or ~/.stx/credentials. client, err := stx.New() if err != nil { log.Fatal(err) }
me, err := client.Account.Me(ctx) if err != nil { log.Fatal(err) } fmt.Println(me.UserID)
page, err := client.Markets.List(ctx, &stx.MarketsQuery{Status: []string{"open"}, Limit: 5}) if err != nil { log.Fatal(err) } for _, m := range page.Items { fmt.Println(m.Symbol) }}e6528824-b4e0-4ff8-bd70-36e5904738d1STXNHL-26OCT101600EDMSJ-GAMEEDMSTXNHL-26OCT101600EDMSJ-SOGSJCMCDAVID209555-3.5STXNHL-26OCT101600EDMSJ-SOGEDMCMCDAVID97-3.5STXNBA-26OCT102000LALGSW-GAMELALSTXNBA-26OCT102000LALGSW-PTSLALLJAMES23-24.5Authentication shows how to give the client your API key, and Environments lists the exchanges and where to get a key. What you can do maps every feature to its SDK calls and shows which exchange has which.
How the SDK is shaped
Section titled “How the SDK is shaped”- One client.
stx.Newreturns a*stx.Clientwith a field per area:client.Account,client.Markets,client.Events,client.Orders,client.Portfolio,client.Leaderboardandclient.Combos. Create it once and share it: it is safe for concurrent use. - Context first. Every call takes a
context.Contextas its first argument, so deadlines and cancellation work the way they do in the rest of your program. - Errors are values. Calls return an
error; nothing panics. API errors are*stx.APIError, and sentinels such asstx.ErrNotFoundandstx.ErrRateLimitedwork witherrors.Is. See Errors & retries. - Iterators for paging. List methods return one
*stx.Page[T]; theirAlltwins return aniter.Seq2[T, error]that follows the cursor for you. See Markets.
Prices and quantities are decimals
Section titled “Prices and quantities are decimals”Amounts are stx.Decimal, a string type that keeps the exact digits the API sends (order.Price == "0.5800"). Orders take decimals too: stx.MustDecimal("0.58"). Nothing in a money path is a float64. Decimal.Rat gives you a *big.Rat for arithmetic, and Decimal.Cmp compares two values numerically.
Where to go next
Section titled “Where to go next”Released under the MIT license.

