Documentation ¶
Index ¶
- Constants
- Variables
- func NewSubscribeMessage(symbol string) (handlers.WebsocketEncodedMessage, error)
- func NewSubscribeMessages(symbols []string) ([]handlers.WebsocketEncodedMessage, error)
- func NewWebSocketDataHandler(logger *zap.Logger, ws config.WebSocketConfig) (types.PriceWebSocketDataHandler, error)
- type BaseMessage
- type Channel
- type ErrorCode
- type ErrorMessage
- type Event
- type SubscribeMessage
- type SubscribedMessage
- type WebSocketHandler
- func (h *WebSocketHandler) Copy() types.PriceWebSocketDataHandler
- func (h *WebSocketHandler) CreateMessages(tickers []types.ProviderTicker) ([]handlers.WebsocketEncodedMessage, error)
- func (h *WebSocketHandler) HandleMessage(message []byte) (types.PriceResponse, []handlers.WebsocketEncodedMessage, error)
- func (h *WebSocketHandler) HeartBeatMessages() ([]handlers.WebsocketEncodedMessage, error)
Constants ¶
const ( // EventSubscribe indicates a subscribe action. EventSubscribe Event = "subscribe" // EventSubscribed indicates that a subscription was successful. EventSubscribed Event = "subscribed" // EventError indicates that an error occurred. EventError Event = "error" // ChannelTicker is the channel name for the ticker channel. ChannelTicker Channel = "ticker" // IDHeartbeat is the id always used for a heartbeat. IDHeartbeat = "hb" // ExpectedStreamPayloadLength is the expected length of the payload of a data stream. ExpectedStreamPayloadLength = 10 // ExpectedBaseStreamLength is the expected length of a stream base message. ExpectedBaseStreamLength = 2 // ErrorUnknownEvent indicates an unknown event. ErrorUnknownEvent ErrorCode = 10000 // ErrorUnknownPair indicates an unknown pari. ErrorUnknownPair ErrorCode = 10001 // ErrorLimitOpenChannels indicates the limit of open channels has been exceeded. ErrorLimitOpenChannels ErrorCode = 10305 // ErrorSubscriptionFailed indicates a subscription failed. ErrorSubscriptionFailed ErrorCode = 10400 // ErrorNotSubscribed indicates you are not subscribed to the given topic. ErrorNotSubscribed ErrorCode = 104001 )
const ( // Name is the name of the BitFinex provider. Name = "bitfinex_ws" // URLProd is the public BitFinex Websocket URL. URLProd = "wss://api-pub.bitfinex.com/ws/2" // DefaultMaxSubscriptionsPerConnection is the default maximum number of subscriptions // per connection. By default, BitFinex accepts up to 30 subscriptions per connection. // However, we limit this to 20 to prevent overloading the connection. DefaultMaxSubscriptionsPerConnection = 20 )
Variables ¶
var DefaultWebSocketConfig = config.WebSocketConfig{ Name: Name, Enabled: true, MaxBufferSize: 1000, ReconnectionTimeout: config.DefaultReconnectionTimeout, PostConnectionTimeout: config.DefaultPostConnectionTimeout, Endpoints: []config.Endpoint{{URL: URLProd}}, ReadBufferSize: config.DefaultReadBufferSize, WriteBufferSize: config.DefaultWriteBufferSize, HandshakeTimeout: config.DefaultHandshakeTimeout, EnableCompression: config.DefaultEnableCompression, ReadTimeout: config.DefaultReadTimeout, WriteTimeout: config.DefaultWriteTimeout, PingInterval: config.DefaultPingInterval, WriteInterval: config.DefaultWriteInterval, MaxReadErrorCount: config.DefaultMaxReadErrorCount, MaxSubscriptionsPerConnection: DefaultMaxSubscriptionsPerConnection, MaxSubscriptionsPerBatch: config.DefaultMaxSubscriptionsPerBatch, }
DefaultWebSocketConfig is the default configuration for the BitFinex Websocket.
Functions ¶
func NewSubscribeMessage ¶
func NewSubscribeMessage(symbol string) (handlers.WebsocketEncodedMessage, error)
NewSubscribeMessage creates a new subscribe message given the ticker symbol.
func NewSubscribeMessages ¶
func NewSubscribeMessages(symbols []string) ([]handlers.WebsocketEncodedMessage, error)
NewSubscribeMessages creates subscription messages for the given tickers.
func NewWebSocketDataHandler ¶
func NewWebSocketDataHandler( logger *zap.Logger, ws config.WebSocketConfig, ) (types.PriceWebSocketDataHandler, error)
NewWebSocketDataHandler returns a new BitFinex PriceWebSocketDataHandler.
Types ¶
type BaseMessage ¶
type BaseMessage struct {
Event string `json:"event" validate:"required"`
}
BaseMessage is the base message structure for subscription requests and responses in the BitFinex websocket API.
type Channel ¶
type Channel string
Channel is the channel of a message sent over the BitFinex websocket API.
type ErrorCode ¶
type ErrorCode int64
ErrorCode is a type alias for an error code sent from the BitFinex websocket API.
type ErrorMessage ¶
type ErrorMessage struct { BaseMessage Msg string `json:"msg" validate:"required"` Code int64 `json:"code" validate:"required"` }
ErrorMessage represent an error returned by the peer.
Ex.
{ "event": "error", "msg": ERROR_MSG, "code": ERROR_CODE }
type Event ¶
type Event string
Event is the event type of message sent over the BitFinex websocket API.
type SubscribeMessage ¶
type SubscribeMessage struct { BaseMessage Channel string `json:"channel" validate:"required"` Symbol string `json:"symbol" validate:"required"` }
SubscribeMessage is a base message used to make a subscription request.
Ex:
{ event: "subscribe", channel: "ticker", symbol: SYMBOL }
type SubscribedMessage ¶
type SubscribedMessage struct { BaseMessage Channel string `json:"channel" validate:"required"` ChannelID int `json:"chanId" validate:"required"` Pair string `json:"pair" validate:"required"` }
SubscribedMessage is message indicating the status of a subscription request.
Ex:
{ event: "subscribed", channel: "ticker", chanId: CHANNEL_ID, symbol: SYMBOL, pair: PAIR }
type WebSocketHandler ¶
type WebSocketHandler struct {
// contains filtered or unexported fields
}
WebSocketHandler implements the WebSocketDataHandler interface. This is used to handle messages received from the BitFinex websocket API.
func (*WebSocketHandler) Copy ¶
func (h *WebSocketHandler) Copy() types.PriceWebSocketDataHandler
Copy is used to create a copy of the WebSocketHandler.
func (*WebSocketHandler) CreateMessages ¶
func (h *WebSocketHandler) CreateMessages( tickers []types.ProviderTicker, ) ([]handlers.WebsocketEncodedMessage, error)
CreateMessages is used to create an initial subscription message to send to the data provider. Only the tickers that are specified in the config are subscribed to. The only channel that is subscribed to is the index tickers channel - which supports spot markets.
func (*WebSocketHandler) HandleMessage ¶
func (h *WebSocketHandler) HandleMessage( message []byte, ) (types.PriceResponse, []handlers.WebsocketEncodedMessage, error)
HandleMessage is used to handle a message received from the data provider. The BitFinex provider sends four types of messages:
- Subscribed response message. The subscribe response message is used to determine if the subscription was successful. If successful, the channel ID is saved.
- Error response messages. These messages provide info about errors from requests sent to the BitFinex websocket API.
- Ticker stream message. This is sent when a ticker update is received from the BitFinex websocket API.
- Heartbeat stream messages. These are sent every 15 seconds by the BitFinex API.
func (*WebSocketHandler) HeartBeatMessages ¶
func (h *WebSocketHandler) HeartBeatMessages() ([]handlers.WebsocketEncodedMessage, error)
HeartBeatMessages is not used for BitFinex.