okx

package
v0.2.20 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractSymbol

func ExtractSymbol(symbol string) string

ExtractSymbol extracts base currency from OKX format (e.g., BTC-USDT-SWAP → BTC) Kept for backward compatibility.

func ExtractSymbolWithQuote added in v0.1.2

func ExtractSymbolWithQuote(symbol, quote string) string

ExtractSymbolWithQuote extracts base currency by trimming quote-related suffixes

func FormatSpotSymbolWithQuote added in v0.1.2

func FormatSpotSymbolWithQuote(symbol, quote string) string

FormatSpotSymbolWithQuote converts base currency for OKX spot (e.g., BTC + USDC → BTC-USDC)

func FormatSymbol

func FormatSymbol(symbol string) string

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

func FormatSymbolWithQuote(symbol, quote, instType string) string

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

func NewAdapter(ctx context.Context, opts Options) (*Adapter, error)

NewAdapter creates a new OKX adapter

func (*Adapter) CancelAllOrders

func (a *Adapter) CancelAllOrders(ctx context.Context, symbol string) error

func (*Adapter) CancelOrder

func (a *Adapter) CancelOrder(ctx context.Context, orderID, symbol string) error

func (*Adapter) CancelOrderWS added in v0.2.9

func (a *Adapter) CancelOrderWS(ctx context.Context, orderID, symbol string) error

func (*Adapter) Close

func (a *Adapter) Close() error

func (*Adapter) ExtractSymbol

func (a *Adapter) ExtractSymbol(instId string) string

func (*Adapter) FetchAccount

func (a *Adapter) FetchAccount(ctx context.Context) (*exchanges.Account, error)

func (*Adapter) FetchAllFundingRates

func (a *Adapter) FetchAllFundingRates(ctx context.Context) ([]exchanges.FundingRate, error)

GetAllFundingRates retrieves funding rates for all perpetual symbols

func (*Adapter) FetchBalance

func (a *Adapter) FetchBalance(ctx context.Context) (decimal.Decimal, error)

func (*Adapter) FetchFeeRate

func (a *Adapter) FetchFeeRate(ctx context.Context, symbol string) (*exchanges.FeeRate, error)

func (*Adapter) FetchFundingRate

func (a *Adapter) FetchFundingRate(ctx context.Context, symbol string) (*exchanges.FundingRate, error)

GetFundingRate retrieves funding rate for a symbol

func (*Adapter) FetchFundingRateHistory added in v0.2.19

func (a *Adapter) FetchFundingRateHistory(ctx context.Context, symbol string, opts *exchanges.FundingRateHistoryOpts) ([]exchanges.FundingRate, error)

FetchFundingRateHistory retrieves historical funding rates for a symbol. OKX emits per-period rates; convert to per-hour using the instrument's funding interval (same rule used by FetchFundingRate).

func (*Adapter) FetchHistoricalTrades added in v0.2.19

func (a *Adapter) FetchHistoricalTrades(ctx context.Context, symbol string, opts *exchanges.HistoricalTradeOpts) ([]exchanges.Trade, error)

FetchHistoricalTrades returns paginated historical public trades. Uses OKX's /api/v5/market/history-trades endpoint in tradeId-cursor mode (type=1) when FromID is set; otherwise timestamp-cursor mode (type=2).

func (*Adapter) FetchKlines

func (a *Adapter) FetchKlines(ctx context.Context, symbol string, interval exchanges.Interval, opts *exchanges.KlineOpts) ([]exchanges.Kline, error)

func (*Adapter) FetchOpenInterest added in v0.2.19

func (a *Adapter) FetchOpenInterest(ctx context.Context, symbol string) (*exchanges.OpenInterest, error)

FetchOpenInterest retrieves current open interest for a perp symbol.

func (*Adapter) FetchOpenOrders

func (a *Adapter) FetchOpenOrders(ctx context.Context, symbol string) ([]exchanges.Order, error)

