websocket

package
v2.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// OrderPlaceSpotWsApiMethod define method for creation order via websocket API
	OrderPlaceSpotWsApiMethod WsApiMethodType = "order.place"

	// OrderPlaceFuturesWsApiMethod define method for creation order via websocket API
	OrderPlaceFuturesWsApiMethod WsApiMethodType = "order.place"

	// CancelFuturesWsApiMethod define method for cancel order via websocket API
	CancelFuturesWsApiMethod WsApiMethodType = "order.cancel"

	// SessionLogonSpotWsApiMethod define method to authenticate, or change the API key associated with the connection
	SessionLogonSpotWsApiMethod = "session.logon"

	// SessionStatusSpotWsApiMethod define method to check connection status and the current API key
	SessionStatusSpotWsApiMethod = "session.status"

	// SessionLogoutSpotWsApiMethod define method to forget the API key associated with the connection
	SessionLogoutSpotWsApiMethod = "session.logout"

	// UserDataStreamSubscribeSpotWsApiMethod define method to subscribe to user data stream via websocket API
	UserDataStreamSubscribeSpotWsApiMethod = "userDataStream.subscribe"

	// UserDataStreamUnsubscribeSpotWsApiMethod define method to unsubscribe from user data stream via websocket API
	UserDataStreamUnsubscribeSpotWsApiMethod = "userDataStream.unsubscribe"

	UserMarginDataStreamSubscribeWsApiMethod = "userDataStream.subscribe.listenToken"
)

Variables

View Source
var (
	// ErrorWsReadConnectionTimeout defines that connection read timeout expired
	ErrorWsReadConnectionTimeout = errors.New("ws error: read connection timeout")

	// ErrorWsIdAlreadySent defines that request with the same id was already sent
	ErrorWsIdAlreadySent = errors.New("ws error: request with same id already sent")

	// KeepAlivePingDeadline defines deadline to send ping frame
	KeepAlivePingDeadline = 10 * time.Second

	// WaitCheckInternal defines interval for ticker when it checks pending requests while stop application
	WaitCheckInternal = 300 * time.Millisecond
)
View Source
var (
	// ErrorRequestIDNotSet defines that request ID is not set
	ErrorRequestIDNotSet = errors.New("ws service: request id is not set")

	// ErrorApiKeyIsNotSet defines that ApiKey is not set
	ErrorApiKeyIsNotSet = errors.New("ws service: api key is not set")

	// ErrorSecretKeyIsNotSet defines that SecretKey is not set
	ErrorSecretKeyIsNotSet = errors.New("ws service: secret key is not set")
)
View Source
var (
	// WriteSyncWsTimeout defines timeout for WriteSync method of client_ws
	WriteSyncWsTimeout = 5 * time.Second
)

Functions

func CreateRequest

func CreateRequest(reqData RequestData, method WsApiMethodType, params map[string]interface{}) ([]byte, error)

CreateRequest creates signed ws request

func CreateUnsignedRequest

func CreateUnsignedRequest(requestID string, method WsApiMethodType, params map[string]interface{}) ([]byte, error)

CreateUnsignedRequest creates unsigned ws request

Types

type Client

type Client interface {
	Write(id string, data []byte) error
	WriteSync(id string, data []byte, timeout time.Duration) ([]byte, error)
	GetReadChannel() <-chan []byte
	GetReadErrorChannel() <-chan error
	GetReconnectCount() int64
	Wait(timeout time.Duration)
}

func NewClient

func NewClient(conn Connection) (Client, error)

NewClient init client

type Connection

type Connection interface {
	WriteMessage(messageType int, data []byte) error
	ReadMessage() (messageType int, p []byte, err error)
	RestoreConnection() (Connection, error)
	Close() error
}

func NewConnection

func NewConnection(
	initUnderlyingWsConnFn func() (*websocket.Conn, error),
	isKeepAliveNeeded bool,
	keepaliveTimeout time.Duration,
) (Connection, error)

NewConnection constructor for connection

type RequestData

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

func NewRequestData

func NewRequestData(
	requestID string,
	apiKey string,
	secretKey string,
	timeOffset int64,
	keyType string,
) RequestData

type RequestList

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

RequestList state of requests that was sent/received

func NewRequestList

func NewRequestList() RequestList

NewRequestList creates request list

func (*RequestList) Add

func (l *RequestList) Add(id string)

Add adds request into list

func (*RequestList) IsAlreadyInList

func (l *RequestList) IsAlreadyInList(id string) bool

IsAlreadyInList checks if id is presented in requests list

func (*RequestList) Len

func (l *RequestList) Len() int

Len get list length

func (*RequestList) RecreateList

func (l *RequestList) RecreateList()

RecreateList creates new request list

func (*RequestList) Remove

func (l *RequestList) Remove(id string)

Remove adds request from list

type WsApiMethodType

type WsApiMethodType string

WsApiMethodType define method name for websocket API

type WsApiRequest

type WsApiRequest struct {
	Id     string                 `json:"id"`
	Method WsApiMethodType        `json:"method"`
	Params map[string]interface{} `json:"params,omitempty"`
}

WsApiRequest define common websocket API request

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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