Automated Trading Bots.
Last few years I have been trading cryptocurrencies and as a computer scientist, I always been interested in automated trading bots. I have read some stories and saw some videos about this topic. So I decided to try this technology. But first of all, a little advise, I am not an investment expert so be aware of the risk of trading. Do not gamble with money you are not willing to lose. After this little introduction, let's see how we can start with automated trading.
Do not reinvent the wheel.
Every time I am thinking about a new software project, I check Github. There thousands of incredible open-source projects. And even though that perhaps I am trying to learn or code something new, see other code and projects is always a good source of ideas.
Right now if we look into GitHub for crypto trading bot we will obtain 695 repositories.
crypto trading bot on GitHub.
The first three projects seem to be very interesting but I will choose freqtrade for testing
auto trading. I am not choosing freqtrade only for the number of stars, there are several key factors that I like:
It is developed in Python and with active development. I personally preferred Python for scripting projects like this. It can be easily controlled through a Telegram bot. Popular exchanges like Binance or Bittrex are supported. Support strategy customization. You can create your own strategies.
So if you think about that, you can create your own bot for learning purposes. But the key factor of a bot is the strategy that you are going to follow. I prefer to spend some time testing and developing strategies.
Installing freqtrade.
The easiest way of running freqtrade is through docker-compose. Of course, you will need to have docker installed, but this is easily accomplished using the official documentation of docker and docker-compose.
mkdir ft_userdata cd ft_userdata/ # Download the docker-compose file https://raw.githubusercontent.com/freqtrade/freqtrade/stable/docker-compose.yml -o docker-compose.yml # Pull the freqtrade image docker-compose pull # Create user directory structure docker-compose run --rm freqtrade create-userdir --userdir user_data.
There is also the possibility of installing feqtrade traditionally using a bash script or manually installing the necessary dependencies of the project.
sudo apt intall python3.7 sudo apt intall python3.7-dev sudo apt install python3-pip sudo apt install python3-venv git clone https://github.com/freqtrade/freqtrade.git cd freqtrade git checkout stable ./setup.sh -i.
This setup will install everything that we need and will create a Python virtual environment.
source ./.env/bin/activate.
Where to run freqtrade?
Theoretically, you will not stop freqtrade if everything is running correctly. So the best option for running a trading bot is a virtual private server (VPS), in order to be up 24/7. My own choice for VPS is Digital Ocean, great support and prices but you can choose any cloud provider.
Another thing to take into account is to run freqtrade into Linux systems. If you want to install freqtrade into windows the recommended way is to use Windows Subsystem for Linux (WSL).
Config freqtrade.
In order to run freqtrade you will need to set up some configurations. This can be easily done using the new-config command.
# If you are using docker-compose docker-compose run --rm freqtrade new-config --config user_data/config.json # If you are using a traditional installation freqtrade new-config --config user_data/config.json.
new-config is an interactive command that will help us to complete the configuration answering some questions.
Here I am enabling dry-run (simulation), using BTC for buying other cryptocurrencies with an amount of 0.01 BTC and a maximum of 3 open trades. The timeframe uses for taking decisions will be 5m and binary option auto tradig the reporting fiat currency will be USD. Finally, the exchange that I will operate will be Binance.
Enabling Telegram bot.
As mentioned before a cool and useful feature of freqtrade is to use a Telegram bot. This bot will allow us to control the
trading, get alerts and check the status of the trades. After selecting the exchange using new-config we will be asked for a Telegram token and chat id.
A Telegram token can be obtained talking with BotFather inside Telegram and typing /newbot . We will need to name it and then a token will be provided.
Besides this token, we will need to provide a chat id. This chat id is our account id in Telegram. Talking to userinfobot will give us our id.
After finishing this process a config.json will be generated under user_data.
config.json.
With this configuration, we can start to play with the bot in safe mode. All of it will be a simulation. But if we like to start to gamble we will need to change a few things in config.json.
First, we will need to disable dry_run mode and then add the necessary API Keys. These API keys will need to be created into your exchange account. But be aware that these API keys will have trading permissions .
It is a must that your VPS and config.json need to be properly secured. These API keys are very sensitive data. Your VPS server should be properly hardened, perhaps in the future, I will write a guide about this.
freqtrade strategies.
The main core and differences between trading bots are the strategies that are used. freqtrade strategies need to be placed under /user_data/strategies, and you can create your own strategies for
binary option freqtrade bot.
If you do not know about market strategies, there are some open-source strategies on GitHub. We can download these strategies and move it to our /user_data/strategies folder.
git clone
https://github.com/freqtrade/freqtrade-strategies mv freqtrade-strategies/user_data/strategies/berlinguyinca/* /user_data/strategies/
Here are pretty interesting strategies, base on Bollinger Bands, MACD, RSI and binary option auto tradig other trade indicators. But the question is, which of them will generate profit?
Backtesting.
It very uncertain how the market will operate in the future but we can test these strategies with historical data.
The first thing we need to do is to download historical data:
# Data download for "1m" and "5m" timeframes freqtrade download-data # Data download for "1h" timeframe freqtrade download-data -t 1h.
After that we can test our strategies against this data:
freqtrade backtesting --strategy-list ADXMomentum ClucMay72018 MACDStrategy_crossed Simple AdxSmas CMCWinner MACDStrategy ASDTSRockwellTrading CofiBitStrategy SmoothScalp AverageStrategy CombinedBinHAndCluc DoesNothingStrategy Quickie BbandRsi EMASkipPump ReinforcedQuickie --ticker-interval=5m.
This backtesting will generate several metrics. Checking Tot Profit % we can see how several strategies lose a lot of money, like ASDTSRockwellTrading. But others like EMASkipPump or ReinforcedQuickie seems to be promising. Again we can not know how the market will operate in the future with a 100% certainty . But if the markets operate similarly to our data we will obtain gains with these strategies.
Backtesting with 5m ticker interval.
Run the bot.
The last thing to do will be run our bot with the chosen strategy.
# Create user directory structure freqtrade trade --strategy BbandRsi.
Also, remember that if you are using docker-compose you will need to specify the commands using docker-compose run --rm.
# Create user directory structure docker-compose run --rm freqtrade trade --strategy BbandRsi.
Controlling the trading bot.
As mentioned earlier the easiest way of controlling our trading bot is through Telegram. After start freqtrade we can go to our TelegramBot and start to get information.
Every time the bot buy or sell a cryptocurrency we will receive an alert:
And you can also control stop or check the status of the trading bot through Telegram.
Conclusions.