ws

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 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)

Determine the request type according to the args request parameter For example: {"channel": "account","ccy": "BTC"} The type is EVENT_BOOK_ACCOUNT

func GetInfoFromErrCode

func GetInfoFromErrCode(data ErrData) Event

Judge the event type by ErrorCode

func GetInfoFromErrMsg

func GetInfoFromErrMsg(raw string) (channel string)

Resolve the corresponding channel from the error return

   Sample error message
{"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"`
}

Server response details Timestamp: The time when the message was received Info: The received message string

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"`     //订阅结果数据
}

Message structure after subscription result encapsulation

func (*ProcessDetail) String

func (p *ProcessDetail) String() string

type ReceivedDataCallback

type ReceivedDataCallback func(*Msg) error

Global callback function

type ReceivedDepthDataCallback

type ReceivedDepthDataCallback func(time.Time, DepthData) error

Deep subscription push data callback function

type ReceivedMsgDataCallback

type ReceivedMsgDataCallback func(time.Time, MsgData) error

Ordinary subscription push data callback function

type ReqFunc

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

type WsClient

type WsClient struct {
	WsEndPoint string
	WsApi      *ApiInfo

	OnErrorHook ReceivedDataCallback //Error handling callback function

	// Record depth information
	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

Add callback function for subscription message processing

func (*WsClient) AddDepthHook

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

Add callback function for in-depth message processing For example: cli.AddDepthHook(func(ts time.Time, data DepthData) error { return nil })

func (*WsClient) AddErrMsgHook

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

Add callback function for error message processing

func (*WsClient) AddMessageHook

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

Add callback function for global message processing

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

Determine if the connection is alive

func (*WsClient) IsQuit

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

Client exit message channel

func (*WsClient) Jrpc

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

jrpc request

func (*WsClient) Login

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

Sign in to private channel

func (*WsClient) MergeDepth

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

After the in-depth data management function is turned on, the system will automatically merge in-depth information

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)

Estimated delivery/exercise price channel

func (*WsClient) PubFundRate

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

Funding rate channel

func (*WsClient) PubIndexTickers

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

Index market channel

func (*WsClient) PubInstruemnts

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

Product Channel

func (*WsClient) PubKLine

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

K line channel

func (*WsClient) PubKLineIndex

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

Index K-Line Channel

func (*WsClient) PubLimitPrice

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

Limit channel

func (*WsClient) PubMarkPrice

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

Mark price channel

func (*WsClient) PubMarkPriceCandle

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

Mark price K-line channel

func (*WsClient) PubOpenInsterest

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

Total position channel

func (*WsClient) PubOptionSummary

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

Option Pricing Channel

func (*WsClient) PubOrderBooks

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

Deep channel

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)

Quotes Channel

func (*WsClient) PubTrade

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

Trading channel

func (*WsClient) Send

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

Send a message to the server

func (*WsClient) SetDailTimeout

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

设置dial超时时间

func (*WsClient) Start

func (a *WsClient) Start() error

Non-blocking start

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)

Subscribe to the channel. req: request json string

func (*WsClient) UnSubscribe

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

Unsubscribe from the channel. req: request json string

Directories

Path Synopsis
错误数据 JRPC请求/响应数据
错误数据 JRPC请求/响应数据

Jump to

Keyboard shortcuts

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