ws

package
Version: v0.0.0-...-5ae7496 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TradeChannel        = "trades"
	RawOrderBookChannel = "raw_orderbook"
	OrderChannel        = "orders"
	OrderBookChannel    = "orderbook"
	OHLCVChannel        = "ohlcv"
	LoginChannel        = "login"
	BalancesChannel     = "balances"
)

Variables

This section is empty.

Functions

func ConnectionEndpoint

func ConnectionEndpoint(w http.ResponseWriter, r *http.Request)

ConnectionEndpoint is the the handleFunc function for websocket connections It handles incoming websocket messages and routes the message according to channel parameter in channelMessage

func IsClientConnected

func IsClientConnected(a string, client *Client) bool

func IsClientConnectedToSession

func IsClientConnectedToSession(sessionId string, c *Client) bool

func OrderSocketUnsubscribeHandler

func OrderSocketUnsubscribeHandler(a string) func(client *Client)

func RegisterChannel

func RegisterChannel(channel string, fn func(interface{}, *Client)) error

func RegisterConnectionUnsubscribeHandler

func RegisterConnectionUnsubscribeHandler(c *Client, fn func(*Client))

RegisterConnectionUnsubscribeHandler needs to be called whenever a connection subscribes to a new channel. At the time of connection closing the ConnectionUnsubscribeHandler handlers associated with that connection are triggered.

func RegisterOrderConnection

func RegisterOrderConnection(a string, c *Client)

RegisterOrderConnection registers a connection with and orderID. It is called whenever a message is recieved over order channel

func SendBalancesMessage

func SendBalancesMessage(msgType string, address string, balances map[string]int64, event string)

func SendOrderMessage

func SendOrderMessage(msgType string, a string, payload interface{})

Types

type Client

type Client struct {
	*websocket.Conn

	RpcMutex sync.Mutex
	// contains filtered or unexported fields
}

func NewClient

func NewClient(c *websocket.Conn) *Client

func (*Client) SendMessage

func (c *Client) SendMessage(channel string, msgType string, payload interface{}, h ...string)

SendMessage constructs the message with proper structure to be sent over websocket

func (*Client) SendOrderErrorMessage

func (c *Client) SendOrderErrorMessage(err error, h string)

type LoginSocket

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

LoginSocket holds the map of connections subscribed to session ids corresponding to the key/event they have subscribed to.

func GetLoginSocket

func GetLoginSocket() *LoginSocket

func NewLoginSocket

func NewLoginSocket() *LoginSocket

func (*LoginSocket) LinkAddressToClient

func (s *LoginSocket) LinkAddressToClient(sessionId string, address string)

func (*LoginSocket) SendErrorMessage

func (s *LoginSocket) SendErrorMessage(c *Client, p interface{})

SendErrorMessage sends an error message on the login channel

func (*LoginSocket) SendInitMessage

func (s *LoginSocket) SendInitMessage(c *Client, p interface{})

SendInitMessage is responsible for sending message on trade ohlcv channel at subscription

func (*LoginSocket) SendMessage

func (s *LoginSocket) SendMessage(c *Client, msgType string, p interface{})

SendMessage sends a websocket message on the login channel

func (*LoginSocket) SendMessageBySession

func (s *LoginSocket) SendMessageBySession(sessionId string, p interface{})

BroadcastMessage broadcasts login message to all subscribed sockets

func (*LoginSocket) SendUpdateMessage

func (s *LoginSocket) SendUpdateMessage(c *Client, p interface{})

SendUpdateMessage is responsible for sending message on trade ohlcv channel at subscription

func (*LoginSocket) Subscribe

func (s *LoginSocket) Subscribe(sessionId string, c *Client) error

Subscribe registers a new websocket connections to the login channel updates

func (*LoginSocket) Unsubscribe

func (s *LoginSocket) Unsubscribe(c *Client)

func (*LoginSocket) UnsubscribeChannel

func (s *LoginSocket) UnsubscribeChannel(sessionId string, c *Client)

Unsubscribe removes a websocket connection from the login channel updates

func (*LoginSocket) UnsubscribeChannelHandler

func (s *LoginSocket) UnsubscribeChannelHandler(sessionId string) func(c *Client)

UnsubscribeHandler unsubscribes a connection from a certain login channel id

func (*LoginSocket) UnsubscribeHandler

func (s *LoginSocket) UnsubscribeHandler() func(c *Client)

type OHLCVSocket

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

OHLCVSocket holds the map of subscribtions subscribed to pair channels corresponding to the key/event they have subscribed to.

func GetOHLCVSocket

func GetOHLCVSocket() *OHLCVSocket

GetOHLCVSocket return singleton instance of PairSockets type struct