func (*Adapter) FetchOrderBook

func (a *Adapter) FetchOrderBook(ctx context.Context, symbol string, limit int) (*exchanges.OrderBook, error)

func (*Adapter) FetchOrderByID added in v0.2.0

func (a *Adapter) FetchOrderByID(ctx context.Context, orderID, symbol string) (*exchanges.Order, error)

func (*Adapter) FetchOrders added in v0.2.0

func (a *Adapter) FetchOrders(ctx context.Context, symbol string) ([]exchanges.Order, error)

func (*Adapter) FetchPositions

func (a *Adapter) FetchPositions(ctx context.Context) ([]exchanges.Position, error)

func (*Adapter) FetchSymbolDetails

func (a *Adapter) FetchSymbolDetails(ctx context.Context, symbol string) (*exchanges.SymbolDetails, error)

func (*Adapter) FetchTicker

func (a *Adapter) FetchTicker(ctx context.Context, symbol string) (*exchanges.Ticker, error)

func (*Adapter) FetchTrades

func (a *Adapter) FetchTrades(ctx context.Context, symbol string, limit int) ([]exchanges.Trade, error)

func (*Adapter) FormatSymbol

func (a *Adapter) FormatSymbol(symbol string) string

func (*Adapter) GetLocalOrderBook

func (a *Adapter) GetLocalOrderBook(symbol string, depth int) *exchanges.OrderBook

GetLocalOrderBook get local orderbook

func (*Adapter) IsConnected

func (a *Adapter) IsConnected(ctx context.Context) (bool, error)

func (*Adapter) ModifyOrder

func (a *Adapter) ModifyOrder(ctx context.Context, orderID, symbol string, params *exchanges.ModifyOrderParams) (*exchanges.Order, error)

func (*Adapter) ModifyOrderWS added in v0.2.9

func (a *Adapter) ModifyOrderWS(ctx context.Context, orderID, symbol string, params *exchanges.ModifyOrderParams) error

func (*Adapter) PlaceOrder

func (a *Adapter) PlaceOrder(ctx context.Context, params *exchanges.OrderParams) (*exchanges.Order, error)

func (*Adapter) PlaceOrderWS added in v0.2.9

func (a *Adapter) PlaceOrderWS(ctx context.Context, params *exchanges.OrderParams) error

func (*Adapter) RefreshPositionMode

func (a *Adapter) RefreshPositionMode(ctx context.Context) error

func (*Adapter) RefreshSymbolDetails

func (a *Adapter) RefreshSymbolDetails(ctx context.Context) error

func (*Adapter) SetLeverage

func (a *Adapter) SetLeverage(ctx context.Context, symbol string, leverage int) error

func (*Adapter) StopWatchFills added in v0.2.7

func (a *Adapter) StopWatchFills(ctx context.Context) error

func (*Adapter) StopWatchKlines

func (a *Adapter) StopWatchKlines(ctx context.Context, symbol string, interval exchanges.Interval) error

func (*Adapter) StopWatchOrderBook

func (a *Adapter) StopWatchOrderBook(ctx context.Context, symbol string) error

func (*Adapter) StopWatchOrders

func (a *Adapter) StopWatchOrders(ctx context.Context) error

func (*Adapter) StopWatchPositions

func (a *Adapter) StopWatchPositions(ctx context.Context) error

func (*Adapter) StopWatchTicker

func (a *Adapter) StopWatchTicker(ctx context.Context, symbol string) error

func (*Adapter) StopWatchTrades

func (a *Adapter) StopWatchTrades(ctx context.Context, symbol string) error

func (*Adapter) WaitOrderBookReady

func (a *Adapter) WaitOrderBookReady(ctx context.Context, symbol string) error

WaitOrderBookReady waits for orderbook to be ready

func (*Adapter) WatchFills added in v0.2.7

