okx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package okx is the library behind the okx command line: the HTTP client, request shaping, and the typed data models for the OKX crypto exchange public market data API.

The Client paces requests, retries transient errors (429 and 5xx), and sets an honest User-Agent. All four operations (ticker, tickers, candles, instruments) read from OKX public endpoints that need no API key.

Index

Constants

View Source
const BaseURL = "https://www.okx.com/api/v5"

BaseURL is the root every API request is built from.

View Source
const DefaultUserAgent = "okx-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to OKX.

View Source
const Host = "www.okx.com"

Host is the OKX hostname this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candle

type Candle struct {
	Timestamp string `kit:"id" json:"timestamp"`
	Open      string `json:"open"`
	High      string `json:"high"`
	Low       string `json:"low"`
	Close     string `json:"close"`
	Volume    string `json:"volume"`
}

Candle is one OHLCV bar for an instrument.

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to the OKX public API over HTTPS.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func (*Client) Get

func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)

Get fetches rawURL and returns the body. It paces and retries transient errors.

func (*Client) GetCandles

func (c *Client) GetCandles(ctx context.Context, symbol, bar string, count int) ([]*Candle, error)

GetCandles fetches OHLCV candlestick bars for a symbol. bar is one of 1m, 5m, 15m, 30m, 1H, 4H, 1D, 1W, 1M. count is the number of bars; OKX max is 300.

func (*Client) GetInstruments

func (c *Client) GetInstruments(ctx context.Context, instType string, limit int) ([]*Instrument, error)

GetInstruments fetches the list of trading instruments for an instrument type. Results are capped at limit; pass 0 for no cap.

func (*Client) GetTicker

func (c *Client) GetTicker(ctx context.Context, symbol string) (*Ticker, error)

GetTicker fetches the current price and 24h stats for one instrument (e.g. "BTC-USDT").

func (*Client) GetTickers

func (c *Client) GetTickers(ctx context.Context, instType string, limit int) ([]*Ticker, error)

GetTickers fetches all tickers for an instrument type (SPOT, SWAP, FUTURES, OPTION). Results are capped at limit; pass 0 for no cap.

type Domain

type Domain struct{}

Domain is the okx driver. It carries no state.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns a symbol into (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live OKX page URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Instrument

type Instrument struct {
	ID       string `kit:"id" json:"id"`
	Base     string `json:"base"`
	Quote    string `json:"quote"`
	MinSize  string `json:"min_size"`
	TickSize string `json:"tick_size"`
	State    string `json:"state"`
}

Instrument is a trading pair listed on OKX.

type Ticker

type Ticker struct {
	Symbol  string `kit:"id" json:"symbol"`
	Last    string `json:"last"`
	Bid     string `json:"bid"`
	Ask     string `json:"ask"`
	Open24h string `json:"open_24h"`
	High24h string `json:"high_24h"`
	Low24h  string `json:"low_24h"`
	Vol24h  string `json:"vol_24h"`
}

Ticker holds current price and 24h stats for one instrument.

Jump to

Keyboard shortcuts

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