Documentation
¶
Index ¶
- Constants
- func NewExchange(options map[string]interface{}) (banexg.BanExchange, *errs.Error)
- type Balance
- type BalanceDetail
- type Bill
- type FundingRate
- type FundingRateHistory
- type Instrument
- type LeverageInfo
- type OKX
- func (e *OKX) CalcMaintMargin(symbol string, cost float64) (float64, *errs.Error)
- func (e *OKX) CancelOrder(id string, symbol string, params map[string]interface{}) (*banexg.Order, *errs.Error)
- func (e *OKX) CreateOrder(symbol, odType, side string, amount, price float64, ...) (*banexg.Order, *errs.Error)
- func (e *OKX) EditOrder(symbol, orderId, side string, amount, price float64, ...) (*banexg.Order, *errs.Error)
- func (e *OKX) FetchAccountAccess(params map[string]interface{}) (*banexg.AccountAccess, *errs.Error)
- func (e *OKX) FetchAccountPositions(symbols []string, params map[string]interface{}) ([]*banexg.Position, *errs.Error)
- func (e *OKX) FetchBalance(params map[string]interface{}) (*banexg.Balances, *errs.Error)
- func (e *OKX) FetchFundingRate(symbol string, params map[string]interface{}) (*banexg.FundingRateCur, *errs.Error)
- func (e *OKX) FetchFundingRateHistory(symbol string, since int64, limit int, params map[string]interface{}) ([]*banexg.FundingRate, *errs.Error)
- func (e *OKX) FetchFundingRates(symbols []string, params map[string]interface{}) ([]*banexg.FundingRateCur, *errs.Error)
- func (e *OKX) FetchIncomeHistory(inType string, symbol string, since int64, limit int, ...) ([]*banexg.Income, *errs.Error)
- func (e *OKX) FetchLastPrices(symbols []string, params map[string]interface{}) ([]*banexg.LastPrice, *errs.Error)
- func (e *OKX) FetchOHLCV(symbol, timeframe string, since int64, limit int, ...) ([]*banexg.Kline, *errs.Error)
- func (e *OKX) FetchOpenOrders(symbol string, since int64, limit int, params map[string]interface{}) ([]*banexg.Order, *errs.Error)
- func (e *OKX) FetchOrder(symbol, id string, params map[string]interface{}) (*banexg.Order, *errs.Error)
- func (e *OKX) FetchOrderBook(symbol string, limit int, params map[string]interface{}) (*banexg.OrderBook, *errs.Error)
- func (e *OKX) FetchOrders(symbol string, since int64, limit int, params map[string]interface{}) ([]*banexg.Order, *errs.Error)
- func (e *OKX) FetchPositions(symbols []string, params map[string]interface{}) ([]*banexg.Position, *errs.Error)
- func (e *OKX) FetchTicker(symbol string, params map[string]interface{}) (*banexg.Ticker, *errs.Error)
- func (e *OKX) FetchTickerPrice(symbol string, params map[string]interface{}) (map[string]float64, *errs.Error)
- func (e *OKX) FetchTickers(symbols []string, params map[string]interface{}) ([]*banexg.Ticker, *errs.Error)
- func (e *OKX) GetLeverage(symbol string, notional float64, account string) (float64, float64)
- func (e *OKX) Init() *errs.Error
- func (e *OKX) LoadLeverageBrackets(reload bool, params map[string]interface{}) *errs.Error
- func (e *OKX) SetLeverage(leverage float64, symbol string, params map[string]interface{}) (map[string]interface{}, *errs.Error)
- func (e *OKX) UnWatchMarkPrices(symbols []string, params map[string]interface{}) *errs.Error
- func (e *OKX) UnWatchOHLCVs(jobs [][2]string, params map[string]interface{}) *errs.Error
- func (e *OKX) UnWatchOrderBooks(symbols []string, params map[string]interface{}) *errs.Error
- func (e *OKX) UnWatchTrades(symbols []string, params map[string]interface{}) *errs.Error
- func (e *OKX) WatchAccountConfig(params map[string]interface{}) (chan *banexg.AccountConfig, *errs.Error)
- func (e *OKX) WatchBalance(params map[string]interface{}) (chan *banexg.Balances, *errs.Error)
- func (e *OKX) WatchMarkPrices(symbols []string, params map[string]interface{}) (chan map[string]float64, *errs.Error)
- func (e *OKX) WatchMyTrades(params map[string]interface{}) (chan *banexg.MyTrade, *errs.Error)
- func (e *OKX) WatchOHLCVs(jobs [][2]string, params map[string]interface{}) (chan *banexg.PairTFKline, *errs.Error)
- func (e *OKX) WatchOrderBooks(symbols []string, limit int, params map[string]interface{}) (chan *banexg.OrderBook, *errs.Error)
- func (e *OKX) WatchPositions(params map[string]interface{}) (chan []*banexg.Position, *errs.Error)
- func (e *OKX) WatchTrades(symbols []string, params map[string]interface{}) (chan *banexg.Trade, *errs.Error)
- type Order
- type OrderBook
- type OrderResult
- type Position
- type PositionTier
- type Ticker
- type WsAlgoOrder
- type WsOrder
- type WsPendingRecon
Constants ¶
const ( HostPublic = "public" HostPrivate = "private" HostWsPublic = "ws_public" HostWsPrivate = "ws_private" HostWsBusiness = "ws_business" )
const ( FldInstType = "instType" FldInstId = "instId" FldInstFamily = "instFamily" FldUly = "uly" FldMgnMode = "mgnMode" FldTdMode = "tdMode" FldPosSide = "posSide" FldOrdType = "ordType" FldSide = "side" FldSz = "sz" FldPx = "px" FldOrdId = "ordId" FldClOrdId = "clOrdId" FldCcy = "ccy" FldLever = "lever" FldBar = "bar" FldLimit = "limit" FldAfter = "after" FldBefore = "before" FldBegin = "begin" FldEnd = "end" FldType = "type" FldChannel = "channel" FldTgtCcy = "tgtCcy" FldNewSz = "newSz" FldNewPx = "newPx" FldReduceOnly = "reduceOnly" FldCloseFraction = "closeFraction" FldTag = "tag" FldBanAmend = "banAmend" FldPxAmendType = "pxAmendType" FldStpMode = "stpMode" FldAlgoId = "algoId" FldAlgoClOrdId = "algoClOrdId" FldTpTriggerPx = "tpTriggerPx" FldTpOrdPx = "tpOrdPx" FldSlTriggerPx = "slTriggerPx" FldSlOrdPx = "slOrdPx" FldTpTriggerPxType = "tpTriggerPxType" FldSlTriggerPxType = "slTriggerPxType" FldTriggerPx = "triggerPx" FldOrderPx = "orderPx" FldOrdPx = "ordPx" FldCallbackRatio = "callbackRatio" FldCallbackSpread = "callbackSpread" FldActivePx = "activePx" FldSzLimit = "szLimit" FldPxLimit = "pxLimit" FldTimeInterval = "timeInterval" FldTradeQuoteCcy = "tradeQuoteCcy" )
OKX API field keys
const ( WsChanTrades = "trades" WsChanBooks = "books" WsChanBooks5 = "books5" WsChanBalancePosition = "balance_and_position" WsChanPositions = "positions" WsChanOrders = "orders" WsChanOrdersAlgo = "orders-algo" // Algo orders channel (trigger/conditional/oco/twap/move_order_stop) WsChanMarkPrice = "mark-price" WsChanCandlePrefix = "candle" )
OKX WebSocket channel names
const ( InstTypeSpot = "SPOT" InstTypeMargin = "MARGIN" InstTypeSwap = "SWAP" InstTypeFutures = "FUTURES" InstTypeOption = "OPTION" )
OKX instType values
const ( TgtCcyQuote = "quote_ccy" InstIdAny = "ANY" )
OKX special values
const ( MethodPublicGetInstruments = "publicGetInstruments" MethodMarketGetTicker = "marketGetTicker" MethodMarketGetTickers = "marketGetTickers" MethodMarketGetBooks = "marketGetBooks" MethodMarketGetBooksFull = "marketGetBooksFull" MethodMarketGetCandles = "marketGetCandles" MethodMarketGetHistoryCandles = "marketGetHistoryCandles" MethodPublicGetFundingRate = "publicGetFundingRate" MethodPublicGetFundingRateHistory = "publicGetFundingRateHistory" MethodPublicGetPositionTiers = "publicGetPositionTiers" MethodAccountGetBalance = "accountGetBalance" MethodAccountGetConfig = "accountGetConfig" MethodAccountGetBills = "accountGetBills" MethodAccountGetBillsArchive = "accountGetBillsArchive" MethodAccountGetPositions = "accountGetPositions" MethodAccountGetLeverageInfo = "accountGetLeverageInfo" MethodAccountGetPositionTiers = "accountGetPositionTiers" MethodAccountSetLeverage = "accountSetLeverage" MethodTradePostOrder = "tradePostOrder" MethodTradePostCancelOrder = "tradePostCancelOrder" MethodTradePostAmendOrder = "tradePostAmendOrder" MethodTradeGetOrder = "tradeGetOrder" MethodTradeGetOrdersPending = "tradeGetOrdersPending" MethodTradeGetOrdersHistory = "tradeGetOrdersHistory" MethodTradeGetOrdersHistoryArchive = "tradeGetOrdersHistoryArchive" MethodTradePostOrderAlgo = "tradePostOrderAlgo" MethodTradePostCancelAlgos = "tradePostCancelAlgos" MethodTradePostAmendAlgos = "tradePostAmendAlgos" MethodTradeGetOrderAlgo = "tradeGetOrderAlgo" MethodTradeGetOrdersAlgoPending = "tradeGetOrdersAlgoPending" MethodTradeGetOrdersAlgoHistory = "tradeGetOrdersAlgoHistory" )
const (
TdModeCash = "cash"
)
OKX tdMode values
Variables ¶
This section is empty.
Functions ¶
func NewExchange ¶
func NewExchange(options map[string]interface{}) (banexg.BanExchange, *errs.Error)
Types ¶
type Balance ¶
type Balance struct {
UTime string `json:"uTime"`
TotalEq string `json:"totalEq"`
Details []BalanceDetail `json:"details"`
}
Balance describes /account/balance response item.
type BalanceDetail ¶
type Bill ¶
type Bill struct {
InstType string `json:"instType"`
InstId string `json:"instId"`
BillId string `json:"billId"`
Type string `json:"type"`
SubType string `json:"subType"`
Ts string `json:"ts"`
BalChg string `json:"balChg"`
Pnl string `json:"pnl"`
Fee string `json:"fee"`
Ccy string `json:"ccy"`
TradeId string `json:"tradeId"`
Notes string `json:"notes"`
}
Bill describes /account/bills response item.
type FundingRate ¶
type FundingRate struct {
InstType string `json:"instType"`
InstId string `json:"instId"`
FundingRate string `json:"fundingRate"`
FundingTime string `json:"fundingTime"`
NextFundingTime string `json:"nextFundingTime"`
InterestRate string `json:"interestRate"`
Ts string `json:"ts"`
}
FundingRate describes /public/funding-rate response item.
type FundingRateHistory ¶
type FundingRateHistory struct {
InstType string `json:"instType"`
InstId string `json:"instId"`
FundingRate string `json:"fundingRate"`
RealizedRate string `json:"realizedRate"`
FundingTime string `json:"fundingTime"`
FormulaType string `json:"formulaType"`
Method string `json:"method"`
}
FundingRateHistory describes /public/funding-rate-history response item.
type Instrument ¶
type Instrument struct {
InstType string `json:"instType"`
InstId string `json:"instId"`
InstFamily string `json:"instFamily"`
Uly string `json:"uly"`
BaseCcy string `json:"baseCcy"`
QuoteCcy string `json:"quoteCcy"`
SettleCcy string `json:"settleCcy"`
CtVal string `json:"ctVal"`
CtMult string `json:"ctMult"`
CtType string `json:"ctType"`
Lever string `json:"lever"`
TickSz string `json:"tickSz"`
LotSz string `json:"lotSz"`
MinSz string `json:"minSz"`
State string `json:"state"`
ListTime string `json:"listTime"`
ExpTime string `json:"expTime"`
TradeQuoteCcyList []string `json:"tradeQuoteCcyList"`
}
Instrument describes /public/instruments response item.
type LeverageInfo ¶
type LeverageInfo struct {
Ccy string `json:"ccy"`
InstId string `json:"instId"`
MgnMode string `json:"mgnMode"`
PosSide string `json:"posSide"`
Lever string `json:"lever"`
}
LeverageInfo describes /account/leverage-info response item.
type OKX ¶
type OKX struct {
*banexg.Exchange
RecvWindow int
// LeverageBrackets caches leverage tiers by symbol or instFamily.
LeverageBrackets map[string]*banexg.SymbolLvgBrackets
LeverageBracketsLock deadlock.Mutex
// WsAuthDone tracks login completion channels per client key.
// Each channel receives nil on success or an error on failure.
WsAuthDone map[string]chan *errs.Error
// WsAuthed tracks whether each client has successfully logged in.
WsAuthed map[string]bool
// WsPendingRecons stores pending reconnection info to restore subs after login.
WsPendingRecons map[string]*WsPendingRecon
WsAuthLock deadlock.Mutex
// WsMyTradesChanKey stores the channel key for mytrades output.
// Used to ensure algo orders (business endpoint) write to the same channel as regular orders (private endpoint).
WsMyTradesChanKey string
}
func (*OKX) CalcMaintMargin ¶
func (*OKX) CancelOrder ¶
func (*OKX) CreateOrder ¶
func (*OKX) FetchAccountAccess ¶ added in v0.2.47
func (*OKX) FetchAccountPositions ¶
func (*OKX) FetchBalance ¶
func (*OKX) FetchFundingRate ¶
func (*OKX) FetchFundingRateHistory ¶
func (*OKX) FetchFundingRates ¶
func (*OKX) FetchIncomeHistory ¶
func (*OKX) FetchLastPrices ¶
func (*OKX) FetchOHLCV ¶
func (*OKX) FetchOpenOrders ¶
func (*OKX) FetchOrder ¶
func (*OKX) FetchOrderBook ¶
func (*OKX) FetchOrders ¶
func (*OKX) FetchPositions ¶
func (*OKX) FetchTicker ¶
func (*OKX) FetchTickerPrice ¶
func (*OKX) FetchTickers ¶
func (*OKX) GetLeverage ¶
func (*OKX) LoadLeverageBrackets ¶
func (*OKX) SetLeverage ¶
func (*OKX) UnWatchMarkPrices ¶
func (*OKX) UnWatchOHLCVs ¶
func (*OKX) UnWatchOrderBooks ¶
func (*OKX) UnWatchTrades ¶
func (*OKX) WatchAccountConfig ¶
func (*OKX) WatchBalance ¶
func (*OKX) WatchMarkPrices ¶
func (*OKX) WatchMyTrades ¶
func (*OKX) WatchOHLCVs ¶
func (*OKX) WatchOrderBooks ¶
func (*OKX) WatchPositions ¶
type Order ¶
type Order struct {
InstType string `json:"instType"`
InstId string `json:"instId"`
OrdId string `json:"ordId"`
ClOrdId string `json:"clOrdId"`
Px string `json:"px"`
Sz string `json:"sz"`
Side string `json:"side"`
PosSide string `json:"posSide"`
OrdType string `json:"ordType"`
TdMode string `json:"tdMode"`
State string `json:"state"`
AvgPx string `json:"avgPx"`
AccFillSz string `json:"accFillSz"`
Fee string `json:"fee"`
FeeCcy string `json:"feeCcy"`
CTime string `json:"cTime"`
UTime string `json:"uTime"`
}
Order describes /trade/order response item.
type OrderBook ¶
type OrderBook struct {
Asks [][]string `json:"asks"`
Bids [][]string `json:"bids"`
Ts string `json:"ts"`
}
OrderBook describes /market/books response item.
type OrderResult ¶
type OrderResult struct {
OrdId string `json:"ordId"`
ClOrdId string `json:"clOrdId"`
ReqId string `json:"reqId"`
Ts string `json:"ts"`
SCode string `json:"sCode"`
SMsg string `json:"sMsg"`
}
OrderResult describes /trade/order or /trade/cancel-order result item.
type Position ¶
type Position struct {
InstType string `json:"instType"`
InstId string `json:"instId"`
MgnMode string `json:"mgnMode"`
PosId string `json:"posId"`
PosSide string `json:"posSide"`
Pos string `json:"pos"`
AvgPx string `json:"avgPx"`
Upl string `json:"upl"`
Lever string `json:"lever"`
LiqPx string `json:"liqPx"`
MarkPx string `json:"markPx"`
Margin string `json:"margin"`
MgnRatio string `json:"mgnRatio"`
Ccy string `json:"ccy"`
CTime string `json:"cTime"`
UTime string `json:"uTime"`
}
Position describes /account/positions response item.
type PositionTier ¶
type PositionTier struct {
InstType string `json:"instType"`
InstId string `json:"instId"`
InstFamily string `json:"instFamily"`
Uly string `json:"uly"`
Tier string `json:"tier"`
MinSz string `json:"minSz"`
MaxSz string `json:"maxSz"`
Mmr string `json:"mmr"`
Imr string `json:"imr"`
MaxLever string `json:"maxLever"`
OptMgnFactor string `json:"optMgnFactor"`
BaseMaxLoan string `json:"baseMaxLoan"`
QuoteMaxLoan string `json:"quoteMaxLoan"`
}
PositionTier describes /public/position-tiers response item.
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"`
Vol24h string `json:"vol24h"`
SodUtc0 string `json:"sodUtc0"`
SodUtc8 string `json:"sodUtc8"`
Ts string `json:"ts"`
}
Ticker describes /market/ticker(s) response item.
type WsAlgoOrder ¶ added in v0.2.46
type WsAlgoOrder struct {
InstType string `json:"instType"`
InstId string `json:"instId"`
AlgoId string `json:"algoId"`
AlgoClOrdId string `json:"algoClOrdId"`
ClOrdId string `json:"clOrdId"`
OrdId string `json:"ordId"`
Sz string `json:"sz"`
OrdType string `json:"ordType"`
Side string `json:"side"`
PosSide string `json:"posSide"`
TdMode string `json:"tdMode"`
State string `json:"state"`
Lever string `json:"lever"`
ActualSz string `json:"actualSz"`
ActualPx string `json:"actualPx"`
ActualSide string `json:"actualSide"`
TriggerPx string `json:"triggerPx"`
TriggerTime string `json:"triggerTime"`
OrdPx string `json:"ordPx"`
TpTriggerPx string `json:"tpTriggerPx"`
TpOrdPx string `json:"tpOrdPx"`
SlTriggerPx string `json:"slTriggerPx"`
SlOrdPx string `json:"slOrdPx"`
ReduceOnly string `json:"reduceOnly"`
CTime string `json:"cTime"`
UTime string `json:"uTime"`
}
WsAlgoOrder describes websocket "orders-algo" channel item.
type WsOrder ¶
type WsOrder struct {
Order
FillPx string `json:"fillPx"`
FillSz string `json:"fillSz"`
FillTime string `json:"fillTime"`
TradeId string `json:"tradeId"`
ReduceOnly string `json:"reduceOnly"`
FillFee string `json:"fillFee"`
FillFeeCcy string `json:"fillFeeCcy"`
ExecType string `json:"execType"`
AlgoClOrdId string `json:"algoClOrdId"` // Client-defined algo order ID when algo order triggers
AlgoId string `json:"algoId"` // Algo order ID when algo order triggers
}
WsOrder describes websocket "orders" channel item.