func NewOHLCVSocket

func NewOHLCVSocket() *OHLCVSocket

func (*OHLCVSocket) BroadcastOHLCV

func (s *OHLCVSocket) BroadcastOHLCV(channelID string, p interface{}) error

BroadcastOHLCV Message streams message to all the subscriptions subscribed to the pair

func (*OHLCVSocket) SendErrorMessage

func (s *OHLCVSocket) SendErrorMessage(c *Client, p interface{})

SendErrorMessage sends an error message on the trade channel

func (*OHLCVSocket) SendInitMessage

func (s *OHLCVSocket) SendInitMessage(c *Client, p interface{})

SendInitMessage is responsible for sending message on trade ohlcv channel at subscription

func (*OHLCVSocket) SendMessage

func (s *OHLCVSocket) SendMessage(c *Client, msgType string, p interface{})

SendMessage sends a websocket message on the trade channel

func (*OHLCVSocket) SendUpdateMessage

func (s *OHLCVSocket) SendUpdateMessage(c *Client, p interface{})

SendUpdateMessage is responsible for sending message on trade ohlcv channel at subscription

func (*OHLCVSocket) Subscribe

func (s *OHLCVSocket) Subscribe(channelID string, c *Client) error

Subscribe handles the registration of connection to get streaming data over the socker for any pair.

func (*OHLCVSocket) Unsubscribe

func (s *OHLCVSocket) Unsubscribe(c *Client)

func (*OHLCVSocket) UnsubscribeChannel

func (s *OHLCVSocket) UnsubscribeChannel(channelID string, c *Client)

Unsubscribe is used to unsubscribe the connection from listening to the key subscribed to. It can be called on unsubscription message from user or due to some other reason by system

func (*OHLCVSocket) UnsubscribeChannelHandler

func (s *OHLCVSocket) UnsubscribeChannelHandler(channelID string) func(c *Client)

UnsubscribeHandler returns function of type unsubscribe handler, it handles the unsubscription of pair in case of connection closing.

func (*OHLCVSocket) UnsubscribeHandler

func (s *OHLCVSocket) UnsubscribeHandler() func(c *Client)

type OrderBookSocket

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

OrderBookSocket holds the map of subscribtions subscribed to pair channels corresponding to the key/event they have subscribed to.

func GetOrderBookSocket

func GetOrderBookSocket() *OrderBookSocket

GetOrderBookSocket return singleton instance of PairSockets type struct

func NewOrderBookSocket

func NewOrderBookSocket() *OrderBookSocket

func (*OrderBookSocket) BroadcastMessage

func (s *OrderBookSocket) BroadcastMessage(channelID string, p interface{}) error

BroadcastMessage streams message to all the subscribtions subscribed to the pair

func (*OrderBookSocket) SendErrorMessage

func (s *OrderBookSocket) SendErrorMessage(c *Client, data interface{})

SendErrorMessage sends error message on orderbookchannel

func (*OrderBookSocket) SendInitMessage

func (s *OrderBookSocket) SendInitMessage(c *Client, data interface{})

SendInitMessage sends INIT message on orderbookchannel on subscription event

func (*OrderBookSocket) SendUpdateMessage

func (s *OrderBookSocket) SendUpdateMessage(c *Client, data interface{})

SendUpdateMessage sends UPDATE message on orderbookchannel as new data is created

func (*OrderBookSocket) Subscribe

func (s *OrderBookSocket) Subscribe(channelID string, c *Client) error

Subscribe handles the subscription of connection to get streaming data over the socker for any pair. pair := utils.GetPairKey(bt, qt)

func (*OrderBookSocket) Unsubscribe

func (s *OrderBookSocket) Unsubscribe(c *Client)

func (*OrderBookSocket) UnsubscribeChannel

func (s *OrderBookSocket) UnsubscribeChannel(channelID string, c *Client)

Unsubscribe is used to unsubscribe the connection from listening to the key subscribed to. It can be called on unsubscription message from user or due to some other reason by system

func (*OrderBookSocket) UnsubscribeHandler

func (s *OrderBookSocket) UnsubscribeHandler(channelID string) func(c *Client)

UnsubscribeHandler returns function of type unsubscribe handler, it handles the unsubscription of pair in case of connection closing.

type OrderConnection

type OrderConnection []*Client

func GetOrderConnections

func GetOrderConnections(address string) OrderConnection

GetOrderConn returns the connection associated with an order ID

type RawOrderBookSocket

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

RawOrderBookSocket holds the map of subscribtions subscribed to pair channels corresponding to the key/event they have subscribed to.

func GetRawOrderBookSocket

func GetRawOrderBookSocket() *RawOrderBookSocket

