ws

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PUBLIC  ChannelType = "public"  // 公共频道
	PRIVATE ChannelType = "private" // 私有频道

	PublicUrl  common.BaseURL = "wss://ws.okex.com:8443/ws/v5/public"  // 实盘公共API交易地址
	PrivateUrl common.BaseURL = "wss://ws.okex.com:8443/ws/v5/private" // 实盘私有API交易地址

	AwsPublicUrl  common.BaseURL = "wss://wsaws.okex.com:8443/ws/v5/public"  // AWS公共地址
	AwsPrivateUrl common.BaseURL = "wss://wsaws.okex.com:8443/ws/v5/private" // AWS私有地址

	SimulatePublicUrl  common.BaseURL = "wss://wspap.okex.com:8443/ws/v5/public?brokerId=9999"  // 模拟盘公共
	SimulatePrivateUrl common.BaseURL = "wss://wspap.okex.com:8443/ws/v5/private?brokerId=9999" // 模拟盘私有

	AccountEventType            EventType = "account"              // 账户信息
	PositionsEventType          EventType = "positions"            // 持仓信息
	BalanceAndPositionEventType EventType = "balance_and_position" // 账户余额和持仓信息
	OrdersEventType             EventType = "orders"               // 订单信息
)

Variables

View Source
var (
	UseTestnet = false            // UseTestnet 使用测试api
	UseAWSnet  = false            // UseAWSnet 使用AWS api
	Timeout    = time.Second * 10 // WebsocketTimeout 发送ping时间间隔
	KeepAlive  = true             // WebsocketKeepalive 是否一直连接
)

Functions

func SubscribeAccount added in v0.1.1

func SubscribeAccount(conf *okex.Config, handler AccountHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error)

SubscribeAccount 订阅账户信息

func SubscribeBalanceAndPosition added in v0.1.1

func SubscribeBalanceAndPosition(conf *okex.Config, handler BalanceAndPositionHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error)

SubscribeBalanceAndPosition 订阅账户余额和持仓频道信息

func SubscribeDepthServe added in v0.1.1

func SubscribeDepthServe(symbolLevels []string, channel DepthChannel, handler DepthHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error)

SubscribeDepthServe 订阅深度信息

func SubscribeOrders added in v0.1.1

func SubscribeOrders(conf *okex.Config, instType common.InstType, handler OrdersHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error)

SubscribeOrders 订阅订单信息

func SubscribePositions added in v0.1.1

func SubscribePositions(conf *okex.Config, instType common.InstType, handler PositionsHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error)

SubscribePositions 订阅持仓信息

Types

type AccountArg added in v0.1.1

type AccountArg struct {
	Channel string `json:"channel"`
	Ccy     string `json:"ccy"`
	UID     string `json:"uid"`
}

type AccountData added in v0.1.1

type AccountData struct {
	UTime       string           `json:"uTime"`
	TotalEq     string           `json:"totalEq"`
	IsoEq       string           `json:"isoEq"`
	AdjEq       string           `json:"adjEq"`
	OrdFroz     string           `json:"ordFroz"`
	Imr         string           `json:"imr"`
	Mmr         string           `json:"mmr"`
	NotionalUsd string           `json:"notionalUsd"`
	MgnRatio    string           `json:"mgnRatio"`
	Details     []AccountDetails `json:"details"`
}

type AccountDetails added in v0.1.1

type AccountDetails struct {
	AvailBal      string `json:"availBal"`
	AvailEq       string `json:"availEq"`
	Ccy           string `json:"ccy"`
	CashBal       string `json:"cashBal"`
	UTime         string `json:"uTime"`
	DisEq         string `json:"disEq"`
	Eq            string `json:"eq"`
	EqUsd         string `json:"eqUsd"`
	FrozenBal     string `json:"frozenBal"`
	Interest      string `json:"interest"`
	IsoEq         string `json:"isoEq"`
	Liab          string `json:"liab"`
	MaxLoan       string `json:"maxLoan"`
	MgnRatio      string `json:"mgnRatio"`
	NotionalLever string `json:"notionalLever"`
	OrdFrozen     string `json:"ordFrozen"`
	Upl           string `json:"upl"`
	UplLiab       string `json:"uplLiab"`
	CrossLiab     string `json:"crossLiab"`
	IsoLiab       string `json:"isoLiab"`
	CoinUsdPrice  string `json:"coinUsdPrice"`
	StgyEq        string `json:"stgyEq"`
	SpotInUseAmt  string `json:"spotInUseAmt"`
	IsoUpl        string `json:"isoUpl"`
}

type AccountEvent added in v0.1.1

