wshandler

package
v0.0.0-...-1ca2487 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// WebsocketNotEnabled alerts of a disabled websocket
	WebsocketNotEnabled = "exchange_websocket_not_enabled"

	WebsocketNotAuthenticatedUsingRest = "%v - Websocket not authenticated, using REST"
	Ping                               = "ping"
	Pong                               = "pong"
	UnhandledMessage                   = " - Unhandled websocket message: "
)

Websocket functionality list and state consts

Variables

This section is empty.

Functions

This section is empty.

Types

type FundingData

type FundingData struct {
	Timestamp    time.Time
	CurrencyPair currency.Pair
	AssetType    asset.Item
	Exchange     string
	Amount       float64
	Rate         float64
	Period       int64
	Side         order.Side
}

FundingData defines funding data

type KlineData

type KlineData struct {
	Timestamp  time.Time
	Pair       currency.Pair
	AssetType  asset.Item
	Exchange   string
	StartTime  time.Time
	CloseTime  time.Time
	Interval   string
	OpenPrice  float64
	ClosePrice float64
	HighPrice  float64
	LowPrice   float64
	Volume     float64
}

KlineData defines kline feed

type TradeData

type TradeData struct {
	Timestamp    time.Time
	CurrencyPair currency.Pair
	AssetType    asset.Item
	Exchange     string
	EventType    order.Type
	Price        float64
	Amount       float64
	Side         order.Side
}

TradeData defines trade data

type UnhandledMessageWarning

type UnhandledMessageWarning struct {
	Message string
}

UnhandledMessageWarning is used for unhandled websocket messages

type Websocket

type Websocket struct {
	DataHandler chan interface{}
	// ShutdownC is the main shutdown channel which controls all websocket go funcs
	ShutdownC chan struct{}
	// Orderbook is a local cache of orderbooks
	Orderbook wsorderbook.WebsocketOrderbookLocal
	// Wg defines a wait group for websocket routines for cleanly shutting down
	// routines
	Wg sync.WaitGroup
	// TrafficAlert monitors if there is a halt in traffic throughput
	TrafficAlert chan struct{}
	// ReadMessageErrors will received all errors from ws.ReadMessage() and verify if its a disconnection
	ReadMessageErrors chan error
	// contains filtered or unexported fields
}

Websocket defines a return type for websocket connections via the interface wrapper for routine processing in routines.go

func New

func New() *Websocket

New initialises the websocket struct

func (*Websocket) CanUseAuthenticatedEndpoints

func (w *Websocket) CanUseAuthenticatedEndpoints() bool

CanUseAuthenticatedEndpoints gets canUseAuthenticatedEndpoints val in a thread safe manner

func (*Websocket) CanUseAuthenticatedWebsocketForWrapper

func (w *Websocket) CanUseAuthenticatedWebsocketForWrapper() bool

CanUseAuthenticatedWebsocketForWrapper Handles a common check to verify whether a wrapper can use an authenticated websocket endpoint

func (*Websocket) Connect

func (w *Websocket) Connect() error

Connect initiates a websocket connection by using a package defined connection function

func (*Websocket) GetDefaultURL

func (w *Websocket) GetDefaultURL() string

GetDefaultURL returns the default websocket URL

func (*Websocket) GetName

func (w *Websocket) GetName() string

GetName returns exchange name

func (*Websocket) GetProxyAddress

func (w *Websocket) GetProxyAddress() string

GetProxyAddress returns the current websocket proxy

func (*Websocket) GetSubscriptions

func (w *Websocket) GetSubscriptions() []WebsocketChannelSubscription

GetSubscriptions returns a copied list of subscriptions subscriptions is a private member and cannot be manipulated

func (*Websocket) GetWebsocketURL

func (w *Websocket) GetWebsocketURL() string

GetWebsocketURL returns the running websocket URL

func (*Websocket) Initialise

func (w *Websocket) Initialise() error

Initialise verifies status and connects

func (*Websocket) IsConnected

func (w *Websocket) IsConnected() bool

IsConnected returns status of connection

func (*Websocket) IsConnecting

