Email Bot

From Haasonline Software Wiki
Jump to: navigation, search

The Email Bot can be used to integrate with TradingView's email alerts. It will fetch emails and compare them with predefined messages. If there is a match it will execute a defined action.

Restriction

  • Unable to backtest.

Email Provider setup guide:

  1. Prepare subscription and a main account that you use to login to TradingView
  2. Create a new Gmail address dedicated for the bots.
    (important step, because using your main email for this would cause lots of inconvenience)
  3. Enable "Less secure apps" in your new account
    (make sure that you are logged in the correct Gmail account when doing this)
  4. Add the dedicated email credentials as a provider in Settings - Email Providers:
    • Name: name of this Email Provider (can be anything)
    • Email: your new Gmail address (e.g. [email protected])
    • Password: the password of Gmail account above
    • Approved Contacts: sender emails which are allowed to be used as signals (e.g. [email protected])
      (if left empty, emails from any sender will be used as potential signals)
  5. Create a filter on your main email account to forward emails from TradingView to your new dedicated account.
  6. Restart the HTS.
  7. You are ready to setup alerts and bots.

Important note: adding an Email Provider creates a "Processed Signals" label in that email.
Deleting this label will make the bot work incorrect which will lead to losses. Do not delete this label!

Positive Notes

  • Multiple emails coming in for different Email Bots simultaneously are handled just fine (tested max - 9, but potentially there is no limit)
  • You can combine multiple signals for 1 action. If all the signal are received within X seconds, the action will be executed.
  • Can be used with any signal provider (not only TradingView) as long as they can send emails
  • You can run multiple bots on the same signal email.
  • No limit on the number of signals per bot.
  • Spot, Margin & Leverage.

Negative Notes

  • You need to enable "less secure apps" on your account. Hence the recommendation for creating new Email specifically for the bot.
  • You can't use the same alert for triggering 2 different bots. Use different alert text for each bot.

Performance

  • General performance in different market conditions depends entirely on the strategy that you choose that will be giving commands to the Email Bot. (For example, the TradingView script or a combination of scripts/indicators that you use as the source of the email alerts)
  • If the exchange is overloaded or for some other reason does not accept the order, the bot will not try to resubmit the order, it will wait for another email signal to come. However, Order Persistence Bot Extension solves this problem very well.

Parameters

In the trade settings section you can set the trade amount limits for the bot. You can also set the order type for the bot.

Coin position indicates which position you are starting with.

  • For margin/leverage this usually is set to No Position, unless you already have entered a long/short position and want the bot to manage it further.
  • For spot market it can be Sold, which indicates you are in the secondary (base) currency or it can be Bought, which means you now have the first currency, i.e. ETH in ETHUSD pair.
  • If you have both first and second currency then you can select either of the starting coin position options.

When a bot makes a trade later on, the coin position will change here automatically.

Trade Amount Type has 3 options:

  1. Static (adjusted for fees) - will trade whatever amount is set in the "Trade Amount" field. If the amount in the wallet is less than trade amount, it will stop trading and will display message "Trade Amount too high" and the dollar sign of the Trade Settings button will light up red.
  2. All-in - this option will trade 99% of what total of the capital there is in the wallet. Be careful, as you can run into an unexpected situation where you start a bot to trade 10 ETH that you have in the wallet. The bot would sell 9.9 ETH and get for example $4000 for them. Now next step is where the problem can arise. If you have any more USD other than those $4000, the bot will sell 99% of all USD and buy as much ETH as it can with it.
  3. Maximum Trade Amount - is probably the best choice for most traders. It is kind of a mix between Static and All-in. It will trade whatever the amount is set in Trade Amount field, but if there is less funds available, it will not stop trading and instead trade with 99% of what is available. If it has enough funds later on, it will start again trying to sell/buy the original amount that was set by user.

Entering/exiting position decision

EmailParameters.png


Minimum Price Change To Buy When the bot has sold, the price needs to drop a determined percentage in order to buy again. When set on 0% this safety is ignored.

Maximum Price Change To Sell After the bot has bought, the price needs to rise to a determined percentage in order to sell again. When set on 0% this safety is ignored.

Stop Loss After the bot has bought, and the price drops a determined percentage, the bot will execute a sell order. When set on 0% this safety is ignored.

Email Actions

EmailActions.png


EditActions.png


Providers HTS support emails from multiple email addresses. With the provider filter you can specify which email address the bot reacts to.

Action Action to perform when an email is a match.

Timeout When using multiple signals, the timeout allows a certain timespan between the emails. If all the messages are received before the timeout, the action is executed.

