refactor deploy-examples repo

This commit is contained in:
david-hummingbot
2024-04-23 10:06:08 +00:00
parent b8fb57de47
commit 7032ff8f69
27 changed files with 207 additions and 2083 deletions

256
README.md
View File

@@ -1,83 +1,241 @@
# Deploying Hummingbot with Docker
# Deploy Multiple Hummingbot Instances with different profiles
## Intro
This guide explains how to install two [Hummingbot](https://github.com/hummingbot/hummingbot) instances. You can choose to configure the bots to use either a **master_account** or **sub_accounts** for credentials and API keys. This feature is particularly useful if you manage multiple API keys or have set up subaccounts on exchanges and wish for an easy method to switch between them.
This repository provides various examples of how to deploy Hummingbot using Docker Compose. [Hummingbot](https://github.com/hummingbot/hummingbot) is an open source framework that helps you build automated trading strategies, or bots that run on cryptocurrency exchanges, and [Docker Compose](https://docs.docker.com/compose/) is a tool for defining and running multi-container Docker applications
## Prerequisites
It also contains standalone bash scripts that assist you to setting up Hummingbot with Docker, but we recommend using Docker Compose instead.
This configuration requires [Docker Compose](https://docs.docker.com/compose/), a tool for defining and running multi-container Docker applications. The recommended way to get Docker Compose is to install [Docker Desktop](https://www.docker.com/products/docker-desktop/), which includes Docker Compose along with Docker Engine and Docker CLI which are Compose prerequisites.
See [Docker](./DOCKER.md) for more information about how to install and use Docker.
See [Docker](../DOCKER.md) for more information about how to install and use Docker Compose, as well as helpful commands.
## How do I use this repo?
## Getting Started
Each folder showcases a different deployment type using Docker Compose, such as:
* A single Hummingbot instance along with a dashboard that analyzes it
* A single Hummingbot instance that auto-starts a strategy or script
* Linked Hummingbot and Gateway instances
* Multiple instances of Hummingbot
Verify that Docker Compose is installed correctly by checking the version:
The important files in each folder are:
* `docker-compose.yml`: A sample configuration file for that deployment type.
* `README.md`: A detailed README file that guides users through the steps required to deploy Hummingbot using Docker, including how to build and run the containers, how to configure the bot, and how to monitor its performance.
```bash
docker compose version
```
The output should be: `Docker Compose version v2.17.2` or similar. Ensure that you are using Docker Compose V2, as V1 is deprecated.
## 1. Clone the **deploy-examples** repo
Clone the repository to your machine and navigate to the folder:
```
git clone https://github.com/hummingbot/deploy-examples.git
cd deploy-examples
```
## 2. Initial Configuration
### Create sub_account folder
By default, both bots will utilize the **master_account**. However, to configure the first bot with the **master_account** and the second bot with a **sub_account**—using a different Hummingbot password and API keys from the **master account**—follow the instructions below:
Create a new folder named **sub_account** under the **/credentials** folder, resulting in two folders:
```
deploy-examples/
├── credentials/
│ ├── master_account/
│ └── sub_account/
```
### Modify the Docker Compose file
Edit the Docker Compose file, updating the **bot_2** section to redirect the credentials folder to the newly created **sub_account** folder. Also, comment out the **environment** and **CONFIG_PASSWORD** fields for now, as we will be updating the password.
```bash hl_lines="5-6 12"
bot_2:
container_name: bot_2
image: hummingbot/hummingbot:development
volumes:
- ./credentials/sub_account:/home/hummingbot/conf
- ./credentials/sub_account/connectors:/home/hummingbot/conf/connectors
- ./instances/bot_2/logs:/home/hummingbot/logs
- ./instances/bot_2/data:/home/hummingbot/data
- ./conf/scripts:/home/hummingbot/conf/scripts
- ./conf/controllers:/home/hummingbot/conf/controllers
# environment:
# - CONFIG_PASSWORD=a
# - CONFIG_FILE_NAME=v2_generic_with_controllers.py
# - SCRIPT_CONFIG=conf_v2_generic_with_contorllers_2.yml
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: 5
tty: true
stdin_open: true
```
Save your changes
### Launch Hummingbot
From the root folder, run the following command to download the image and start the instances:
After you have configured it properly, each deployment can be launched with the command:
```
docker compose up -d
```
## Deployment types using Docker Compose
Upon successful download, you should see an output similar to:
```
[+] Running 4/4
⠿ Network multiple_bots_setup Created
⠿ Container bot_1 Started
⠿ Container bot_2 Started
```
### [Hummingbot with Dashboard](./hummingbot_with_dashboard)
Both bots will be running but we will need to configure **bot_2** first so we will need to attach to it
⭐️⭐️⭐️ We recommend that new Hummingbot users follow this route ⭐️⭐️⭐️
```
docker attach bot_2
```
This installs a single [Hummingbot](https://github.com/hummingbot/hummingbot) instance with a companion [Hummingbot Dashboard](https://github.com/hummingbot/dashboard) running.
Set your preferred password for the **sub_account**, using **b** as an example. After setting the password, proceed to enter the API keys for your sub-accounts. Once completed, exit the Hummingbot client with:
### [Simple Hummingbot Compose](./simple_hummingbot_compose)
```
exit
```
This installs a single [Hummingbot](https://github.com/hummingbot/hummingbot) instance as a Docker container.
Then use **docker compose down** to exit out all the running instances
### [Autostart Hummingbot Compose](./autostart_hummingbot_compose)
This installs a single [Hummingbot](https://github.com/hummingbot/hummingbot) instance as a Docker container and automatically starts running a pre-configured script or strategy.
```
docker compose down
```
### [Hummingbot Gateway Compose](./hummingbot_gateway_compose)
### Update Docker Compose configuration
This installs a [Hummingbot](https://github.com/hummingbot/hummingbot) instance linked to a [Hummingbot Gateway](https://github.com/hummingbot/gateway) instance.
Edit the Docker Compose file again to enable auto-start with the new password. Uncomment the **environment** section and the **CONFIG_PASSWORD**, setting the password for **bot_2** as "**b**":
### [Multiple Hummingbot Gateway Compose](./multiple_hummingbot_gateway_compose)
```bash hl_lines="5-6 12"
bot_2:
container_name: bot_2
image: hummingbot/hummingbot:development
volumes:
- ./credentials/sub_account:/home/hummingbot/conf
- ./credentials/sub_account/connectors:/home/hummingbot/conf/connectors
- ./instances/bot_2/logs:/home/hummingbot/logs
- ./instances/bot_2/data:/home/hummingbot/data
- ./conf/scripts:/home/hummingbot/conf/scripts
- ./conf/controllers:/home/hummingbot/conf/controllers
environment:
- CONFIG_PASSWORD=b
# - CONFIG_FILE_NAME=v2_generic_with_controllers.py
# - SCRIPT_CONFIG=conf_v2_generic_with_contorllers_2.yml
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: 5
tty: true
stdin_open: true
This installs two [Hummingbot](https://github.com/hummingbot/hummingbot) instances, linked to a single [Hummingbot Gateway](https://github.com/hummingbot/gateway) instance.
```
### [Hummingbot Gateway Broker Compose](./hummingbot_gateway_broker_compose)
### Relaunch Hummingbot
This installs a [Hummingbot](https://github.com/hummingbot/hummingbot) instance linked to a [Hummingbot Gateway](https://github.com/hummingbot/gateway) instance, along with an EMQX [Broker](https://github.com/hummingbot/brokers).
After saving the updates to the Docker Compose file, restart the bots by running:
!!! note "Experimental deployment"
This deployment is still undergoing testing, so we recommend using the standalone deployments for message brokers from the [hummingbot/brokers](https://github.com/hummingbot/brokers) repository.
```
docker compose up -d
```
## [Bash scripts (older)](./bash_scripts)
These standalone bash scripts can also assist you to setting up Hummingbot and Gateway with Docker, but we recommend using Docker Compose instead.
To attach to any container use
The following operations are possible using the bash scripts:
```
docker attach [container name]
```
- Create a Hummingbot container
- Update the Hummingbot image version
- Start a stopped container of Hummingbot
- Create a Gateway container
- Copy the certificates to the corresponding gateway path
## Other Hummingbot Repos
### Adding more bots
Following this configuration, you can add more bots with different credentials by simply adjusting the **credentials** folder and **CONFIG_PASSWORD** field as needed. For instance, to add a third bot using **sub_account** credentials, append the Docker Compose file accordingly.
```bash hl_lines="1-2 5-6 12"
bot_3:
container_name: bot_3
image: hummingbot/hummingbot:development
volumes:
- ./credentials/sub_account:/home/hummingbot/conf
- ./credentials/sub_account/connectors:/home/hummingbot/conf/connectors
- ./instances/bot_2/logs:/home/hummingbot/logs
- ./instances/bot_2/data:/home/hummingbot/data
- ./conf/scripts:/home/hummingbot/conf/scripts
- ./conf/controllers:/home/hummingbot/conf/controllers
environment:
- CONFIG_PASSWORD=b
# - CONFIG_FILE_NAME=v2_generic_with_controllers.py
# - SCRIPT_CONFIG=conf_v2_generic_with_contorllers_2.yml
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: 5
tty: true
stdin_open: true
```
Here we added the name of the new bot to **bot_3**, made sure the credentials volume is mapped to the **sub_account** folder and set the autostart password for **sub_account** which is **b**
## Updating to the Latest Version of Hummingbot
Hummingbot and Hummingbot Gateway are updated on a monthly basis, with each new version marked by a code release on Github and DockerHub, accompanied by the publication of comprehensive release notes. To upgrade to the most recent version, you just need to pull the `latest` Docker images.
Follow the steps below to upgrade your Hummingbot system:
1. **Ensure no containers are running**
Before you initiate the update process, it is crucial to verify that no Docker containers are currently running. Use the following command to shut down any active containers:
```
docker compose down
```
2. **Fetch the latest Docker image**
Once you have confirmed that no containers are running, proceed to pull the latest Docker image. Use the following command to accomplish this:
```
docker pull hummingbot/hummingbot
```
3. **Start the updated containers**
Having pulled the latest Docker image, you can now start up your containers. They will be running the latest version of Hummingbot. Use the following command to start the containers:
```
docker compose up -d
```
With these steps, you will have successfully updated your Hummingbot to the latest version.
## Deleting unused Docker images
Use the below command to manually remove unused Docker images and free up space
```
docker rmi [image_name]
```
To remove all unused images, not just dangling ones, you can use:
```
docker image prune -a
```
This command removes all images without at least one container associated with them. Use it with caution, as it can remove images that you may wish to keep.
* [Hummingbot Docs](https://github.com/hummingbot/hummingbot-site): Official documentation for Hummingbot - we welcome contributions here too!
* [Awesome Hummingbot](https://github.com/hummingbot/awesome-hummingbot): All the Hummingbot links
* [Hummingbot StreamLit Apps](https://github.com/hummingbot/streamlit-apps): Hummingbot-related StreamLit data apps and dashboards
* [Community Tools](https://github.com/hummingbot/community-tools): Community contributed resources related to Hummingbot
* [Brokers](https://github.com/hummingbot/brokers): Different brokers that can be used to communicate with multiple instances of Hummingbot
* [Deploy Examples](https://github.com/hummingbot/deploy-examples): Deploy Hummingbot in various configurations with Docker
* [Remote Client](https://github.com/hummingbot/hbot-remote-client-py): A remote client for Hummingbot in Python
## Contributions
Hummingbot belongs to its community, so we welcome contributions! Users are encouraged to submit pull requests with their own examples and use cases for deploying Hummingbot with Docker.