websocket

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2019 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteChannel

func DeleteChannel(id string)

func GetMarketOrderbookSnapshotV2

func GetMarketOrderbookSnapshotV2(fetcher SnapshotFetcher, marketID string) *common.SnapshotV2

func RunChannel

func RunChannel(c IChannel)

func StartConsumer

func StartConsumer(ctx context.Context, queueConfig interface{})

StartConsumer initializes a queue instance and ready events from it

func StartSocketServer

func StartSocketServer(ctx context.Context)

Types

type AddressChannel

type AddressChannel struct {
	*Channel
}

Special Implements of IChannel

func CreateAddressChannel

func CreateAddressChannel(channelID string) *AddressChannel

type Channel

type Channel struct {
	ID      string
	Clients map[string]*Client

	Subscribe   chan *Client
	Unsubscribe chan string
	Messages    chan *common.WebSocketMessage
}

func (*Channel) AddMessage

func (c *Channel) AddMessage(msg *common.WebSocketMessage)

func (*Channel) AddSubscriber

func (c *Channel) AddSubscriber(client *Client)

func (*Channel) GetID

func (c *Channel) GetID() string

func (*Channel) MessagesChan

func (c *Channel) MessagesChan() chan *common.WebSocketMessage

func (*Channel) RemoveSubscriber

func (c *Channel) RemoveSubscriber(ID string)

func (*Channel) Stop

func (c *Channel) Stop()

func (*Channel) SubScribeChan

func (c *Channel) SubScribeChan() chan *Client

func (*Channel) UnsubscribeChan

func (c *Channel) UnsubscribeChan() chan string

type Client

type Client struct {
	ID       string
	Conn     ClientConn
	Channels map[string]*Channel
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func (*Client) Send

func (c *Client) Send(data interface{}) error

type ClientConn

type ClientConn interface {
	WriteJSON(interface{}) error
	ReadJSON(interface{}) error
	RemoteAddr() net.Addr
}

For Mock Test

type ClientRequest

type ClientRequest struct {
	Type     string
	Channels []string
}

type DefaultSnapshotFetcher

type DefaultSnapshotFetcher struct{}

func (*DefaultSnapshotFetcher) GetV2

func (*DefaultSnapshotFetcher) GetV2(marketID string) *common.SnapshotV2

type IChannel

type IChannel interface {
	GetID() string

	// Thread safe calls
	AddSubscriber(*Client)
	RemoveSubscriber(string)
	AddMessage(message *common.WebSocketMessage)

	UnsubscribeChan() chan string
	SubScribeChan() chan *Client
	MessagesChan() chan *common.WebSocketMessage

	Stop()
	// contains filtered or unexported methods
}

func CreateChannelByID

func CreateChannelByID(ChannelID string) IChannel

func FindChannel

func FindChannel(id string) IChannel

type MarketChannel

type MarketChannel struct {
	*Channel
	MarketID  string
	Orderbook *Orderbook
}

func CreateMarketChannel

func CreateMarketChannel(channelID, marketID string) *MarketChannel

type OnMessageResult

type OnMessageResult struct {
	Price  decimal.Decimal
	Side   string
	Amount decimal.Decimal
}

type Orderbook

type Orderbook struct {
	Sequence uint64
	*common.Orderbook
}

func InitOrderbook

func InitOrderbook(marketID string) *Orderbook

type OrderbookLevel2Snapshot

type OrderbookLevel2Snapshot struct {
	Type     string      `json:"type"`
	MarketID string      `json:"marketID"`
	Bids     [][2]string `json:"bids"`
	Asks     [][2]string `json:"asks"`
}

func NewOrderbookLevel2Snapshot

func NewOrderbookLevel2Snapshot(marketID string, bids, asks [][2]string) *OrderbookLevel2Snapshot

type OrderbookLevel2Update

type OrderbookLevel2Update struct {
	Type     string `json:"type"`
	MarketID string `json:"marketID"`
	Price    string `json:"price"`
	Side     string `json:"side"`
	Amount   string `json:"amount"`
}

func NewOrderbookLevel2Update

func NewOrderbookLevel2Update(marketID string, side, price, amount string) *OrderbookLevel2Update

type SnapshotFetcher

type SnapshotFetcher interface {
	GetV2(marketID string) *common.SnapshotV2
}

Jump to

Keyboard shortcuts

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