websocket

package
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: MIT Imports: 13 Imported by: 3

Documentation

Index

Constants

This section is empty.

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
)
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

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)
}

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

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"
)

type WsApiRequest

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

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