bybit

package
v0.0.0-...-41d977e Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Subscribe   = "subscribe"
	UnSubscribe = "unsubscribe"
)
View Source
const (
	Name    = "bybit.api.go"
	Version = "1.0.2"
	// Https
	MAINNET       = "https://api.bybit.com"
	MAINNET_BACKT = "https://api.bytick.com"
	TESTNET       = "https://api-testnet.bybit.com"
	// WebSocket public channel - Mainnet
	SPOT_MAINNET    = "wss://stream.bybit.com/v5/public/spot"
	LINEAR_MAINNET  = "wss://stream.bybit.com/v5/public/linear"
	INVERSE_MAINNET = "wss://stream.bybit.com/v5/public/inverse"
	OPTION_MAINNET  = "wss://stream.bybit.com/v5/public/option"

	// WebSocket public channel - Testnet
	SPOT_TESTNET    = "wss://stream-testnet.bybit.com/v5/public/spot"
	LINEAR_TESTNET  = "wss://stream-testnet.bybit.com/v5/public/linear"
	INVERSE_TESTNET = "wss://stream-testnet.bybit.com/v5/public/inverse"
	OPTION_TESTNET  = "wss://stream-testnet.bybit.com/v5/public/option"

	// WebSocket private channel
	WEBSOCKET_PRIVATE_MAINNET = "wss://stream.bybit.com/v5/private"
	WEBSOCKET_PRIVATE_TESTNET = "wss://stream-testnet.bybit.com/v5/private"

	// V3
	V3_CONTRACT_PRIVATE = "wss://stream.bybit.com/contract/private/v3"
	V3_UNIFIED_PRIVATE  = "wss://stream.bybit.com/unified/private/v3"
	V3_SPOT_PRIVATE     = "wss://stream.bybit.com/spot/private/v3"
)

Variables

This section is empty.

Functions

func GetCurrentTime

func GetCurrentTime() int64

func ParseCurrencyPair

func ParseCurrencyPair(symbol string) gocoinex.CurrencyPair

Types

type Bybit

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

func New

func New(client *http.Client, accesskey, secretkey string) *Bybit

func (*Bybit) CancelOrder

func (g *Bybit) CancelOrder(orderId string, currencyPair CurrencyPair) (bool, error)

func (*Bybit) GetAccount

func (g *Bybit) GetAccount() (*Account, error)

func (*Bybit) GetBestTicker

func (g *Bybit) GetBestTicker(currencyPair CurrencyPair) (*BestTicker, error)

func (*Bybit) GetCurrencyPairs

func (g *Bybit) GetCurrencyPairs() ([]CurrencyPair, error)

获取所有交易对

func (*Bybit) GetDepth

func (g *Bybit) GetDepth(size int, currencyPair CurrencyPair) (*Depth, error)

func (*Bybit) GetExchangeName

func (g *Bybit) GetExchangeName() string

func (*Bybit) GetKlineRecords

func (g *Bybit) GetKlineRecords(currencyPair CurrencyPair, period KlinePeriod, size int, optional ...OptionalParameter) ([]Kline, error)

func (*Bybit) GetOneOrder

func (g *Bybit) GetOneOrder(orderId string, currencyPair CurrencyPair) (*Order, error)

优先在在挂订单中查询,查找不到时去查询历史订单

func (*Bybit) GetOrderHistorys

func (g *Bybit) GetOrderHistorys(currencyPair CurrencyPair, optional ...OptionalParameter) ([]Order, error)

func (*Bybit) GetSubAccount

func (g *Bybit) GetSubAccount(coin Currency) (*SubAccount, error)

func (*Bybit) GetTicker

func (g *Bybit) GetTicker(currencyPair CurrencyPair) (*Ticker, error)

func (*Bybit) GetTradeFee

func (g *Bybit) GetTradeFee(currencyPair CurrencyPair) (*TradeFee, error)

私有权限

func (*Bybit) GetTrades

func (g *Bybit) GetTrades(currencyPair CurrencyPair, size int64) ([]Trade, error)

非个人,整个交易所的交易记录

func (*Bybit) GetUnfinishOrders

func (g *Bybit) GetUnfinishOrders(currencyPair CurrencyPair) ([]Order, error)

