kraken

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: 9 Imported by: 0

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

View Source
const BaseURL = "https://" + Host + "/0/public"

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "kraken/dev (+https://github.com/tamnd/kraken-cli)"

DefaultUserAgent identifies the client to Kraken.

View Source
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 NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func (*Client) Get

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

Get fetches url and returns the response body. It paces and retries according to the client's settings.

func (*Client) GetAssets

func (c *Client) GetAssets(ctx context.Context, limit int) ([]*Asset, error)

GetAssets fetches all assets, optionally limited to limit items (0 = all).

func (*Client) GetOHLC

func (c *Client) GetOHLC(ctx context.Context, pair string, interval, limit int) ([]*Candle, error)

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).

func (*Client) GetPairs

func (c *Client) GetPairs(ctx context.Context, pairs string, limit int) ([]*Pair, error)

GetPairs fetches asset pairs. If pairs is non-empty it is passed as the "pair" query parameter (comma-separated). Optionally limited to limit items.

func (*Client) GetTicker

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

GetTicker fetches the current ticker for a pair (e.g. "XBTUSD").

type Config

type Config struct {
	UserAgent string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
}

Config holds optional overrides a caller can apply to a new Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Domain

type Domain struct{}

Domain is the Kraken driver.

func (Domain) Classify

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

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.

func (Domain) Locate

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

Locate returns the live web 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 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.

Jump to

Keyboard shortcuts

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