Hi! If you're looking for a way to automate your regular crypto purchases via Kraken, you
have come to the right place. The kraken_api_dca.py
script allows you to specify orders in all trading pairs on
Kraken. Just let your computer run the script at regular intervals and you have your
automated Dollar cost averaging bot.
If this code is useful to you, consider supporting me! This way I can continue maintaining and improving your DCA script.
This script needs the krakenex
pip package. To install it run
pip install -r requirements.txt
To use the script, you need to:
- Create a Kraken API key and save it to the file
kraken.key
. See here for an explanation. - Create a file
orders.json
and specify your orders. . See this description of how to place your orders. - Run the script via
python3 kraken_api_dca.py
To use this script, you need a Kraken API key that allows creating orders.
Below we explain how to create an API key if you don't have one already.
To create your API key, click on your profile icon. Then go to Security->API
. You will see the following screen.
Click on 'Add key' to add a new API key.
This will take you to the next screen.
Make sure you check Create & Modify Orders.
You should not check any other fields. Especially not 'Withdraw Funds', as this would allow people with access to your API key to withdraw your funds.
Then click on 'Generate key'.
This creates your key and takes you to the next screen. Here you see your public and private key. This is the
information you have to store in the kraken.key
file.
Copy the information from the 'API key' line and write it into the first line in kraken.key
.
Then copy the private key and save it in the second line of kraken.key
.
Finally, click 'Save.'
Your kraken.key
file should look like this.
<API key>
<Private key>
To specify your orders, create a file called orders.json
. The file should contain a list of orders in JSON format.
Each order object can contain the following fields:
pair (string)
: The trading pair you want to buy (for exampleALGOUSD
for trading Algorand for US$). Have a look attrading_pairs.txt
for an overview of all trading pairs. Note that Bitcoin is calledXBT
.amount_in_fiat (number)
: The amount you want to buy (in fiat currency). E.g. if you want to buy 400$ of Bitcoin, enter400
and choose theXXBTZUSD
trading pair.debug (boolean)
: This gives you the possibility to test the script before you let it place orders for you. If you setdebug:true
the order will be placed as a limit order for 1% of the current price. This is, so you can verify that the order is created and delete the order before it is executed. After you checked that everything worked, setdebug:false
for all your orders.
An example orders.json
could look like this:
[
{
"pair": "XETHZUSD",
"amount_in_fiat": 100,
"debug": true
},
{
"pair": "XXBTZUSD",
"amount_in_fiat": 200,
"debug": true
}
]
This would create two orders. The first order buys 100$ of Ether, the second order buys 200$ of Bitcoin. Both orders
have debug mode activated, which means they will be placed as limit orders on 1% of the current price. This way you can
check that everything works out, delete the created orders and set debug:false
once you want to start using the
script.
On Linux you can use anacron
to schedule execution of the script. To run the script monthly, you can add the following
line to /etc/anacrontab
:
@monthly 7 kraken-api-dca-script cd ~/kraken_api_dca && python3 ~/kraken_api_dca/kraken_api_dca.py
anacron
has the advantage over cron
that if your computer is turned off, the script will be executed the next time
the computer is turned on.
See here for more information on anacron
.
On Windows you could try the following library to schedule script execution: Advanced Python Scheduler (Note: I couldn't test this, since I don't have a Windows machine)
The script will write logs to a file called logs.txt
. Check this file for the results of your API calls.
This code is correct to the best of my knowledge and belief. If you decide to use it, you do so at your own risk. I will not be liable for any losses or damages in connection with using my code.