func (a *Adapter) WatchFills(ctx context.Context, callback exchanges.FillCallback) error

func (*Adapter) WatchKlines

func (a *Adapter) WatchKlines(ctx context.Context, symbol string, interval exchanges.Interval, callback exchanges.KlineCallback) error

func (*Adapter) WatchOrderBook

func (a *Adapter) WatchOrderBook(ctx context.Context, symbol string, depth int, cb exchanges.OrderBookCallback) error

func (*Adapter) WatchOrders

func (a *Adapter) WatchOrders(ctx context.Context, callback exchanges.OrderUpdateCallback) error

func (*Adapter) WatchPositions

func (a *Adapter) WatchPositions(ctx context.Context, callback exchanges.PositionUpdateCallback) error

func (*Adapter) WatchTicker

func (a *Adapter) WatchTicker(ctx context.Context, symbol string, callback exchanges.TickerCallback) error

func (*Adapter) WatchTrades

func (a *Adapter) WatchTrades(ctx context.Context, symbol string, callback exchanges.TradeCallback) error

func (*Adapter) WsAccountConnected

func (a *Adapter) WsAccountConnected(ctx context.Context) error

func (*Adapter) WsMarketConnected

func (a *Adapter) WsMarketConnected(ctx context.Context) error

func (*Adapter) WsOrderConnected

func (a *Adapter) WsOrderConnected(ctx context.Context) error

type OptionAdapter added in v0.2.20

type OptionAdapter struct {
	*exchanges.BaseAdapter
	// contains filtered or unexported fields
}

func NewOptionAdapter added in v0.2.20

func NewOptionAdapter(ctx context.Context, opts Options) (*OptionAdapter, error)

func (*OptionAdapter) CancelAllOrders added in v0.2.20

func (a *OptionAdapter) CancelAllOrders(ctx context.Context, symbol string) error

func (*OptionAdapter) CancelOrder added in v0.2.20

func (a *OptionAdapter) CancelOrder(ctx context.Context, orderID, symbol string) error

func (*OptionAdapter) CancelOrderWS added in v0.2.20

func (a *OptionAdapter) CancelOrderWS(context.Context, string, string) error

func (*OptionAdapter) Close added in v0.2.20

func (a *OptionAdapter) Close() error

func (*OptionAdapter) ExtractSymbol added in v0.2.20

func (a *OptionAdapter) ExtractSymbol(symbol string) string

func (*OptionAdapter) FetchAccount added in v0.2.20

func (a *OptionAdapter) FetchAccount(ctx context.Context) (*exchanges.Account, error)

func (*OptionAdapter) FetchBalance added in v0.2.20

func (a *OptionAdapter) FetchBalance(ctx context.Context) (decimal.Decimal, error)

func (*OptionAdapter) FetchFeeRate added in v0.2.20

func (a *OptionAdapter) FetchFeeRate(ctx context.Context, symbol string) (*exchanges.FeeRate, error)

func (*OptionAdapter) FetchKlines added in v0.2.20

func (a *OptionAdapter) FetchKlines(ctx context.Context, symbol string, interval exchanges.Interval, opts *exchanges.KlineOpts) ([]exchanges.Kline, error)

func (*OptionAdapter) FetchOpenOrders added in v0.2.20

func (a *OptionAdapter) FetchOpenOrders(ctx context.Context, symbol string) ([]exchanges.Order, error)

func (*OptionAdapter) FetchOptionContract added in v0.2.20

func (a *OptionAdapter) FetchOptionContract(ctx context.Context, contractSymbol string) (*exchanges.OptionContract, error)

func (*OptionAdapter) FetchOrderBook added in v0.2.20

func (a *OptionAdapter) FetchOrderBook(ctx context.Context, symbol string, limit int) (*exchanges.OrderBook, error)

func (*OptionAdapter) FetchOrderByID added in v0.2.20

