ws

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HostReal    = "wss://stream.bybit.com/realtime"
	HostTestnet = "wss://stream-testnet.bybit.com/realtime"
)
View Source
const (
	WSOrderBook25L1 = "orderBookL2_25" // 新版25档orderBook: order_book_25L1.BTCUSD
	WSKLine         = "kline"          // K线: kline.BTCUSD.1m
	WSTrade         = "trade"          // 实时交易: trade/trade.BTCUSD
	WSInsurance     = "insurance"      // 每日保险基金更新: insurance
	WSInstrument    = "instrument"     // 产品最新行情: instrument

	WSPosition  = "position"  // 仓位变化: position
	WSExecution = "execution" // 委托单成交信息: execution
	WSOrder     = "order"     // 委托单的更新: order

	WSDisconnected = "disconnected" // WS断开事件
)
View Source
const (
	MaxTryTimes = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ByBitWS

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

func New

func New(config *Configuration) *ByBitWS

func (*ByBitWS) Auth

func (b *ByBitWS) Auth() error

func (*ByBitWS) Close

func (b *ByBitWS) Close()

func (*ByBitWS) Emit

func (b *ByBitWS) Emit(event interface{}, arguments ...interface{}) *emission.Emitter

Emit emits an event

func (*ByBitWS) IsConnected

func (b *ByBitWS) IsConnected() bool

IsConnected returns the WebSocket connection state

func (*ByBitWS) Off

func (b *ByBitWS) Off(event interface{}, listener interface{}) *emission.Emitter

Off removes a listener for an event

func (*ByBitWS) On

func (b *ByBitWS) On(event interface{}, listener interface{}) *emission.Emitter

On adds a listener to a specific event

func (*ByBitWS) Send

func (b *ByBitWS) Send(msg string) (err error)

func (*ByBitWS) SendCmd

func (b *ByBitWS) SendCmd(cmd Cmd) error

func (*ByBitWS) Start

func (b *ByBitWS) Start() error

func (*ByBitWS) Subscribe

func (b *ByBitWS) Subscribe(arg string)

type Cmd

type Cmd struct {
	Op   string        `json:"op"`
	Args []interface{} `json:"args"`
}

ws.send('{"op":"subscribe","args":["topic","topic.filter"]}');

// 同一个类型的filter有多个时,以'|'分割 // 如订阅BTCUSD一分钟和三分钟的kline ws.send('{"op":"subscribe","args":["kline.BTCUSD.1m|3m"]}');

// 订阅同一个类型filter的所有数据时请使用'*' // 如订阅所有产品的所有interval kline ws.send('{"op":"subscribe","args":["kline.*.*"]}')

type Configuration

type Configuration struct {
	Addr          string `json:"addr"`
	ApiKey        string `json:"api_key"`
	SecretKey     string `json:"secret_key"`
	AutoReconnect bool   `json:"auto_reconnect"`
	DebugMode     bool   `json:"debug_mode"`
}

type Execution

type Execution struct {
	Symbol      string    `json:"symbol"`
	Side        string    `json:"side"`
	OrderID     string    `json:"order_id"`
	ExecID      string    `json:"exec_id"`
	OrderLinkID string    `json:"order_link_id"`
	Price       float64   `json:"price,string"`
	OrderQty    float64   `json:"order_qty"`
	ExecType    string    `json:"exec_type"`
	ExecQty     float64   `json:"exec_qty"`
	ExecFee     float64   `json:"exec_fee,string"`
	LeavesQty   float64   `json:"leaves_qty"`
	IsMaker     bool      `json:"is_maker"`
	TradeTime   time.Time `json:"trade_time"`
}

type Instrument

type Instrument struct {
	Symbol     string  `json:"symbol"`
	MarkPrice  float64 `json:"mark_price"`
	IndexPrice float64 `json:"index_price"`
}

type Insurance

type Insurance struct {
	Currency      string    `json:"currency"`
	Timestamp     time.Time `json:"timestamp"`
	WalletBalance int64     `json:"wallet_balance"`
}

type Item

type Item struct {
	Amount float64 `json:"amount"`
	Price  float64 `json:"price"`
}

Item stores the amount and price values

type KLine

type KLine struct {
	ID       int64   `json:"id"`        // 563
	Symbol   string  `json:"symbol"`    // BTCUSD
	OpenTime int64   `json:"open_time"` // 1539918000
	Open     float64 `json:"open"`
	High     float64 `json:"high"`
	Low      float64 `json:"low"`
	Close    float64 `json:"close"`
	Volume   float64 `json:"volume"`
	Turnover float64 `json:"turnover"` // 0.0013844
	Interval string  `json:"interval"` // 1m
}

type Order

type Order struct {
	OrderID       string    `json:"order_id"`
	OrderLinkID   string    `json:"order_link_id"`
	Symbol        string    `json:"symbol"`
	Side          string    `json:"side"`
	OrderType     string    `json:"order_type"`
	Price         float64   `json:"price,string"`
	Qty           float64   `json:"qty"`
	TimeInForce   string    `json:"time_in_force"` // GoodTillCancel/ImmediateOrCancel/FillOrKill/PostOnly
	CreateType    string    `json:"create_type"`
	CancelType    string    `json:"cancel_type"`
	OrderStatus   string    `json:"order_status"`
	LeavesQty     float64   `json:"leaves_qty"`
	CumExecQty    float64   `json:"cum_exec_qty"`
	CumExecValue  float64   `json:"cum_exec_value,string"`
	CumExecFee    float64   `json:"cum_exec_fee,string"`
	Timestamp     time.Time `json:"timestamp"`
	TakeProfit    float64   `json:"take_profit,string"`
	StopLoss      float64   `json:"stop_loss,string"`
	TrailingStop  float64   `json:"trailing_stop,string"`
	LastExecPrice float64   `json:"last_exec_price,string"`
}

type OrderBook

type OrderBook struct {
	Bids      []Item    `json:"bids"`
	Asks      []Item    `json:"asks"`
	Timestamp time.Time `json:"timestamp"`
}

type OrderBookL2

type OrderBookL2 struct {
	ID     int64   `json:"id"`
	Price  float64 `json:"price,string"`
	Side   string  `json:"side"`
	Size   int64   `json:"size"`
	Symbol string  `json:"symbol"`
}

func (*OrderBookL2) Key

func (o *OrderBookL2) Key() string

type OrderBookL2Delta

type OrderBookL2Delta struct {
	Delete []*OrderBookL2 `json:"delete"`
	Update []*OrderBookL2 `json:"update"`
	Insert []*OrderBookL2 `json:"insert"`
}

type OrderBookLocal

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

func NewOrderBookLocal

func NewOrderBookLocal() *OrderBookLocal

func (*OrderBookLocal) GetOrderBook

func (o *OrderBookLocal) GetOrderBook() (ob OrderBook)

func (*OrderBookLocal) LoadSnapshot

func (o *OrderBookLocal) LoadSnapshot(newOrderbook []*OrderBookL2) error

func (*OrderBookLocal) Update

func (o *OrderBookLocal) Update(delta *OrderBookL2Delta)

type Position

type Position struct {
	UserID           int64   `json:"user_id"`
	Symbol           string  `json:"symbol"`
	Size             float64 `json:"size"`
	Side             string  `json:"side"`
	PositionValue    float64 `json:"position_value,string"`
	EntryPrice       float64 `json:"entry_price,string"`
	LiqPrice         float64 `json:"liq_price,string"`
	BustPrice        float64 `json:"bust_price,string"`
	Leverage         float64 `json:"leverage,string"`
	OrderMargin      float64 `json:"order_margin,string"`
	PositionMargin   float64 `json:"position_margin,string"`
	AvailableBalance float64 `json:"available_balance,string"`
	TakeProfit       float64 `json:"take_profit,string"`
	StopLoss         float64 `json:"stop_loss,string"`
	RealisedPnl      float64 `json:"realised_pnl,string"`
	TrailingStop     float64 `json:"trailing_stop,string"`
	TrailingActive   float64 `json:"trailing_active,string"`
	WalletBalance    float64 `json:"wallet_balance,string"`
	RiskID           int     `json:"risk_id"`
	OccClosingFee    float64 `json:"occ_closing_fee,string"`
	OccFundingFee    float64 `json:"occ_funding_fee,string"`
	AutoAddMargin    int     `json:"auto_add_margin"`
	CumRealisedPnl   float64 `json:"cum_realised_pnl,string"`
	PositionStatus   string  `json:"position_status"`
	PositionSeq      int64   `json:"position_seq"`
}

type Trade

type Trade struct {
	Timestamp     time.Time `json:"timestamp"`
	Symbol        string    `json:"symbol"`
	Side          string    `json:"side"`
	Size          int       `json:"size"`
	Price         float64   `json:"price"`
	TickDirection string    `json:"tick_direction"`
	TradeID       string    `json:"trade_id"`
	CrossSeq      int       `json:"cross_seq"`
}

Jump to

Keyboard shortcuts

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