Documentation
¶
Index ¶
- func Do[T any](r *Request) (resp *T, err error)
- func DoRaw(r *Request) ([]byte, error)
- func DoRawResult(r *Request) ([]byte, error)
- func HMACSign(secret, uriPath, nonce, postData string) (string, error)
- func Subscribe[T any](ctx context.Context, c WsClient, channel string, params map[string]any, ...) (done chan<- struct{}, stop <-chan struct{}, err error)
- func SubscribeRaw(ctx context.Context, c WsClient, channel string, params map[string]any, ...) (done chan<- struct{}, stop <-chan struct{}, err error)
- type Client
- type Request
- type SignFn
- type WsClient
- type WsError
- type WsPush
- type WsPushType
- type WsTradeConn
- type WsTradeResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Do ¶
Do executes the request and decodes the envelope's result field into *T. A non-empty error array is returned as a *client.APIError.
func DoRawResult ¶
DoRawResult executes the request and returns the raw JSON bytes of the envelope's "result" field (after verifying the error array is empty). Tests use it to diff the real response shape against the typed structs.
func HMACSign ¶
HMACSign is Kraken's default request signer:
API-Sign = base64( HMAC-SHA512( base64decode(secret), uriPath + SHA256(nonce + postData) ) )
where uriPath is the full path (e.g. "/0/private/AddOrder"), postData is the url-encoded POST body (which itself begins with "nonce=..."), and nonce is that same nonce value as a string. The secret is the base64 "Private Key" from the Kraken API-management page and is decoded to raw bytes before use as the HMAC key.
func Subscribe ¶
func Subscribe[T any](ctx context.Context, c WsClient, channel string, params map[string]any, private bool, cb func(*WsPush[T], error)) (done chan<- struct{}, stop <-chan struct{}, err error)
Subscribe opens a dedicated connection to the public or private v2 gateway, subscribes to the channel with the given params (injecting the auth token when private), and invokes cb for every data push (decoded into *WsPush[T]). It returns a done channel (close to stop) and a stop channel (closed when the reader exits).
Types ¶
type Client ¶
type Client interface {
GetHttpClient() *resty.Client
GetAPIKey() string
GetAPISecret() string
GetLogger() log.Logger
GetSignFn() SignFn
Nonce() int64
}
Client is what every endpoint Service needs from the Kraken REST client. All getters are read-only; the concrete *client.Client satisfies it.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func Get ¶
Get builds a GET request for a public endpoint. Any params maps are merged (empty values dropped) into the query string.
func Post ¶
Post builds a POST request, used for both public and (with WithSign) private endpoints. Any params maps are merged into the url-encoded form body.
type SignFn ¶
SignFn mirrors client.SignFn: it turns the request components into the API-Sign header value, given the configured (base64-encoded) secret.
type WsClient ¶
type WsClient interface {
GetPublicURL() string
GetPrivateURL() string
GetLogger() log.Logger
GetDialer() *websocket.Dialer
Token(ctx context.Context) (string, error)
}
WsClient is what the subscribe/trade framework needs from a *client.WebSocketClient.
type WsError ¶
type WsError struct {
Message string
}
WsError is a Kraken WebSocket control-frame error.
type WsPush ¶
type WsPush[T any] struct { Channel string `json:"channel"` Type WsPushType `json:"type"` Data T `json:"data"` }
WsPush is the envelope Kraken pushes for a channel data event. Type is WsPushTypeSnapshot (full) or WsPushTypeUpdate (incremental).
type WsPushType ¶ added in v0.20260622.1
type WsPushType string
WsPushType classifies a channel data frame: a full snapshot or an incremental update.
const ( WsPushTypeSnapshot WsPushType = "snapshot" // full state WsPushTypeUpdate WsPushType = "update" // incremental change )
type WsTradeConn ¶
type WsTradeConn struct {
// contains filtered or unexported fields
}
WsTradeConn is a persistent private connection for placing/managing orders over WebSocket. Unlike the subscription channels it is request/response: each call sends a method frame tagged with a unique req_id and waits for the matching reply. One connection serves any number of concurrent calls. The auth token (fetched at dial) is injected into every request's params.
func DialWsTrade ¶
func DialWsTrade(ctx context.Context, c WsClient) (*WsTradeConn, error)
DialWsTrade opens the private v2 gateway, fetches an auth token, and returns a ready trade connection. Close it when done.
func (*WsTradeConn) Close ¶
func (t *WsTradeConn) Close() error
Close terminates the connection and fails any in-flight calls.
type WsTradeResponse ¶
type WsTradeResponse[T any] struct { Method string `json:"method"` ReqID int64 `json:"req_id"` Result T `json:"result"` Success bool `json:"success"` Error string `json:"error"` TimeIn string `json:"time_in"` TimeOut string `json:"time_out"` }
WsTradeResponse is the reply to a trade method frame. Result carries the method-specific payload (e.g. the order id).
func WsTradeCall ¶
func WsTradeCall[T any](ctx context.Context, t *WsTradeConn, method string, params map[string]any) (*WsTradeResponse[T], error)
WsTradeCall sends a trade method and decodes the reply, returning a *WsError on a non-success response.