Message A message can be defined in 3 way:

- Exact match (case insensitive)
- Wildcard. Use an * as a wild card. For example: *Sell_BTC_USDT_1
- Regular expressions. For example: .*Sell_BTC_USDT_1

Tradingview Alert Guide

TradingView has a great collection of alerts users can utilize. Ranging from simple price alerts to indicator crosses. This guide will show you how to create a price alert and a indicator alert for the bot to act on.

Price alerts

  1. Go to www.tradingview.com and select the market you wish to trade on (Bitstamp BTC/USD for example)..
  2. Click on alert in the header. A new popup will show with the configuration settings.
  3. In the Condition section, change “Crossing” to “Crossing up” and change the value to the price on which the alert should fire. $10.000 for example.
  4. Make sure “Send Email” is enabled.
  5. Change the message to something unique. BOT_1_BUY_BTC for example and hit save. When the price break 10.000 USD, Tradingview will send you a email with this a subject: TradingView Alert: BOT_1_BUY_BTC
  6. Go to the Email bot in HTS and add an action. Select the action you want to perform once the price reached 10.000 USD (buy for example). In the message section add the subject defined in 5.
  7. Save the action and start the bot.

The bot will wait for an email to be received where the subject matched the one we have defined. Once that email is received the bot will place a buy order at the current price.

Indicator alerts

  1. Go to www.tradingview.com and select the market you wish to trade on (Bitstamp BTC/USD for example).
  2. Click on “Indicator” in the header and add an indicator (MA for example). Modify the indicator settings if needed.
  3. Click on alert in the header. A new popup will show with the configuration settings.
  4. In the Condition section, change “Crossing” to “Crossing up” and select the indicator in the “Value” dropdown.
  5. Make sure “Send Email” is enabled.
  6. Change the message to something unique. BOT_1_MA_UP_BTC for example and hit save. When the MA crossed over, Tradingview will send you an email with this a subject: TradingView Alert: BOT_1_MA_UP_BTC
  7. Add a second alert, but change “Crossing” to “Crossing down”. Make sure the message is unique again. BOT_1_MA_DOWN_BTC for example.
  8. Go to the Email bot in HTS and add an action. Select the action you want to perform once the MA has crossed over (buy for example). In the message section, add the subject defined in 5.
  9. Save the action and add a second action to sell once the MA has crossed down.
  10. Start the bot.

The bot will wait for an email to be received where the subject matched the one we have defined. Once that email is received the bot will place a buy or sell order at the current price depending on the coin position of the bot and the email received.

Troubleshooting

If you can't add an Email Provider, here are the common reasons:

  1. There is a typo in password or email. Please check that the password and email address are correct. Also, note that Haas Email Bot currently only supports Gmail.
  2. Less Secure Apps was not enabled or was enabled on the wrong Gmail account. Please go back to the Less Secure Apps page and make sure in the top right corner that you are currently working from the correct Google account, and then enable "Less Secure Apps".
  3. VPS is in another country, so Google denied access and sent a "Security Alert" email, in this case you will need to open that email, click "Check Activity", then click on the Unknown Device and select "it is me" or similar. Make sure that the time and location of the of the access from the VPS matches that of the Unknown Device!

If you have set up the bot and it is activated, the emails are coming in, but nothing happens, here are the most common problems:

  1. You possibly forgot to restart HTS after adding or editing an Email Provider. To solve, simply restart the HTS and reselect the Email Provider inside the Actions of an Email Bot.
  2. The text of the Action and that inside the email don't match. For it to match one often needs to add asterisk in the beginning of the text, like *long-xrpbtc-4h (on HTS side, not on TV side), to substitute the "TradingView Alert:" part with asterisk.
  3. Wrong coin position. If for example the emails coming in call for buying (longing), but the Coin (Funds) Position of the bot is already Bought (Long), it won't react to the buy signals. However, you will be able to see a message describing exactly this happening in the logbook of the Email Bot.
  4. Approved Contacts are wrong or have a typo in them. Check your Approved Contacts for typos. Also, it's good to know that when using a filter for forwarding in Gmail, the displayed sender (thus the email that should be entered as Approved Contact) will be the original sender (for example, [email protected]), not the forwarding account.
  5. If the exchange is often overloaded or for some other reason the order fails to reach the exchange, the bot will will not try to resubmit the order, it wait for another email signal. Order Persistence Bot Extension solves this problem very well.
  6. If you are running your HTS on Linux and the Email Bot does not take any action towards the signals that it has processed, please ensure that you have installed mono-vbnc on your machine.
sudo apt install mono-vbnc