func (w *Websocket) IsConnecting() bool

IsConnecting returns status of connecting

func (*Websocket) IsConnectionMonitorRunning

func (w *Websocket) IsConnectionMonitorRunning() bool

IsConnectionMonitorRunning returns status of connection monitor

func (*Websocket) IsEnabled

func (w *Websocket) IsEnabled() bool

IsEnabled returns status of enabled

func (*Websocket) IsInit

func (w *Websocket) IsInit() bool

IsInit returns status of init

func (*Websocket) IsTrafficMonitorRunning

func (w *Websocket) IsTrafficMonitorRunning() bool

IsTrafficMonitorRunning returns status of the traffic monitor

func (*Websocket) RemoveSubscribedChannels

func (w *Websocket) RemoveSubscribedChannels(channels []WebsocketChannelSubscription)

RemoveSubscribedChannels removes supplied channels from channelsToSubscribe

func (*Websocket) ResubscribeToChannel

func (w *Websocket) ResubscribeToChannel(subscribedChannel WebsocketChannelSubscription)

ResubscribeToChannel calls unsubscribe func and removes it from subscribedChannels to trigger a subscribe event

func (*Websocket) SetCanUseAuthenticatedEndpoints

func (w *Websocket) SetCanUseAuthenticatedEndpoints(val bool)

SetCanUseAuthenticatedEndpoints sets canUseAuthenticatedEndpoints val in a thread safe manner

func (*Websocket) SetChannelSubscriber

func (w *Websocket) SetChannelSubscriber(subscriber func(channelToSubscribe WebsocketChannelSubscription) error)

SetChannelSubscriber sets the function to use the base subscribe func

func (*Websocket) SetChannelUnsubscriber

func (w *Websocket) SetChannelUnsubscriber(unsubscriber func(channelToUnsubscribe WebsocketChannelSubscription) error)

SetChannelUnsubscriber sets the function to use the base unsubscribe func

func (*Websocket) SetConnector

func (w *Websocket) SetConnector(connector func() error)

SetConnector sets connection function

func (*Websocket) SetDefaultURL

func (w *Websocket) SetDefaultURL(defaultURL string)

SetDefaultURL sets default websocket URL

func (*Websocket) SetExchangeName

func (w *Websocket) SetExchangeName(exchName string)

SetExchangeName sets exchange name

func (*Websocket) SetProxyAddress

func (w *Websocket) SetProxyAddress(proxyAddr string) error

SetProxyAddress sets websocket proxy address

func (*Websocket) SetWebsocketURL

func (w *Websocket) SetWebsocketURL(websocketURL string)

SetWebsocketURL sets websocket URL

func (*Websocket) Setup

func (w *Websocket) Setup(setupData *WebsocketSetup) error

Setup sets main variables for websocket connection

func (*Websocket) Shutdown

func (w *Websocket) Shutdown() error

Shutdown attempts to shut down a websocket connection and associated routines by using a package defined shutdown function

func (*Websocket) SubscribeToChannels

func (w *Websocket) SubscribeToChannels(channels []WebsocketChannelSubscription)

SubscribeToChannels appends supplied channels to channelsToSubscribe

type WebsocketChannelSubscription

type WebsocketChannelSubscription struct {
	Channel  string
	Currency currency.Pair
	Params   map[string]interface{}
}

WebsocketChannelSubscription container for websocket subscriptions Currently only a one at a time thing to avoid complexity

func (*WebsocketChannelSubscription) Equal

func (w *WebsocketChannelSubscription) Equal(subscribedChannel *WebsocketChannelSubscription) bool

Equal two WebsocketChannelSubscription to determine equality

type WebsocketConnection

type WebsocketConnection struct {
	sync.Mutex
	Verbose bool

	RateLimit    float64
	ExchangeName string
	URL          string
	ProxyURL     string
	Wg           sync.WaitGroup
	Connection   *websocket.Conn
	Shutdown     chan struct{}
	// These are the request IDs and the corresponding response JSON
	IDResponses          map[int64][]byte
	ResponseCheckTimeout time.Duration
	ResponseMaxLimit     time.Duration
	TrafficTimeout       time.Duration
	// contains filtered or unexported fields
}

WebsocketConnection contains all the data needed to send a message to a WS

func (*WebsocketConnection) Dial

func (w *WebsocketConnection) Dial(dialer *websocket.Dialer, headers http.Header) error

Dial sets proxy urls and then connects to the websocket

func (*WebsocketConnection) GenerateMessageID

func (w *WebsocketConnection) GenerateMessageID(useNano bool) int64

GenerateMessageID Creates a messageID to checkout

func (*WebsocketConnection) IsConnected

func (w *WebsocketConnection) IsConnected() bool

IsConnected exposes websocket connection status

func (*WebsocketConnection) IsIDWaitingForResponse

func (w *WebsocketConnection) IsIDWaitingForResponse(id int64) bool

IsIDWaitingForResponse will verify whether the websocket is awaiting a response with a correlating ID. If true, the datahandler won't process the data, and instead will be processed by the wrapper function

func (*WebsocketConnection) ReadMessage

func (w *WebsocketConnection) ReadMessage() (WebsocketResponse, error)

ReadMessage reads messages, can handle text, gzip and binary

func (*WebsocketConnection) SendJSONMessage

func (w *WebsocketConnection) SendJSONMessage(data interface{}) error

SendJSONMessage sends a JSON encoded message over the connection

func (*WebsocketConnection) SendMessageReturnResponse

func (w *WebsocketConnection) SendMessageReturnResponse(id int64, request interface{}) ([]byte, error)

SendMessageReturnResponse will send a WS message to the connection It will then run a goroutine to await a JSON response If there is no response it will return an error

func (*WebsocketConnection) SendRawMessage

func (w *WebsocketConnection) SendRawMessage(messageType int, message []byte) error

SendRawMessage sends a message over the connection without JSON encoding it

func (*WebsocketConnection) SetResponseIDAndData

func (w *WebsocketConnection) SetResponseIDAndData(id int64, data []byte)

SetResponseIDAndData adds data to IDResponses with locks and a nil check

func (*WebsocketConnection) SetupPingHandler

func (w *WebsocketConnection) SetupPingHandler(handler WebsocketPingHandler)

SetupPingHandler will automatically send ping or pong messages based on WebsocketPingHandler configuration

func (*WebsocketConnection) WaitForResult

func (w *WebsocketConnection) WaitForResult(id int64, wg *sync.WaitGroup)

WaitForResult will keep checking w.IDResponses for a response ID If the timer expires, it will return without

type WebsocketOrderbookUpdate

type WebsocketOrderbookUpdate struct {
	Pair     currency.Pair
	Asset    asset.Item
	Exchange string
}

WebsocketOrderbookUpdate defines a websocket event in which the orderbook has been updated in the orderbook package

type WebsocketPingHandler

type WebsocketPingHandler struct {
	UseGorillaHandler bool
	MessageType       int
	Message           []byte
	Delay             time.Duration
}

WebsocketPingHandler container for ping handler settings

type WebsocketPositionUpdated

type WebsocketPositionUpdated struct {
	Timestamp time.Time
	Pair      currency.Pair
	AssetType asset.Item
	Exchange  string
}

WebsocketPositionUpdated reflects a change in orders/contracts on an exchange

type WebsocketResponse

type WebsocketResponse struct {
	Type int
	Raw  []byte
}

WebsocketResponse defines generalised data from the websocket connection

type WebsocketSetup

type WebsocketSetup struct {
	Enabled                          bool
	Verbose                          bool
	AuthenticatedWebsocketAPISupport bool
	WebsocketTimeout                 time.Duration
	DefaultURL                       string
	ExchangeName                     string
	RunningURL                       string
	Connector                        func() error
	Subscriber                       func(channelToSubscribe WebsocketChannelSubscription) error
	UnSubscriber                     func(channelToUnsubscribe WebsocketChannelSubscription) error
	Features                         *protocol.Features
}

WebsocketSetup defines variables for setting up a websocket connection

Jump to

Keyboard shortcuts

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