ws

package
v0.0.0-...-a1efc93 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OP_LOGIN       = "login"
	OP_ERROR       = "error"
	OP_SUBSCRIBE   = "subscribe"
	OP_UNSUBSCRIBE = "unsubscribe"
)

操作符

View Source
const (
	SPOT    = "SPOT"
	SWAP    = "SWAP"
	FUTURES = "FUTURES"
	OPTION  = "OPTION"
	ANY     = "ANY"
)

instrument Type

Variables

This section is empty.

Functions

func GetEventByParam

func GetEventByParam(param map[string]string) (evtId Event)

根据args请求参数判断请求类型 如:{"channel": "account","ccy": "BTC"} 类型为 EVENT_BOOK_ACCOUNT

func GetInfoFromErrCode

func GetInfoFromErrCode(data ErrData) Event

通过ErrorCode判断事件类型

func GetInfoFromErrMsg

func GetInfoFromErrMsg(raw string) (channel string)
从error返回中解析出对应的channel
error信息样例

{"event":"error","msg":"channel:index-tickers,instId:BTC-USDT1 doesn't exist","code":"60018"}

Types

type Decorator

type Decorator func(ReqFunc) ReqFunc

type Msg

type Msg struct {
	Timestamp time.Time   `json:"timestamp"`
	Info      interface{} `json:"info"`
}

服务端响应详细信息 Timestamp: 接受到消息的时间 Info: 接受到的消息字符串

func (*Msg) Print

func (this *Msg) Print()

type ProcessDetail

type ProcessDetail struct {
	EndPoint string        `json:"endPoint"`
	ReqInfo  string        `json:"ReqInfo"`  //订阅请求
	SendTime time.Time     `json:"sendTime"` //发送订阅请求的时间
	RecvTime time.Time     `json:"recvTime"` //接受到订阅结果的时间
	UsedTime time.Duration `json:"UsedTime"` //耗时
	Data     []*Msg        `json:"data"`     //订阅结果数据
}

订阅结果封装后的消息结构体

func (*ProcessDetail) String

func (p *ProcessDetail) String() string

type ReceivedDataCallback

type ReceivedDataCallback func(*Msg) error

全局回调函数

type ReceivedDepthDataCallback

type ReceivedDepthDataCallback func(time.Time, DepthData) error

深度订阅推送数据回调函数

type ReceivedMsgDataCallback

type ReceivedMsgDataCallback func(time.Time, MsgData) error

普通订阅推送数据回调函数

type ReqFunc

type ReqFunc func(...interface{}) (res bool, msg *Msg, err error)

type WsClient

type WsClient struct {
	WsEndPoint string
	WsApi      *ApiInfo

	OnErrorHook ReceivedDataCallback //错误处理回调函数

	// 记录深度信息
	DepthDataList map[string]DepthDetail

	DepthDataLock sync.RWMutex
	// contains filtered or unexported fields
}

websocket

func NewWsClient

func NewWsClient(ep string) (r *WsClient, err error)

创建ws对象

func (*WsClient) AddBookMsgHook

func (a *WsClient) AddBookMsgHook(fn ReceivedMsgDataCallback) error

添加订阅消息处理的回调函数

func (*WsClient) AddDepthHook

func (a *WsClient) AddDepthHook(fn ReceivedDepthDataCallback) error

添加深度消息处理的回调函数 例如: cli.AddDepthHook(func(ts time.Time, data DepthData) error { return nil })

func (*WsClient) AddErrMsgHook

func (a *WsClient) AddErrMsgHook(fn ReceivedDataCallback) error

添加错误类型消息处理的回调函数

func (*WsClient) AddMessageHook

func (a *WsClient) AddMessageHook(fn ReceivedDataCallback) error

添加全局消息处理的回调函数

func (*WsClient) AmendOrder

func (a *WsClient) AmendOrder(id string, param map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error)

单个改单 参数说明:

id: 请求ID
params: 请求参数
timeOut: 超时时间

func (*WsClient) BatchAmendOrders

func (a *WsClient) BatchAmendOrders(id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error)

批量改单 参数说明:

id: 请求ID
params: 请求参数
timeOut: 超时时间

func (*WsClient) BatchCancelOrders

func (a *WsClient) BatchCancelOrders(id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error)

批量撤单 参数说明:

id: 请求ID
params: 请求参数
timeOut: 超时时间

func (*WsClient) BatchPlaceOrders

func (a *WsClient) BatchPlaceOrders(id string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error)

批量下单 参数说明:

id: 请求ID
params: 请求参数
timeOut: 超时时间

func (*WsClient) CancelOrder

func (a *WsClient) CancelOrder(id string, param map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error)

单个撤单 参数说明:

id: 请求ID
params: 请求参数
timeOut: 超时时间

func (*WsClient) EnableAutoDepthMgr

func (a *WsClient) EnableAutoDepthMgr(b bool) error