type AccountEvent struct {
	BaseEvent
	EventType EventType
	Arg       AccountArg    `json:"arg"`
	Data      []AccountData `json:"data"`
}

AccountEvent 账户信息

type AccountHandler added in v0.1.1

type AccountHandler func(event *AccountEvent)

type Arg added in v0.1.1

type Arg struct {
	Channel string `json:"channel"`
	InstID  string `json:"instId"`
}

type BalData added in v0.1.1

type BalData struct {
	Ccy     string `json:"ccy"`
	CashBal string `json:"cashBal"`
	UTime   string `json:"uTime"`
}

type BalanceAndPositionArg added in v0.1.1

type BalanceAndPositionArg struct {
	Channel string `json:"channel"`
	UID     string `json:"uid"`
}

type BalanceAndPositionData added in v0.1.1

type BalanceAndPositionData struct {
	PTime     string    `json:"pTime"`
	EventType string    `json:"eventType"`
	BalData   []BalData `json:"balData"`
	PosData   []PosData `json:"posData"`
}

type BalanceAndPositionEvent added in v0.1.1

type BalanceAndPositionEvent struct {
	BaseEvent
	EventType EventType
	Arg       BalanceAndPositionArg    `json:"arg"`
	Data      []BalanceAndPositionData `json:"data"`
}

BalanceAndPositionEvent 账户余额和持仓频道数据

type BalanceAndPositionHandler added in v0.1.1

type BalanceAndPositionHandler func(event *BalanceAndPositionEvent)

type BaseEvent added in v0.1.2

type BaseEvent struct {
	Event string `json:"event"`
	Code  string `json:"code"`
	Msg   string `json:"msg"`
}

type ChannelType

type ChannelType string

type CreateOrder added in v0.1.1

type CreateOrder struct {
	Id      string         `json:"id,omitempty"`
	Op      common.Operate `json:"op,omitempty"`
	ExpTime string         `json:"expTime,omitempty"`
	Args    []*OrderArgs   `json:"args,omitempty"`
}

CreateOrder 创建订单

func NewBatchOrder added in v0.1.5

func NewBatchOrder() *CreateOrder

func NewCreateOrder added in v0.1.1

func NewCreateOrder(op common.Operate) *CreateOrder

func NewOrder added in v0.1.5

func NewOrder() *CreateOrder

func (*CreateOrder) SetArgs added in v0.1.1

func (o *CreateOrder) SetArgs(args *OrderArgs) *CreateOrder

func (*CreateOrder) SetExpTime added in v0.1.1

func (o *CreateOrder) SetExpTime(expTime string) *CreateOrder

func (*CreateOrder) SetId added in v0.1.1

func (o *CreateOrder) SetId(id string) *CreateOrder

type CreateOrderEvent added in v0.1.1

type CreateOrderEvent struct {
	Done bool
	ID   string      `json:"id"`
	Op   string      `json:"op"`
	Data []OrderData `json:"data"`
	Code string      `json:"code"`
	Msg  string      `json:"msg"`
}

type Data added in v0.1.1

type Data struct {
	Asks     [][]string `json:"asks"`
	Bids     [][]string `json:"bids"`
	Ts       string     `json:"ts"`
	Checksum int        `json:"checksum"`
}

type DepthChannel

type DepthChannel string

DepthChannel 深度频道

const (
	DepthBooks        DepthChannel = "books"
	DepthBooks5       DepthChannel = "books5"
	DepthBooks12tbt   DepthChannel = "books-12-tbt"
	DepthBooks5012tbt DepthChannel = "books50-12-tbt"
)

type DepthEvent added in v0.1.1

type DepthEvent struct {
	BaseEvent
	Arg    Arg    `json:"arg"`
	Action string `json:"action"`
	Data   []Data `json:"data"`
}

DepthEvent 深度数据

type DepthHandler added in v0.1.1

type DepthHandler func(event *DepthEvent)

DepthHandler 深度处理器

type ErrHandler

type ErrHandler func(err error)

ErrHandler 处理错误

type EventType added in v0.1.1

type EventType string

type Handler added in v0.1.1

type Handler interface {
	// contains filtered or unexported methods
}

type OrderArgs added in v0.1.1

type OrderArgs struct {
	Side       common.SideType  `json:"side,omitempty"`    // 订单方向
	PosSide    common.PosSide   `json:"posSide,omitempty"` // 持仓方向
	InstID     string           `json:"instId,omitempty"`
	TdMode     common.TdMode    `json:"tdMode,omitempty"`
	OrdType    common.OrderType `json:"ordType,omitempty"`
	Sz         string           `json:"sz,omitempty"`
	Ccy        string           `json:"ccy,omitempty"`
	ClOrdID    string           `json:"clOrdId,omitempty"`
	Tag        string           `json:"tag,omitempty"`
	Px         string           `json:"px,omitempty"`
	ReduceOnly string           `json:"reduceOnly,omitempty"`
	TgtCcy     string           `json:"tgtCcy,omitempty"`
	BanAmend   string           `json:"banAmend,omitempty"`
}

func NewOrderArgs added in v0.1.1

func NewOrderArgs() *OrderArgs

func (*OrderArgs) SetBanAmend added in v0.1.1

func (o *OrderArgs) SetBanAmend(banAmend string) *OrderArgs

func (*OrderArgs) SetCcy added in v0.1.1

func (o *OrderArgs) SetCcy(ccy string) *OrderArgs

func (*OrderArgs) SetClOrdID added in v0.1.1

func (o *OrderArgs) SetClOrdID(clOrdID string) *OrderArgs

func (*OrderArgs) SetInstID added in v0.1.1

func (o *OrderArgs) SetInstID(instID string) *OrderArgs

func (*OrderArgs) SetOrdType added in v0.1.1

func (o *OrderArgs) SetOrdType(ordType common.OrderType) *OrderArgs

func (*OrderArgs) SetPosSide added in v0.1.1

func (o *OrderArgs) SetPosSide(posSide common.PosSide) *OrderArgs

func (*OrderArgs) SetPx added in v0.1.1

func (o *OrderArgs) SetPx(px string) *OrderArgs

func (*OrderArgs) SetReduceOnly added in v0.1.1

func (o *OrderArgs) SetReduceOnly(reduceOnly string) *OrderArgs

func (*OrderArgs) SetSide added in v0.1.1

func (o *OrderArgs) SetSide(side common.SideType) *OrderArgs

func (*OrderArgs) SetSz added in v0.1.1

func (o *OrderArgs) SetSz(sz string) *OrderArgs

func (*OrderArgs) SetTag added in v0.1.1

func (o *OrderArgs) SetTag(tag string) *OrderArgs

func (*OrderArgs) SetTdMode added in v0.1.1

func (o *OrderArgs) SetTdMode(tdMode common.TdMode) *OrderArgs

func (*OrderArgs) SetTgtCcy added in v0.1.1

func (o *OrderArgs) SetTgtCcy(tgtCcy string) *OrderArgs

type OrderData added in v0.1.1

type OrderData struct {
	ClOrdID string `json:"clOrdId"`
	OrdID   string `json:"ordId"`
	Tag     string `json:"tag"`
	SCode   string `json:"sCode"`
	SMsg    string `json:"sMsg"`
}

type OrdersArg added in v0.1.1

type OrdersArg struct {
	Channel  string `json:"channel"`
	InstType string `json:"instType"`
	InstID   string `json:"instId"`
	UID      string `json:"uid"`
}

type OrdersData added in v0.1.1

type OrdersData struct {
	AccFillSz       string `json:"accFillSz"`
	AmendResult     string `json:"amendResult"`
	AvgPx           string `json:"avgPx"`
	CTime           string `json:"cTime"`
	Category        string `json:"category"`
	Ccy             string `json:"ccy"`
	ClOrdID         string `json:"clOrdId"`
	Code            string `json:"code"`
	ExecType        string `json:"execType"`
	Fee             string `json:"fee"`
	FeeCcy          string `json:"feeCcy"`
	FillFee         string `json:"fillFee"`
	FillFeeCcy      string `json:"fillFeeCcy"`
	FillNotionalUsd string `json:"fillNotionalUsd"`
	FillPx          string `json:"fillPx"`
	FillSz          string `json:"fillSz"`
	FillTime        string `json:"fillTime"`
	InstID          string `json:"instId"`
	InstType        string `json:"instType"`
	Lever           string `json:"lever"`
	Msg             string `json:"msg"`
	NotionalUsd     string `json:"notionalUsd"`
	OrdID           string `json:"ordId"`
	OrdType         string `json:"ordType"`
	Pnl             string `json:"pnl"`
	PosSide         string `json:"posSide"`
	Px              string `json:"px"`
	Rebate          string `json:"rebate"`
	RebateCcy       string `json:"rebateCcy"`
	ReduceOnly      string `json:"reduceOnly"`
	ReqID           string `json:"reqId"`
	Side            string `json:"side"`
	SlOrdPx         string `json:"slOrdPx"`
	SlTriggerPx     string `json:"slTriggerPx"`
	SlTriggerPxType string `json:"slTriggerPxType"`
	Source          string `json:"source"`
	State           string `json:"state"`
	Sz              string `json:"sz"`
	Tag             string `json:"tag"`
	TdMode          string `json:"tdMode"`
	TgtCcy          string `json:"tgtCcy"`
	TpOrdPx         string `json:"tpOrdPx"`
	TpTriggerPx     string `json:"tpTriggerPx"`
	TpTriggerPxType string `json:"tpTriggerPxType"`
	TradeID         string `json:"tradeId"`
	UTime           string `json:"uTime"`
}

