Implementing a Kraken REST API interface using the Bourne Again shell (bash) and some associated commands (openssl, base64, xxd, etc.) can be a convenient and efficient solution for interacting with Kraken's markets (although it would not be the fastest implementation compared to compiled code).
Bash and the required commands are readily available (pre-installed) on most UNIX, Linux, and macOS systems, and can be easily installed on Windows and other systems, so all of the required software is available without using any additional third party API tools or libraries.
Using a plain text editor (even an old school editor such as vi) and a few lines of code, it is possible to access both public market data and private account data, and also to place/cancel orders on Kraken's markets.
The following shows a bash code implementation for calling the REST API Balance endpoint (with syntax highlighting for ease of understanding):
while the following provides the same code as plain text for copying/pasting:
#!/usr/bin/env bash # API public/private keys copied from account management web site api_key='gxTXpC4Ag/N0QPKlYnRhL1qVB2G/HZV1eB2drl7eOXga30dEKoB+EUMs' api_private='62kRfRX7BI8G8T/jl7clnZ+vSfJt7YmQN23JQkJfHCE6oxecJX4fN4i2RitmRhyFzfJ4efKy2yCo4H068rfv0A==' # API variables (URL, endpoint, nonce, etc.) api_host='https://api.kraken.com' api_endpoint='/0/private/Balance' api_nonce=`date +%s` api_post="nonce=$api_nonce" # Authentication algorithm (SHA256 and HMAC SHA512) api_private_hex=`echo -n $api_private | base64 -d | xxd -p | tr -d "\n"` api_sha256=$api_endpoint`echo -n $api_nonce$api_post | openssl dgst -sha256 -binary` api_sign=`echo -n $api_sha256 | openssl dgst -binary -sha512 -mac HMAC -macopt hexkey:$api_private_hex | base64` # HTTP request (POST) curl --header "API-Key: $api_key" --header "API-Sign: $api_sign" --data $api_post $api_host$api_endpoint
and the matching code can also be downloaded (as a kapi_bash.sh file).
To retrieve your own account balances, the example API key should be replaced with an API key from your own Kraken account, and additional API endpoints can be enabled simply by modifying the api_endpoint variable and the api_post variable (if needed).