GetRawOrderBookSocket return singleton instance of PairSockets type struct

func NewRawOrderBookSocket

func NewRawOrderBookSocket() *RawOrderBookSocket

func (*RawOrderBookSocket) BroadcastMessage

func (s *RawOrderBookSocket) BroadcastMessage(channelID string, p interface{}) error

BroadcastMessage streams message to all the subscribtions subscribed to the pair

func (*RawOrderBookSocket) SendErrorMessage

func (s *RawOrderBookSocket) SendErrorMessage(c *Client, data interface{})

func (*RawOrderBookSocket) SendInitMessage

func (s *RawOrderBookSocket) SendInitMessage(c *Client, data interface{})

SendInitMessage sends INIT message on orderbookchannel on subscription event

func (*RawOrderBookSocket) SendUpdateMessage

func (s *RawOrderBookSocket) SendUpdateMessage(c *Client, data interface{})

SendUpdateMessage sends UPDATE message on orderbookchannel as new data is created

func (*RawOrderBookSocket) Subscribe

func (s *RawOrderBookSocket) Subscribe(channelID string, c *Client) error

Subscribe handles the subscription of connection to get streaming data over the socker for any pair. pair := utils.GetPairKey(bt, qt)

func (*RawOrderBookSocket) Unsubscribe

func (s *RawOrderBookSocket) Unsubscribe(c *Client)

func (*RawOrderBookSocket) UnsubscribeChannel

func (s *RawOrderBookSocket) UnsubscribeChannel(channelID string, c *Client)

Unsubscribe is used to unsubscribe the connection from listening to the key subscribed to. It can be called on unsubscription message from user or due to some other reason by system

func (*RawOrderBookSocket) UnsubscribeChannelHandler

func (s *RawOrderBookSocket) UnsubscribeChannelHandler(channelID string) func(c *Client)

UnsubscribeHandler returns function of type unsubscribe handler, it handles the unsubscription of pair in case of connection closing.

func (*RawOrderBookSocket) UnsubscribeHandler

func (s *RawOrderBookSocket) UnsubscribeHandler() func(c *Client)

type TradeSocket

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

TradeSocket holds the map of connections subscribed to pair channels corresponding to the key/event they have subscribed to.

func GetTradeSocket

func GetTradeSocket() *TradeSocket

func NewTradeSocket

func NewTradeSocket() *TradeSocket

func (*TradeSocket) BroadcastMessage

func (s *TradeSocket) BroadcastMessage(channelID string, p interface{})

BroadcastMessage broadcasts trade message to all subscribed sockets

func (*TradeSocket) SendErrorMessage

func (s *TradeSocket) SendErrorMessage(c *Client, p interface{})

SendErrorMessage sends an error message on the trade channel

func (*TradeSocket) SendInitMessage

func (s *TradeSocket) SendInitMessage(c *Client, p interface{})

SendInitMessage is responsible for sending message on trade ohlcv channel at subscription

func (*TradeSocket) SendMessage

func (s *TradeSocket) SendMessage(c *Client, msgType string, p interface{})

SendMessage sends a websocket message on the trade channel

func (*TradeSocket) SendUpdateMessage

func (s *TradeSocket) SendUpdateMessage(c *Client, p interface{})

SendUpdateMessage is responsible for sending message on trade ohlcv channel at subscription

func (*TradeSocket) Subscribe

func (s *TradeSocket) Subscribe(channelID string, c *Client) error

Subscribe registers a new websocket connections to the trade channel updates

func (*TradeSocket) Unsubscribe

func (s *TradeSocket) Unsubscribe(c *Client)

func (*TradeSocket) UnsubscribeChannel

func (s *TradeSocket) UnsubscribeChannel(channelID string, c *Client)

Unsubscribe removes a websocket connection from the trade channel updates

func (*TradeSocket) UnsubscribeChannelHandler

func (s *TradeSocket) UnsubscribeChannelHandler(channelID string) func(c *Client)

UnsubscribeHandler unsubscribes a connection from a certain trade channel id

func (*TradeSocket) UnsubscribeHandler

func (s *TradeSocket) UnsubscribeHandler() func(c *Client)

type WebsocketLogger

type WebsocketLogger struct {
	*logging.Logger
	// contains filtered or unexported fields
}

func NewWebsocketLogger

func NewWebsocketLogger() *WebsocketLogger

func (*WebsocketLogger) LogMessageIn

func (l *WebsocketLogger) LogMessageIn(msg *types.WebsocketMessage)

func (*WebsocketLogger) LogMessageOut

func (l *WebsocketLogger) LogMessageOut(msg *types.WebsocketMessage)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL