Documentation
¶
Index ¶
- func IsAPIError(err error) bool
- type APIError
- type Client
- type Option
- type Options
- func WithAuth(apiKey, apiSecret string) Options
- func WithBaseURL(baseURL string) Options
- func WithHTTPClient(client *resty.Client) Options
- func WithLogger(logger log.Logger) Options
- func WithNetwork(network krakenCommon.Network) Options
- func WithNonce(nonceFn func() int64) Options
- func WithProxy(proxyURL string) Options
- func WithSignFn(signFn SignFn) Options
- type SignFn
- type TokenFn
- type WebSocketClient
- func (c *WebSocketClient) GetAPIKey() string
- func (c *WebSocketClient) GetAPISecret() string
- func (c *WebSocketClient) GetDialer() *websocket.Dialer
- func (c *WebSocketClient) GetLogger() log.Logger
- func (c *WebSocketClient) GetPrivateURL() string
- func (c *WebSocketClient) GetProxyURL() string
- func (c *WebSocketClient) GetPublicURL() string
- func (c *WebSocketClient) SetTokenFn(fn TokenFn)
- func (c *WebSocketClient) Token(ctx context.Context) (string, error)
- type WebSocketOption
- type WebSocketOptions
- func WithWebSocketAuth(apiKey, apiSecret string) WebSocketOptions
- func WithWebSocketLogger(logger log.Logger) WebSocketOptions
- func WithWebSocketNetwork(network krakenCommon.Network) WebSocketOptions
- func WithWebSocketPrivateURL(u string) WebSocketOptions
- func WithWebSocketProxy(proxyURL string) WebSocketOptions
- func WithWebSocketPublicURL(u string) WebSocketOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAPIError ¶
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").
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 (*Client) GetAPISecret ¶
func (*Client) GetHttpClient ¶
func (*Client) Nonce ¶
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 Options ¶
type Options func(*Option)
func WithAuth ¶
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 ¶
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 ¶
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 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 ¶
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 ¶
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 ¶
WithSignFn replaces the default HMAC-SHA512 signer. Use it to delegate signing to an HSM / remote signer.
type SignFn ¶
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 ¶
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.