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 (
	GlobalMarketWsBaseURL       = "wss://api.hbdm.com/linear-swap-ws"
	GlobalIndexWsBaseURL        = "wss://api.hbdm.com/ws_index"
	GlobalSystemStatusWsBaseURL = "wss://api.hbdm.com/center-notification"
)
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 {
	ContractCode string `validate:"required"`
	Type         string `` /* 154-byte string literal not displayed */
}

type KlineTopicParam

type KlineTopicParam struct {
	ContractCode string                  `validate:"required"`
	Interval     usdmtypes.KlineInterval `validate:"required,oneof=1min 5min 15min 30min 1hour 4hour 1day 1mon"`
}

type Listener

type Listener func(any)

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(contractCode 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) GetMarketTradeTopic

func (m *MarketWsClient) GetMarketTradeTopic(contractCode 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
	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