Telegram Kraken Bot

Python 3 bot to trade on Kraken via Telegram messenger

Demo GIF of bot

Overview

This Python script is a polling (not webhook) based Telegram bot. It can trade crypto-currencies on the Kraken marketplace and has a user friendly interface (custom keyboards with buttons).

Features

Files

In the following list you will find detailed information about all the files that the project consists of - and if they are necessary to run the bot or not.

Summary

These are the files that are important to run the bot:

Configuration

Before starting up the bot you have to take care of some settings. You need to edit two files:

config.json

This file holds the configuration for your bot. You have to at least edit the values for user_id and bot_token. After a value has been changed you have to restart the bot for the applied changes to take effect.

kraken.key

This file holds two keys that are necessary in order to communicate with Kraken. Both keys have to be considered secret and you should be the only one that knows them.

If you don’t know where to get or how to generate the keys:

  1. Login to Kraken
  2. Click on Settings
  3. Click on API
  4. Click on Generate New Key
  5. Enter Telegram-Kraken-Bot in Key Description
  6. Enter 4 in Nonce Window (or just use the default value)
  7. Select all available permissions at Key Permissions
  8. Click on Generate Key

When you have your Kraken API keys, open the file kraken.key and replace some_api_key (first line) with the value of API Key and some_private_key (second line) with the value of Private Key.

Installation

In order to run the bot you need to execute the script telegram_kraken_bot.py. If you don’t have any idea where to host it, take a look at Where to host Telegram Bots. Since you have to provide sensitive data (Kraken API keys) to use the bot, i would only host this script on a server that you own. But services like Heroku should be save too. You can also run the script locally on your computer for testing purposes.

Prerequisites

Python version

You have to use Python 3.6 to execute the script (because of enum method auto()). If you would like to use Python 3.4 or 3.5, you have to remove auto from imports and set the values in WorkflowEnum and KeyboardEnum yourself. Python 2.x is not supported.

Installing needed modules from requirements.txt

Install a set of module-versions that is known to work together for sure (highly recommended):

pip3.6 install -r requirements.txt
Install newest versions of needed modules

If you want to install the newest versions of the needed modules, execute the following:

pip3.6 install python-telegram-bot -U
pip3.6 install beautifulsoup4 -U
pip3.6 install krakenex -U

Starting

To start the script, execute

python3.6 telegram_kraken_bot.py &

Stopping

To stop the script, execute

pkill python

which will kill every Python process that is currently running. Or shut the bot down with the /shutdown command (recommended).

Usage

If you configured the bot correctly and execute the script, you should see some checks that the bot performs. After that a welcome message will be shown along with the information if you are using the latest version. There should also be a custom keyboard that shows you all the available commands. Click on a button to execute the command or type the command in manually (not case sensitive).

:warning: In general, while entering the volume, make sure that you don’t use smaller values then Kraken supports. Take a look at the order limits for various coins. If you do use smaller values, the bot will tell you it’s not possible to use that value and will let you enter the volume again.

Available commands

If you want to show a list of available commands as you type, open a chat with Telegram user BotFather and send the command /setcommands. Then choose the bot you want to activate the list for and after that send the list of commands with description. Something like this:

trade - buy or sell assets
orders - show or close orders
balance - show all your assets
price - show current price for asset
value - calculate value for assets
chart - display trading charts
history - show completed trades
funding - deposit or withdraw currencies
bot - update, restart or shutdown

Development

I know that it is unusual to have the whole source code in just one file. At some point i should have been switching to object orientation and multiple files but i kind of like the idea to have it all in just one file and object orientation would only blow up the code. This also makes the /update command much simpler :)

Todo

Priority 1
Priority 2
Priority 3

Troubleshooting

In case you experience any issues, please take a look at this section to check if it is described here. If not, create an issue on GitHub.

:warning: It depends on the error but it is possible that a request to Kraken will return with an error and still be executed correctly.

:warning: If it happens that a specific command doesn’t trigger any action (no response from the bot on button click), try to reload the keyboard with /reload or if that doesn’t help, restart the bot with /restart.

Disclaimer

I use this bot personally to trade on Kraken so i guess it’s kind of stable but if you use it, then you are doing this on your own responsibility !!! I can not be made responsible for lost coins or other stuff that might happen due to some fuckup within the code. Use at your own risk!

Donating

If you find Telegram-Kraken-Bot suitable for your needs or maybe even made some money because of it, please consider donating whatever amount you like to:

Monero (XMR)

46tUdg4LnqSKroZBR1hnQ2K6NnmPyrYjC8UBLhHiKYufCipQUaACfxcBeQUmYGFvqCdU3ghCpYq2o5Aqyj1nH6mfLVNka26

Ethereum (ETH)

0xccb2fa97f47f0d58558d878f359013fef4097937

How else can you support me?

If you can’t or don’t want to donate, please consider signing up on listed exchanges below. They are really good and by using these links to register an account i get a share of the trading-fee that you pay to the exchange if you execute a trade.