mirror of
https://github.com/d0zingcat/deploy.git
synced 2026-06-05 07:26:52 +00:00
edit autostart example
This commit is contained in:
@@ -1,33 +1,143 @@
|
|||||||
# Deploy and autostart a single Hummingbot instance with docker Compose
|
# Deploy and Auto-start a single Hummingbot instance with Docker Compose
|
||||||
|
|
||||||
# How to use it
|
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.
|
||||||
|
|
||||||
1. Ensure that you have Docker and Docker Compose installed on your machine.
|
## Prerequisites
|
||||||
2. To autostart, you will need the `config_file` of the strategy and the password already generated.
|
|
||||||
3. **Important:**
|
|
||||||
- In this example, the password generated is `a`, and it was done on a Mac. If you are using a different OS or want to use a different password, make sure to delete the `.password_verification` file under the `conf` folder and follow the instructions in the troubleshooting section.
|
|
||||||
- You can autostart a strategy or a script. In this case, on line `13`, we are autostarting a script that is inside the `scripts` folder. If you want to start a strategy, there is one `config` file under `conf/strategies`. You can change `format_status.py` for `conf_pure_mm_1.yml` to test it!
|
|
||||||
4. Make sure that the compose file on lines `12` and `13` have the correct path to the config file and the password.
|
|
||||||
5. Run the following command:
|
|
||||||
```
|
|
||||||
docker-compose up -d
|
|
||||||
```
|
|
||||||
6. Attach the terminal:
|
|
||||||
```
|
|
||||||
docker attach simple_hummingbot_compose-bot-1
|
|
||||||
```
|
|
||||||
7. Now you have Hummingbot running and autostarted! Remember that you can detach the terminal without stopping the bot by pressing `Ctrl + P` and `Ctrl + Q`.
|
|
||||||
|
|
||||||
## Troubleshooting
|
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.
|
||||||
If you don't have the password, you can:
|
|
||||||
1. Remove lines `12` and `13` from the compose file.
|
Docker Desktop is available on:
|
||||||
2. Start the bot with the following command:
|
|
||||||
```
|
* [Linux](https://docs.docker.com/desktop/install/linux-install/)
|
||||||
docker-compose up -d
|
* [Mac](https://docs.docker.com/desktop/install/mac-install/)
|
||||||
```
|
* [Windows](https://docs.docker.com/desktop/install/windows-install/)
|
||||||
3. Attach the terminal:
|
|
||||||
```
|
|
||||||
docker attach autostart_hummingbot_compose-bot-1
|
## Apple M1/M2 and other ARM machines
|
||||||
```
|
|
||||||
4. Create the password and exit the client.
|
If you have a recent Mac that uses Apple Silicon (M1/M2) chipset or another ARM-based machine, you need to change the image tag to ensure that you pull a container that is optimized for your chip architecture.
|
||||||
5. Add lines `12` and `13` to the compose file and start over!
|
|
||||||
|
Use an IDE like [VSCode](https://code.visualstudio.com/) to edit the `docker-compose.yml` file. Change the the image tag from `latest` to `latest-arm` to pull the image built for ARM-based machines. You can also comment out the line that contains `latest` and uncomment the line that contains `latest-arm`:
|
||||||
|
```
|
||||||
|
# image: hummingbot/hummingbot:latest
|
||||||
|
image: hummingbot/hummingbot:latest-arm
|
||||||
|
```
|
||||||
|
|
||||||
|
Afterwards, save the file and proceed to the next step.
|
||||||
|
|
||||||
|
If you are using a Mac with an Intel (x86) chipset, Windows or any other Intel-based machine, you don't need to make any changes before deploying a container.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
If you have installed Docker Compose successfully, the `docker-compose` command should be available in Terminal/Bash:
|
||||||
|
```
|
||||||
|
docker-compose
|
||||||
|
|
||||||
|
Usage: docker compose [OPTIONS] COMMAND
|
||||||
|
```
|
||||||
|
|
||||||
|
Clone this repo or copy the `docker-compose.yml` file to a directory on your machine where you want to store your Hummingbot files. This is where your encrypted keys, scripts, trades, configs, logs, and other files related to your bots will be saved.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Auto-starting a script/strategy lets you start a bot from the command line, skipping the Hummingbot UI. However, before you can auto-start a script or strategy, you will do need two things first:
|
||||||
|
1. Set the password used to encrypt your keys (`CONFIG_PASSWORD`)
|
||||||
|
2. Define your script or strategy config file (`CONFIG_FILE_NAME`)
|
||||||
|
|
||||||
|
The sample `docker-compose.yml` contains dummy values for these variables. Let's fill them in!
|
||||||
|
|
||||||
|
### Setting the Hummingbot password
|
||||||
|
|
||||||
|
Start the bot with the following command:
|
||||||
|
```
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
You should see the following output:
|
||||||
|
```
|
||||||
|
[+] Running 1/1
|
||||||
|
⠿ Container autostart_hummingbot_compose-bot-1 Started
|
||||||
|
```
|
||||||
|
|
||||||
|
After it has started, attach to the instance:
|
||||||
|
```
|
||||||
|
docker attach autostart_hummingbot_compose-bot-1
|
||||||
|
```
|
||||||
|
|
||||||
|
If installation was successful, you should see the Hummingbot welcome screen:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Set your Hummingbot [password](https://docs.hummingbot.org/operation/password/) and write it down. This is the `CONFIG_PASSWORD` environment variable in your `docker-compose.yml` file.
|
||||||
|
|
||||||
|
### Defining your script or strategy
|
||||||
|
|
||||||
|
You can auto-start either a [Script](https://docs.hummingbot.org/scripts/) or a [Strategy](https://docs.hummingbot.org/strategies/).
|
||||||
|
|
||||||
|
Scripts are Python files that contain all strategy logic. If you define a `.py` file as `CONFIG_FILE_NAME`, Hummingbot assumes it's a script file and looks for the `.py` file in the `scripts` directory. See `scripts/simple_pmm_example.py` for an example.
|
||||||
|
|
||||||
|
Strategies are configurable strategy templates. If you define a `.yml` file as `CONFIG_FILE_NAME`, Hummingbot assumes it's a strategy config file and looks for the `.yml` file in the `conf/strategies` directory. See `conf/strategies/conf_pure_mm_1.yml` for an example.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Now, use an IDE like [VSCode](https://code.visualstudio.com/) to edit the `docker-compose.yml` file.
|
||||||
|
|
||||||
|
Uncomment out the lines that define the `CONFIG_PASSWORD` and `CONFIG_FILE_NAME` environment variables:
|
||||||
|
```yaml
|
||||||
|
# environment:
|
||||||
|
# - CONFIG_PASSWORD=[your-password]
|
||||||
|
# - CONFIG_FILE_NAME=simple_pmm_example.py
|
||||||
|
# - CONFIG_FILE_NAME=conf_pure_mm_1.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
Uncomment the `environment:` line, the `CONFIG_PASSWORD` line and add the password you set earlier, and one of `CONFIG_FILE_NAME` lines. Then, replace `CONFIG_PASSWORD` and `CONFIG_FILE_NAME` with the values you defined above. The final section of the file should look like this:
|
||||||
|
```yaml
|
||||||
|
environment:
|
||||||
|
- CONFIG_PASSWORD=[your-password]
|
||||||
|
- CONFIG_FILE_NAME=simple_pmm_example.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Afterwards, save the file. Now, the script or strategy will auto-start when you create the container:
|
||||||
|
```
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Useful Docker Commands
|
||||||
|
|
||||||
|
Use the commands below or use the Docker Desktop application to manage your Hummingbot container:
|
||||||
|
|
||||||
|
### Create the container
|
||||||
|
```
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
### Attach to the container
|
||||||
|
```
|
||||||
|
docker attach autostart_hummingbot_compose-bot-1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Detach from the container and return to command line
|
||||||
|
|
||||||
|
Press keys <kbd>Ctrl</kbd> + <kbd>P</kbd> then <kbd>Ctrl</kbd> + <kbd>Q</kbd>
|
||||||
|
|
||||||
|
|
||||||
|
### Update the container to the latest image
|
||||||
|
```
|
||||||
|
docker-compose up --force-recreate --build -d
|
||||||
|
```
|
||||||
|
|
||||||
|
### List all containers
|
||||||
|
```
|
||||||
|
docker ps -a
|
||||||
|
```
|
||||||
|
|
||||||
|
### Stop a container
|
||||||
|
```
|
||||||
|
docker stop <instance-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Remove a container
|
||||||
|
```
|
||||||
|
docker rm <instance-name>
|
||||||
|
```
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ version: "3.9"
|
|||||||
services:
|
services:
|
||||||
bot:
|
bot:
|
||||||
image: hummingbot/hummingbot:latest
|
image: hummingbot/hummingbot:latest
|
||||||
|
# image: hummingbot/hummingbot:latest-arm
|
||||||
volumes:
|
volumes:
|
||||||
- "./hummingbot_files/conf:/conf"
|
- "./hummingbot_files/conf:/conf"
|
||||||
- "./hummingbot_files/conf/connectors:/conf/connectors"
|
- "./hummingbot_files/conf/connectors:/conf/connectors"
|
||||||
@@ -10,9 +11,10 @@ services:
|
|||||||
- "./hummingbot_files/data:/data"
|
- "./hummingbot_files/data:/data"
|
||||||
- "./hummingbot_files/scripts:/scripts"
|
- "./hummingbot_files/scripts:/scripts"
|
||||||
- "./hummingbot_files/certs:/certs"
|
- "./hummingbot_files/certs:/certs"
|
||||||
environment:
|
# environment:
|
||||||
- CONFIG_PASSWORD=a
|
# - CONFIG_PASSWORD=[your-password]
|
||||||
- CONFIG_FILE_NAME=format_status.py
|
# - CONFIG_FILE_NAME=simple_pmm_example.py
|
||||||
|
# - CONFIG_FILE_NAME=conf_pure_mm_1.yml
|
||||||
logging:
|
logging:
|
||||||
driver: "json-file"
|
driver: "json-file"
|
||||||
options:
|
options:
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ market: ETH-USDT
|
|||||||
# Spread of 1 = 1% away from mid price at that time.
|
# Spread of 1 = 1% away from mid price at that time.
|
||||||
# Example if mid price is 100 and bid_spread is 1.
|
# Example if mid price is 100 and bid_spread is 1.
|
||||||
# Your bid is placed at 99.
|
# Your bid is placed at 99.
|
||||||
bid_spread: 1.0
|
bid_spread: 0.1
|
||||||
|
|
||||||
# How far away from mid price to place the ask order.
|
# How far away from mid price to place the ask order.
|
||||||
# Spread of 1 = 1% away from mid price at that time.
|
# Spread of 1 = 1% away from mid price at that time.
|
||||||
# Example if mid price is 100 and ask_spread is 1.
|
# Example if mid price is 100 and ask_spread is 1.
|
||||||
# Your bid is placed at 101.
|
# Your bid is placed at 101.
|
||||||
ask_spread: 1.0
|
ask_spread: 0.1
|
||||||
|
|
||||||
# Minimum Spread
|
# Minimum Spread
|
||||||
# How far away from the mid price to cancel active orders
|
# How far away from the mid price to cancel active orders
|
||||||
@@ -29,7 +29,7 @@ minimum_spread: -100.0
|
|||||||
|
|
||||||
# Time in seconds before cancelling and placing new orders.
|
# Time in seconds before cancelling and placing new orders.
|
||||||
# If the value is 60, the bot cancels active orders and placing new ones after a minute.
|
# If the value is 60, the bot cancels active orders and placing new ones after a minute.
|
||||||
order_refresh_time: 10.0
|
order_refresh_time: 15.0
|
||||||
|
|
||||||
# Time in seconds before replacing existing order with new orders at the same price.
|
# Time in seconds before replacing existing order with new orders at the same price.
|
||||||
max_order_age: 1800.0
|
max_order_age: 1800.0
|
||||||
@@ -39,7 +39,7 @@ max_order_age: 1800.0
|
|||||||
order_refresh_tolerance_pct: 0.0
|
order_refresh_tolerance_pct: 0.0
|
||||||
|
|
||||||
# Size of your bid and ask order.
|
# Size of your bid and ask order.
|
||||||
order_amount: 0.5
|
order_amount: 0.1
|
||||||
|
|
||||||
# Price band ceiling.
|
# Price band ceiling.
|
||||||
price_ceiling: -1.0
|
price_ceiling: -1.0
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
from hummingbot.strategy.script_strategy_base import ScriptStrategyBase
|
|
||||||
|
|
||||||
|
|
||||||
class FormatStatusExample(ScriptStrategyBase):
|
|
||||||
"""
|
|
||||||
This example shows how to add a custom format_status to a strategy and query the order book.
|
|
||||||
Run the command status --live, once the strategy starts.
|
|
||||||
"""
|
|
||||||
markets = {
|
|
||||||
"binance_paper_trade": {"ETH-USDT"},
|
|
||||||
"kucoin_paper_trade": {"ETH-USDT"},
|
|
||||||
"gate_io_paper_trade": {"ETH-USDT"},
|
|
||||||
}
|
|
||||||
|
|
||||||
def format_status(self) -> str:
|
|
||||||
"""
|
|
||||||
Returns status of the current strategy on user balances and current active orders. This function is called
|
|
||||||
when status command is issued. Override this function to create custom status display output.
|
|
||||||
"""
|
|
||||||
if not self.ready_to_trade:
|
|
||||||
return "Market connectors are not ready."
|
|
||||||
lines = []
|
|
||||||
warning_lines = []
|
|
||||||
warning_lines.extend(self.network_warning(self.get_market_trading_pair_tuples()))
|
|
||||||
|
|
||||||
balance_df = self.get_balance_df()
|
|
||||||
lines.extend(["", " Balances:"] + [" " + line for line in balance_df.to_string(index=False).split("\n")])
|
|
||||||
market_status_df = self.get_market_status_df_with_depth()
|
|
||||||
lines.extend(["", " Market Status Data Frame:"] + [" " + line for line in market_status_df.to_string(index=False).split("\n")])
|
|
||||||
|
|
||||||
warning_lines.extend(self.balance_warning(self.get_market_trading_pair_tuples()))
|
|
||||||
if len(warning_lines) > 0:
|
|
||||||
lines.extend(["", "*** WARNINGS ***"] + warning_lines)
|
|
||||||
return "\n".join(lines)
|
|
||||||
|
|
||||||
def get_market_status_df_with_depth(self):
|
|
||||||
market_status_df = self.market_status_data_frame(self.get_market_trading_pair_tuples())
|
|
||||||
market_status_df["Exchange"] = market_status_df.apply(lambda x: x["Exchange"].strip("PaperTrade") + "paper_trade", axis=1)
|
|
||||||
market_status_df["Volume (+1%)"] = market_status_df.apply(lambda x: self.get_volume_for_percentage_from_mid_price(x, 0.01), axis=1)
|
|
||||||
market_status_df["Volume (-1%)"] = market_status_df.apply(lambda x: self.get_volume_for_percentage_from_mid_price(x, -0.01), axis=1)
|
|
||||||
return market_status_df
|
|
||||||
|
|
||||||
def get_volume_for_percentage_from_mid_price(self, row, percentage):
|
|
||||||
price = row["Mid Price"] * (1 + percentage)
|
|
||||||
is_buy = percentage > 0
|
|
||||||
result = self.connectors[row["Exchange"]].get_volume_for_price(row["Market"], is_buy, price)
|
|
||||||
return result.result_volume
|
|
||||||
Reference in New Issue
Block a user