13

Connecting Hodloo With a 3Commas Bot (API Version)

 2 years ago
source link: https://dev.to/nobbi/connecting-hodloo-with-a-3commas-bot-api-version-4od0
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

This is a follow up to my last article on Hodloo. While last time I explained how to receive Hodloo alerts for USDT pairs, this time I'm showing you how to send the signals to 3Commas and trade hands-free - so you can get rich relaxing on the beach (see the cover image). Just joking, we all know it doesn't work that way, but it is a step in the direction.

Recap

Let's recap what we have when following the other article. We have a Python script running 24/7 on a VPS that parses messages from the official Hodloo API and sends USDT pairs to a Discord channel.

Now, instead of sending alerts to a Discord channel, we want to send them to a bot which does the buying/selling.

Why combining Hodloo with a bot? Why not trade manually?
I'm not doing this full-time. I have a day to day job. Also, the crypto market is running 24/7 and it happened too often in the past that a drop occured while I was asleep or not in front of my computer. By using a bot, I'm participating in the drop immidiatly.

In addition, I suck at trading. I'm FOMOing in all the time with too much size and then carry red bags for months. The bot keeps me away from the trading terminal.

Why 3Commas?
I find it intuitive and easy to work with. I'm using the bot mainly to get in a trade and then taking care of the rest manually. That means I often switch the bot's deal to a smart trade to get out when I want and not at a fixed percentage.

Why do you not use the built-in QFL algos in 3Commas
Because they suck - period. Hodloo bases are way better respected. And I need well-respected bases. I just can't take losses mentally and because of silly tax rules in my country.

Can I run this on my Windows/macOS machine?
Yes. Python is cross-platform. Remember that you need to let the machine running all the time. I don't want that hence I'm using a Linux VPS.

Why is this so complex and why can't I use a public service for this?
It's not available, unfortunately.

Preparing The QFL Bots

Head over to 3Commas and create two multi-pair bots. One for the 5% alerts and one for the 10% alerts. You choose the pairs you want to trade in the bot settings. While the script will send all Hodloo alerts to 3Commas, 3Commas will only create deals for the pairs you've selected in the bots.

You can see that I've chosen six pairs for the bot but max deals is set to four. The bot will start a deal for the first Hodloo alert it receives to a maximum of four deals. Hence not all pairs you've configured will get a deal. First-come first-serve so to say.

You can also choose USDT_ALL. Note that this will include leveraged tokens and stablecoin pairs. Typically, you don't want to trade these and put them on the 3Commas blacklist. But that is cumbersome, instead you may want to use my script to do filter out leveraged tokens and stablecoin pairs. Just read on, it will be explained later.

Your safety order should be double the size of your base order.

Set the deal start condition to manually as the bot receives the signal through the Python script.

I wrote above that I like to get out of a trade manually. But, you have to set the take profit value to something and if it bounces to a 30% profit while I'm asleep - I'm okay with that ;-)

Now the juicy part - the buy layers. The above settings make sure that you get in with a small size and double-down when it goes south.

  • For the 5% bot the deepest layer is around 45% under the base.
  • For the 10% bot the deepest layer is around 50% under the base.

Save and start the bot. On the following page scroll down to the bottom and write down the bot ID. You need that later.

Preparing The Panic Sell Bot

Panic sells are a new Hodloo signal which is not availalbe via the Telegram alerts, but only with the new API. It detects a higher than normal sell off which is often where it bounces. If you have access to the new API, the panic sells are the green arrows in the charts.

Panic sells

I'm currently testing these myself and do not have a best-practice bot setting for you, you have to find it out yourself. So, create a bot and write down the bot ID.

Script Requirements

  1. Copy everything from my GitHub repository to a local folder. I'm using /opt/nobbi/hodloo.
  2. Install required Python libraries for all users:
sudo su
cd ~
pip install -r /opt/nobbi/hodloo/requirements.txt
Enter fullscreen modeExit fullscreen mode
  1. Rename config.py.example to config.py and change the variables. The variables are very well documented in the file itself hence I won't cover this here. For your reference the variables below:
# 3c
TC_API_KEY = ''
TC_API_SECRET = ''
BOT_ID_5 = '' # Bot to start deal for pair 5% under the base. Leave empty if not desired.
BOT_ID_10 = '' # Bot to start deal for pair 10% under the base. Leave empty if not desired.
BOT_ID_PANIC = '' # Bot to start a deal for a panic sell. Leave empty if not desired.
MODE = 'paper' # 'real' or 'paper'
TC_EXCLUDE_LEVERAGED_TOKENS = True # Set to false to trade leveraged tokens. Currently supports excluding Binance and Kucoin leveraged tokens.
TC_DENYLIST = ["USDN/USDT","USDC/USDT","USDJ/USDT","CEUR/USDT","SUSD/USDT"] # Pairs on this list will not be traded.

# Discord
DISCORD_NOTIFICATIONS = '' # Discord Webhook of channel for trade notifications. Leave empty if not desired.
DISCORD_ERRORS = '' # Discord Webhook of channel for script errors. Mandatory.

# Hodloo
HODLOO_URI = '' # Hodloo Websocket API. Request the info from Pete in the Hodloo Discussions Telegram channel as it is private.
HODLOO_EXCHANGES = ["Binance"] # Multiple exchanges -> ["Binance","Kucoin"] Note that only Binance and Kucoin are fully supported at the moment.
Enter fullscreen modeExit fullscreen mode

Saw the variables TC_EXCLUDE_LEVERAGED_TOKENS and TC_DENYLIST? By using these you don't need to click 1,000 times in 3Commas to build a blacklist. I prefer the term denylist btw, it's 2021 after all...

Running The Script

Run the script to see if everything is running as expected: python3 /opt/nobbi/hodloo/hodloo-to-3commas.py

Running the script like above will work but is not very handy because as soon as you close the terminal or the session, the script stops. So we need a way to run the script in the background and also after a server reboot. Check the next chapter on how to achieve this.

Running the Script in Background

We need a way to run the script in the background and also after a server reboot. There are multiple ways to achieve that and the easiest method for Ubuntu I found is using the tool supervisor.

Installing supervisor:

sudo apt-get install supervisor
Enter fullscreen modeExit fullscreen mode

Checking the status of supervisor:

sudo service supervisor status
Enter fullscreen modeExit fullscreen mode

Starting supervisor:

sudo service supervisor start
Enter fullscreen modeExit fullscreen mode

Stopping and restarting supervisor:

sudo service supervisor stop
sudo service supervisor restart
Enter fullscreen modeExit fullscreen mode

Create an entry for the hodloo-to-3commas.py script. The following example uses vi.

sudo vi /etc/supervisor/conf.d/hodloo-to-3commas.conf
Enter fullscreen modeExit fullscreen mode

Contents of the file (change the paths accordingly):

[program:hodloo-to-3commas]
command=python3 -u hodloo-to-3commas.py
directory=/opt/nobbi/hodloo
stdout_logfile=/opt/nobbi/hodloo/hodloo-to-3commas.log
redirect_stderr=true
autorestart=true
Enter fullscreen modeExit fullscreen mode

Configure supervisor:

sudo supervisorctl
reread
add hodloo-to-3commas
status
Enter fullscreen modeExit fullscreen mode

To check whether your python script is running use the following:

sudo ps -axs | grep python
Enter fullscreen modeExit fullscreen mode

Conclusion

Congratulations! You've automated QFL-style trading with Hodloo bases, Python, and 3Commas.

Happy Hodlooing!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK