Documentation
¶
Index ¶
- Constants
- func Request[T any](c *Client, ctx context.Context, method Method, path string, ...) ([]T, error)
- type APIError
- type AccountConfig
- type Announcement
- type Balance
- type BalanceDetail
- type BaseResponse
- type CancelOrderRequest
- type Candle
- type Client
- func (c *Client) CancelOrder(ctx context.Context, instId, ordId, clOrdId string) ([]OrderId, error)
- func (c *Client) CancelOrders(ctx context.Context, reqs []CancelOrderRequest) ([]OrderId, error)
- func (c *Client) ClosePosition(ctx context.Context, instId, mgnMode string) ([]ClosePosition, error)
- func (c *Client) Do(ctx context.Context, method Method, path string, payload interface{}, ...) ([]byte, error)
- func (c *Client) GetAccountBalance(ctx context.Context, ccy *string) ([]Balance, error)
- func (c *Client) GetAccountConfig(ctx context.Context) ([]AccountConfig, error)
- func (c *Client) GetAllFundingRates(ctx context.Context) ([]FundingRateData, error)
- func (c *Client) GetAnnouncements(ctx context.Context, annType string) ([]Announcement, error)
- func (c *Client) GetCandles(ctx context.Context, instId string, bar *string, after *string, before *string, ...) ([]Candle, error)
- func (c *Client) GetFundingRate(ctx context.Context, instId string) (*FundingRateData, error)
- func (c *Client) GetInstruments(ctx context.Context, instType string) ([]Instrument, error)
- func (c *Client) GetOrder(ctx context.Context, instId, ordId, clOrdId string) ([]Order, error)
- func (c *Client) GetOrderBook(ctx context.Context, instId string, sz *int) ([]OrderBook, error)
- func (c *Client) GetOrders(ctx context.Context, instType, instId *string) ([]Order, error)
- func (c *Client) GetPositions(ctx context.Context, instType, instId *string) ([]Position, error)
- func (c *Client) GetTicker(ctx context.Context, instId string) ([]Ticker, error)
- func (c *Client) GetTickers(ctx context.Context, instType string, instFamily *string) ([]Ticker, error)
- func (c *Client) GetTradeFee(ctx context.Context, instType string, instId *string) ([]TradeFee, error)
- func (c *Client) ModifyOrder(ctx context.Context, req *ModifyOrderRequest) ([]OrderId, error)
- func (c *Client) PlaceOrder(ctx context.Context, req *OrderRequest) ([]OrderId, error)
- func (c *Client) SetLeverage(ctx context.Context, params SetLeverage) ([]SetLeverage, error)
- func (c *Client) SetPositionMode(ctx context.Context, posMode string) ([]PositionMode, error)
- func (c *Client) WithCredentials(apiKey, secretKey, passphrase string) *Client
- type ClosePosition
- type Environment
- type FeeGroup
- type FundingRate
- type FundingRateData
- type Instrument
- type LinkedAlgoOrder
- type Method
- type MgnMode
- type ModifyOrderRequest
- type Order
- type OrderBook
- type OrderId
- type OrderRequest
- type OrderStatus
- type OrderType
- type PendingRequest
- type PosSide
- type Position
- type PositionMode
- type SetLeverage
- type Side
- type Signer
- type TdMode
- type Ticker
- type TradeFee
- type WsClient
- func (c *WsClient) AddPendingRequest(id int64) (chan []byte, chan []byte)
- func (c *WsClient) CancelOrderWS(instId string, ordId, clOrdId *string) (*OrderId, error)
- func (c *WsClient) CancelOrdersWS(reqs []CancelOrderRequest) ([]OrderId, error)
- func (c *WsClient) Connect() error
- func (c *WsClient) Login() error
- func (c *WsClient) ModifyOrderWS(req *ModifyOrderRequest) (*OrderId, error)
- func (c *WsClient) PlaceOrderWS(req *OrderRequest) (*OrderId, error)
- func (c *WsClient) RemovePendingRequest(id int64)
- func (c *WsClient) Subscribe(args WsSubscribeArgs, handler func(data []byte)) error
- func (c *WsClient) SubscribeOrderBook(instId string, handler func(*OrderBook, string)) error
- func (c *WsClient) SubscribeOrders(instType string, instId *string, handler func(*Order)) error
- func (c *WsClient) SubscribePositions(instType string, handler func(*Position)) error
- func (c *WsClient) SubscribeTicker(instId string, handler func(*Ticker)) error
- func (c *WsClient) Unsubscribe(args WsSubscribeArgs) error
- func (c *WsClient) WithCredentials(apiKey, secretKey, passphrase string) *WsClient
- type WsEvent
- type WsOrderData
- type WsOrderOp
- type WsPositionData
- type WsPushData
- type WsSubscribeArgs
- type WsSubscribeRes
Constants ¶
const ( ReadTimeout = 60 * time.Second ReconnectWait = 5 * time.Second WSBaseURL = "wss://ws.okx.com:8443/ws/v5/public" WSPrivateBaseURL = "wss://ws.okx.com:8443/ws/v5/private" )
const ( ArgChannel = "channel" ArgInstId = "instId" ArgInstType = "instType" )
Common args keys
const (
BaseURL = "https://www.okx.com"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AccountConfig ¶
type AccountConfig struct {
AcctLv string `json:"acctLv"`
AcctStpMode string `json:"acctStpMode"`
AutoLoan bool `json:"autoLoan"`
CtIsoMode string `json:"ctIsoMode"`
EnableSpotBorrow bool `json:"enableSpotBorrow"`
GreeksType string `json:"greeksType"`
FeeType string `json:"feeType"`
Ip string `json:"ip"`
Type string `json:"type"`
KycLv string `json:"kycLv"`
Label string `json:"label"`
Level string `json:"level"`
LevelTmp string `json:"levelTmp"`
LiquidationGear string `json:"liquidationGear"`
MainUid string `json:"mainUid"`
MgnIsoMode string `json:"mgnIsoMode"`
OpAuth string `json:"opAuth"`
Perm string `json:"perm"`
PosMode string `json:"posMode"`
RoleType string `json:"roleType"`
SpotBorrowAutoRepay bool `json:"spotBorrowAutoRepay"`
SpotOffsetType string `json:"spotOffsetType"`
SpotRoleType string `json:"spotRoleType"`
SpotTraderInsts []string `json:"spotTraderInsts"`
StgyType string `json:"stgyType"`
TraderInsts []string `json:"traderInsts"`
Uid string `json:"uid"`
SettleCcy string `json:"settleCcy"`
SettleCcyList []string `json:"settleCcyList"`
}
type Announcement ¶
type Announcement struct {
Title string `json:"title"`
URL string `json:"url"` // Full URL to announcement
AnnType string `json:"annType"` // Type of announcement
PublishTime string `json:"pTime"` // Timestamp in milliseconds
BusinessTime string `json:"businessPTime"` // Business timestamp in milliseconds
}
Announcement represents a single announcement detail from OKX API Based on /api/v5/support/announcements response structure
type Balance ¶
type Balance struct {
AdjEq string `json:"adjEq"`
AvailEq string `json:"availEq"`
BorrowFroz string `json:"borrowFroz"`
Delta string `json:"delta"`
DeltaLever string `json:"deltaLever"`
DeltaNeutralStatus string `json:"deltaNeutralStatus"`
Details []BalanceDetail `json:"details"`
Imr string `json:"imr"`
IsoEq string `json:"isoEq"`
MgnRatio string `json:"mgnRatio"`
Mmr string `json:"mmr"`
NotionalUsd string `json:"notionalUsd"`
NotionalUsdForBorrow string `json:"notionalUsdForBorrow"`
NotionalUsdForFutures string `json:"notionalUsdForFutures"`
NotionalUsdForOption string `json:"notionalUsdForOption"`
NotionalUsdForSwap string `json:"notionalUsdForSwap"`
OrdFroz string `json:"ordFroz"`
TotalEq string `json:"totalEq"`
UTime string `json:"uTime"`
Upl string `json:"upl"`
}
type BalanceDetail ¶
type BalanceDetail struct {
AutoLendStatus string `json:"autoLendStatus"`
AutoLendMtAmt string `json:"autoLendMtAmt"`
AvailBal string `json:"availBal"`
AvailEq string `json:"availEq"`
BorrowFroz string `json:"borrowFroz"`
CashBal string `json:"cashBal"`
Ccy string `json:"ccy"`
CrossLiab string `json:"crossLiab"`
ColRes string `json:"colRes"`
CollateralEnabled bool `json:"collateralEnabled"`
CollateralRestrict bool `json:"collateralRestrict"`
ColBorrAutoConversion string `json:"colBorrAutoConversion"`
DisEq string `json:"disEq"`
Eq string `json:"eq"`
EqUsd string `json:"eqUsd"`
SmtSyncEq string `json:"smtSyncEq"`
SpotCopyTradingEq string `json:"spotCopyTradingEq"`
FixedBal string `json:"fixedBal"`
FrozenBal string `json:"frozenBal"`
FrpType string `json:"frpType"`
Imr string `json:"imr"`
Interest string `json:"interest"`
IsoEq string `json:"isoEq"`
IsoLiab string `json:"isoLiab"`
IsoUpl string `json:"isoUpl"`
Liab string `json:"liab"`
MaxLoan string `json:"maxLoan"`
MgnRatio string `json:"mgnRatio"`
Mmr string `json:"mmr"`
NotionalLever string `json:"notionalLever"`
OrdFrozen string `json:"ordFrozen"`
RewardBal string `json:"rewardBal"`
SpotInUseAmt string `json:"spotInUseAmt"`
ClSpotInUseAmt string `json:"clSpotInUseAmt"`
MaxSpotInUse string `json:"maxSpotInUse"`
SpotIsoBal string `json:"spotIsoBal"`
StgyEq string `json:"stgyEq"`
Twap string `json:"twap"`
UTime string `json:"uTime"`
Upl string `json:"upl"`
UplLiab string `json:"uplLiab"`
SpotBal string `json:"spotBal"`
OpenAvgPx string `json:"openAvgPx"`
AccAvgPx string `json:"accAvgPx"`
SpotUpl string `json:"spotUpl"`
SpotUplRatio string `json:"spotUplRatio"`
TotalPnl string `json:"totalPnl"`
TotalPnlRatio string `json:"totalPnlRatio"`
}
type BaseResponse ¶
type BaseResponse[T any] struct { Code string `json:"code"` Message string `json:"msg"` Data []T `json:"data"` }
BaseResponse is the standard response wrapper for OKX API. generic type T allows flexible data parsing.
type CancelOrderRequest ¶
type Candle ¶
type Candle [9]string
[0] ts [1] open [2] high [3] low [4] close [5] volume size [6] volume ccy [7] volume ccy quote [8] confirm: 0 (not finish) or 1 (finish)
type Client ¶
type Client struct {
ApiKey string
SecretKey string
Passphrase string
HTTPClient *http.Client
Signer *Signer
}
func (*Client) CancelOrder ¶
CancelOrder cancels an incomplete order.
func (*Client) CancelOrders ¶
CancelOrders cancels multiple orders (max 20).
func (*Client) ClosePosition ¶
func (c *Client) ClosePosition(ctx context.Context, instId, mgnMode string) ([]ClosePosition, error)
ClosePosition closes a position.
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, method Method, path string, payload interface{}, auth bool) ([]byte, error)
Do executes a generic HTTP request and returns the raw response body. It handles authentication signatures if auth is required.
func (*Client) GetAccountBalance ¶
GetAccountBalance retrieves the account balance. ccy: optional, comma-separated list of currencies (e.g. "BTC,ETH")
func (*Client) GetAccountConfig ¶
func (c *Client) GetAccountConfig(ctx context.Context) ([]AccountConfig, error)
GetAccountConfig retrieves the account configuration.
func (*Client) GetAllFundingRates ¶
func (c *Client) GetAllFundingRates(ctx context.Context) ([]FundingRateData, error)
GetAllFundingRates retrieves funding rates for all instruments Returns per-hour funding rates (standardized)
func (*Client) GetAnnouncements ¶
GetAnnouncements returns a list of announcements. annType: Announcement type (optional) page: Page number (optional, default 1)
func (*Client) GetCandles ¶
func (c *Client) GetCandles(ctx context.Context, instId string, bar *string, after *string, before *string, limit *int) ([]Candle, error)
GetCandles retrieves candles for a specific instrument. bar: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h limit: default 100, max 300
func (*Client) GetFundingRate ¶
GetFundingRate retrieves the current funding rate for a specific instrument Returns per-hour funding rate (standardized)
func (*Client) GetInstruments ¶
GetInstruments retrieves instruments information. instType: SPOT, SWAP, FUTURES, OPTION, MARGIN
func (*Client) GetOrderBook ¶
GetOrderBook retrieves order book depth. sz: depth size, e.g. 400
func (*Client) GetOrders ¶
GetOrders retrieves pending orders. instType: SPOT, MARGIN, SWAP, FUTURES, OPTION instId: optional, Instrument ID
func (*Client) GetPositions ¶
GetPositions retrieves the account positions. instId: optional, instrument ID posType: optional, position type
func (*Client) GetTickers ¶
func (c *Client) GetTickers(ctx context.Context, instType string, instFamily *string) ([]Ticker, error)
GetTickers retrieves the tickers for a specific instrument type and family.
func (*Client) GetTradeFee ¶
func (c *Client) GetTradeFee(ctx context.Context, instType string, instId *string) ([]TradeFee, error)
GetTradeFee retrieves the trade fee rates. instType: SPOT, MARGIN, SWAP, FUTURES, OPTION instId: instrument ID
func (*Client) ModifyOrder ¶
ModifyOrder amends an incomplete order.
func (*Client) PlaceOrder ¶
PlaceOrder submits a new order.
func (*Client) SetLeverage ¶
func (c *Client) SetLeverage(ctx context.Context, params SetLeverage) ([]SetLeverage, error)
SetLeverage sets the leverage. instId: instrument ID lever: leverage mgnMode: isolated or cross
func (*Client) SetPositionMode ¶
SetPositionMode sets the position mode. posMode: long_short_mode or net_mode(for perp and option)
func (*Client) WithCredentials ¶
type ClosePosition ¶
type Environment ¶
type Environment string
Environment type
const ( Production Environment = "0" Simulated Environment = "1" )
type FundingRate ¶
type FundingRate struct {
InstrumentType string `json:"instType"`
InstrumentID string `json:"instId"`
FundingRate string `json:"fundingRate"`
NextFundingRate string `json:"nextFundingRate"`
FundingTime string `json:"fundingTime"`
NextFundingTime string `json:"nextFundingTime"`
Premium string `json:"premium"`
SettFundingRate string `json:"settFundingRate"`
SettState string `json:"settState"`
Ts string `json:"ts"`
}
type FundingRateData ¶
type FundingRateData struct {
Symbol string `json:"symbol"`
FundingRate string `json:"fundingRate"` // Per-hour funding rate (standardized)
FundingIntervalHours int64 `json:"fundingIntervalHours"` // Calculated from time difference
FundingTime string `json:"fundingTime"`
NextFundingTime string `json:"nextFundingTime"`
}
FundingRateData contains standardized funding rate information
type Instrument ¶
type Instrument struct {
InstId string `json:"instId"`
Uly string `json:"uly"`
BaseCcy string `json:"baseCcy"`
QuoteCcy string `json:"quoteCcy"`
SettCcy string `json:"settCcy"`
CtVal string `json:"ctVal"`
CtMult string `json:"ctMult"`
CtValCcy string `json:"ctValCcy"`
OptType string `json:"optType"`
Stk string `json:"stk"`
ListTime string `json:"listTime"`
ExpTime string `json:"expTime"`
Leverage string `json:"leverage"`
TickSz string `json:"tickSz"`
LotSz string `json:"lotSz"`
MinSz string `json:"minSz"`
InstType string `json:"instType"`
State string `json:"state"`
}
type LinkedAlgoOrder ¶
type LinkedAlgoOrder struct {
AlgoId string `json:"algoId"`
}
type ModifyOrderRequest ¶
type ModifyOrderRequest struct {
InstId string `json:"instId"`
OrdId *string `json:"ordId,omitempty"`
ClOrdId *string `json:"clOrdId,omitempty"`
NewSz *string `json:"newSz,omitempty"`
NewPx *string `json:"newPx,omitempty"`
CxlOnFail *bool `json:"cxlOnFail,omitempty"`
ReqId *string `json:"reqId,omitempty"`
}
type Order ¶
type Order struct {
AccFillSz string `json:"accFillSz"`
AlgoClOrdId string `json:"algoClOrdId"`
AlgoId string `json:"algoId"`
AttachAlgoClOrdId string `json:"attachAlgoClOrdId"`
AttachAlgoOrds []int `json:"attachAlgoOrds"`
AvgPx string `json:"avgPx"`
CTime string `json:"cTime"`
CancelSource string `json:"cancelSource"`
CancelSourceReason string `json:"cancelSourceReason"`
Category string `json:"category"`
Ccy string `json:"ccy"`
ClOrdId string `json:"clOrdId"`
Fee string `json:"fee"`
FillPx string `json:"fillPx"`
FillSz string `json:"fillSz"`
FillTime string `json:"fillTime"`
InstId string `json:"instId"`
InstType string `json:"instType"`
IsTpLimit string `json:"isTpLimit"`
Lever string `json:"lever"`
LinkedAlgoOrder LinkedAlgoOrder `json:"linkedAlgoOrder"`
OrdId string `json:"ordId"`
OrdType OrderType `json:"ordType"`
Pnl string `json:"pnl"`
PosSide PosSide `json:"posSide"`
Px string `json:"px"`
PxType string `json:"pxType"`
PxUsd string `json:"pxUsd"`
PxVol string `json:"pxVol"`
QuickMgnType string `json:"quickMgnType"`
Rebate string `json:"rebate"`
RebateCcy string `json:"rebateCcy"`
ReduceOnly string `json:"reduceOnly"`
Side Side `json:"side"`
SlOrdPx string `json:"slOrdPx"`
SlTriggerPx string `json:"slTriggerPx"`
SlTriggerPxType string `json:"slTriggerPxType"`
Source string `json:"source"`
State OrderStatus `json:"state"`
StpId string `json:"stpId"`
StpMode string `json:"stpMode"`
Sz string `json:"sz"`
Tag string `json:"tag"`
TdMode TdMode `json:"tdMode"`
TgtCcy string `json:"tgtCcy"`
TpOrdPx string `json:"tpOrdPx"`
TpTriggerPx string `json:"tpTriggerPx"`
TpTriggerPxType string `json:"tpTriggerPxType"`
TradeId string `json:"tradeId"`
TradeQuoteCcy string `json:"tradeQuoteCcy"`
UTime string `json:"uTime"`
}
type OrderRequest ¶
type OrderRequest struct {
InstId string `json:"instId"`
TdMode string `json:"tdMode"` // cross, isolated, cash (spot)
ClOrdId *string `json:"clOrdId,omitempty"`
Side string `json:"side"` // buy, sell
PosSide *string `json:"posSide,omitempty"` // long, short, net (required for long/short mode)
OrdType string `json:"ordType"` // market, limit, etc.
Sz string `json:"sz"`
Px *string `json:"px,omitempty"`
Ccy *string `json:"ccy,omitempty"`
TgtCcy *string `json:"tgtCcy,omitempty"`
Tag *string `json:"tag,omitempty"`
ReduceOnly *bool `json:"reduceOnly,omitempty"`
}
type OrderStatus ¶
type OrderStatus string
const ( OrderStatusLive OrderStatus = "live" OrderStatusPartiallyFilled OrderStatus = "partially_filled" OrderStatusFilled OrderStatus = "filled" OrderStatusCanceled OrderStatus = "canceled" OrderStatusMmpCanceled OrderStatus = "mmp_canceled" // 做市商保护机制的自动撤单 )
type PendingRequest ¶
PendingRequest holds channels for success and error responses
type Position ¶
type Position struct {
Adl string `json:"adl"`
AvailPos string `json:"availPos"`
AvgPx string `json:"avgPx"`
BaseBal string `json:"baseBal"`
BaseBorrowed string `json:"baseBorrowed"`
BaseInterest string `json:"baseInterest"`
BePx string `json:"bePx"`
BizRefId string `json:"bizRefId"`
BizRefType string `json:"bizRefType"`
CTime string `json:"cTime"`
Ccy string `json:"ccy"`
ClSpotInUseAmt string `json:"clSpotInUseAmt"`
CloseOrderAlgo []interface{} `json:"closeOrderAlgo"`
DeltaBS string `json:"deltaBS"`
DeltaPA string `json:"deltaPA"`
Fee string `json:"fee"`
FundingFee string `json:"fundingFee"`
GammaBS string `json:"gammaBS"`
GammaPA string `json:"gammaPA"`
HedgedPos string `json:"hedgedPos"`
IdxPx string `json:"idxPx"`
Imr string `json:"imr"`
InstId string `json:"instId"`
InstType string `json:"instType"`
Interest string `json:"interest"`
Last string `json:"last"`
Lever string `json:"lever"`
Liab string `json:"liab"`
LiabCcy string `json:"liabCcy"`
LiqPenalty string `json:"liqPenalty"`
LiqPx string `json:"liqPx"`
Margin string `json:"margin"`
MarkPx string `json:"markPx"`
MaxSpotInUseAmt string `json:"maxSpotInUseAmt"`
MgnMode MgnMode `json:"mgnMode"`
MgnRatio string `json:"mgnRatio"`
Mmr string `json:"mmr"`
NotionalUsd string `json:"notionalUsd"`
OptVal string `json:"optVal"`
PendingCloseOrdLiabVal string `json:"pendingCloseOrdLiabVal"`
Pnl string `json:"pnl"`
Pos string `json:"pos"`
PosCcy string `json:"posCcy"`
PosId string `json:"posId"`
PosSide PosSide `json:"posSide"`
QuoteBal string `json:"quoteBal"`
QuoteBorrowed string `json:"quoteBorrowed"`
QuoteInterest string `json:"quoteInterest"`
RealizedPnl string `json:"realizedPnl"`
SpotInUseAmt string `json:"spotInUseAmt"`
SpotInUseCcy string `json:"spotInUseCcy"`
ThetaBS string `json:"thetaBS"`
ThetaPA string `json:"thetaPA"`
TradeId string `json:"tradeId"`
UTime string `json:"uTime"`
Upl string `json:"upl"`
UplLastPx string `json:"uplLastPx"`
UplRatio string `json:"uplRatio"`
UplRatioLastPx string `json:"uplRatioLastPx"`
UsdPx string `json:"usdPx"`
VegaBS string `json:"vegaBS"`
VegaPA string `json:"vegaPA"`
NonSettleAvgPx string `json:"nonSettleAvgPx"`
SettledPnl string `json:"settledPnl"`
}
type PositionMode ¶
type PositionMode struct {
PosMode string `json:"posMode"`
}
type SetLeverage ¶
type Signer ¶
type Signer struct {
SecretKey string
}
Signer handles OKX API signature generation.
func (*Signer) SignRequest ¶
func (s *Signer) SignRequest(req *http.Request, method, path, body string, apiKey, passphrase string)
SignRequest adds necessary authentication headers to the request. OKX requires: OK-ACCESS-KEY OK-ACCESS-SIGN OK-ACCESS-TIMESTAMP OK-ACCESS-PASSPHRASE OK-ACCESS-SIMULATED-TRADING (if demo)
type Ticker ¶
type Ticker struct {
InstType string `json:"instType"`
InstId string `json:"instId"`
Last string `json:"last"`
LastSz string `json:"lastSz"`
AskPx string `json:"askPx"`
AskSz string `json:"askSz"`
BidPx string `json:"bidPx"`
BidSz string `json:"bidSz"`
Open24h string `json:"open24h"`
High24h string `json:"high24h"`
Low24h string `json:"low24h"`
VolCcy24h string `json:"volCcy24h"` // base volume, 以币为单位
Vol24h string `json:"vol24h"` // not quote, 张数
Ts string `json:"ts"`
SodUtc0 string `json:"sodUtc0"`
SodUtc8 string `json:"sodUtc8"`
}
type WsClient ¶
type WsClient struct {
Conn *websocket.Conn
WriteMu sync.Mutex
IsPrivate bool
URL string
ApiKey string
SecretKey string
Passphrase string
Subs map[WsSubscribeArgs]func([]byte)
PendingReqs map[int64]*PendingRequest
Dialer *websocket.Dialer
Connected chan bool // for private connection
Logger *zap.SugaredLogger
// contains filtered or unexported fields
}
func NewWsClient ¶
func (*WsClient) AddPendingRequest ¶
AddPendingRequest adds a channel for a specific ID
func (*WsClient) CancelOrderWS ¶
CancelOrderWS cancels an order via WebSocket.
func (*WsClient) CancelOrdersWS ¶
func (c *WsClient) CancelOrdersWS(reqs []CancelOrderRequest) ([]OrderId, error)
CancelOrdersWS cancels a batch of orders via WebSocket.
func (*WsClient) ModifyOrderWS ¶
func (c *WsClient) ModifyOrderWS(req *ModifyOrderRequest) (*OrderId, error)
ModifyOrderWS amends an order via WebSocket.
func (*WsClient) PlaceOrderWS ¶
func (c *WsClient) PlaceOrderWS(req *OrderRequest) (*OrderId, error)
PlaceOrderWS places an order via WebSocket.
func (*WsClient) RemovePendingRequest ¶
RemovePendingRequest removes the channel for a specific ID
func (*WsClient) Subscribe ¶
func (c *WsClient) Subscribe(args WsSubscribeArgs, handler func(data []byte)) error
func (*WsClient) SubscribeOrderBook ¶
SubscribeOrderBook subscribes to books channel. Default depth is 400
func (*WsClient) SubscribeOrders ¶
SubscribeOrders subscribes to orders channel.
func (*WsClient) SubscribePositions ¶
SubscribePositions subscribes to positions channel.
func (*WsClient) SubscribeTicker ¶
SubscribeTicker subscribes to ticker channel.
func (*WsClient) Unsubscribe ¶
func (c *WsClient) Unsubscribe(args WsSubscribeArgs) error
func (*WsClient) WithCredentials ¶
type WsEvent ¶
type WsEvent struct {
Event string `json:"event"`
Code string `json:"code"`
Msg string `json:"msg"`
}
WsEvent represents standard websocket event messages (login, subscribe).
type WsOrderData ¶
type WsOrderData struct {
// Reusing OrderDetails from types.go if possible or defining new
// OKX WS Order push structure is very similar to REST
Order
}
WsOrder push data structure is same as OrderDetails
type WsOrderOp ¶
type WsOrderOp struct {
Id string `json:"id"` // Request ID
Op string `json:"op"` // "order", "batch-orders", "cancel-order", "batch-cancel-orders"
Args []interface{} `json:"args"`
}
WsOrderRequest represents the structure for placing/cancelling orders via WS.
type WsPushData ¶
type WsPushData[T any] struct { Arg map[string]string `json:"arg"` Data []T `json:"data"` Action string `json:"action,omitempty"` // for order updates: snapshot/update? Actually OKX doesn't use action field much for orders but for depth. }
WsPushData generic struct for pushed data.
type WsSubscribeArgs ¶
type WsSubscribeArgs struct {
Channel string `json:"channel"`
InstType string `json:"instType,omitempty"`
InstId string `json:"instId,omitempty"`
}
WsSubscribeReq is used for subscribe requests
type WsSubscribeRes ¶
type WsSubscribeRes struct {
// request/response map by id
ID *string `json:"id,omitempty"`
Event *string `json:"event,omitempty"`
Arg *WsSubscribeArgs `json:"arg,omitempty"`
// if code not nil, throw error
Code *string `json:"code,omitempty"`
Msg *string `json:"msg,omitempty"`
// push data
Data *json.RawMessage `json:"data,omitempty"`
}
WsSubscribeRes is used for subscribe responses