func (a *OptionAdapter) FetchOrderByID(ctx context.Context, orderID, symbol string) (*exchanges.Order, error)

func (*OptionAdapter) FetchOrders added in v0.2.20

func (a *OptionAdapter) FetchOrders(context.Context, string) ([]exchanges.Order, error)

func (*OptionAdapter) FetchSymbolDetails added in v0.2.20

func (a *OptionAdapter) FetchSymbolDetails(ctx context.Context, symbol string) (*exchanges.SymbolDetails, error)

func (*OptionAdapter) FetchTicker added in v0.2.20

func (a *OptionAdapter) FetchTicker(ctx context.Context, symbol string) (*exchanges.Ticker, error)

func (*OptionAdapter) FetchTrades added in v0.2.20

func (a *OptionAdapter) FetchTrades(ctx context.Context, symbol string, limit int) ([]exchanges.Trade, error)

func (*OptionAdapter) FormatSymbol added in v0.2.20

func (a *OptionAdapter) FormatSymbol(symbol string) string

func (*OptionAdapter) ListOptionContracts added in v0.2.20

func (a *OptionAdapter) ListOptionContracts(ctx context.Context, underlying string) ([]exchanges.OptionContract, error)

func (*OptionAdapter) PlaceOrder added in v0.2.20

func (a *OptionAdapter) PlaceOrder(ctx context.Context, params *exchanges.OrderParams) (*exchanges.Order, error)

func (*OptionAdapter) PlaceOrderWS added in v0.2.20

func (*OptionAdapter) StopWatchFills added in v0.2.20

func (a *OptionAdapter) StopWatchFills(context.Context) error

func (*OptionAdapter) StopWatchKlines added in v0.2.20

func (a *OptionAdapter) StopWatchKlines(context.Context, string, exchanges.Interval) error

func (*OptionAdapter) StopWatchOrderBook added in v0.2.20

func (a *OptionAdapter) StopWatchOrderBook(context.Context, string) error

func (*OptionAdapter) StopWatchOrders added in v0.2.20

func (a *OptionAdapter) StopWatchOrders(context.Context) error

func (*OptionAdapter) StopWatchPositions added in v0.2.20

func (a *OptionAdapter) StopWatchPositions(context.Context) error

func (*OptionAdapter) StopWatchTicker added in v0.2.20

func (a *OptionAdapter) StopWatchTicker(context.Context, string) error

func (*OptionAdapter) StopWatchTrades added in v0.2.20

func (a *OptionAdapter) StopWatchTrades(context.Context, string) error

func (*OptionAdapter) WatchFills added in v0.2.20

func (*OptionAdapter) WatchKlines added in v0.2.20

func (*OptionAdapter) WatchOrderBook added in v0.2.20

func (*OptionAdapter) WatchOrders added in v0.2.20

func (*OptionAdapter) WatchPositions added in v0.2.20

func (*OptionAdapter) WatchTicker added in v0.2.20

func (*OptionAdapter) WatchTrades added in v0.2.20

type Options

type Options struct {
	APIKey         string
	SecretKey      string
	Passphrase     string
	QuoteCurrency  exchanges.QuoteCurrency // "USDT" (default for CEX) or "USDC"
	OptionFamilies []string
	Logger         exchanges.Logger
}

Options configures an OKX adapter.

type OrderBook

type OrderBook struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewOrderBook

func NewOrderBook(symbol string, ctVal decimal.Decimal) *OrderBook

func (*OrderBook) GetBestAsk

func (ob *OrderBook) GetBestAsk() (decimal.Decimal, decimal.Decimal)

GetBestAsk gets the best ask (Price, Quantity). Returns 0,0 if no asks.

func (*OrderBook) GetBestBid

func (ob *OrderBook) GetBestBid() (decimal.Decimal, decimal.Decimal)

GetBestBid gets the best bid (Price, Quantity). Returns 0,0 if no bids.

