Documentation ¶
Index ¶
- Constants
- type Channel
- type ChannelRawMessage
- type ChannelType
- type Client
- func (c *Client) Business() *Client
- func (c *Client) Clone() *Client
- func (c *Client) Close() (err error)
- func (c *Client) Login(ctx context.Context, apis ...okxapigo.Api) error
- func (c *Client) Private() *Client
- func (c *Client) Public() *Client
- func (c *Client) Run(ctx context.Context) (err error)
- func (c *Client) Subscribe(ctx context.Context, channels ...Channel) error
- func (c *Client) Unsubscribe(ctx context.Context, channels ...Channel) error
- type MessageHandler
- type NoopMessageHandler
- type OptFn
- type PushData
- type Request
- type Response
- type TickersChannel
- type TickersData
Constants ¶
const ( PublicChannelType = "public" PrivateChannelType = "private" BusinessChannelType = "business" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelRawMessage ¶
type ChannelRawMessage struct {
json.RawMessage
}
ChannelRawMessage
func (ChannelRawMessage) GetChannel ¶
func (m ChannelRawMessage) GetChannel() (string, error)
GetChannel get channel name
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client okx api v5 client using websocket protocol
func (*Client) Unsubscribe ¶
Unsubscribe
https://www.okx.com/docs-v5/en/#overview-websocket-unsubscribe
type MessageHandler ¶
type MessageHandler interface { // HandleUnknownMessage HandleUnknownMessage(ctx context.Context, msg []byte) // HandlePushData HandlePushData(context.Context, PushData[ChannelRawMessage, json.RawMessage]) // HandleResponse HandleResponse(context.Context, Response[ChannelRawMessage]) }
MessageHandler message handler
type NoopMessageHandler ¶
type NoopMessageHandler struct{}
NoopMessageHandler implement MessageHandler but do nonthing
func (NoopMessageHandler) HandlePushData ¶
func (h NoopMessageHandler) HandlePushData(ctx context.Context, data PushData[ChannelRawMessage, json.RawMessage])
func (NoopMessageHandler) HandleResponse ¶
func (h NoopMessageHandler) HandleResponse(ctx context.Context, resp Response[ChannelRawMessage])
func (NoopMessageHandler) HandleUnknownMessage ¶
func (h NoopMessageHandler) HandleUnknownMessage(ctx context.Context, msg []byte)
type OptFn ¶
type OptFn func(*options)
OptFn client functional options
func WithMessageHandler ¶
func WithMessageHandler(handler MessageHandler) OptFn
WithMessageHandler set message's handler
type PushData ¶
type PushData[Arg Channel, Data any] struct { // Successfully subscribed channel Arg Arg `json:"arg,omitempty"` // Subscribed data Data []Data `json:"data,omitempty"` // contains filtered or unexported fields }
PushData Push data parameters
func MapPushData ¶
func MapPushData[Arg Channel, Data any](input PushData[ChannelRawMessage, json.RawMessage]) (output PushData[Arg, Data], err error)
MapPushData convert input to output
func (PushData[A, D]) GetRawMessage ¶
GetRawMessage get raw websocket message
type Request ¶
type Request[T any] struct { // Unique identifier of the messageProvided by client. // It will be returned in response message for identifying the corresponding request. // A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters. Id string `json:"id,omitempty"` // Operation Op string `json:"op,omitempty"` // Request Parameters Args []T `json:"args,omitempty"` }
Request
type Response ¶
type Response[T Channel] struct { // Operation // login // subscribe // unsubscribe // error Event string `json:"event"` Arg T `json:"arg"` // Error code Code string `json:"code"` // Error message Msg string `json:"msg"` // WebSocket connection ID ConnId string `json:"connId"` // contains filtered or unexported fields }
Response Operation result
func MapResponse ¶
func MapResponse[T Channel](input Response[ChannelRawMessage]) (output Response[T], err error)
MapResponse map input to output
func (Response[T]) GetRawMessage ¶
GetRawMessage get raw websocket message
type TickersChannel ¶
type TickersChannel struct { // Channel name Channel string `json:"channel,omitempty"` // Instrument ID InstId string `json:"instId"` }
TickersChannel
https://www.okx.com/docs-v5/en/#order-book-trading-market-data-ws-tickers-channel
func (TickersChannel) GetChannel ¶
func (t TickersChannel) GetChannel() (string, error)
GetChannel implement Channel interface
type TickersData ¶
type TickersData struct { // Instrument type InstType string `json:"instType"` // Instrument ID InstID string `json:"instId"` // Last traded price Last string `json:"last"` // Last traded size LastSz string `json:"lastSz"` // Best ask price AskPx string `json:"askPx"` // Best ask size AskSz string `json:"askSz"` // Best bid price BidPx string `json:"bidPx"` // Best bid size BidSz string `json:"bidSz"` // Open price in the past 24 hours Open24H string `json:"open24h"` // Highest price in the past 24 hours High24H string `json:"high24h"` // Lowest price in the past 24 hours Low24H string `json:"low24h"` // Open price in the UTC 0 SodUtc0 string `json:"sodUtc0"` // Open price in the UTC 8 SodUtc8 string `json:"sodUtc8"` // 24h trading volume, with a unit of currency. // If it is a derivatives contract, the value is the number of base currency. // If it is SPOT/MARGIN, the value is the quantity in quote currency. VolCcy24H string `json:"volCcy24h"` // 24h trading volume, with a unit of contract. // If it is a derivatives contract, the value is the number of contracts. // If it is SPOT/MARGIN, the value is the quantity in base currency. Vol24H string `json:"vol24h"` // Ticker data generation time, Unix timestamp format in milliseconds, e.g. 1597026383085 Ts string `json:"ts"` }
TickersData