设置是否自动深度管理,开启 true,关闭 false

func (*WsClient) GetSnapshotByChannel

func (a *WsClient) GetSnapshotByChannel(data DepthData) (snapshot *DepthDetail, err error)

获取当前的深度快照信息(合并后的)

func (*WsClient) IsAlive

func (a *WsClient) IsAlive() bool

判断连接是否存活

func (*WsClient) IsQuit

func (a *WsClient) IsQuit() <-chan struct{}

客户端退出消息channel

func (*WsClient) Jrpc

func (a *WsClient) Jrpc(id, op string, params []map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error)

jrpc请求

func (*WsClient) Login

func (a *WsClient) Login(apiKey, secKey, passPhrase string, timeOut ...int) (res bool, detail *ProcessDetail, err error)

登录私有频道

func (*WsClient) MergeDepth

func (a *WsClient) MergeDepth(depData DepthData) (err error)

开启了深度数据管理功能后,系统会自动合并深度信息

func (*WsClient) Ping

func (a *WsClient) Ping(timeOut ...int) (res bool, detail *ProcessDetail, err error)

Ping服务端保持心跳。 timeOut:超时时间(毫秒),如果不填默认为5000ms

func (*WsClient) PlaceOrder

func (a *WsClient) PlaceOrder(id string, param map[string]interface{}, timeOut ...int) (res bool, detail *ProcessDetail, err error)

单个下单 参数说明:

id: 请求ID
params: 请求参数
timeOut: 超时时间

func (*WsClient) PrivAccout

func (a *WsClient) PrivAccout(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

订阅账户频道

func (*WsClient) PrivBalAndPos

func (a *WsClient) PrivBalAndPos(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

订阅账户余额和持仓频道

func (*WsClient) PrivBookAlgoOrder

func (a *WsClient) PrivBookAlgoOrder(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

订阅策略委托订单频道

func (*WsClient) PrivBookOrder

func (a *WsClient) PrivBookOrder(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

订阅订单频道

func (*WsClient) PrivPostion

func (a *WsClient) PrivPostion(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

订阅持仓频道

func (*WsClient) PubChannel

func (a *WsClient) PubChannel(evtId Event, op string, params []map[string]string, pd Period, timeOut ...int) (res bool, msg []*Msg, err error)

func (*WsClient) PubEstDePrice

func (a *WsClient) PubEstDePrice(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

预估交割/行权价格频道

func (*WsClient) PubFundRate

func (a *WsClient) PubFundRate(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

资金费率频道

func (*WsClient) PubIndexTickers

func (a *WsClient) PubIndexTickers(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

指数行情频道

func (*WsClient) PubInstruemnts

func (a *WsClient) PubInstruemnts(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

产品频道

func (*WsClient) PubKLine

func (a *WsClient) PubKLine(op string, period Period, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

K线频道

func (*WsClient) PubKLineIndex

func (a *WsClient) PubKLineIndex(op string, pd Period, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

指数K线频道

func (*WsClient) PubLimitPrice

func (a *WsClient) PubLimitPrice(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

限价频道

func (*WsClient) PubMarkPrice

func (a *WsClient) PubMarkPrice(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

标记价格频道

func (*WsClient) PubMarkPriceCandle

func (a *WsClient) PubMarkPriceCandle(op string, pd Period, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

标记价格K线频道

func (*WsClient) PubOpenInsterest

func (a *WsClient) PubOpenInsterest(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

持仓总量频道

func (*WsClient) PubOptionSummary

func (a *WsClient) PubOptionSummary(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

期权定价频道

func (*WsClient) PubOrderBooks

func (a *WsClient) PubOrderBooks(op string, channel string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

深度频道

func (*WsClient) PubStatus

func (a *WsClient) PubStatus(op string, timeOut ...int) (res bool, msg []*Msg, err error)

func (*WsClient) PubTickers

func (a *WsClient) PubTickers(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

行情频道

func (*WsClient) PubTrade

func (a *WsClient) PubTrade(op string, params []map[string]string, timeOut ...int) (res bool, msg []*Msg, err error)

交易频道

func (*WsClient) Send

func (a *WsClient) Send(ctx context.Context, op WSReqData) (err error)

发送消息到服务端

func (*WsClient) SetDailTimeout

func (a *WsClient) SetDailTimeout(tm time.Duration)

设置dial超时时间

func (*WsClient) Start

func (a *WsClient) Start() error

非阻塞启动

func (*WsClient) Stop

func (a *WsClient) Stop() error

func (*WsClient) Subscribe

func (a *WsClient) Subscribe(param map[string]string, timeOut ...int) (res bool, detail *ProcessDetail, err error)

订阅频道。 req:请求json字符串

func (*WsClient) UnSubscribe

func (a *WsClient) UnSubscribe(param map[string]string, timeOut ...int) (res bool, detail *ProcessDetail, err error)

取消订阅频道。 req:请求json字符串

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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