查询指定交易对所有挂单

func (*Bybit) LimitBuy

func (p *Bybit) LimitBuy(amount, price string, currencyPair CurrencyPair, optional ...LimitOrderOptionalParameter) (*Order, error)

限价买单

func (*Bybit) LimitSell

func (p *Bybit) LimitSell(amount, price string, currencyPair CurrencyPair, optional ...LimitOrderOptionalParameter) (*Order, error)

func (*Bybit) MarketBuy

func (p *Bybit) MarketBuy(amount, price string, currencyPair CurrencyPair) (*Order, error)

func (*Bybit) MarketSell

func (p *Bybit) MarketSell(amount, price string, currencyPair CurrencyPair) (*Order, error)

func (*Bybit) PlaceOrder

func (g *Bybit) PlaceOrder(amount, price string, currencyPair CurrencyPair, orderType, orderSide string) (*Order, error)

type Category

type Category string
const (
	CategorySpot    Category = "spot"
	CategoryLinear  Category = "linear"  //Unified Account: USDT perpetual, and USDC contract, including USDC perp, USDC futures; Classic Account: USDT perp
	CategoryInverse Category = "inverse" // Inverse contract, including Inverse perp, Inverse futures
	CategoryOption  Category = "option"
)

type CoinInfo

type CoinInfo struct {
	Coin                string `json:"coin"`
	Equity              string `json:"equity"`
	UsdValue            string `json:"usdValue"`
	WalletBalance       string `json:"walletBalance"`
	Free                string `json:"free"`
	Locked              string `json:"locked"`
	BorrowAmount        string `json:"borrowAmount"`
	AvailableToBorrow   string `json:"availableToBorrow"`
	AvailableToWithdraw string `json:"availableToWithdraw"`
	AccruedInterest     string `json:"accruedInterest"`
	TotalOrderIM        string `json:"totalOrderIM"`
	TotalPositionIM     string `json:"totalPositionIM"`
	TotalPositionMM     string `json:"totalPositionMM"`
	UnrealisedPnl       string `json:"unrealisedPnl"`
	CumRealisedPnl      string `json:"cumRealisedPnl"`
	Bonus               string `json:"bonus"`
	CollateralSwitch    bool   `json:"collateralSwitch"`
	MarginCollateral    bool   `json:"marginCollateral"`
}

type FeeRateItem

type FeeRateItem struct {
	Symbol       string `json:"symbol"`
	BaseCoin     string `json:"baseCoin"`
	TakerFeeRate string `json:"takerFeeRate"`
	MakerFeeRate string `json:"makerFeeRate"`
}

type FeeRatesInfo

type FeeRatesInfo struct {
	Category string        `json:"category"`
	List     []FeeRateItem `json:"list"`
}

交易手续费相关

type Instrument

type Instrument struct {
	Symbol             string         `json:"symbol"`
	ContractType       string         `json:"contractType"`
	OptionType         string         `json:"optionType"`
	Innovation         string         `json:"innovation"`
	Status             SymbolStatus   `json:"status"`
	BaseCoin           string         `json:"baseCoin"`
	QuoteCoin          string         `json:"quoteCoin"`
	LaunchTime         string         `json:"launchTime"`
	DeliveryTime       string         `json:"deliveryTime"`
	DeliveryFeeRate    string         `json:"deliveryFeeRate"`
	PriceScale         string         `json:"priceScale"`
	MarginTrading      string         `json:"marginTrading"`
	LeverageFilter     LeverageFilter `json:"leverageFilter"`
	PriceFilter        PriceFilter    `json:"priceFilter"`
	LotSizeFilter      LotSizeFilter  `json:"lotSizeFilter"`
	UnifiedMarginTrade bool           `json:"unifiedMarginTrade"`
	FundingInterval    int            `json:"fundingInterval"`
	SettleCoin         string         `json:"settleCoin"`
	CopyTrading        string         `json:"copyTrading"`
}

type InstrumentInfoResponse

type InstrumentInfoResponse struct {
	Category       Category     `json:"category"`
	NextPageCursor string       `json:"nextPageCursor"`
	List           []Instrument `json:"list"`
}

交易对信息相关 struct

type LeverageFilter

type LeverageFilter struct {
	MinLeverage  string `json:"minLeverage"`
	MaxLeverage  string `json:"maxLeverage"`
	LeverageStep string `json:"leverageStep"`
}

type LotSizeFilter

type LotSizeFilter struct {
	MaxOrderQty         string `json:"maxOrderQty"`
	MinOrderQty         string `json:"minOrderQty"`
	QtyStep             string `json:"qtyStep"`
	PostOnlyMaxOrderQty string `json:"postOnlyMaxOrderQty"`
	BasePrecision       string `json:"basePrecision"`
	QuotePrecision      string `json:"quotePrecision"`
	MaxOrderAmt         string `json:"maxOrderAmt"`
	MinOrderAmt         string `jsoN:"minOrderAmt"`
}

type MarketKlineResponse

type MarketKlineResponse struct {
	Category Category   `json:"category"`
	Symbol   string     `json:"symbol"`
	List     [][]string `json:"list"`
}

Kline 相关

type MarketTickers

type MarketTickers struct {
	Category string        `json:"category"`
	List     []*TickerInfo `json:"list"`
}

ticker相关

type OrderBookInfo

type OrderBookInfo struct {
	Symbol    string     `json:"s"`
	Bids      [][]string `json:"b"`
	Asks      [][]string `json:"a"`
	Timestamp int64      `json:"ts"`
	UpdateID  int64      `json:"u"`
}

深度相关

type OrderInfo

type OrderInfo struct {
	OrderId            string      `json:"orderId"`
	OrderLinkId        string      `json:"orderLinkId"`
	BlockTradeId       string      `json:"blockTradeId"`
	Symbol             string      `json:"symbol"`
	Price              string      `json:"price"`
	Qty                string      `json:"qty"`
	Side               string      `json:"side"`
	IsLeverage         string      `json:"isLeverage"`
	PositionIdx        int         `json:"positionIdx"`
	OrderStatus        OrderStatus `json:"orderStatus"`
	CancelType         string      `json:"cancelType"`
	RejectReason       string      `json:"rejectReason"`
	AvgPrice           string      `json:"avgPrice"`
	LeavesQty          string      `json:"leavesQty"`
	LeavesValue        string      `json:"leavesValue"`
	CumExecQty         string      `json:"cumExecQty"`
	CumExecValue       string      `json:"cumExecValue"`
	CumExecFee         string      `json:"cumExecFee"`
	TimeInForce        string      `json:"timeInForce"`
	OrderType          string      `json:"orderType"`
	StopOrderType      string      `json:"stopOrderType"`
	OrderIv            string      `json:"orderIv"`
	TriggerPrice       string      `json:"triggerPrice"`
	TakeProfit         string      `json:"takeProfit"`
	StopLoss           string      `json:"stopLoss"`
	TpslMode           string      `json:"tpslMode"`
	OcoTriggerType     string      `json:"ocoTriggerType"`
	TpLimitPrice       string      `json:"tpLimitPrice"`
	SlLimitPrice       string      `json:"slLimitPrice"`
	TpTriggerBy        string      `json:"tpTriggerBy"`
	SlTriggerBy        string      `json:"slTriggerBy"`
	TriggerDirection   int         `json:"triggerDirection"`
	TriggerBy          string      `json:"triggerBy"`
	LastPriceOnCreated string      `json:"lastPriceOnCreated"`
	ReduceOnly         bool        `json:"reduceOnly"`
	CloseOnTrigger     bool        `json:"closeOnTrigger"`
	PlaceType          string      `json:"placeType"`
	SmpType            string      `json:"smpType"`
	SmpGroup           int         `json:"smpGroup"`
	SmpOrderId         string      `json:"smpOrderId"`
	CreatedTime        string      `json:"createdTime"`
	UpdatedTime        string      `json:"updatedTime"`
}

订单相关

type OrderInfoResponse

type OrderInfoResponse struct {
	Category       string       `json:"category"`
	NextPageCursor string       `json:"nextPageCursor"`
	List           []*OrderInfo `json:"list"`
}

type OrderStatus

type OrderStatus string
const (
	OrderStatusCreated                 OrderStatus = "Created" // order has been accepted by the system but not yet put through the matching engine
	OrderStatusNew                     OrderStatus = "New"     // order has been placed successfully
	OrderStatusRejected                OrderStatus = "Rejected"
	OrderStatusPartiallyFilled         OrderStatus = "PartiallyFilled"
	OrderStatusPartiallyFilledCanceled OrderStatus = "PartiallyFilledCanceled" //Only spot has this order status
	OrderStatusFilled                  OrderStatus = "Filled"
	OrderStatusCancelled               OrderStatus = "Cancelled" // In derivatives, orders with this status may have an executed qty
	OrderStatusUntriggered             OrderStatus = "Untriggered"
	OrderStatusTriggered               OrderStatus = "Triggered"
	OrderStatusDeactivated             OrderStatus = "Deactivated" // UTA: Spot tp/sl order, conditional order, OCO order are cancelled before they are triggered
)

type PriceFilter

type PriceFilter struct {
	MinPrice string `json:"minPrice"`
	MaxPrice string `json:"maxPrice"`
	TickSize string `json:"tickSize"`
}

type PublicRecentTradeHistory

type PublicRecentTradeHistory struct {
	Category string      `json:"category"`
	List     []TradeInfo `json:"list"`
}

交易trade相关

type ServerResponse

type ServerResponse struct {
	RetCode    int             `json:"retCode"`
	RetMsg     string          `json:"retMsg"`
	Result     json.RawMessage `json:"result"`
	RetExtInfo struct{}        `json:"retExtInfo"`
	Time       int64           `json:"time"`
}

api server response

type SpotWs

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

func NewSpotWs

func NewSpotWs(accesskey, secretkey, proxy string) *SpotWs

func (*SpotWs) Auth

func (s *SpotWs) Auth()

func (*SpotWs) BestTickerCallback

func (s *SpotWs) BestTickerCallback(f func(ticker *gocoinex.BestTicker, exchange string))

func (*SpotWs) DepthCallback

func (s *SpotWs) DepthCallback(f func(depth *gocoinex.Depth, exchange string))

func (*SpotWs) HeartbeatData

func (s *SpotWs) HeartbeatData() []byte

func (*SpotWs) SubscribeBestTicker

func (s *SpotWs) SubscribeBestTicker(pair gocoinex.CurrencyPair) error

func (*SpotWs) SubscribeDepth

func (s *SpotWs) SubscribeDepth(pair gocoinex.CurrencyPair) error

func (*SpotWs) SubscribeTicker

func (s *SpotWs) SubscribeTicker(pair gocoinex.CurrencyPair) error

func (*SpotWs) SubscribeTrade

func (s *SpotWs) SubscribeTrade(pair gocoinex.CurrencyPair) error

func (*SpotWs) SubscribeUserBalance

func (s *SpotWs) SubscribeUserBalance() error

func (*SpotWs) SubscribeUserOrder

func (s *SpotWs) SubscribeUserOrder() error

func (*SpotWs) TickerCallback

func (s *SpotWs) TickerCallback(f func(ticker *gocoinex.Ticker, exchange string))

func (*SpotWs) TradeCallback

func (s *SpotWs) TradeCallback(f func(trade *gocoinex.Trade, exchange string))

func (*SpotWs) UnSubscribeBestTicker

func (s *SpotWs) UnSubscribeBestTicker(pair gocoinex.CurrencyPair) error

func (*SpotWs) UnSubscribeDepth

func (s *SpotWs) UnSubscribeDepth(pair gocoinex.CurrencyPair) error

func (*SpotWs) UnSubscribeTicker

func (s *SpotWs) UnSubscribeTicker(pair gocoinex.CurrencyPair) error

func (*SpotWs) UnSubscribeTrade

func (s *SpotWs) UnSubscribeTrade(pair gocoinex.CurrencyPair) error

func (*SpotWs) UnSubscribeUserBalance

func (s *SpotWs) UnSubscribeUserBalance() error

func (*SpotWs) UnSubscribeUserOrder

func (s *SpotWs) UnSubscribeUserOrder() error

func (*SpotWs) UserBalanceCallback

func (s *SpotWs) UserBalanceCallback(f func(trade *gocoinex.SubAccount, exchange string))