func (*OrderBook) GetDepth

func (ob *OrderBook) GetDepth(limit int) ([]exchanges.Level, []exchanges.Level)

func (*OrderBook) IsInitialized

func (ob *OrderBook) IsInitialized() bool

IsInitialized returns whether the orderbook has received its first snapshot

func (*OrderBook) ProcessUpdate

func (ob *OrderBook) ProcessUpdate(data *okx.OrderBook, action string)

func (*OrderBook) Timestamp

func (ob *OrderBook) Timestamp() int64

Timestamp satisfies the LocalOrderBook interface

func (*OrderBook) ToAdapterOrderBook

func (ob *OrderBook) ToAdapterOrderBook(depth int) *exchanges.OrderBook

func (*OrderBook) WaitReady

func (ob *OrderBook) WaitReady(ctx context.Context, timeout time.Duration) bool

WaitReady 等待 OrderBook 初始化完成

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) CancelOrderWS added in v0.2.9

func (a *SpotAdapter) CancelOrderWS(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 (a *SpotAdapter) FetchAccount(ctx context.Context) (*exchanges.Account, error)

func (*SpotAdapter) FetchBalance

func (a *SpotAdapter) FetchBalance(ctx context.Context) (decimal.Decimal, error)

func (*SpotAdapter) FetchFeeRate

func (a *SpotAdapter) FetchFeeRate(ctx context.Context, symbol string) (*exchanges.FeeRate, error)

func (*SpotAdapter) FetchKlines

func (a *SpotAdapter) FetchKlines(ctx context.Context, symbol string, interval exchanges.Interval, opts *exchanges.KlineOpts) ([]exchanges.Kline, error)

func (*SpotAdapter) FetchOpenOrders

func (a *SpotAdapter) FetchOpenOrders(ctx context.Context, symbol string) ([]exchanges.Order, error)

func (*SpotAdapter) FetchOrderBook

func (a *SpotAdapter) FetchOrderBook(ctx context.Context, symbol string, limit int) (*exchanges.OrderBook, error)

func (*SpotAdapter) FetchOrderByID added in v0.2.0

func (a *SpotAdapter) FetchOrderByID(ctx context.Context, orderID, symbol string) (*exchanges.Order, error)

func (*SpotAdapter) FetchOrders added in v0.2.0

func (a *SpotAdapter) FetchOrders(ctx context.Context, symbol string) ([]exchanges.Order, error)

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 (a *SpotAdapter) FetchTicker(ctx context.Context, symbol string) (*exchanges.Ticker, error)

func (*SpotAdapter) FetchTrades

func (a *SpotAdapter) FetchTrades(ctx context.Context, symbol string, limit int) ([]exchanges.Trade, error)

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) ModifyOrderWS added in v0.2.9

func (a *SpotAdapter) ModifyOrderWS(ctx context.Context, orderID, symbol string, params *exchanges.ModifyOrderParams) error

func (*SpotAdapter) PlaceOrder

func (a *SpotAdapter) PlaceOrder(ctx context.Context, params *exchanges.OrderParams) (*exchanges.Order, error)

func (*SpotAdapter) PlaceOrderWS added in v0.2.9

func (a *SpotAdapter) PlaceOrderWS(ctx context.Context, params *exchanges.OrderParams) error

func (*SpotAdapter) RefreshSymbolDetails

func (a *SpotAdapter) RefreshSymbolDetails(ctx context.Context) error

func (*SpotAdapter) StopWatchFills added in v0.2.7

func (a *SpotAdapter) StopWatchFills(ctx context.Context) error

func (*SpotAdapter) StopWatchKlines

func (a *SpotAdapter) StopWatchKlines(ctx context.Context, symbol string, interval exchanges.Interval) error

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) WatchFills added in v0.2.7

func (a *SpotAdapter) WatchFills(ctx context.Context, callback exchanges.FillCallback) error

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, depth int, 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL