Documentation
¶
Overview ¶
Package kraken is the library behind the kraken command line: the HTTP client, request shaping, and the typed data models for the Kraken crypto exchange public API (api.kraken.com/0/public).
The Client is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries transient failures (429 and 5xx). Build your endpoint calls and JSON decoding on top of Get.
Index ¶
- Constants
- type Asset
- type Candle
- type Client
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) GetAssets(ctx context.Context, limit int) ([]*Asset, error)
- func (c *Client) GetOHLC(ctx context.Context, pair string, interval, limit int) ([]*Candle, error)
- func (c *Client) GetPairs(ctx context.Context, pairs string, limit int) ([]*Pair, error)
- func (c *Client) GetTicker(ctx context.Context, pair string) (*Ticker, error)
- type Config
- type Domain
- type Pair
- type Ticker
Constants ¶
const BaseURL = "https://" + Host + "/0/public"
BaseURL is the root every request is built from.
const DefaultUserAgent = "kraken/dev (+https://github.com/tamnd/kraken-cli)"
DefaultUserAgent identifies the client to Kraken.
const Host = "api.kraken.com"
Host is the Kraken public API host.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Asset ¶
type Asset struct {
ID string `kit:"id" json:"id"`
AltName string `json:"alt_name"`
Decimals int `json:"decimals"`
Status string `json:"status"`
}
Asset describes a single Kraken asset (currency).
type Candle ¶
type Candle struct {
Pair string `kit:"id" json:"pair"`
Time int64 `json:"time"`
Open string `json:"open"`
High string `json:"high"`
Low string `json:"low"`
Close string `json:"close"`
VWAP string `json:"vwap"`
Volume string `json:"volume"`
Count int `json:"count"`
}
Candle is one OHLC bar.
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
// Base overrides BaseURL for testing. Leave empty to use BaseURL.
Base string
// contains filtered or unexported fields
}
Client talks to Kraken over HTTP.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client's settings.
func (*Client) GetAssets ¶
GetAssets fetches all assets, optionally limited to limit items (0 = all).
func (*Client) GetOHLC ¶
GetOHLC fetches OHLC candles for a pair. interval is in minutes (1|5|15|60|1440). limit caps the number of returned candles (0 = all).
type Domain ¶
type Domain struct{}
Domain is the Kraken driver.
func (Domain) Classify ¶
Classify turns a reference (pair name or URL) into the canonical (type, id). Pair-like inputs (contain "USD", "EUR", "BTC", "XBT", "ETH", or "USDT") classify as "pair"; other inputs classify as "asset".
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity used for the binary's help and version.
type Pair ¶
type Pair struct {
ID string `kit:"id" json:"id"`
AltName string `json:"alt_name"`
Base string `json:"base"`
Quote string `json:"quote"`
Status string `json:"status"`
}
Pair describes a Kraken tradeable asset pair.
type Ticker ¶
type Ticker struct {
Pair string `kit:"id" json:"pair"`
Price string `json:"price"` // c[0] = last trade price
High24h string `json:"high_24h"` // h[1]
Low24h string `json:"low_24h"` // l[1]
Volume string `json:"volume"` // v[1]
Trades float64 `json:"trades"` // t[1]
}
Ticker holds the current price summary for an asset pair.