clients

package
v0.0.0-...-ca4f705 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: Unlicense Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultCoinbaseRateFeedWebsocketURL – WebSocket scheme/host/port of Coinbase rate feed to connect to
	DefaultCoinbaseRateFeedWebsocketURL = "wss://ws-feed.exchange.coinbase.com"
	// DefaultCoinbaseRateFeedChannel – default channel with transactions
	DefaultCoinbaseRateFeedChannel = "matches"

	// TypeSubscribe – request type for subscribing
	TypeSubscribe = "subscribe"
	// TypeUnsubscribe – request type for unsubscribing
	TypeUnsubscribe = "unsubscribe"
)

Variables

View Source
var (
	// CommandTimeout – maximum timeout for waiting for the command response
	CommandTimeout = 500 * time.Millisecond

	// ErrBadConfiguration – wrong configuration of service
	ErrBadConfiguration = errors.New("bad configuration")
	// ErrBadJSON – could not parse JSON from Coinbase rate feed WebSocket
	ErrBadJSON = errors.New("could not parse JSON")
	// ErrFailedToDeserialize – failed to deserialize data from JSON to corresponding entity
	ErrFailedToDeserialize = errors.New("failed to deserialize")
	// ErrUnsupportedMessageType – received message of unknown type
	ErrUnsupportedMessageType = errors.New("skipping unsupported message with unknown type")
)
View Source
var (
	// ErrWSCanceled – connection cancelled
	ErrWSCanceled = errors.New("cancelled")
	// ErrWSOutputChannelClosed – trying to send message to the closed output channel
	ErrWSOutputChannelClosed = errors.New("output channel closed")
	// ErrWSControlChannelClosed – trying to send message to the closed control channel
	ErrWSControlChannelClosed = errors.New("control channel closed")
)

Functions

This section is empty.

Types

type CoinbaseRateFeedInterface

type CoinbaseRateFeedInterface interface {
	RegisterMatchConsumer(consumer consumers.Consumer)
	Run()
	Stop()
}

CoinbaseRateFeedInterface – interface of Coinbase rate feed client

func NewCoinbaseRateFeed

func NewCoinbaseRateFeed(logger *log.Logger, wg *sync.WaitGroup, config *entity.Config) (CoinbaseRateFeedInterface,
	error)

NewCoinbaseRateFeed – create WebSocket client for Coinbase rate feed

type WSCommand

type WSCommand byte

WSCommand – type for sending commands

const (
	// WS_QUIT – disconnected
	WS_QUIT WSCommand = 16 + iota
	// WS_PING – test connection
	WS_PING
	// WS_USE_TEXT – switch to text protocol
	WS_USE_TEXT
	// WS_USE_BINARY – switch to binary protocol
	WS_USE_BINARY
)

commands

func (WSCommand) String

func (c WSCommand) String() string

type WSMachine

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

WSMachine – WebSocket state machine structure

func NewWebSocket

func NewWebSocket(logger *log.Logger, url string, headers http.Header) *WSMachine

NewWebSocket – constructor of WebSocket state machine

func (*WSMachine) Command

func (m *WSMachine) Command() chan<- WSCommand

Command – get Command channel

func (*WSMachine) Headers

func (m *WSMachine) Headers() http.Header

Headers – get request headers

func (*WSMachine) Input

func (m *WSMachine) Input() <-chan []byte

Input – get input channel

func (*WSMachine) MainLoop

func (m *WSMachine) MainLoop()

MainLoop – start WebSocket state machine

func (*WSMachine) Output

func (m *WSMachine) Output() chan<- []byte

Output – get output channel

func (*WSMachine) Status

func (m *WSMachine) Status() <-chan WSStatus

Status – get status channel

func (*WSMachine) URL

func (m *WSMachine) URL() string

URL – get WebSocket URL

type WSState

type WSState byte

WSState – type for holding states

const (
	// WS_DISCONNECTED – websocket is disconnected
	WS_DISCONNECTED WSState = iota
	// WS_CONNECTING – connecting to a websocket
	WS_CONNECTING
	// WS_CONNECTED – connected to the webscoket
	WS_CONNECTED
	// WS_WAITING – waiting before a retry
	WS_WAITING
)

states

func (WSState) String

func (s WSState) String() string

type WSStatus

type WSStatus struct {
	State WSState
	Error error
}

WSStatus – status structure

Jump to

Keyboard shortcuts

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