ws

package
v2.7.7 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountEventHandler

type AccountEventHandler interface {
	// Subscribe to markets.
	// You can set the buffSize for the channel.
	// If you have many subscriptions at once you may need to increase the buffSize
	// Default buffSize: 50
	Subscribe(markets []string, buffSize ...uint64) (<-chan OrderEvent, <-chan FillEvent, error)

	// Unsubscribe from markets.
	Unsubscribe(markets []string) error

	// Unsubscribe from every market.
	UnsubscribeAll() error
}

type Action

type Action enum.Member[string]

type AuthEvent

type AuthEvent struct {
	// Describes the returned event over the socket.
	Event string `json:"event"`

	// Whether the user is authenticated.
	Authenticated bool `json:"authenticated"`
}

type BaseEvent

type BaseEvent struct {
	Event WsEvent `json:"event"`
}

func (*BaseEvent) UnmarshalJSON added in v2.7.5

func (b *BaseEvent) UnmarshalJSON(bytes []byte) error

type BookEvent

type BookEvent struct {
	// Describes the returned event over the socket.
	Event string `json:"event"`

	// The market which was requested in the subscription.
	Market string `json:"market"`

	// The book containing the bids and asks.
	Book types.Book `json:"book"`
}

func (*BookEvent) UnmarshalJSON

func (b *BookEvent) UnmarshalJSON(bytes []byte) error

type CandlesEvent

type CandlesEvent struct {
	// Describes the returned event over the socket.
	Event string `json:"event"`

	// The market which was requested in the subscription.
	Market string `json:"market"`

	// The interval which was requested in the subscription.
	Interval string `json:"interval"`

	// The candle in the defined time period.
	Candle types.Candle `json:"candle"`
}

func (*CandlesEvent) UnmarshalJSON

func (c *CandlesEvent) UnmarshalJSON(bytes []byte) error

type CandlesEventHandler

type CandlesEventHandler interface {
	// Subscribe to markets with interval.
	// You can set the buffSize for this channel.
	//
	// If you have many subscriptions at once you may need to increase the buffSize
	//
	// Default buffSize: 50
	Subscribe(markets []string, interval string, buffSize ...uint64) (<-chan CandlesEvent, error)

	// Unsubscribe from markets with interval
	Unsubscribe(markets []string, interval string) error

	// Unsubscribe from every market with interval
	UnsubscribeAll() error
}

type Channel

type Channel struct {
	Name      string   `json:"name"`
	Intervals []string `json:"interval,omitempty"`
	Markets   []string `json:"markets,omitempty"`
}

type ChannelName

type ChannelName enum.Member[string]

type EventHandler

type EventHandler[T any] interface {
	// Subscribe to markets.
	// You can set the buffSize for the channel.
	//
	// If you have many subscriptions at once you may need to increase the buffSize
	//
	// Default buffSize: 50
	Subscribe(markets []string, buffSize ...uint64) (<-chan T, error)

	// Unsubscribe from markets.
	Unsubscribe(markets []string) error

	// Unsubscribe from every market.
	UnsubscribeAll() error
}

type FillEvent

type FillEvent struct {
	// Describes the returned event over the socket
	Event string `json:"event"`
	// The market which was requested in the subscription
	Market string `json:"market"`
	// The fill itself
	Fill types.Fill `json:"fill"`
}

func (*FillEvent) UnmarshalJSON

func (f *FillEvent) UnmarshalJSON(bytes []byte) error

type Option

type Option func(*wsClient)

func WithAutoReconnect

func WithAutoReconnect(autoReconnect bool) Option

Auto reconnect if websocket disconnects. default: true

func WithErrorChannel

func WithErrorChannel(errchn chan<- error) Option

Receive websocket connection errors (e.g. reconnect error, auth error, write failed, read failed)

func WithWriteBuffSize

func WithWriteBuffSize(buffSize uint64) Option

The buff size for the write channel, by default the write channel is unbuffered. The write channel writes messages to the websocket.

type OrderEvent

type OrderEvent struct {
	// Describes the returned event over the socket.
	Event string `json:"event"`

	// The market which was requested in the subscription.
	Market string `json:"market"`

	// The order itself.
	Order types.Order `json:"order"`
}

func (*OrderEvent) UnmarshalJSON

func (o *OrderEvent) UnmarshalJSON(bytes []byte) error

type Ticker24hEvent

type Ticker24hEvent struct {
	// Describes the returned event over the socket.
	Event string `json:"event"`

	// The market which was requested in the subscription.
	Market string `json:"market"`

	// The ticker24h containing the prices etc.
	Ticker24h types.Ticker24h `json:"ticker24h"`
}

func (*Ticker24hEvent) UnmarshalJSON

func (t *Ticker24hEvent) UnmarshalJSON(bytes []byte) error

type TickerEvent

type TickerEvent struct {
	// Describes the returned event over the socket.
	Event string `json:"event"`

	// The market which was requested in the subscription.
	Market string `json:"market"`

	// The ticker containing the prices.
	Ticker types.Ticker `json:"ticker"`
}

func (*TickerEvent) UnmarshalJSON

func (t *TickerEvent) UnmarshalJSON(bytes []byte) error

type TradesEvent

type TradesEvent struct {
	// Describes the returned event over the socket.
	Event string `json:"event"`

	// The market which was requested in the subscription.
	Market string `json:"market"`

	// The trade containing the price, side etc.
	Trade types.Trade `json:"trade"`
}

func (*TradesEvent) UnmarshalJSON

func (t *TradesEvent) UnmarshalJSON(bytes []byte) error

type WebSocketMessage

type WebSocketMessage struct {
	Action   string    `json:"action"`
	Channels []Channel `json:"channels,omitempty"`

	// Api Key.
	Key string `json:"key,omitempty"`
	// SHA256 HMAC hex digest of timestamp + method + url + body.
	Signature string `json:"signature,omitempty"`
	// The current timestamp in milliseconds since 1 Jan 1970.
	Timestamp int64 `json:"timestamp,omitempty"`
}

type WsClient

type WsClient interface {
	// Close everything, including subscriptions, underlying websockets, graceful shutdown...
	Close() error

	// Candles event handler to handle candle events and subscriptions.
	Candles() CandlesEventHandler

	// Ticker event handler to handle ticker events and subscriptions.
	Ticker() EventHandler[TickerEvent]

	// Ticker24h event handler to handle ticker24h events and subscriptions.
	Ticker24h() EventHandler[Ticker24hEvent]

	// Trades event handler to handle trade events and subscriptions.
	Trades() EventHandler[TradesEvent]

	// Book event handler to handle book events and subscriptions.
	Book() EventHandler[BookEvent]

	// Account event handler to handle order/fill events, requires authentication.
	Account(apiKey string, apiSecret string) AccountEventHandler
}

func NewWsClient

func NewWsClient(options ...Option) (WsClient, error)

type WsEvent

type WsEvent enum.Member[string]

Jump to

Keyboard shortcuts

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