A local development environment that mimics the Kraken Spot REST API.
Kraken only provides a UAT environment to "Business Pro" accounts and "third party service developers" both of which require several hoops to create. Kraken support told me:
Our usual recommendation for testing is to use a real account and place real orders for very small amounts by adding small funds in the account.
Umm, fuck that.
-
Clone this repository:
git clone https://github.com/sudosammy/kraken-sandbox.git cd kraken-sandbox -
Create the docker network. This will expose the container at
kraken-sandbox:5555to other containers on this network:docker network create kraken_network -
Start the Docker container:
docker compose up -
The API will be available on the host at http://localhost:5555 and API credentials will be printed to the console and are available at http://localhost:5555/admin. If you started the server with
docker compose up -dyou can also find the credentials viadocker compose logs kraken-sandbox
-
Clone this repository:
git clone https://github.com/sudosammy/kraken-sandbox.git cd kraken-sandbox -
Install dependencies:
pip install -r requirements.txt -
Start the API server:
python app.py -
The API will be available on the host at http://localhost:5555 and API credentials will be printed to the console & are available at http://localhost:5555/admin.
/0/public/Time- Get server time/0/public/Assets- Get information about assets/0/public/AssetPairs- Get information about trading pairs/0/public/Ticker- Get current price information/0/public/OHLC- Get Open, High, Low, Close data/0/public/Depth- Get order book/0/public/Trades- Get recent trades/0/public/Spread- Get recent spread data/0/public/SystemStatus- Get system status
/0/private/Balance- Get account balances (includes assets with .B, .M, and .F appendages)/0/private/OpenOrders- Get open orders/0/private/AddOrder- Place a market order/0/private/ClosedOrders- Get closed orders/0/private/QueryOrders- Get information about specific orders/0/private/QueryTrades- Get detailed information about specific trades/0/private/TradesHistory- Get trade history/0/private/CancelOrder- Cancel an open order/0/private/EditOrder- Edit an existing order by canceling it and creating a new one/0/private/AmendOrder- Amend an order in-place without losing queue position
- BTC/USD (XXBTZUSD)
- ETH/USD (XETHZUSD)
- BTC/AUD (XXBTZAUD)
- ETH/AUD (XETHZAUD)
To add new trading pairs, update the seed_asset_pairs function in database.py.
The Kraken Sandbox API simulates realistic order execution behavior:
- Market Orders: Always execute immediately at the current market price.
- Limit Orders:
- Limit orders placed within 5% of the current market price are automatically executed.
- Limit orders placed more than 5% away from the current market price remain open.
- This behavior allows for testing both order execution and order management (cancellation, editing).
If you want to access the API from another container, ensure you have created the kraken_network network and specify it via --network or an external: true network configuration in the other container's docker-compose.yml. Then the sandbox API will be available at http://kraken-sandbox:5555.
Public endpoints can be accessed directly via GET (or POST) requests:
curl http://localhost:5555/0/public/Ticker?pair=XXBTZUSD
Private endpoints require API key authentication:
curl -X POST \
-H "API-Key: YOUR_API_KEY" \
-H "API-Sign: YOUR_API_SIGN" \
-d "nonce=$(date +%s000)" \
http://localhost:5555/0/private/Balance
The API automatically generates an API key and secret when first started. These credentials will be printed to the console. All private API requests must include:
API-Keyheader with your API keyAPI-Signheader with a valid signaturenonceparameter in the request body
For testing purposes, the sandbox has simplified authentication - it only checks if the API key exists.
A test script (test_kraken_sandbox.sh) is included to verify that all API endpoints are working correctly. To run the test script:
# After starting the API server
./test_kraken_sandbox.sh localhost:5555 your_api_key your_api_secretThe test script will:
- Test all public endpoints
- Test all private endpoints
- Place various types of orders (market, limit)
- Test order cancellation and editing
- Verify trades and order history
By default, logging is set to INFO which will print all API requests to the console. Set an environment variable LOG_LEVEL=ERROR to change this.
The Kraken Sandbox includes an admin dashboard at http://localhost:5555/admin that provides an interface to view all data in the database.
Simply delete the SQLite database in data/kraken_sandbox.db and re-run the program. It will regenerate and reseed a new clean database.
