Documentation ¶
Index ¶
- Constants
- type FundingData
- type KlineData
- type TradeData
- type UnhandledMessageWarning
- type Websocket
- func (w *Websocket) CanUseAuthenticatedEndpoints() bool
- func (w *Websocket) CanUseAuthenticatedWebsocketForWrapper() bool
- func (w *Websocket) Connect() error
- func (w *Websocket) GetDefaultURL() string
- func (w *Websocket) GetName() string
- func (w *Websocket) GetProxyAddress() string
- func (w *Websocket) GetSubscriptions() []WebsocketChannelSubscription
- func (w *Websocket) GetWebsocketURL() string
- func (w *Websocket) Initialise() error
- func (w *Websocket) IsConnected() bool
- func (w *Websocket) IsConnecting() bool
- func (w *Websocket) IsConnectionMonitorRunning() bool
- func (w *Websocket) IsEnabled() bool
- func (w *Websocket) IsInit() bool
- func (w *Websocket) IsTrafficMonitorRunning() bool
- func (w *Websocket) RemoveSubscribedChannels(channels []WebsocketChannelSubscription)
- func (w *Websocket) ResubscribeToChannel(subscribedChannel WebsocketChannelSubscription)
- func (w *Websocket) SetCanUseAuthenticatedEndpoints(val bool)
- func (w *Websocket) SetChannelSubscriber(subscriber func(channelToSubscribe WebsocketChannelSubscription) error)
- func (w *Websocket) SetChannelUnsubscriber(unsubscriber func(channelToUnsubscribe WebsocketChannelSubscription) error)
- func (w *Websocket) SetConnector(connector func() error)
- func (w *Websocket) SetDefaultURL(defaultURL string)
- func (w *Websocket) SetExchangeName(exchName string)
- func (w *Websocket) SetProxyAddress(proxyAddr string) error
- func (w *Websocket) SetWebsocketURL(websocketURL string)
- func (w *Websocket) Setup(setupData *WebsocketSetup) error
- func (w *Websocket) Shutdown() error
- func (w *Websocket) SubscribeToChannels(channels []WebsocketChannelSubscription)
- type WebsocketChannelSubscription
- type WebsocketConnection
- func (w *WebsocketConnection) Dial(dialer *websocket.Dialer, headers http.Header) error
- func (w *WebsocketConnection) GenerateMessageID(useNano bool) int64
- func (w *WebsocketConnection) IsConnected() bool
- func (w *WebsocketConnection) IsIDWaitingForResponse(id int64) bool
- func (w *WebsocketConnection) ReadMessage() (WebsocketResponse, error)
- func (w *WebsocketConnection) SendJSONMessage(data interface{}) error
- func (w *WebsocketConnection) SendMessageReturnResponse(id int64, request interface{}) ([]byte, error)
- func (w *WebsocketConnection) SendRawMessage(messageType int, message []byte) error
- func (w *WebsocketConnection) SetResponseIDAndData(id int64, data []byte)
- func (w *WebsocketConnection) SetupPingHandler(handler WebsocketPingHandler)
- func (w *WebsocketConnection) WaitForResult(id int64, wg *sync.WaitGroup)
- type WebsocketOrderbookUpdate
- type WebsocketPingHandler
- type WebsocketPositionUpdated
- type WebsocketResponse
- type WebsocketSetup
Constants ¶
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 (*Websocket) CanUseAuthenticatedEndpoints ¶
CanUseAuthenticatedEndpoints gets canUseAuthenticatedEndpoints val in a thread safe manner
func (*Websocket) CanUseAuthenticatedWebsocketForWrapper ¶
CanUseAuthenticatedWebsocketForWrapper Handles a common check to verify whether a wrapper can use an authenticated websocket endpoint
func (*Websocket) Connect ¶
Connect initiates a websocket connection by using a package defined connection function
func (*Websocket) GetDefaultURL ¶
GetDefaultURL returns the default websocket URL
func (*Websocket) GetProxyAddress ¶
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 ¶
GetWebsocketURL returns the running websocket URL
func (*Websocket) Initialise ¶
Initialise verifies status and connects
func (*Websocket) IsConnected ¶
IsConnected returns status of connection
func (*Websocket) IsConnecting ¶
IsConnecting returns status of connecting
func (*Websocket) IsConnectionMonitorRunning ¶
IsConnectionMonitorRunning returns status of connection monitor
func (*Websocket) IsTrafficMonitorRunning ¶
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 ¶
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 ¶
SetConnector sets connection function
func (*Websocket) SetDefaultURL ¶
SetDefaultURL sets default websocket URL
func (*Websocket) SetExchangeName ¶
SetExchangeName sets exchange name
func (*Websocket) SetProxyAddress ¶
SetProxyAddress sets websocket proxy address
func (*Websocket) SetWebsocketURL ¶
SetWebsocketURL sets websocket URL
func (*Websocket) Setup ¶
func (w *Websocket) Setup(setupData *WebsocketSetup) error
Setup sets main variables for websocket connection
func (*Websocket) Shutdown ¶
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) 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 ¶
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 ¶
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