# Go SDK

> The Go SDK for the STX exchange.

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

`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](/websockets/), with every request signed by your API key. Response fields are described in the [API reference](/api/rest/).

```bash
go get github.com/stxapp/stx-go
```

```go
package 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)
	}
}
```

```text
e6528824-b4e0-4ff8-bd70-36e5904738d1
STXNHL-26OCT101600EDMSJ-GAMEEDM
STXNHL-26OCT101600EDMSJ-SOGSJCMCDAVID209555-3.5
STXNHL-26OCT101600EDMSJ-SOGEDMCMCDAVID97-3.5
STXNBA-26OCT102000LALGSW-GAMELAL
STXNBA-26OCT102000LALGSW-PTSLALLJAMES23-24.5
```

[Authentication](/sdks/go/authentication/) shows how to give the client your API key, and [Environments](/environments/) lists the exchanges and where to get a key. [What you can do](/sdks/go/capabilities/) maps every feature to its SDK calls and shows which exchange has which.

## How the SDK is shaped

- **One client.** `stx.New` returns a `*stx.Client` with a field per area: `client.Account`, `client.Markets`, `client.Events`, `client.Orders`, `client.Portfolio`, `client.Leaderboard` and `client.Combos`. Create it once and share it: it is safe for concurrent use.
- **Context first.** Every call takes a `context.Context` as 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 as `stx.ErrNotFound` and `stx.ErrRateLimited` work with `errors.Is`. See [Errors & retries](/sdks/go/errors-and-retries/).
- **Iterators for paging.** List methods return one `*stx.Page[T]`; their `All` twins return an `iter.Seq2[T, error]` that follows the cursor for you. See [Markets](/sdks/go/markets#pagination).

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

- [What you can do](/sdks/go/capabilities/): Every feature, its SDK calls, and where it is available.
- [Installation](/sdks/go/installation/): Add the module and import it.
- [Authentication](/sdks/go/authentication/): Pass your API key to the client.
- [Environments](/sdks/go/environments/): Pick the exchange to connect to.
- [Markets](/sdks/go/markets/): Markets, events and pagination.
- [Trading](/sdks/go/trading/): Place and cancel orders.
- [Portfolio](/sdks/go/portfolio/): Balance, positions, fills and history.
- [WebSockets](/sdks/go/websockets/): Stream channels and keep a live account view.
- [Combos](/sdks/go/combos/): Request and quote combos.
- [Apps](/sdks/go/apps/): Act for members with OAuth, and call app routes with an app token.
- [Errors & retries](/sdks/go/errors-and-retries/): Typed errors and what the client retries.
- [API reference](/sdks/go/reference/): Every type, function and method.
- [Example programs](https://github.com/stxapp/stx-go-demo): List markets, place and cancel an order, stream live data.

Released under the MIT license.
