-
Notifications
You must be signed in to change notification settings - Fork 0
Models and Numeric Precision
The SDK's models package supplies typed request and response structures for the implemented UTA API surface. It intentionally preserves prices, quantities, balances, PnL, fees, timestamps, and many other API scalar values as string, matching Bitget's wire representation rather than silently converting financial values to float64. 1
Why this matters. Binary floating-point cannot represent many decimal fractions exactly. Preserve SDK strings or convert them with an exact-decimal approach when the value affects risk checks, order sizing, accounting, or reconciliation.
The package uses string aliases so callers can still pass values introduced by Bitget later. Prefer the supplied constants for common values:
| Group | Constants | API values |
|---|---|---|
| Product category |
CategorySpot, CategoryMargin, CategoryUSDTFutures, CategoryCoinFutures, CategoryUSDCFutures
|
SPOT, MARGIN, USDT-FUTURES, COIN-FUTURES, USDC-FUTURES
|
| Order side |
SideBuy, SideSell
|
buy, sell
|
| Position side |
PosSideLong, PosSideShort
|
long, short
|
| Order type |
OrderTypeLimit, OrderTypeMarket
|
limit, market
|
| Time in force |
TimeInForceIOC, TimeInForceFOK, TimeInForceGTC, TimeInForcePostOnly, TimeInForceRPI
|
ioc, fok, gtc, post_only, rpi
|
| Margin mode |
MarginModeCrossed, MarginModeIsolated
|
crossed, isolated
|
These constants are defined as aliases such as type Category = string, not distinct named types. 1
math/big.Rat is one standard-library option for exact rational calculations. It is appropriate when the operation and rounding policy are under your control.
import "math/big"
func multiplyDecimalStrings(a, b string) (string, error) {
x, ok := new(big.Rat).SetString(a)
if !ok {
return "", fmt.Errorf("invalid decimal %q", a)
}
y, ok := new(big.Rat).SetString(b)
if !ok {
return "", fmt.Errorf("invalid decimal %q", b)
}
return new(big.Rat).Mul(x, y).FloatString(18), nil
}FloatString(18) is an output-format choice, not a universal exchange rounding rule. Before constructing an order, apply the instrument's reported price/quantity precision and other Bitget constraints. 2 3
Bitget REST responses use an envelope with code, msg, requestTime, and data. The generic type models.BitgetResponse[T] mirrors this external shape. Public service methods in this SDK decode the data portion for you and return the typed result directly, such as []models.Ticker or *models.AccountAssets. 1 4
// Protocol shape, useful when working with raw Bitget response data:
type BitgetResponse[T any] struct {
Code string
Msg string
RequestTime int64
Data T
}| Area | Primary request models | Primary response models |
|---|---|---|
| Market | Method parameters only |
Instrument, Ticker, OrderBook, OrderBookLevel
|
| Account | SetLeverageRequest |
AccountAssets, AssetHolding, AccountSettings, SymbolConfig, CoinConfig
|
| Trading |
PlaceOrderRequest, ModifyOrderRequest, CancelOrderRequest
|
OrderRef, Order, OrderList, Position, PositionList, FeeDetail
|
| WebSocket |
WSArg, WSSubscribeRequest, WSLoginRequest
|
WSEvent, WSPush, FastFill
|
models.Instrument contains the symbol's product specification and control fields, including minimum/maximum order quantities, price/quantity precision, supported leverage ranges, order count limits, status, and product metadata. models.Ticker contains a 24-hour view with last, bid, ask, high/low, volume, turnover, and product-specific derivatives fields. 2
An order book has a compact shape:
type OrderBookLevel [2]string // [price, quantity]
type OrderBook struct {
Asks []OrderBookLevel
Bids []OrderBookLevel
Ts string
}AccountAssets combines account-level risk/equity fields with Assets []AssetHolding. AccountSettings adds account, asset, and hold modes plus per-symbol and per-coin configuration arrays. Treat their numeric string fields as exact values and consult Bitget UTA documentation for the selected account mode's financial meaning. 3 5
The three mutation request models are deliberately direct representations of Bitget request bodies. For example, PlaceOrderRequest includes basic order identity fields and optional client ID, margin controls, reduce-only flag, and TP/SL fields. ModifyOrderRequest and CancelOrderRequest support either OrderID or ClientOid; the model documentation specifies that OrderID wins if both are set. 6
OrderList provides List []Order and a Cursor, while PositionList contains List []Position. The Order and Position models retain exchange ID fields, product context, PnL, fee, price, quantity, status, and timestamp values as strings. 6
WSPush is the generic stream envelope:
type WSPush struct {
Arg WSArg
Action string
Data json.RawMessage
Ts int64
}Decode Data according to the channel. The SDK includes models.FastFill for Bitget's currently implemented typed private fast-fill channel. Other supported subscriptions stay generic at the SDK boundary and should be decoded from json.RawMessage by the application using Bitget's channel documentation. 7 8