bitget

package
v0.0.0-...-c0411a1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ID = "bitget"

	PlatformToken = "BGB"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountEvent

type AccountEvent struct {
	Balances []Balance
	// contains filtered or unexported fields
}

type ActionType

type ActionType string
const (
	ActionTypeSnapshot ActionType = "snapshot"
	ActionTypeUpdate   ActionType = "update"
)

type Balance

type Balance struct {
	Coin      string           `json:"coin"`
	Available fixedpoint.Value `json:"available"`
	// Amount of frozen assets Usually frozen when the order is placed
	Frozen fixedpoint.Value `json:"frozen"`
	// Amount of locked assets Locked assests required to become a fiat merchants, etc.
	Locked fixedpoint.Value `json:"locked"`
	// Restricted availability For spot copy trading
	LimitAvailable fixedpoint.Value           `json:"limitAvailable"`
	UpdatedTime    types.MillisecondTimestamp `json:"uTime"`
}

type BookEvent

type BookEvent struct {
	Events []struct {
		// Order book on sell side, ascending order
		Asks types.PriceVolumeSlice `json:"asks"`
		// Order book on buy side, descending order
		Bids     types.PriceVolumeSlice     `json:"bids"`
		Ts       types.MillisecondTimestamp `json:"ts"`
		Checksum int                        `json:"checksum"`
	}
	// contains filtered or unexported fields
}
{
   "asks":[
      [
         "28350.78",
         "0.2082"
      ],
   ],
   "bids":[
      [
         "28350.70",
         "0.5585"
      ],
   ],
   "checksum":0,
   "ts":"1697593934630"
}

func (*BookEvent) ToGlobalOrderBooks

func (e *BookEvent) ToGlobalOrderBooks() []types.SliceOrderBook

type ChannelType

type ChannelType string
const (
	ChannelAccount ChannelType = "account"
	// ChannelOrderBook snapshot and update might return less than 200 bids/asks as per symbol's orderbook various from
	// each other; The number of bids/asks is not a fixed value and may vary in the future
	ChannelOrderBook ChannelType = "books"
	// ChannelOrderBook5 top 5 order book of "books" that begins from bid1/ask1
	ChannelOrderBook5 ChannelType = "books5"
	// ChannelOrderBook15 top 15 order book of "books" that begins from bid1/ask1
	ChannelOrderBook15 ChannelType = "books15"
	ChannelTrade       ChannelType = "trade"
	ChannelOrders      ChannelType = "orders"
)

type Exchange

type Exchange struct {
	// contains filtered or unexported fields
}

func New

func New(key, secret, passphrase string) *Exchange

func (*Exchange) CancelOrders

func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (errs error)

func (*Exchange) Name

func (e *Exchange) Name() types.ExchangeName

func (*Exchange) NewStream

func (e *Exchange) NewStream() types.Stream

func (*Exchange) PlatformFeeCurrency

func (e *Exchange) PlatformFeeCurrency() string

func (*Exchange) QueryAccount

func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error)

func (*Exchange) QueryAccountBalances

func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap, error)

func (*Exchange) QueryClosedOrders

func (e *Exchange) QueryClosedOrders(
	ctx context.Context, symbol string, since, until time.Time, lastOrderID uint64,
) (orders []types.Order, err error)

QueryClosedOrders queries closed order by time range(`CreatedTime`) and id. The order of the response is in descending order. If you need to retrieve all data, please utilize the function pkg/exchange/batch.ClosedOrderBatchQuery.

REMARK: If your start time is 90 days earlier, we will update it to now - 90 days. ** Since is inclusive, Until is exclusive. If you use a time range to query, you must provide both a start time and an end time. ** ** Since and Until cannot exceed 90 days. ** ** Since from the last 90 days can be queried **

func (*Exchange) QueryKLines

func (e *Exchange) QueryKLines(
	ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions,
) ([]types.KLine, error)

QueryKLines queries the k line data by interval and time range...etc.

If you provide only the start time, the system will return the latest data. If you provide both the start and end times, the system will return data within the specified range. If you provide only the end time, the system will return data that occurred before the end time.

The end time has different limits. 1m, 5m can query for one month,15m can query for 52 days,30m can query for 62 days, 1H can query for 83 days,4H can query for 240 days,6H can query for 360 days.

func (*Exchange) QueryMarkets

func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error)

func (*Exchange) QueryOpenOrders

func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders []types.Order, err error)

