Documentation
¶
Overview ¶
Package bitget is an idiomatic Go SDK for the Bitget Unified Trading Account (UTA) API v3.
Index ¶
Constants ¶
const ( DefaultPublicWSURL = "wss://ws.bitget.com/v3/ws/public" DefaultPrivateWSURL = "wss://ws.bitget.com/v3/ws/private" DemoPublicWSURL = "wss://wspap.bitget.com/v3/ws/public" DemoPrivateWSURL = "wss://wspap.bitget.com/v3/ws/private" )
Public/private WebSocket endpoints.
Docs: https://www.bitget.com/api-doc/uta/guide
const DefaultBaseURL = "https://api.bitget.com"
DefaultBaseURL is Bitget's production UTA v3 REST endpoint.
Docs: https://www.bitget.com/api-doc/uta/guide
const DefaultTimeout = 15 * time.Second
DefaultTimeout is applied to the internal *http.Client when none is supplied via WithHTTPClient.
Variables ¶
var ( ErrInvalidSignature = errors.New("bitget: invalid signature") ErrInvalidTimestamp = errors.New("bitget: invalid or expired timestamp") ErrPermissionDenied = errors.New("bitget: permission denied for this API key") ErrRateLimited = errors.New("bitget: rate limit exceeded") ErrInvalidParameter = errors.New("bitget: invalid request parameter") ErrInsufficientFunds = errors.New("bitget: insufficient balance") ErrOrderNotFound = errors.New("bitget: order not found") ErrInternalServer = errors.New("bitget: internal server error") )
Sentinel errors that callers can match with errors.Is, wrapped alongside the detailed *Error (retrievable via errors.As) on every failed call.
Functions ¶
func MapErrorCode ¶
MapErrorCode maps a Bitget API response "code" to a sentinel error so callers can use errors.Is without parsing raw codes themselves. Unknown codes return nil (caller should fall back to the raw *Error).
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the low-level authenticated HTTP transport shared by every service under RestClient. Most callers should construct a *RestClient via NewRestClient instead of using Client directly.
func NewClient ¶
NewClient creates a low-level Client. apiKey/secretKey/passphrase are the credentials generated for an API key in the Bitget web console (https://www.bitget.com/api-doc/uta/guide). Most callers want NewRestClient instead, which additionally wires up all API services.
type Error ¶ added in v1.0.4
Error represents a structured error returned by the Bitget UTA API, preserving the exact code/message pair sent back in the response envelope.
type Logger ¶
type Logger interface {
Debug(msg string, args ...any)
Info(msg string, args ...any)
Warn(msg string, args ...any)
Error(msg string, args ...any)
}
Logger is a minimal structured-logging interface. Pass an adapter (see NewSlogLogger) or your own implementation via WithLogger; the default is a no-op logger.
func NewSlogLogger ¶
NewSlogLogger wraps l so it can be passed to WithLogger. A nil logger uses the same no-op behavior as a client without an explicitly configured logger.
type Option ¶
type Option func(*Client)
Option configures a Client at construction time.
func WithBaseURL ¶
WithBaseURL overrides the REST base URL, e.g. for Bitget's Lo-La (VIP/institutional) endpoint or a test server.
func WithDemoTrading ¶
func WithDemoTrading() Option
WithDemoTrading enables Bitget's simulated-trading mode by sending the "paptrading: 1" header on every request. Use together with a Demo API key; see https://www.bitget.com/api-doc/uta/guide.
func WithHTTPClient ¶
WithHTTPClient injects a custom *http.Client (for proxies, custom transports, or test doubles). The client is used as-is; DefaultTimeout is not applied when this option is used.
func WithLocale ¶
WithLocale sets the "locale" header sent on every request (e.g. "en-US", "zh-CN"). Defaults to "en-US".
func WithLogger ¶
WithLogger sets a structured logger for request/response diagnostics. Never logs ACCESS-KEY, ACCESS-SIGN, or ACCESS-PASSPHRASE values.
func WithTimeout ¶
WithTimeout sets the timeout of the internally constructed *http.Client. Ignored if WithHTTPClient is also used.
type RestClient ¶
type RestClient struct {
*Client
// Market provides public, unauthenticated market-data endpoints.
Market *market.Client
// Account provides private account/balance/leverage endpoints.
Account *account.Client
// Trade provides private order-placement and position endpoints.
Trade *trade.Client
}
RestClient is the main entry point for the REST API, grouping every service under one struct. Construct it with NewRestClient.
func NewRestClient ¶
func NewRestClient(apiKey, secretKey, passphrase string, opts ...Option) *RestClient
NewRestClient creates a fully wired Bitget UTA v3 REST client. apiKey, secretKey, and passphrase come from the API key created in the Bitget web console; see https://www.bitget.com/api-doc/uta/guide.
Public endpoints (RestClient.Market) work even with empty credentials.
type WSClient ¶
type WSClient struct {
// contains filtered or unexported fields
}
WSClient is a reconnecting WebSocket client for Bitget's public or private UTA v3 streams. Create one with NewPublicWSClient or NewPrivateWSClient.
Docs: https://www.bitget.com/api-doc/uta/websocket/private/Fast-Fill-Channel
func NewPrivateWSClient ¶
NewPrivateWSClient creates a client for Bitget's private WebSocket streams (order fills, positions, etc.), authenticating automatically on Connect.
func NewPublicWSClient ¶
NewPublicWSClient creates a client for Bitget's public market-data WebSocket streams (no authentication).
func (*WSClient) Close ¶
Close terminates the connection and stops all background loops. Safe to call multiple times.
func (*WSClient) Connect ¶
Connect dials the WebSocket endpoint, logs in (for private clients), and starts the background read/ping/reconnect loops. Connect blocks until the initial connection (and, for private clients, login) succeeds or ctx is done.
type WSOption ¶
type WSOption func(*WSClient)
WSOption configures a WSClient at construction time.
func WithWSAutoReconnect ¶
WithWSAutoReconnect toggles automatic reconnection with exponential backoff on unexpected disconnects. Enabled by default.
func WithWSLogger ¶
WithWSLogger sets a structured logger for connection lifecycle events.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
rest
command
Command rest_example demonstrates public market data plus an optional, explicitly gated authenticated call.
|
Command rest_example demonstrates public market data plus an optional, explicitly gated authenticated call. |
|
websocket
command
Command websocket_example demonstrates connecting to Bitget's public WebSocket, subscribing to a channel, and handling reconnects.
|
Command websocket_example demonstrates connecting to Bitget's public WebSocket, subscribing to a channel, and handling reconnects. |
|
Package models contains typed request/response structures for the Bitget UTA v3 API.
|
Package models contains typed request/response structures for the Bitget UTA v3 API. |
|
rest
|
|
|
account
Package account implements Bitget UTA v3's private account endpoints.
|
Package account implements Bitget UTA v3's private account endpoints. |
|
market
Package market implements Bitget UTA v3's public market-data endpoints.
|
Package market implements Bitget UTA v3's public market-data endpoints. |
|
trade
Package trade implements Bitget UTA v3's private order and position endpoints.
|
Package trade implements Bitget UTA v3's private order and position endpoints. |
