How to make a cryptocurrency trading bot — Part 3
Initial Alertatron setup and BitMex API integration
Quick caveats:
- Not trading advice.
- Some others know bot-building/Pine/etc. better than I.
- I personally have no affiliation with TradingView, Alertatron, exchanges, or any mentioned services.
- Most products I’m showing here I use for several years already.
- You can help this project by registering with the referral links in the post.
Ask everything about bots in My Own Crypto Bot discussions
What we are doing here:
Part zero, why I am doing this
Part One, how to generate signals with open source strategy on TradingView.
Part Two, risk management and leverage settings on BitMex.
From Part One: exchange execution is the second crucial part of your bot. The execution could make your strategy as much profit as on backtests or leave your strategy in losses. This is about commissions, slippage, limit/market orders, and many other tiny but hugely important things. This is the topic for the second tutorial.
After following the steps from Part 1 and Part 2, now we have:
a. Profitable strategy
b. Backtesting results
c. Alerts from this strategy
d. Risk management system
All we need to do now is to set up automatic trading, because we need all this to function by itself.
There’re a lot of automation services, with its positive or negative sides, but we need to choose one. I’ve chosen Alertatron service for our bot, because:
1. I personally use is it for more than six months and absolutely love it.
2. The support telegram channel is fabulously helpful. The developer himself is there almost 24/7.
3. Alertatron is the commercial edition of open source project InstaBot Trader by the same developer, so you can download the project from GitHub and run it on your own server for free using commands from this tutorial.
For automated execution, we need to bind four things.
TradingView — Alertatron — Exchange — Telegram.
How will it work?
When your TradingView script wants to take a trade, TradingView sends an alert to buy or sell with the Alertatron-specific code in it. Alertatron reads the code and talk to the Exchange in exchange-specific API language to execute your orders, set stops, and take profits. When executed, the Exchange tells Alertatron that is all done, and Alertatron sends your Exchange balance status in Telegram (also it has Slack and Discord integration). All this is done in seconds.
What do we need to set up?
- Exchange:
a. Your API keys for sending and closing orders.
2. From TradingView
a. To set up all alerts
b. To paste your “Webhook” link in alert
c. To paste Alertatron-specific code in “Message” window - Alertatron:
a. To add Exchange API keys
b. To set up Trading integration in Inbox
c. Set up a new group and add Telegram integration
d. Set up Alertatron Telegram Bot - Telegram:
abc. A couple of clicks.
Get your API form Bitmex
Register on Bitmex (my referral link gives you 10% discount for fees)
Go to Account preferences
Go to “API Keys”
In API Keys, name your keys as you want. Change Order type to “Order”, this will give you the ability to trade with these keys. Leave the “Withdraw” unchecked for security and push the “Create API Keys” button to see a yellow window.
“Please write down the secret key” window will appear only once, which means that when you’ll close this tab, it’ll disappear. API Keys have the same power as login and password, save them in a safe place.
Copy your ID and Secret for use later. You can close BitMex as we will not return there in this tutorial.
Set up your Alertarton
Go to Alertatron register page, and create an account. To make our bot working without our private server/VPS, fully with the Alertatron cloud, we need to buy a subscription that starts from $15, but the good news is that the starting plan is ok for us.
Click on your username in the top right corner and go to the Billing page.
Choose the “Wolf” plan, for automatic trading, see how much month you plat to run your bot (default is 3 months), and send some money to Alertatron’s developers!
When done, you see that that you alert quota was increased from 20 to 40 alerts or more.
Now is time to add your API Keys from the exchange. Go Automated Trading — Configure API Keys.
Scroll down here and choose BitMex, then write “MyBot” name and your keys. We use real money BitMex account so we don’t check “Use Testnet” tumbler.
Ok, now let’s do some more complicated things and make a new group for our TradingView strategy. It’s good practice to separate different strategies alerts to different Alertatron groups. I’ll show you how to do it next.
Go to Main page — Alerts — + Add new group
Name it Test, then keyword “MyBot” or “MYBoT“, since Alertatron is not case sensitive. Choose “Alerts must contain at least one of the words…” and Create new group.
We are now on the new group page and all incoming messages that were filtered by “MyBot” from TradingView alert message will come there.
Now we need to set up re-forwarding these messages to the actual automated trading engine. Push “plus” button and scroll down to “Trading” bloc. Click Add and Configure.
Read T&Cs and consider all positives and negatives.
Here is the trading window, we are done with this.
Alertatron has a fantastic free Telegram integration
Let’s set up it since we are here. Go to “Test” group page and click “plus” button one more time. Find Telegram integration and click “Add Telegram” button.
Here you can read this steps for Telegram.
You can choose three ways of how to get Telegram notifications: chat directly, make a group with the bot, or add the bot as an additional admin of your channel. All of the setups are similar in steps, so let’s make a simple chat.
Open your Telegram app, find @alertatron_bot in Telegram, and push “Start”.
Alertatron answers you with a welcome message, now write /register and code you see on Alertatron site.
All done in Telegram, now return to the integration page and scroll down to the bottom. Switch “Remove content…” and Save Telegram settings.
Let’s test our Telegram integration with some messages. Go Main — Alerts — Saved & Manual Alerts, write sample message that includes “MyBot” keyword and text below four dashes (there will be the code we want to hide in Telegram messages for cleanness).
For example:
MyBot keyword
— —
This will not be shown
Switch “Send this alert NOW!” and send it.
Return to your Telegram app and see that we have the phrase “MyBot keyword” as a message from Alertatron bot. The “This will not be shown” is hidden as we wanted to.
In this part we made with Alertatron, the last thing is to get the connection link to TradingView. Go to the top right corner and choose “Incoming Alerts”.
Copy this long red link and save it in a safe place. It is the link-key to Alertatron that allows other services to communicate with Alertatron and execute trades through this.
Great! In the next chapter, we’ll write Aletratron-friendly messages and will finish TradingView integration. That will be last step to start to trade automatically!