stream

package
v0.0.0-...-cb4139d Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BookChannel        = Channel("book")
	KLineChannel       = Channel("kline")
	BookTickerChannel  = Channel("bookTicker")
	MarketTradeChannel = Channel("trade")
	AggTradeChannel    = Channel("aggTrade")

	// channels for futures
	MarkPriceChannel = Channel("markPrice")

	LiquidationOrderChannel = Channel("liquidationOrder")

	// ContractInfoChannel is the contract info provided by the exchange
	ContractInfoChannel = Channel("contractInfo")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel string

type Depth

type Depth string
const (
	DepthLevelFull   Depth = "FULL"
	DepthLevelMedium Depth = "MEDIUM"
	DepthLevel1      Depth = "1"
	DepthLevel5      Depth = "5"
	DepthLevel20     Depth = "20"
)

type Dispatcher

type Dispatcher func(e interface{})

type EndpointCreator

type EndpointCreator func(ctx context.Context) (string, error)

type Parser

type Parser func(message []byte) (interface{}, error)

type Speed

type Speed string
const (
	SpeedHigh   Speed = "HIGH"
	SpeedMedium Speed = "MEDIUM"
	SpeedLow    Speed = "LOW"
)

type StandardStream

type StandardStream struct {

	// Conn is the websocket connection
	Conn *websocket.Conn

	// ConnCtx is the context of the current websocket connection
	ConnCtx context.Context

	// ConnCancel is the cancel funcion of the current websocket connection
	ConnCancel context.CancelFunc

	// ConnLock is used for locking Conn, ConnCtx and ConnCancel fields.
	// When changing these field values, be sure to call ConnLock
	ConnLock sync.Mutex

	PublicOnly bool

	// ReconnectC is a signal channel for reconnecting
	ReconnectC chan struct{}

	// CloseC is a signal channel for closing stream
	CloseC chan struct{}

	Subscriptions []Subscription
	// contains filtered or unexported fields
}

func NewStandardStream

func NewStandardStream() StandardStream

func (*StandardStream) Close

func (s *StandardStream) Close() error

func (*StandardStream) Connect

func (s *StandardStream) Connect(ctx context.Context) error

Connect starts the stream and create the websocket connection

func (*StandardStream) Dial

func (s *StandardStream) Dial(ctx context.Context, args ...string) (*websocket.Conn, error)

func (*StandardStream) DialAndConnect

func (s *StandardStream) DialAndConnect(ctx context.Context) error

func (*StandardStream) EmitConnect

func (s *StandardStream) EmitConnect()

func (*StandardStream) EmitDisconnect

func (s *StandardStream) EmitDisconnect()

func (*StandardStream) EmitStart

func (s *StandardStream) EmitStart()

func (*StandardStream) GetPublicOnly

func (s *StandardStream) GetPublicOnly() bool

func (*StandardStream) GetSubscriptions

func (s *StandardStream) GetSubscriptions() []Subscription

func (*StandardStream) OnConnect

func (s *StandardStream) OnConnect(cb func())

func (*StandardStream) OnDisconnect

func (s *StandardStream) OnDisconnect(cb func())

func (*StandardStream) OnStart

func (s *StandardStream) OnStart(cb func())

func (*StandardStream) Read

func (s *StandardStream) Read(ctx context.Context, conn *websocket.Conn, cancel context.CancelFunc)

func (*StandardStream) Reconnect

func (s *StandardStream) Reconnect()

func (*StandardStream) SetConn

func (*StandardStream) SetDispatcher

func (s *StandardStream) SetDispatcher(dispatcher Dispatcher)

func (*StandardStream) SetEndpointCreator

func (s *StandardStream) SetEndpointCreator(creator EndpointCreator)

func (*StandardStream) SetParser

func (s *StandardStream) SetParser(parser Parser)

func (*StandardStream) SetPublicOnly

func (s *StandardStream) SetPublicOnly()

func (*StandardStream) Subscribe

func (s *StandardStream) Subscribe(channel Channel, symbol string, options SubscribeOptions)

type StandardStreamEmitter

type StandardStreamEmitter interface {
	Stream
	EmitStart()
	EmitConnect()
	EmitDisconnect()
}

type StandardStreamEventHub

type StandardStreamEventHub interface {
	OnStart(cb func())

	OnConnect(cb func())

	OnDisconnect(cb func())

	OnTradeUpdate(cb func())
}

type Stream

type Stream interface {
	StandardStreamEventHub

	Subscribe(channel Channel, symbol string, options SubscribeOptions)
	GetSubscriptions() []Subscription
	SetPublicOnly()
	GetPublicOnly() bool
	Connect(ctx context.Context) error
	Close() error
}

type SubscribeOptions

type SubscribeOptions struct {
	Depth Depth `json:"depth,omitempty"`
	Speed Speed `json:"speed,omitempty"`
}

SubscribeOptions provides the standard stream options

func (SubscribeOptions) String

func (o SubscribeOptions) String() string

type Subscription

type Subscription struct {
	Symbol  string           `json:"symbol"`
	Channel Channel          `json:"channel"`
	Options SubscribeOptions `json:"options"`
}

Jump to

Keyboard shortcuts

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