A Go module for interacting with the Kraken Spot and Derivatives APIs, offering both REST and WebSocket access to spot and futures exchanges. This library includes utilities for fixed-point arithmetic, callback handlers, and API helpers.
Key features include:
-
Trading operations: add, amend, and cancel orders
-
Real-time market data streams
-
Book builders for L2 and L3 order books with checksum validation
-
Access to private account data such as balances and execution reports
-
Retrieval of instruments and assets
-
Utility functions for asset name normalization and price derivation
To install the module in your Go project:
go get github.com/krakenfx/api-go/...
If you're interested in running examples or contributing to development, clone the repo and install dependencies:
git clone https://github.com/krakenfx/api-go.git
cd api-go
go mod download
Example packages using the module are located in the examples directory.
Before running the scripts, you'll need to set the following environment variables to configure API endpoints and authentication keys:
# REST and WebSocket URLs for Kraken Spot API
export KRAKEN_API_SPOT_REST_URL="https://api.kraken.com"
export KRAKEN_API_SPOT_WS_URL="wss://ws.kraken.com/v2"
export KRAKEN_API_SPOT_WS_AUTH_URL="wss://ws-auth.kraken.com/v2"
export KRAKEN_API_SPOT_PUBLIC="" # Insert your Spot public API key
export KRAKEN_API_SPOT_SECRET="" # Insert your Spot secret API key
# REST and WebSocket URLs for Kraken Futures API
export KRAKEN_API_FUTURES_REST_URL="https://futures.kraken.com"
export KRAKEN_API_FUTURES_WS_URL="wss://futures.kraken.com/ws/v1"
export KRAKEN_API_FUTURES_PUBLIC="" # Insert your Futures public API key
export KRAKEN_API_FUTURES_SECRET="" # Insert your Futures secret API key
To simplify execution of authenticated example scripts, use the provided helper script:
./scripts/run prod ./examples/spotrest/recenttrades
This command sets the correct environment and runs the selected script with authentication enabled.
This module uses the following third-party packages:
-
gorilla/websocket: WebSocket protocol implementation in Go.
-
google/uuid: RFC 4122-compliant UUID generation.
-
golang.org/x/sync: Additional Go concurrency primitives.
Feel free to open issues, suggest features, or submit PRs.