client

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultScheme = "wss"
	ApiV5         = "v5"
	PingInterval  = 30 * time.Second

	PingOperation                   = "ping"
	AuthOperation                   = "auth"
	ReconnectionRetries             = 3
	ReconnectionDelay               = 10 * time.Second
	Public              ChannelType = "public"
	Private             ChannelType = "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 {
	Conn *websocket.Conn

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

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

func NewClient added in v0.1.6

func NewClient(apiKey, apiSecret string, isTestNet bool) (*Client, error)

NewClient initializes a new WSClient instance. apiKey and apiSecret are required for authentication with private channels. isTestNet determines if the client connects to a test network. isPublic specifies if the client connects to a public channel.

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) 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"`
}

PingMsg represents the WebSocket ping message format.

type PrivateChannels added in v0.1.6

type PrivateChannels string

PrivateChannels represents the type for private channels.

type PublicChannels added in v0.1.6

type PublicChannels string

PublicChannels represents the type for public channels.

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
	Op      string `json:"op"`      // Op is the operation of the request
	ConnId  string `json:"conn_id"` // ConnId is the connection ID 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