client

package
v0.1.54 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultScheme       = "wss"
	PingInterval        = 20 * time.Second
	PingOperation       = "ping"
	AuthOperation       = "auth"
	ReconnectionRetries = 3
	ReconnectionDelay   = 10 * time.Second
	Public              = "public"
	Private             = "private"
)
View Source
const (
	// WSMessageText represents the message type for text in WebSocket communications.
	WSMessageText = websocket.TextMessage
)

Variables

View Source
var (
	DefaultReqID = randomString(8)
)

Functions

func GenerateWsSignature

func GenerateWsSignature(apiSecret, data string) string

GenerateWsSignature generates a signature for the WebSocket API.

Types

type ChannelType

type ChannelType string

ChannelType defines the types of channels (public/private) that the WebSocket client can connect to.

type Client added in v0.1.6

type Client struct {
	IsTestNet         bool
	ApiKey            string
	ApiSecret         string
	Channel           ChannelType
	Path              string
	Connected         chan struct{}
	OnConnected       func()
	OnConnectionError func(err error)
	Category          string
	MaxActiveTime     string
	// contains filtered or unexported fields
}

Client is the main WebSocket client struct, managing the connection and its state.

func NewPrivateClient added in v0.1.26

func NewPrivateClient(apiKey, apiSecret string, isTestNet bool, maxActiveTime string, category string) (*Client, error)

NewPrivateClient initializes a new private WSClient instance.

func NewPublicClient added in v0.1.26

func NewPublicClient(isTestNet bool, category string) (*Client, error)

NewPublicClient initializes a new public WSClient instance.

func (*Client) Authenticate added in v0.1.6

func (c *Client) Authenticate(apiKey, expires, signature string) error

Authenticate sends an authentication request to the WebSocket server.

func (*Client) Close added in v0.1.6

func (c *Client) Close()

Close gracefully closes the WebSocket connection.

func (*Client) Connect added in v0.1.6

func (c *Client) Connect() error

Connect establishes a WebSocket connection to the server based on the configuration.

func (*Client) GetConnection added in v0.1.52

func (c *Client) GetConnection() *websocket.Conn

func (*Client) Receive added in v0.1.6

func (c *Client) Receive() ([]byte, error)

Receive listens for a message from the WebSocket server and returns it.

func (*Client) Send added in v0.1.6

func (c *Client) Send(message []byte) error

Send sends a message to the WebSocket server.

type CommonResponse

type CommonResponse struct {
	Op     string `json:"op"`      // Op is the operation of the request
	ConnId string `json:"conn_id"` // ConnId is the connection ID of the request
}

CommonResponse encapsulates fields that are common across various WebSocket responses.

type Environment

type Environment string

Environment denotes the environment in which the Bybit API operates (e.g., "production", "development").

type PingMsg added in v0.1.6

type PingMsg struct {
	Op    string `json:"op"`
	ReqId string `json:"req_id,omitempty"`
}

PingMsg represents the WebSocket ping message format.

type SoppingOptionsResponse

type SoppingOptionsResponse struct {
	Args []string `json:"args"`
	Op   string   `json:"op"`
}

SoppingOptionsResponse describes the sopping options with associated arguments and operations.

type SubChannel

type SubChannel string

SubChannel represents a sub-channel for Bybit API's WebSocket communications.

type SuccessResponse

type SuccessResponse struct {
	CommonResponse
	Success bool   `json:"success"` // Success indicates the success status of the request
	RetMsg  string `json:"ret_msg"` // RetMsg provides details on the return message of the request
}

SuccessResponse represents the response structure for a successful WebSocket request. It provides details about the operation, connection ID, success status, and return message.

type WSPongPrivateLinearInverseResponse

type WSPongPrivateLinearInverseResponse WSPongPrivateResponse

WSPongPrivateLinearInverseResponse represents a specific private pong response for linear inverse operations.

type WSPongPrivateResponse

type WSPongPrivateResponse struct {
	CommonResponse
	ReqId string   `json:"req_id"`
	Args  []string `json:"args"`
}

WSPongPrivateResponse contains fields common to private pong responses. It also provides a unique request ID and arguments associated with the response.

type WSPongPrivateSpotResponse

type WSPongPrivateSpotResponse WSPongPrivateResponse

WSPongPrivateSpotResponse represents a specific private pong response for the spot.

type WSPongPublicLinearInverseResponse

type WSPongPublicLinearInverseResponse struct {
	WSPongPublicResponse
	ReqId string `json:"req_id"`
}

WSPongPublicLinearInverseResponse represents a specific public pong response for linear inverse operations and also contains a unique request ID.

type WSPongPublicResponse

type WSPongPublicResponse struct {
	SuccessResponse
}

WSPongPublicResponse contains fields common to public pong responses.

type WSPongPublicSpotResponse

type WSPongPublicSpotResponse WSPongPublicResponse

WSPongPublicSpotResponse represents a specific public pong response for the spot.

Jump to

Keyboard shortcuts

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