func (*Exchange) QueryTicker

func (e *Exchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error)

func (*Exchange) QueryTickers

func (e *Exchange) QueryTickers(ctx context.Context, symbols ...string) (map[string]types.Ticker, error)

func (*Exchange) QueryTrades

func (e *Exchange) QueryTrades(
	ctx context.Context, symbol string, options *types.TradeQueryOptions,
) (trades []types.Trade, err error)

QueryTrades queries fill trades. The trade of the response is in descending order. The time-based query are typically using (`CreatedTime`) as the search criteria. If you need to retrieve all data, please utilize the function pkg/exchange/batch.TradeBatchQuery.

REMARK: If your start time is 90 days earlier, we will update it to now - 90 days. ** StartTime is inclusive, EndTime is exclusive. If you use the EndTime, the StartTime is required. ** ** StartTime and EndTime cannot exceed 90 days. **

func (*Exchange) SubmitOrder

func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (createdOrder *types.Order, err error)

SubmitOrder submits an order.

Remark: 1. We support only GTC for time-in-force, because the response from queryOrder does not include time-in-force information. 2. For market buy orders, the size unit is quote currency, whereas the unit for order.Quantity is in base currency. Therefore, we need to calculate the equivalent quote currency amount based on the ticker data.

Note that there is a bug in Bitget where you can place a market order with the 'post_only' option successfully, which should not be possible. The issue has been reported.

type InstType

type InstType string

type KLine

type KLine struct {
	StartTime    types.MillisecondTimestamp
	OpenPrice    fixedpoint.Value
	HighestPrice fixedpoint.Value
	LowestPrice  fixedpoint.Value
	ClosePrice   fixedpoint.Value
	Volume       fixedpoint.Value
}

func (KLine) ToGlobal

func (k KLine) ToGlobal(interval types.Interval, symbol string) types.KLine

type KLineEvent

type KLineEvent struct {
	Events KLineSlice
	// contains filtered or unexported fields
}

func (KLineEvent) CacheKey

func (k KLineEvent) CacheKey() string

type KLineSlice

type KLineSlice []KLine

func (*KLineSlice) UnmarshalJSON

func (m *KLineSlice) UnmarshalJSON(b []byte) error

type LogFunction

type LogFunction func(msg string, args ...interface{})

type MarketTrade

type MarketTrade struct {
	Ts    types.MillisecondTimestamp
	Price fixedpoint.Value
	Size  fixedpoint.Value
	Side  SideType
}

func (MarketTrade) ToGlobal

func (m MarketTrade) ToGlobal(symbol string) (types.Trade, error)

type MarketTradeEvent

type MarketTradeEvent struct {
	Events MarketTradeSlice
	// contains filtered or unexported fields
}

type MarketTradeSlice

type MarketTradeSlice []MarketTrade

func (*MarketTradeSlice) UnmarshalJSON

func (m *MarketTradeSlice) UnmarshalJSON(b []byte) error

type Order

type Order struct {
	Trade

	InstId string `json:"instId"`
	// OrderId are always numeric. It's confirmed with official customer service. https://t.me/bitgetOpenapi/24172
	OrderId       types.StrInt64 `json:"orderId"`
	ClientOrderId string         `json:"clientOid"`
	// NewSize represents the order quantity, following the specified rules:
	// when orderType=limit, newSize represents the quantity of base coin,
	// when orderType=marketandside=buy, newSize represents the quantity of quote coin,
	// when orderType=marketandside=sell, newSize represents the quantity of base coin.
	NewSize fixedpoint.Value `json:"newSize"`
	// Buy amount, returned when buying at market price
	Notional      fixedpoint.Value `json:"notional"`
	OrderType     v2.OrderType     `json:"orderType"`
	Force         v2.OrderForce    `json:"force"`
	Side          v2.SideType      `json:"side"`
	AccBaseVolume fixedpoint.Value `json:"accBaseVolume"`
	PriceAvg      fixedpoint.Value `json:"priceAvg"`
	// The Price field is only applicable to limit orders.
	Price       fixedpoint.Value           `json:"price"`
	Status      v2.OrderStatus             `json:"status"`
	CreatedTime types.MillisecondTimestamp `json:"cTime"`
	UpdatedTime types.MillisecondTimestamp `json:"uTime"`
	FeeDetail   []struct {
		FeeCoin string `json:"feeCoin"`
		Fee     string `json:"fee"`
	} `json:"feeDetail"`
	EnterPointSource string `json:"enterPointSource"`
}

