-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
This page takes a new Go project from installation to a first public market-data request, then explains how to opt into private UTA access. The module requires Go 1.21 or newer. 1
Add the library to your module:
go get github.com/tigusigalpa/bitget-goThe root package is typically imported with the bitget alias. Request and response types, as well as convenient constant values, live in the models package. 1
import (
bitget "github.com/tigusigalpa/bitget-go"
"github.com/tigusigalpa/bitget-go/models"
)Private REST endpoints and private WebSocket streams use the following three values.
| Environment variable | Purpose | Required for public market data? |
|---|---|---|
BITGET_API_KEY |
Identifies the API key. | No |
BITGET_SECRET_KEY |
Signs private REST requests and private WebSocket login requests. | No |
BITGET_PASSPHRASE |
Authenticates the API key's passphrase. | No |
Create a key with the minimum permissions required for the operation. For early testing, create a Demo API key in Bitget Demo mode. Bitget documents separate demo credentials and requires the paptrading: 1 REST header for demo API calls. 2
Security note. Do not commit credentials to source control, print them in logs, or pass them in a public chat. Use environment variables or a secret manager in each deployment environment.
A RestClient groups Market, Account, and Trade services. The market service works with empty credential strings because its implemented methods make unsigned requests. 1 3
package main
import (
"context"
"fmt"
"log"
bitget "github.com/tigusigalpa/bitget-go"
"github.com/tigusigalpa/bitget-go/models"
)
func main() {
ctx := context.Background()
client := bitget.NewRestClient("", "", "")
tickers, err := client.Market.GetTickers(ctx, models.CategorySpot, "BTCUSDT")
if err != nil {
log.Fatal(err)
}
if len(tickers) == 0 {
log.Fatal("ticker response was empty")
}
fmt.Printf("BTCUSDT last price: %s\n", tickers[0].LastPrice)
}The explicit models.CategorySpot constant prevents accidental casing or spelling mistakes. Financial data, including LastPrice, remains a string so it can be processed with exact decimal logic. 4
Supply the three credential values when constructing the client, then call an authenticated service. The SDK signs the request with HMAC-SHA256 and Base64 encoding according to Bitget's documented signature format. 2 5
package main
import (
"context"
"fmt"
"log"
"os"
bitget "github.com/tigusigalpa/bitget-go"
)
func main() {
client := bitget.NewRestClient(
os.Getenv("BITGET_API_KEY"),
os.Getenv("BITGET_SECRET_KEY"),
os.Getenv("BITGET_PASSPHRASE"),
)
assets, err := client.Account.GetAssets(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("Account equity: %s\n", assets.AccountEquity)
}The client automatically adds the required ACCESS-KEY, ACCESS-SIGN, ACCESS-TIMESTAMP, and ACCESS-PASSPHRASE headers to signed REST requests. Public market calls do not carry those authentication headers. 2 5
Use Demo credentials together with WithDemoTrading(). The option makes the REST client send Bitget's required paptrading: 1 header on signed requests. 2 6
client := bitget.NewRestClient(
os.Getenv("BITGET_API_KEY"),
os.Getenv("BITGET_SECRET_KEY"),
os.Getenv("BITGET_PASSPHRASE"),
bitget.WithDemoTrading(),
)The repository example adds a second explicit gate before submitting an order: BITGET_ENABLE_TRADING=1. That pattern is recommended for application code because it makes order placement an intentional operational action. 7
Read REST Client and Configuration before changing transports or timeouts. Continue with Market Data for read-only use cases, or Trading only after validating your configuration with Demo credentials.