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
- type Candle
- type Client
- func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)
- func (c *Client) GetCandles(ctx context.Context, symbol, bar string, count int) ([]*Candle, error)
- func (c *Client) GetInstruments(ctx context.Context, instType string, limit int) ([]*Instrument, error)
- func (c *Client) GetTicker(ctx context.Context, symbol string) (*Ticker, error)
- func (c *Client) GetTickers(ctx context.Context, instType string, limit int) ([]*Ticker, error)
- type Domain
- type Instrument
- type Ticker
Constants ¶
const BaseURL = "https://www.okx.com/api/v5"
BaseURL is the root every API request is built from.
const DefaultUserAgent = "okx-cli/0.1 (tamnd87@gmail.com)"
DefaultUserAgent identifies the client to OKX.
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 (*Client) Get ¶
Get fetches rawURL and returns the body. It paces and retries transient errors.
func (*Client) GetCandles ¶
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.
type Domain ¶
type Domain struct{}
Domain is the okx driver. It carries no state.
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.
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.