Go API wrapper for the Tastytrade Open API
This project provides a Go wrapper for the Tastytrade Open API. It allows developers to interact with Tastytrade's financial data and services in a more Go-idiomatic way, abstracting away the details of direct HTTP requests and responses.
To install this project, you can use go get:
go get github.com/optionsvamp/tastytradeThen, import it in your Go code:
import "github.com/optionsvamp/tastytrade"
The client supports two authentication methods.
Session (username/password) — POST /sessions; token is sent as Bearer on subsequent requests:
api := tastytrade.NewTastytradeAPI()
err := api.Authenticate(os.Getenv("TT_USER"), os.Getenv("TT_PASSWORD"))OAuth2 (recommended) — Use an OAuth client registered with Tastytrade. Obtain a refresh token via the Tastytrade UI, then pass it to AuthenticateOAuth2. Access tokens expire in 15 minutes; the client refreshes them automatically.
api := tastytrade.NewTastytradeAPI()
err := api.AuthenticateOAuth2(clientID, clientSecret, refreshToken)All requests include the required User-Agent and Accept: application/json headers, and send the token as Authorization: Bearer <token>. Use SetAPIVersion("YYYYMMDD") to target a specific API version and SetUserAgent("my-app/1.0") to set the User-Agent.
Example: get account balances after authenticating:
api := tastytrade.NewTastytradeAPI()
_ = api.Authenticate(os.Getenv("TT_USER"), os.Getenv("TT_PASSWORD"))
balances, err := api.GetAccountBalances("your-account-number")
if err != nil {
log.Fatal(err)
}
fmt.Println(balances)To run the tests for this project, you can use go test:
go test ./...Contributions to this project are welcome! Please submit a pull request or open an issue on GitHub.
This project is released into the public domain under the Unlicense. For more information, please refer to the LICENSE file or visit https://unlicense.org.