type OrdersEvent added in v0.1.1

type OrdersEvent struct {
	BaseEvent
	EventType EventType
	Arg       OrdersArg    `json:"arg"`
	Data      []OrdersData `json:"data"`
}

OrdersEvent 订单信息

type OrdersHandler added in v0.1.1

type OrdersHandler func(event *OrdersEvent)

type PosData added in v0.1.1

type PosData struct {
	PosID    string `json:"posId"`
	TradeID  string `json:"tradeId"`
	InstID   string `json:"instId"`
	InstType string `json:"instType"`
	MgnMode  string `json:"mgnMode"`
	PosSide  string `json:"posSide"`
	Pos      string `json:"pos"`
	Ccy      string `json:"ccy"`
	PosCcy   string `json:"posCcy"`
	AvgPx    string `json:"avgPx"`
	UTime    string `json:"uTime"`
}

type PositionsArg added in v0.1.1

type PositionsArg struct {
	Channel  string `json:"channel"`
	UID      string `json:"uid"`
	InstType string `json:"instType"`
}

type PositionsData added in v0.1.1

type PositionsData struct {
	Adl          string `json:"adl"`
	AvailPos     string `json:"availPos"`
	AvgPx        string `json:"avgPx"`
	CTime        string `json:"cTime"`
	Ccy          string `json:"ccy"`
	DeltaBS      string `json:"deltaBS"`
	DeltaPA      string `json:"deltaPA"`
	GammaBS      string `json:"gammaBS"`
	GammaPA      string `json:"gammaPA"`
	Imr          string `json:"imr"`
	InstID       string `json:"instId"`
	InstType     string `json:"instType"`
	Interest     string `json:"interest"`
	Last         string `json:"last"`
	Lever        string `json:"lever"`
	Liab         string `json:"liab"`
	LiabCcy      string `json:"liabCcy"`
	LiqPx        string `json:"liqPx"`
	MarkPx       string `json:"markPx"`
	Margin       string `json:"margin"`
	MgnMode      string `json:"mgnMode"`
	MgnRatio     string `json:"mgnRatio"`
	Mmr          string `json:"mmr"`
	NotionalUsd  string `json:"notionalUsd"`
	OptVal       string `json:"optVal"`
	PTime        string `json:"pTime"`
	Pos          string `json:"pos"`
	PosCcy       string `json:"posCcy"`
	PosID        string `json:"posId"`
	PosSide      string `json:"posSide"`
	SpotInUseAmt string `json:"spotInUseAmt"`
	SpotInUseCcy string `json:"spotInUseCcy"`
	ThetaBS      string `json:"thetaBS"`
	ThetaPA      string `json:"thetaPA"`
	TradeID      string `json:"tradeId"`
	UTime        string `json:"uTime"`
	Upl          string `json:"upl"`
	UplRatio     string `json:"uplRatio"`
	VegaBS       string `json:"vegaBS"`
	VegaPA       string `json:"vegaPA"`
}

type PositionsEvent added in v0.1.1

type PositionsEvent struct {
	BaseEvent
	EventType EventType
	Arg       PositionsArg    `json:"arg"`
	Data      []PositionsData `json:"data"`
}

PositionsEvent 持仓信息

type PositionsHandler added in v0.1.1

type PositionsHandler func(event *PositionsEvent)

type WebsocketTrade added in v0.1.1

type WebsocketTrade struct {
	Handler Handler
	// contains filtered or unexported fields
}

func NewWebsocketTrade added in v0.1.1

func NewWebsocketTrade(conf *okex.Config, errHandler ErrHandler) (w *WebsocketTrade)

func (*WebsocketTrade) Dail added in v0.1.1

func (w *WebsocketTrade) Dail() (doneC, stopC chan struct{})

func (*WebsocketTrade) Order added in v0.1.1

func (w *WebsocketTrade) Order(param *CreateOrder) (event CreateOrderEvent, err error)

type WsHandler

type WsHandler func(message []byte)

WsHandler 处理返回信息

Jump to

Keyboard shortcuts

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