type OrderTradeEvent

type OrderTradeEvent struct {
	Orders []Order
	// contains filtered or unexported fields
}

type SideType

type SideType string
const (
	SideBuy  SideType = "buy"
	SideSell SideType = "sell"
)

func (SideType) ToGlobal

func (s SideType) ToGlobal() (types.SideType, error)

type Stream

type Stream struct {
	types.StandardStream

	KLineEventCallbacks []func(o KLineEvent)
	// contains filtered or unexported fields
}

func NewStream

func NewStream(key, secret, passphrase string) *Stream

func (*Stream) EmitAccountEvent

func (s *Stream) EmitAccountEvent(e AccountEvent)

func (*Stream) EmitBookEvent

func (s *Stream) EmitBookEvent(o BookEvent)

func (*Stream) EmitKLineEvent

func (s *Stream) EmitKLineEvent(o KLineEvent)

func (*Stream) EmitMarketTradeEvent

func (s *Stream) EmitMarketTradeEvent(o MarketTradeEvent)

func (*Stream) EmitOrderTradeEvent

func (s *Stream) EmitOrderTradeEvent(e OrderTradeEvent)

func (*Stream) OnAccountEvent

func (s *Stream) OnAccountEvent(cb func(e AccountEvent))

func (*Stream) OnBookEvent

func (s *Stream) OnBookEvent(cb func(o BookEvent))

func (*Stream) OnKLineEvent

func (s *Stream) OnKLineEvent(cb func(o KLineEvent))

func (*Stream) OnMarketTradeEvent

func (s *Stream) OnMarketTradeEvent(cb func(o MarketTradeEvent))

func (*Stream) OnOrderTradeEvent

func (s *Stream) OnOrderTradeEvent(cb func(e OrderTradeEvent))

func (*Stream) SetPrivateChannelSymbols

func (s *Stream) SetPrivateChannelSymbols(symbols []string)

func (*Stream) Unsubscribe

func (s *Stream) Unsubscribe()

type Trade

type Trade struct {
	// Latest filled price
	FillPrice fixedpoint.Value `json:"fillPrice"`
	TradeId   types.StrInt64   `json:"tradeId"`
	// Number of latest filled orders
	BaseVolume fixedpoint.Value           `json:"baseVolume"`
	FillTime   types.MillisecondTimestamp `json:"fillTime"`
	// Transaction fee of the latest transaction, negative value
	FillFee fixedpoint.Value `json:"fillFee"`
	// Currency of transaction fee of the latest transaction
	FillFeeCoin string `json:"fillFeeCoin"`
	// Direction of liquidity of the latest transaction
	TradeScope string `json:"tradeScope"`
}

type WsArg

type WsArg struct {
	InstType InstType    `json:"instType"`
	Channel  ChannelType `json:"channel"`
	// InstId Instrument ID. e.q. BTCUSDT, ETHUSDT
	InstId string `json:"instId"`
	Coin   string `json:"coin"`

	ApiKey     string `json:"apiKey"`
	Passphrase string `json:"passphrase"`
	Timestamp  string `json:"timestamp"`
	Sign       string `json:"sign"`
}

type WsEvent

type WsEvent struct {
	// for comment event
	Arg WsArg `json:"arg"`

	// for op event
	Event WsEventType `json:"event"`
	Code  int         `json:"code"`
	Msg   string      `json:"msg"`
	Op    string      `json:"op"`

	// for data event
	Action ActionType      `json:"action"`
	Data   json.RawMessage `json:"data"`
}

WsEvent is the lowest level of event type. We use this struct to convert the received data, so that we will know whether the event belongs to `op` or `data`.

func (*WsEvent) IsAuthenticated

func (w *WsEvent) IsAuthenticated() bool

func (*WsEvent) IsOp

func (w *WsEvent) IsOp() bool

IsOp represents the data event will be empty

func (*WsEvent) IsValid

func (w *WsEvent) IsValid() error

type WsEventType

type WsEventType string
const (
	WsEventSubscribe   WsEventType = "subscribe"
	WsEventUnsubscribe WsEventType = "unsubscribe"
	WsEventLogin       WsEventType = "login"
	WsEventError       WsEventType = "error"
)

type WsOp

type WsOp struct {
	Op   WsEventType `json:"op"`
	Args []WsArg     `json:"args"`
}

Directories

Path Synopsis
v2

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL