marketws

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GlobalWsBaseURL       = "wss://api.huobi.pro/ws"
	GlobalWsBaseURLForAWS = "wss://api-aws.huobi.pro/ws"

	MBPWsBaseURL       = "wss://api.huobi.pro/feed"
	MBPWsBaseURLForAWS = "wss://api-aws.huobi.pro/feed"
)
View Source
const (
	MaxTryTimes = 5

	TimerIntervalSecond = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyMessage

type AnyMessage struct {
	Ping              *PingMessage
	Response          *Response
	SubscribedMessage *SubscribedMessage
}

AnyMessage represents either a JSON Response or SubscribedMessage.

func (AnyMessage) MarshalJSON

func (m AnyMessage) MarshalJSON() ([]byte, error)

func (*AnyMessage) UnmarshalJSON

func (m *AnyMessage) UnmarshalJSON(data []byte) error

type DepthTopicParam

type DepthTopicParam struct {
	Symbol string `validate:"required"`
	Type   string `validate:"required,oneof=step0 step1 step2 step3 step4 step5"`
}

type KlineTopicParam

type KlineTopicParam struct {
	Symbol   string                  `validate:"required"`
	Interval spottypes.KlineInterval `validate:"required,oneof=1min 5min 15min 30min 60min 4hour 1day 1mon 1week 1year"`
}

type Listener

type Listener func(any)

type MBPDepthRefreshTopicParam

type MBPDepthRefreshTopicParam struct {
	Symbol string `validate:"required"`
	Level  int    `validate:"required,oneof=5 10 20"`
}

type MBPDepthUpdateTopicParam

type MBPDepthUpdateTopicParam struct {
	Symbol string `validate:"required"`
	Level  int    `validate:"required,oneof=5 20 150 400"`
}

type MarketWsClient

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

func NewMarketWsClient

func NewMarketWsClient(cfg *MarketWsClientCfg) (*MarketWsClient, error)

func (*MarketWsClient) AddListener

func (m *MarketWsClient) AddListener(event string, listener Listener) *emission.Emitter

func (*MarketWsClient) Close

func (m *MarketWsClient) Close() error

func (*MarketWsClient) GetBBOTopic

func (m *MarketWsClient) GetBBOTopic(symbol string) (string, error)

func (*MarketWsClient) GetDepthTopic

func (m *MarketWsClient) GetDepthTopic(params *DepthTopicParam) (string, error)

func (*MarketWsClient) GetKlineTopic

func (m *MarketWsClient) GetKlineTopic(params *KlineTopicParam) (string, error)

func (*MarketWsClient) GetListeners

func (m *MarketWsClient) GetListeners(event string, argument any) *emission.Emitter

func (*MarketWsClient) GetMBPDepthUpdateTopic

func (m *MarketWsClient) GetMBPDepthUpdateTopic(params *MBPDepthUpdateTopicParam) (string, error)

func (*MarketWsClient) GetMBPRefreshDepthTopic

func (m *MarketWsClient) GetMBPRefreshDepthTopic(params *MBPDepthRefreshTopicParam) (string, error)

func (*MarketWsClient) GetMarketTradeTopic

func (m *MarketWsClient) GetMarketTradeTopic(symbol string) (string, error)

func (*MarketWsClient) GetTickerTopic

func (m *MarketWsClient) GetTickerTopic(symbol string) (string, error)

func (*MarketWsClient) IsConnected

func (m *MarketWsClient) IsConnected() bool

IsConnected returns the WebSocket connection state

func (*MarketWsClient) Open

func (m *MarketWsClient) Open() error

func (*MarketWsClient) RemoveListener

func (m *MarketWsClient) RemoveListener(event string, listener Listener) *emission.Emitter

func (*MarketWsClient) Subscribe

func (m *MarketWsClient) Subscribe(topic string) error

func (*MarketWsClient) UnSubscribe

func (m *MarketWsClient) UnSubscribe(topic string) error

type MarketWsClientCfg

type MarketWsClientCfg struct {
	Debug         bool
	BaseURL       string `validate:"required"`
	AutoReconnect bool   `validate:"required"`

	Logger *slog.Logger
}

type PingMessage

type PingMessage struct {
	Ping int64 `json:"ping,omitempty"`
}

type PongMessage

type PongMessage struct {
	Pong int64 `json:"pong,omitempty"`
}

type Request

type Request struct {
	ID    string `json:"id,omitempty"`
	Sub   string `json:"sub,omitempty"`
	UnSub string `json:"unsub,omitempty"`
}

type Response

type Response struct {
	ID     string `json:"id,omitempty"`
	Status string `json:"status,omitempty"`
	Subbed string `json:"subbed,omitempty"`
	Ts     int64  `json:"ts,omitempty"`
}

type SubscribedMessage

type SubscribedMessage struct {
	Channel string          `json:"ch,omitempty"`
	Ts      int64           `json:"ts,omitempty"`
	Data    json.RawMessage `json:"tick"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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