CryptoCurrency / Docker · October 23, 2021

FreqTrade: Quickly deploy your BOT ARMY!

In this episode, I build upon the last topic around FreqTrade’s integrated Dashboard, and show you how to quickly scale out your army or FreqTrade bots, by storing the container variables as Docker environment variables, so you only have one place you need to make changes, as you copy and deploy your bots rapidly. Check out the video, and when you’re ready, below is the sample code you came here for!

Also, if you’re looking for a great machine to run your fleet of FreqTrade bots on, I highly recommend this small form-factor Intel NUC – this is an amazing price on a rock-solid piece of hardware, in a compact, silent, power-efficient format! Please note this is an affiliate link and I may receive a commission from your purchase. Clicking this link and completing your regular Amazon purchases is an easy no-cost way to support the channel!

YouTube player

Here’s your sample code for your docker-compose.yml file:

version: '3.3'

networks:
  proxy:
    external: true

services:
  freqtrade:
    image: freqtradeorg/freqtrade:develop
    volumes:
      - ./user_data:/freqtrade/user_data
      - /etc/timezone:/etc/timezone:ro
    command: >
      trade
      --logfile /freqtrade/user_data/logs/freqtrade.log
      --config /freqtrade/user_data/config.json
      --strategy ${STRATEGY}
      --db-url sqlite:///user_data/${DATABASE_FILE}
    networks:
      - proxy
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints:
          - node.role == manager
      restart_policy:
        condition: on-failure
        delay: 5s
      labels:
        - 'traefik.http.routers.${BOTNAME}.tls=true'
        - 'traefik.http.routers.${BOTNAME}.rule=Host(`${BOTNAME}.bots.yourdomain.com`)'
        - 'traefik.http.services.${BOTNAME}.loadbalancer.server.port=8080'

In the above sample code, it’s important that you are using a wildcard subdomain in the bots.yourdomain.com placeholder. If you are not familiar, this means you want everything (*) under that namespace to resolve to the IP of your docker host. If you need a refresher on this, check out my Traefik proxy video, I cover this in-depth!

YouTube player

Next, you need the .env file that contains the variables referenced in the sample docker-compose.yml, so, here you go!

BOTNAME=bot001
STRATEGY=BinHV45
DATABASE_FILE=trades.sqlite

The above file should be saved as a hidden “dot file” in the same path with your docker-compose.yml file, as .env

The BOTNAME variable dictates what the fully-qualified name of the deployed bot will be, ie: https://bot001.bots.yourdomain.com

The STRATEGY variable needs to be the exact (case-sensitive) name of your strategy file, which is stored in user_data/strategies folder

Also remember when you’re copying your base FreqTrade folder (this was bot001 in the video, for example), that you want to go in and remove the existing trades.sqlite database, and clear the logs by removing the logs/freqtrade.log file if it exists, after copying, and before deploying

Lastly, you’re probably looking for that command that lets you use .env variables with a docker stack deploy deployed container! Here you go:

docker stack deploy -c <(docker-compose config) stackName

This looks similar to the standard deploy command, however we can see that in place of where we normally reference the docker-compose.yml file, we’re telling it to evaluate that configuration with docker-compose instead! When this runs, it builds the config, evaluating the variables, and then passes that all back to docker stack deploy to complete the deployment.

I hope this is helpful to you! Please give me a thumbs up on the video if you found it useful, subscribe if you’re not already, and leave me a comment if you have questions or thoughts! Thank you!