Documentation
¶
Index ¶
- func ExtractSymbol(symbol string) string
- func ExtractSymbolWithQuote(symbol, quote string) string
- func FormatSpotSymbolWithQuote(symbol, quote string) string
- func FormatSymbol(symbol string) string
- func FormatSymbolWithQuote(symbol, quote, instType string) string
- type Adapter
- func (a *Adapter) CancelAllOrders(ctx context.Context, symbol string) error
- func (a *Adapter) CancelOrder(ctx context.Context, orderID, symbol string) error
- func (a *Adapter) Close() error
- func (a *Adapter) ExtractSymbol(instId string) string
- func (a *Adapter) FetchAccount(ctx context.Context) (*exchanges.Account, error)
- func (a *Adapter) FetchAllFundingRates(ctx context.Context) ([]exchanges.FundingRate, error)
- func (a *Adapter) FetchBalance(ctx context.Context) (decimal.Decimal, error)
- func (a *Adapter) FetchFeeRate(ctx context.Context, symbol string) (*exchanges.FeeRate, error)
- func (a *Adapter) FetchFundingRate(ctx context.Context, symbol string) (*exchanges.FundingRate, error)
- func (a *Adapter) FetchKlines(ctx context.Context, symbol string, interval exchanges.Interval, ...) ([]exchanges.Kline, error)
- func (a *Adapter) FetchOpenOrders(ctx context.Context, symbol string) ([]exchanges.Order, error)
- func (a *Adapter) FetchOrder(ctx context.Context, orderID, symbol string) (*exchanges.Order, error)
- func (a *Adapter) FetchOrderBook(ctx context.Context, symbol string, limit int) (*exchanges.OrderBook, error)
- func (a *Adapter) FetchPositions(ctx context.Context) ([]exchanges.Position, error)
- func (a *Adapter) FetchSymbolDetails(ctx context.Context, symbol string) (*exchanges.SymbolDetails, error)
- func (a *Adapter) FetchTicker(ctx context.Context, symbol string) (*exchanges.Ticker, error)
- func (a *Adapter) FetchTrades(ctx context.Context, symbol string, limit int) ([]exchanges.Trade, error)
- func (a *Adapter) FormatSymbol(symbol string) string
- func (a *Adapter) GetLocalOrderBook(symbol string, depth int) *exchanges.OrderBook
- func (a *Adapter) IsConnected(ctx context.Context) (bool, error)
- func (a *Adapter) ModifyOrder(ctx context.Context, orderID, symbol string, ...) (*exchanges.Order, error)
- func (a *Adapter) PlaceOrder(ctx context.Context, params *exchanges.OrderParams) (*exchanges.Order, error)
- func (a *Adapter) RefreshPositionMode(ctx context.Context) error
- func (a *Adapter) RefreshSymbolDetails(ctx context.Context) error
- func (a *Adapter) SetLeverage(ctx context.Context, symbol string, leverage int) error
- func (a *Adapter) StopWatchKlines(ctx context.Context, symbol string, interval exchanges.Interval) error
- func (a *Adapter) StopWatchOrderBook(ctx context.Context, symbol string) error
- func (a *Adapter) StopWatchOrders(ctx context.Context) error
- func (a *Adapter) StopWatchPositions(ctx context.Context) error
- func (a *Adapter) StopWatchTicker(ctx context.Context, symbol string) error
- func (a *Adapter) StopWatchTrades(ctx context.Context, symbol string) error
- func (a *Adapter) WaitOrderBookReady(ctx context.Context, symbol string) error
- func (a *Adapter) WatchKlines(ctx context.Context, symbol string, interval exchanges.Interval, ...) error
- func (a *Adapter) WatchOrderBook(ctx context.Context, symbol string, cb exchanges.OrderBookCallback) error
- func (a *Adapter) WatchOrders(ctx context.Context, callback exchanges.OrderUpdateCallback) error
- func (a *Adapter) WatchPositions(ctx context.Context, callback exchanges.PositionUpdateCallback) error
- func (a *Adapter) WatchTicker(ctx context.Context, symbol string, callback exchanges.TickerCallback) error
- func (a *Adapter) WatchTrades(ctx context.Context, symbol string, callback exchanges.TradeCallback) error
- func (a *Adapter) WsAccountConnected(ctx context.Context) error
- func (a *Adapter) WsMarketConnected(ctx context.Context) error
- func (a *Adapter) WsOrderConnected(ctx context.Context) error
- type Options
- type OrderBook
- func (ob *OrderBook) GetBestAsk() (decimal.Decimal, decimal.Decimal)
- func (ob *OrderBook) GetBestBid() (decimal.Decimal, decimal.Decimal)
- func (ob *OrderBook) GetDepth(limit int) ([]exchanges.Level, []exchanges.Level)
- func (ob *OrderBook) IsInitialized() bool
- func (ob *OrderBook) ProcessUpdate(data *okx.OrderBook, action string)
- func (ob *OrderBook) Timestamp() int64
- func (ob *OrderBook) ToAdapterOrderBook(depth int) *exchanges.OrderBook
- func (ob *OrderBook) WaitReady(ctx context.Context, timeout time.Duration) bool
- type SpotAdapter
- func (a *SpotAdapter) CancelAllOrders(ctx context.Context, symbol string) error
- func (a *SpotAdapter) CancelOrder(ctx context.Context, orderID, symbol string) error
- func (a *SpotAdapter) Close() error
- func (a *SpotAdapter) ExtractSymbol(instId string) string
- func (a *SpotAdapter) FetchAccount(ctx context.Context) (*exchanges.Account, error)
- func (a *SpotAdapter) FetchBalance(ctx context.Context) (decimal.Decimal, error)
- func (a *SpotAdapter) FetchFeeRate(ctx context.Context, symbol string) (*exchanges.FeeRate, error)
- func (a *SpotAdapter) FetchKlines(ctx context.Context, symbol string, interval exchanges.Interval, ...) ([]exchanges.Kline, error)
- func (a *SpotAdapter) FetchOpenOrders(ctx context.Context, symbol string) ([]exchanges.Order, error)
- func (a *SpotAdapter) FetchOrder(ctx context.Context, orderID, symbol string) (*exchanges.Order, error)
- func (a *SpotAdapter) FetchOrderBook(ctx context.Context, symbol string, limit int) (*exchanges.OrderBook, error)
- func (a *SpotAdapter) FetchSpotBalances(ctx context.Context) ([]exchanges.SpotBalance, error)
- func (a *SpotAdapter) FetchSymbolDetails(ctx context.Context, symbol string) (*exchanges.SymbolDetails, error)
- func (a *SpotAdapter) FetchTicker(ctx context.Context, symbol string) (*exchanges.Ticker, error)
- func (a *SpotAdapter) FetchTrades(ctx context.Context, symbol string, limit int) ([]exchanges.Trade, error)
- func (a *SpotAdapter) FormatSymbol(symbol string) string
- func (a *SpotAdapter) GetLocalOrderBook(symbol string, depth int) *exchanges.OrderBook
- func (a *SpotAdapter) IsConnected(ctx context.Context) (bool, error)
- func (a *SpotAdapter) ModifyOrder(ctx context.Context, orderID, symbol string, ...) (*exchanges.Order, error)
- func (a *SpotAdapter) PlaceOrder(ctx context.Context, params *exchanges.OrderParams) (*exchanges.Order, error)
- func (a *SpotAdapter) RefreshSymbolDetails(ctx context.Context) error
- func (a *SpotAdapter) StopWatchKlines(ctx context.Context, symbol string, interval exchanges.Interval) error
- func (a *SpotAdapter) StopWatchOrderBook(ctx context.Context, symbol string) error
- func (a *SpotAdapter) StopWatchOrders(ctx context.Context) error
- func (a *SpotAdapter) StopWatchPositions(ctx context.Context) error
- func (a *SpotAdapter) StopWatchTicker(ctx context.Context, symbol string) error
- func (a *SpotAdapter) StopWatchTrades(ctx context.Context, symbol string) error
- func (a *SpotAdapter) TransferAsset(ctx context.Context, params *exchanges.TransferParams) error
- func (a *SpotAdapter) WaitOrderBookReady(ctx context.Context, symbol string) error
- func (a *SpotAdapter) WatchKlines(ctx context.Context, symbol string, interval exchanges.Interval, ...) error
- func (a *SpotAdapter) WatchOrderBook(ctx context.Context, symbol string, callback exchanges.OrderBookCallback) error
- func (a *SpotAdapter) WatchOrders(ctx context.Context, callback exchanges.OrderUpdateCallback) error
- func (a *SpotAdapter) WatchPositions(ctx context.Context, cb exchanges.PositionUpdateCallback) error
- func (a *SpotAdapter) WatchTicker(ctx context.Context, symbol string, callback exchanges.TickerCallback) error
- func (a *SpotAdapter) WatchTrades(ctx context.Context, symbol string, callback exchanges.TradeCallback) error
- func (a *SpotAdapter) WithCredentials(apiKey, secretKey string) exchanges.Exchange
- func (a *SpotAdapter) WsAccountConnected(ctx context.Context) error
- func (a *SpotAdapter) WsMarketConnected(ctx context.Context) error
- func (a *SpotAdapter) WsOrderConnected(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractSymbol ¶
ExtractSymbol extracts base currency from OKX format (e.g., BTC-USDT-SWAP → BTC) Kept for backward compatibility.
func ExtractSymbolWithQuote ¶ added in v0.1.2
ExtractSymbolWithQuote extracts base currency by trimming quote-related suffixes
func FormatSpotSymbolWithQuote ¶ added in v0.1.2
FormatSpotSymbolWithQuote converts base currency for OKX spot (e.g., BTC + USDC → BTC-USDC)
func FormatSymbol ¶
FormatSymbol converts base currency to OKX perp format (e.g., BTC → BTC-USDT-SWAP) Kept for backward compatibility.
func FormatSymbolWithQuote ¶ added in v0.1.2
FormatSymbolWithQuote converts base currency with configurable quote and instType (e.g., BTC + USDC + SWAP → BTC-USDC-SWAP)
Types ¶
type Adapter ¶
type Adapter struct {
*exchanges.BaseAdapter
// contains filtered or unexported fields
}
Adapter OKX 适配器
func NewAdapter ¶
NewAdapter creates a new OKX adapter
func (*Adapter) CancelAllOrders ¶
func (*Adapter) CancelOrder ¶
func (*Adapter) ExtractSymbol ¶
func (*Adapter) FetchAccount ¶
func (*Adapter) FetchAllFundingRates ¶
GetAllFundingRates retrieves funding rates for all perpetual symbols
func (*Adapter) FetchBalance ¶
func (*Adapter) FetchFeeRate ¶
func (*Adapter) FetchFundingRate ¶
func (a *Adapter) FetchFundingRate(ctx context.Context, symbol string) (*exchanges.FundingRate, error)
GetFundingRate retrieves funding rate for a symbol
func (*Adapter) FetchKlines ¶
func (*Adapter) FetchOpenOrders ¶
func (*Adapter) FetchOrder ¶
func (*Adapter) FetchOrderBook ¶
func (*Adapter) FetchPositions ¶
func (*Adapter) FetchSymbolDetails ¶
func (*Adapter) FetchTicker ¶
func (*Adapter) FetchTrades ¶
func (*Adapter) FormatSymbol ¶
func (*Adapter) GetLocalOrderBook ¶
GetLocalOrderBook get local orderbook
func (*Adapter) ModifyOrder ¶
func (*Adapter) PlaceOrder ¶
func (*Adapter) RefreshPositionMode ¶
func (*Adapter) RefreshSymbolDetails ¶
func (*Adapter) SetLeverage ¶
func (*Adapter) StopWatchKlines ¶
func (*Adapter) StopWatchOrderBook ¶
func (*Adapter) StopWatchPositions ¶
func (*Adapter) StopWatchTicker ¶
func (*Adapter) StopWatchTrades ¶
func (*Adapter) WaitOrderBookReady ¶
WaitOrderBookReady waits for orderbook to be ready
func (*Adapter) WatchKlines ¶
func (*Adapter) WatchOrderBook ¶
func (*Adapter) WatchOrders ¶
func (*Adapter) WatchPositions ¶
func (*Adapter) WatchTicker ¶
func (*Adapter) WatchTrades ¶
func (*Adapter) WsAccountConnected ¶
type Options ¶
type Options struct {
APIKey string
SecretKey string
Passphrase string
QuoteCurrency exchanges.QuoteCurrency // "USDT" (default for CEX) or "USDC"
Logger exchanges.Logger
}
Options configures an OKX adapter.
type OrderBook ¶
func (*OrderBook) GetBestAsk ¶
GetBestAsk gets the best ask (Price, Quantity). Returns 0,0 if no asks.
func (*OrderBook) GetBestBid ¶
GetBestBid gets the best bid (Price, Quantity). Returns 0,0 if no bids.
func (*OrderBook) IsInitialized ¶
IsInitialized returns whether the orderbook has received its first snapshot
func (*OrderBook) ProcessUpdate ¶
func (*OrderBook) ToAdapterOrderBook ¶
type SpotAdapter ¶
type SpotAdapter struct {
*exchanges.BaseAdapter
// contains filtered or unexported fields
}
SpotAdapter OKX 现货适配器
func NewSpotAdapter ¶
func NewSpotAdapter(ctx context.Context, opts Options) (*SpotAdapter, error)
NewSpotAdapter creates a new OKX spot adapter
func (*SpotAdapter) CancelAllOrders ¶
func (a *SpotAdapter) CancelAllOrders(ctx context.Context, symbol string) error
func (*SpotAdapter) CancelOrder ¶
func (a *SpotAdapter) CancelOrder(ctx context.Context, orderID, symbol string) error
func (*SpotAdapter) Close ¶
func (a *SpotAdapter) Close() error
func (*SpotAdapter) ExtractSymbol ¶
func (a *SpotAdapter) ExtractSymbol(instId string) string
ExtractSymbol converts OKX InstId (e.g., BTC-USDT) to internal symbol (e.g., BTC)
func (*SpotAdapter) FetchAccount ¶
func (*SpotAdapter) FetchBalance ¶
func (*SpotAdapter) FetchFeeRate ¶
func (*SpotAdapter) FetchKlines ¶
func (*SpotAdapter) FetchOpenOrders ¶
func (*SpotAdapter) FetchOrder ¶
func (*SpotAdapter) FetchOrderBook ¶
func (*SpotAdapter) FetchSpotBalances ¶
func (a *SpotAdapter) FetchSpotBalances(ctx context.Context) ([]exchanges.SpotBalance, error)
func (*SpotAdapter) FetchSymbolDetails ¶
func (a *SpotAdapter) FetchSymbolDetails(ctx context.Context, symbol string) (*exchanges.SymbolDetails, error)
func (*SpotAdapter) FetchTicker ¶
func (*SpotAdapter) FetchTrades ¶
func (*SpotAdapter) FormatSymbol ¶
func (a *SpotAdapter) FormatSymbol(symbol string) string
FormatSymbol converts internal symbol (e.g., BTC) to OKX spot InstId (e.g., BTC-USDT)
func (*SpotAdapter) GetLocalOrderBook ¶
func (a *SpotAdapter) GetLocalOrderBook(symbol string, depth int) *exchanges.OrderBook
GetLocalOrderBook retrieves locally maintained order book
func (*SpotAdapter) IsConnected ¶
func (a *SpotAdapter) IsConnected(ctx context.Context) (bool, error)
func (*SpotAdapter) ModifyOrder ¶
func (a *SpotAdapter) ModifyOrder(ctx context.Context, orderID, symbol string, params *exchanges.ModifyOrderParams) (*exchanges.Order, error)
func (*SpotAdapter) PlaceOrder ¶
func (a *SpotAdapter) PlaceOrder(ctx context.Context, params *exchanges.OrderParams) (*exchanges.Order, error)
func (*SpotAdapter) RefreshSymbolDetails ¶
func (a *SpotAdapter) RefreshSymbolDetails(ctx context.Context) error
func (*SpotAdapter) StopWatchKlines ¶
func (*SpotAdapter) StopWatchOrderBook ¶
func (a *SpotAdapter) StopWatchOrderBook(ctx context.Context, symbol string) error
func (*SpotAdapter) StopWatchOrders ¶
func (a *SpotAdapter) StopWatchOrders(ctx context.Context) error
Unsubscribe methods
func (*SpotAdapter) StopWatchPositions ¶
func (a *SpotAdapter) StopWatchPositions(ctx context.Context) error
func (*SpotAdapter) StopWatchTicker ¶
func (a *SpotAdapter) StopWatchTicker(ctx context.Context, symbol string) error
func (*SpotAdapter) StopWatchTrades ¶
func (a *SpotAdapter) StopWatchTrades(ctx context.Context, symbol string) error
func (*SpotAdapter) TransferAsset ¶
func (a *SpotAdapter) TransferAsset(ctx context.Context, params *exchanges.TransferParams) error
func (*SpotAdapter) WaitOrderBookReady ¶
func (a *SpotAdapter) WaitOrderBookReady(ctx context.Context, symbol string) error
WaitOrderBookReady waits for orderbook to be ready
func (*SpotAdapter) WatchKlines ¶
func (a *SpotAdapter) WatchKlines(ctx context.Context, symbol string, interval exchanges.Interval, callback exchanges.KlineCallback) error
func (*SpotAdapter) WatchOrderBook ¶
func (a *SpotAdapter) WatchOrderBook(ctx context.Context, symbol string, callback exchanges.OrderBookCallback) error
func (*SpotAdapter) WatchOrders ¶
func (a *SpotAdapter) WatchOrders(ctx context.Context, callback exchanges.OrderUpdateCallback) error
func (*SpotAdapter) WatchPositions ¶
func (a *SpotAdapter) WatchPositions(ctx context.Context, cb exchanges.PositionUpdateCallback) error
func (*SpotAdapter) WatchTicker ¶
func (a *SpotAdapter) WatchTicker(ctx context.Context, symbol string, callback exchanges.TickerCallback) error
func (*SpotAdapter) WatchTrades ¶
func (a *SpotAdapter) WatchTrades(ctx context.Context, symbol string, callback exchanges.TradeCallback) error
func (*SpotAdapter) WithCredentials ¶
func (a *SpotAdapter) WithCredentials(apiKey, secretKey string) exchanges.Exchange
func (*SpotAdapter) WsAccountConnected ¶
func (a *SpotAdapter) WsAccountConnected(ctx context.Context) error
func (*SpotAdapter) WsMarketConnected ¶
func (a *SpotAdapter) WsMarketConnected(ctx context.Context) error
func (*SpotAdapter) WsOrderConnected ¶
func (a *SpotAdapter) WsOrderConnected(ctx context.Context) error