func (*SpotWs) UserOrderCallback

func (s *SpotWs) UserOrderCallback(f func(trade *gocoinex.Order, exchange string))

type SymbolStatus

type SymbolStatus string
const (
	SymbolStatusPreLaunch  SymbolStatus = "PreLaunch"
	SymbolStatusTrading    SymbolStatus = "Trading"
	SymbolStatusSettling   SymbolStatus = "Settling"
	SymbolStatusDelivering SymbolStatus = "Delivering"
	SymbolStatusClosed     SymbolStatus = "Closed"
)

type TickerInfo

type TickerInfo struct {
	Symbol                 string `json:"symbol"`
	LastPrice              string `json:"lastPrice"`
	IndexPrice             string `json:"indexPrice"`
	MarkPrice              string `json:"markPrice"`
	PrevPrice24h           string `json:"prevPrice24h"`
	Price24hPcnt           string `json:"price24hPcnt"`
	HighPrice24h           string `json:"highPrice24h"`
	LowPrice24h            string `json:"lowPrice24h"`
	PrevPrice1h            string `json:"prevPrice1h"`
	OpenInterest           string `json:"openInterest"`
	OpenInterestValue      string `json:"openInterestValue"`
	Turnover24h            string `json:"turnover24h"`
	Volume24h              string `json:"volume24h"`
	FundingRate            string `json:"fundingRate"`
	NextFundingTime        string `json:"nextFundingTime"`
	PredictedDeliveryPrice string `json:"predictedDeliveryPrice"`
	BasisRate              string `json:"basisRate"`
	Basis                  string `json:"basis"`
	DeliveryFeeRate        string `json:"deliveryFeeRate"`
	DeliveryTime           string `json:"deliveryTime"`
	Ask1Size               string `json:"ask1Size"`
	Bid1Price              string `json:"bid1Price"`
	Ask1Price              string `json:"ask1Price"`
	Bid1Size               string `json:"bid1Size"`
	Ask1Iv                 string `json:"ask1Iv"`
	Bid1Iv                 string `json:"bid1Iv"`
	MarkIv                 string `json:"markIv"`
	UnderlyingPrice        string `json:"underlyingPrice"`
	TotalVolume            string `json:"totalVolume"`
	TotalTurnover          string `json:"totalTurnover"`
	Change24h              string `json:"change24h"`
	UsdIndexPrice          string `json:"usdIndexPrice"`
}

type TimeInForce

type TimeInForce string
const (
	TimeInForceGTC      TimeInForce = "GTC" //GoodTillCancel
	TimeInForceIOC      TimeInForce = "IOC" //ImmediateOrCancel
	TimeInForceFOK      TimeInForce = "FOK" //FillOrKill
	TimeInForcePostOnly TimeInForce = "PostOnly"
)

type TradeInfo

type TradeInfo struct {
	ExecId       string `json:"execId"`
	Symbol       string `json:"symbol"`
	Price        string `json:"price"`
	Size         string `json:"size"`
	Side         string `json:"side"`
	Time         string `json:"time"`
	IsBlockTrade bool   `json:"isBlockTrade"`
}

type WalletAccountInfo

type WalletAccountInfo struct {
	AccountType            string     `json:"accountType"`
	AccountLTV             string     `json:"accountLTV"`
	AccountIMRate          string     `json:"accountIMRate"`
	AccountMMRate          string     `json:"accountMMRate"`
	TotalEquity            string     `json:"totalEquity"`
	TotalWalletBalance     string     `json:"totalWalletBalance"`
	TotalMarginBalance     string     `json:"totalMarginBalance"`
	TotalAvailableBalance  string     `json:"totalAvailableBalance"`
	TotalPerpUPL           string     `json:"totalPerpUPL"`
	TotalInitialMargin     string     `json:"totalInitialMargin"`
	TotalMaintenanceMargin string     `json:"totalMaintenanceMargin"`
	Coins                  []CoinInfo `json:"coin"`
}

type WalletBalanceInfo

type WalletBalanceInfo struct {
	List []WalletAccountInfo `json:"list"`
}

钱包帐户相关

Jump to

Keyboard shortcuts

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