Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions client/mm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type CEXConfig struct {
APIKey string `json:"apiKey"`
// APISecret is the API secret for the CEX.
APISecret string `json:"apiSecret"`
// APIPassphrase is the API passphrase for the CEX (required by some exchanges like Bitget).
APIPassphrase string `json:"apiPassphrase,omitempty"`
}

// AutoRebalanceConfig configures deposits and withdrawals by setting minimum
Expand Down Expand Up @@ -143,12 +145,12 @@ type BotConfig struct {
CEXName string `json:"cexName"`
// CEXBaseID will be different from BaseID if the bot is configured to arbitrage
// with a CEX, but the DEX base asset must be bridged to the CEX base asset before
// deposits and after withdrawals.
CEXBaseID uint32 `json:"cexBaseID,omitempty"`
// deposits and after withdrawals. When CEXName is set, this defaults to BaseID.
CEXBaseID uint32 `json:"cexBaseID"`
// CEXQuoteID will be different from QuoteID if the bot is configured to arbitrage
// with a CEX, but the DEX quote asset must be bridged to the CEX quote asset before
// deposits and after withdrawals.
CEXQuoteID uint32 `json:"cexQuoteID,omitempty"`
// deposits and after withdrawals. When CEXName is set, this defaults to QuoteID.
CEXQuoteID uint32 `json:"cexQuoteID"`
// BaseBridgeName is the name of the bridge to use for deposits and withdrawals
// of the base asset.
BaseBridgeName string `json:"baseBridgeName,omitempty"`
Expand Down
232 changes: 232 additions & 0 deletions client/mm/libxc/bgtypes/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package bgtypes

import "encoding/json"

// Bitget API v2 response structures

// APIResponse is the standard wrapper for all Bitget API responses
type APIResponse struct {
Code string `json:"code"`
Msg string `json:"msg"`
RequestTime int64 `json:"requestTime"`
Data json.RawMessage `json:"data"`
}

// CoinInfo represents information about a coin/asset
type CoinInfo struct {
Coin string `json:"coin"`
Transfer string `json:"transfer"` // YES or NO
Chains []*ChainInfo `json:"chains"`
}

// ChainInfo represents blockchain network information for a coin
type ChainInfo struct {
Chain string `json:"chain"`
NeedTag string `json:"needTag"` // YES or NO
Withdrawable string `json:"withdrawable"` // YES or NO
Rechargeable string `json:"rechargeable"` // YES or NO
WithdrawFee string `json:"withdrawFee"`
ExtraWithdrawFee string `json:"extraWithdrawFee"`
DepositConfirm string `json:"depositConfirm"`
WithdrawConfirm string `json:"withdrawConfirm"`
MinDepositAmount string `json:"minDepositAmount"`
MinWithdrawAmount string `json:"minWithdrawAmount"`
BrowserUrl string `json:"browserUrl"`
ContractAddress string `json:"contractAddress"`
WithdrawStep string `json:"withdrawStep"`
CongestionLevel string `json:"congestionLevel"`
EstimatedArrivalTime int `json:"estimatedArrivalTime"`
Label string `json:"label"`
WithdrawIntegerMultiple string `json:"withdrawIntegerMultiple"`
}

// SymbolInfo represents trading symbol/market information
type SymbolInfo struct {
Symbol string `json:"symbol"`
BaseCoin string `json:"baseCoin"`
QuoteCoin string `json:"quoteCoin"`
MinTradeAmount string `json:"minTradeAmount"`
MaxTradeAmount string `json:"maxTradeAmount"`
TakerFeeRate string `json:"takerFeeRate"`
MakerFeeRate string `json:"makerFeeRate"`
PricePrecision string `json:"pricePrecision"`
QuantityPrecision string `json:"quantityPrecision"`
QuotePrecision string `json:"quotePrecision"`
MinTradeUSDT string `json:"minTradeUSDT"`
Status string `json:"status"` // live, halt, etc.
BuyLimitPriceRatio string `json:"buyLimitPriceRatio"`
SellLimitPriceRatio string `json:"sellLimitPriceRatio"`
}

// TickerData represents 24hr ticker data
type TickerData struct {
Symbol string `json:"symbol"`
High24h string `json:"high24h"`
Low24h string `json:"low24h"`
Close string `json:"close"`
QuoteVol string `json:"quoteVol"`
BaseVol string `json:"baseVol"`
UsdtVol string `json:"usdtVol"`
Ts string `json:"ts"`
BidPr string `json:"bidPr"`
AskPr string `json:"askPr"`
BidSz string `json:"bidSz"`
AskSz string `json:"askSz"`
OpenUtc string `json:"openUtc"`
ChangeUtc24h string `json:"changeUtc24h"`
Change24h string `json:"change24h"`
}

// OrderbookSnapshot represents a full orderbook snapshot from REST API
type OrderbookSnapshot struct {
Asks [][]string `json:"asks"` // [price, quantity]
Bids [][]string `json:"bids"` // [price, quantity]
Ts string `json:"ts"`
}

// AssetBalance represents account balance for an asset
type AssetBalance struct {
Coin string `json:"coin"`
Available string `json:"available"`
Frozen string `json:"frozen"`
Locked string `json:"locked"`
LimitAvailable string `json:"limitAvailable"`
UTime string `json:"uTime"`
}

// OrderRequest represents a new order request
type OrderRequest struct {
Symbol string `json:"symbol"`
Side string `json:"side"` // buy or sell
OrderType string `json:"orderType"` // limit, market
Force string `json:"force,omitempty"` // GTC, IOC, FOK, POST_ONLY
Price string `json:"price,omitempty"`
Size string `json:"size"` // base currency quantity for limit orders
QuoteSize string `json:"quoteSize,omitempty"` // quote currency amount for market buy
ClientOid string `json:"clientOid"`
}

// OrderResponse represents the response when placing an order
type OrderResponse struct {
OrderId string `json:"orderId"`
ClientOid string `json:"clientOid"`
}

// CancelOrderRequest represents a request to cancel an order
type CancelOrderRequest struct {
Symbol string `json:"symbol"`
OrderId string `json:"orderId,omitempty"`
ClientOid string `json:"clientOid,omitempty"`
}

// OrderDetail represents detailed order information
type OrderDetail struct {
UserId string `json:"userId"`
Symbol string `json:"symbol"`
OrderId string `json:"orderId"`
ClientOid string `json:"clientOid"`
Price string `json:"price"`
Size string `json:"size"`
OrderType string `json:"orderType"`
Side string `json:"side"`
Status string `json:"status"` // live, partially_filled, filled, cancelled
PriceAvg string `json:"priceAvg"`
BaseVolume string `json:"baseVolume"` // filled base quantity
QuoteVolume string `json:"quoteVolume"` // filled quote quantity
EnterPointSource string `json:"enterPointSource"`
FeeDetail string `json:"feeDetail"`
OrderSource string `json:"orderSource"`
CTime string `json:"cTime"`
UTime string `json:"uTime"`
}

// FillDetail represents a single fill/trade execution
type FillDetail struct {
Fee string `json:"fee"`
FeeCoin string `json:"feeCoin"`
}

// DepositAddress represents a deposit address for an asset
type DepositAddress struct {
Coin string `json:"coin"`
Chain string `json:"chain"`
Address string `json:"address"`
Tag string `json:"tag"`
Url string `json:"url"`
}

// ModifyDepositAccountRequest represents a request to modify deposit account type
type ModifyDepositAccountRequest struct {
Coin string `json:"coin"`
AccountType string `json:"accountType"` // spot, funding, coin-futures, usdt-futures, usdc-futures
}

// WithdrawalRequest represents a withdrawal request
type WithdrawalRequest struct {
Coin string `json:"coin"`
TransferType string `json:"transferType"` // "on_chain" for blockchain withdrawals, "internal_transfer" for internal transfers
Chain string `json:"chain"`
Address string `json:"address"`
Tag string `json:"tag,omitempty"`
Size string `json:"size"`
Remark string `json:"remark,omitempty"`
ClientOid string `json:"clientOid,omitempty"`
}

// WithdrawalResponse represents the response to a withdrawal request
type WithdrawalResponse struct {
OrderId string `json:"orderId"`
ClientOid string `json:"clientOid"`
}

// WithdrawalRecord represents a withdrawal record
type WithdrawalRecord struct {
OrderId string `json:"orderId"`
TradeId string `json:"tradeId"`
ClientOid string `json:"clientOid"`
Coin string `json:"coin"`
Chain string `json:"chain"`
Address string `json:"address"`
Tag string `json:"tag"`
Size string `json:"size"`
Fee string `json:"fee"`
Status string `json:"status"` // pending, success, failed, etc.
TxId string `json:"txId"`
CTime string `json:"cTime"`
UTime string `json:"uTime"`
}

// DepositRecord represents a deposit record
type DepositRecord struct {
OrderId string `json:"orderId"`
TradeId string `json:"tradeId"`
Coin string `json:"coin"`
Chain string `json:"chain"`
Address string `json:"address"`
Tag string `json:"tag"`
Size string `json:"size"`
Status string `json:"status"` // pending, success, failed, etc.
TxId string `json:"txId"`
CTime string `json:"cTime"`
UTime string `json:"uTime"`
}

// Market represents processed market information for internal use
type Market struct {
Symbol string
BaseCoin string
QuoteCoin string
MinTradeAmount float64
MaxTradeAmount float64
PricePrecision int
QuantityPrecision int
MinTradeUSDT float64
PriceStep uint64 // Message rate step
LotSize uint64 // Minimum quantity step in base asset atoms
MinQty uint64
MaxQty uint64
MinNotional uint64 // in quote asset atoms
}
129 changes: 129 additions & 0 deletions client/mm/libxc/bgtypes/ws.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package bgtypes

// WebSocket message structures for Bitget API v2

// WsRequest represents a WebSocket subscription/unsubscription request
type WsRequest struct {
Op string `json:"op"` // subscribe, unsubscribe, login
Args []WsArg `json:"args"`
}

// WsArg represents an argument for WebSocket operations
type WsArg struct {
InstType string `json:"instType"` // SPOT, MARGIN, etc.
Channel string `json:"channel"` // books, account, orders, etc.
InstId string `json:"instId,omitempty"` // Trading pair symbol or "default" for all
Coin string `json:"coin,omitempty"` // Coin filter for account channel ("default" for all)
}

// WsResponse represents a standard WebSocket response
type WsResponse struct {
Event string `json:"event,omitempty"` // subscribe, unsubscribe, error, login
Code string `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
Op string `json:"op,omitempty"`
Arg *WsArg `json:"arg,omitempty"`
}

// WsLoginRequest represents a login request for private WebSocket channels
type WsLoginRequest struct {
Op string `json:"op"`
Args []WsLoginArg `json:"args"`
}

// WsLoginArg represents login credentials
type WsLoginArg struct {
ApiKey string `json:"apiKey"`
Passphrase string `json:"passphrase"`
Timestamp string `json:"timestamp"`
Sign string `json:"sign"`
}

// WsDataMessage represents a data update message
type WsDataMessage struct {
Action string `json:"action,omitempty"` // snapshot, update
Arg *WsArg `json:"arg"`
Data []WsData `json:"data"`
Ts int64 `json:"ts,omitempty"`
}

// WsData is a generic container for WebSocket data
type WsData interface{}

// WsBookData represents orderbook data from WebSocket
type WsBookData struct {
Asks [][]string `json:"asks"` // [price, quantity]
Bids [][]string `json:"bids"` // [price, quantity]
Checksum int64 `json:"checksum,omitempty"`
Seq int64 `json:"seq,omitempty"` // Sequence number
Ts string `json:"ts"`
}

// WsOrderData represents order update data from WebSocket
// Per: https://www.bitget.com/api-doc/spot/websocket/private/Order-Channel
type WsOrderData struct {
InstId string `json:"instId"` // Product ID, e.g. BTCUSDT
OrderId string `json:"orderId"` // Order ID
ClientOid string `json:"clientOid"` // Client order ID
Price string `json:"price,omitempty"` // Order price
Size string `json:"size"` // Order amount (quote for buy, base for sell)
NewSize string `json:"newSize"` // Order quantity (base for limit, varies for market)
Notional string `json:"notional"` // Buy amount for market orders
OrderType string `json:"orderType"` // "market" or "limit"
Force string `json:"force"` // GTC, post_only, FOK, IOC
Side string `json:"side"` // "buy" or "sell"
FillPrice string `json:"fillPrice"` // Latest filled price
TradeId string `json:"tradeId"` // Latest transaction ID
BaseVolume string `json:"baseVolume"` // Latest fill quantity (incremental)
FillTime string `json:"fillTime"` // Latest transaction time
FillFee string `json:"fillFee"` // Latest transaction fee (negative)
FillFeeCoin string `json:"fillFeeCoin"` // Fee currency
TradeScope string `json:"tradeScope"` // "T"=taker, "M"=maker
AccBaseVolume string `json:"accBaseVolume"` // Total filled quantity (cumulative)
PriceAvg string `json:"priceAvg"` // Average filled price
Status string `json:"status"` // live, partially_filled, filled, cancelled
CTime string `json:"cTime"` // Order creation time (ms)
UTime string `json:"uTime"` // Order update time (ms)
StpMode string `json:"stpMode"` // STP mode
EnterPointSource string `json:"enterPointSource"` // Order source
FeeDetail []WsFeeDetail `json:"feeDetail"` // Fee list (can be multiple)
}

// WsFeeDetail represents fee information (simple structure per API)
type WsFeeDetail struct {
FeeCoin string `json:"feeCoin"` // Transaction fee currency
Fee string `json:"fee"` // Transaction fee amount
}

// WsAccountData represents account balance update from WebSocket
type WsAccountData struct {
Coin string `json:"coin"` // Token name
Available string `json:"available"` // Available coin assets
Frozen string `json:"frozen"` // Frozen when order is placed
Locked string `json:"locked"` // Locked for fiat merchant, etc.
LimitAvailable string `json:"limitAvailable"` // Restricted for spot copy trading
UTime string `json:"uTime"` // Update time (milliseconds)
}

// WsPingMessage represents a ping message
type WsPingMessage struct {
Op string `json:"op"` // "ping"
}

// WsPongMessage represents a pong response
type WsPongMessage struct {
Op string `json:"op"` // "pong"
}

// BookUpdate represents an orderbook update (converted from WsBookData)
type BookUpdate struct {
Bids [][]float64
Asks [][]float64
BidsOriginal [][]string // Original string format for checksum calculation
AsksOriginal [][]string // Original string format for checksum calculation
IsSnapshot bool // true if action='snapshot', false if action='update'
Checksum int32 // Bitget's checksum for validation (0 if not provided)
}
Loading