client

package
v0.20260622.2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAPIError

func IsAPIError(err error) bool

IsAPIError reports whether err is a Kraken *APIError.

Types

type APIError

type APIError struct {
	Errors []string `json:"error"`
}

APIError is the error envelope Kraken returns. Every REST response carries an "error" array of strings; it is empty on success and otherwise holds one or more error codes of the form "ECategory:Detail" (e.g. "EOrder:Insufficient funds", "EAPI:Invalid nonce", "EGeneral:Invalid arguments").

func (*APIError) Error

func (e *APIError) Error() string

Error returns the joined Kraken error strings.

func (*APIError) Has

func (e *APIError) Has(substr string) bool

Has reports whether any of the returned error strings contains substr. Kraken codes are not stable enough to match exactly across endpoints, so callers match on a substring such as "Invalid nonce" or "Insufficient funds".

func (*APIError) IsValid

func (e *APIError) IsValid() bool

IsValid reports whether e represents an actual API-level error (a non-empty error array).

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the shared, product-agnostic REST core. Kraken's whole spot API (market data, account, trading, funding, earn) is just a set of request paths layered on top of this same signing + transport machinery, so the core carries no endpoint-specific state.

func NewClient

func NewClient(options ...Options) *Client

func (*Client) GetAPIKey

func (c *Client) GetAPIKey() string

func (*Client) GetAPISecret

func (c *Client) GetAPISecret() string

func (*Client) GetHttpClient

func (c *Client) GetHttpClient() *resty.Client

func (*Client) GetLogger

func (c *Client) GetLogger() log.Logger

func (*Client) GetSignFn

func (c *Client) GetSignFn() SignFn

func (*Client) Nonce

func (c *Client) Nonce() int64

Nonce returns the next request nonce: an always-increasing, unsigned 64-bit integer required on every private request and folded into its signature. Kraken rejects a nonce that is not strictly greater than the previous one seen for the key, so the generator is strictly monotonic.

type Option

type Option struct {
	// contains filtered or unexported fields
}

type Options

type Options func(*Option)

func WithAuth

func WithAuth(apiKey, apiSecret string) Options

WithAuth sets the API credentials used to sign private requests. Both values come from the Kraken API-management page; apiSecret is the base64-encoded "Private Key" shown when the key was created.

func WithBaseURL

func WithBaseURL(baseURL string) Options

WithBaseURL overrides the REST base URL derived from WithNetwork. Use it to point the client at a custom or proxied endpoint. An empty value is ignored.

func WithHTTPClient

func WithHTTPClient(client *resty.Client) Options

WithHTTPClient supplies a pre-configured resty client (custom transport, timeouts, TLS, etc.). The JSON (un)marshalers and base URL are still set by the SDK afterwards.

func WithLogger

func WithLogger(logger log.Logger) Options

func WithNetwork

func WithNetwork(network krakenCommon.Network) Options

WithNetwork selects the Kraken environment. Kraken exposes a single production domain for spot, so this currently only accepts common.Mainnet; it exists for forward symmetry with sibling SDKs.

func WithNonce

func WithNonce(nonceFn func() int64) Options

WithNonce replaces the default nonce generator. The supplied function must return a strictly increasing value on each call for the lifetime of the API key (Kraken rejects a non-increasing nonce). Use it to share one nonce sequence across several clients, or to switch to a millisecond/microsecond resolution to match another tool already using the key.

func WithProxy

func WithProxy(proxyURL string) Options

WithProxy routes all REST traffic through the given proxy. Supported schemes: http, https, socks5, socks5h. Pass userinfo in the URL for authenticated proxies. Invalid URLs are logged and skipped.

func WithSignFn

func WithSignFn(signFn SignFn) Options

WithSignFn replaces the default HMAC-SHA512 signer. Use it to delegate signing to an HSM / remote signer.

type SignFn

type SignFn = func(secret, uriPath, nonce, postData string) (signature string, err error)

SignFn produces the API-Sign header value for a private Kraken request. The default implementation (request.HMACSign) computes

base64( HMAC-SHA512( base64decode(secret), uriPath + SHA256(nonce + postData) ) )

Supply a custom one via WithSignFn to delegate signing to an HSM or remote signer (in which case secret may carry an opaque key handle).

type TokenFn

type TokenFn = func(ctx context.Context) (token string, expiresSeconds int64, err error)

TokenFn fetches a fresh Kraken WebSocket authentication token together with its validity in seconds (via the REST GetWebSocketsToken endpoint). It is injected by the SDK's WebSocket constructor so the client package itself does not import the REST request layer.

type WebSocketClient

type WebSocketClient struct {
	// contains filtered or unexported fields
}

WebSocketClient holds the configuration shared by every Kraken v2 stream. Public channels need no credentials; private channels and WebSocket order entry authenticate with a short-lived token obtained from the REST API and cached here.

func NewWebSocketClient

func NewWebSocketClient(options ...WebSocketOptions) *WebSocketClient

func (*WebSocketClient) GetAPIKey

func (c *WebSocketClient) GetAPIKey() string

func (*WebSocketClient) GetAPISecret

func (c *WebSocketClient) GetAPISecret() string

func (*WebSocketClient) GetDialer

func (c *WebSocketClient) GetDialer() *websocket.Dialer

func (*WebSocketClient) GetLogger

func (c *WebSocketClient) GetLogger() log.Logger

func (*WebSocketClient) GetPrivateURL

func (c *WebSocketClient) GetPrivateURL() string

func (*WebSocketClient) GetProxyURL

func (c *WebSocketClient) GetProxyURL() string

func (*WebSocketClient) GetPublicURL

func (c *WebSocketClient) GetPublicURL() string

func (*WebSocketClient) SetTokenFn

func (c *WebSocketClient) SetTokenFn(fn TokenFn)

SetTokenFn installs the token fetcher (wired by kraken.NewWebSocketClient from the REST GetWebSocketsToken endpoint).

func (*WebSocketClient) Token

func (c *WebSocketClient) Token(ctx context.Context) (string, error)

Token returns a valid WebSocket auth token, fetching (and caching) a fresh one when the cached token is missing or near expiry. Kraken tokens are valid for ~15 minutes and may be reused across connections within that window.

type WebSocketOption

type WebSocketOption struct {
	// contains filtered or unexported fields
}

type WebSocketOptions

type WebSocketOptions func(*WebSocketOption)

func WithWebSocketAuth

func WithWebSocketAuth(apiKey, apiSecret string) WebSocketOptions

WithWebSocketAuth sets the credentials used to fetch the WebSocket token required by private channels and order entry. Same key/secret as the REST client.WithAuth.

func WithWebSocketLogger

func WithWebSocketLogger(logger log.Logger) WebSocketOptions

func WithWebSocketNetwork

func WithWebSocketNetwork(network krakenCommon.Network) WebSocketOptions

func WithWebSocketPrivateURL

func WithWebSocketPrivateURL(u string) WebSocketOptions

WithWebSocketPrivateURL overrides the private (auth) stream URL. Empty is ignored.

func WithWebSocketProxy

func WithWebSocketProxy(proxyURL string) WebSocketOptions

WithWebSocketProxy routes the stream dial (and the REST token fetch) through the given proxy (http, https, socks5, socks5h). Invalid URLs are logged and skipped.

func WithWebSocketPublicURL

func WithWebSocketPublicURL(u string) WebSocketOptions

WithWebSocketPublicURL overrides the public stream URL. Empty is ignored.

Jump to

Keyboard shortcuts

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