Skip to main content

Tradingview Webhooks

With Gunbot webhooks, you can send a POST request to a specific URL every time a Tradingview alert is triggered. This functionality can be enabled when creating or modifying alerts within your Tradingview.com Chart. By entering your Gunbot public IP, Tradingview.com will immediately send a request as soon as an Alert is triggered.

Webhooks configuration

Click on the 3 dots in the Header and select Tradingview alerts.

Now, navigate to the Webhooks tab and enter the port number.

The port has to be 443 as a secure SSL connection is required.

In the webhooks passphrase field, enter a password. This password should be unique, contain alphanumeric and special characters to prevent anyone from having access to your webhooks listener endpoint. This passphrase has to will have to be used everytime for tradingview when it sends the alerts to your Gunbot.

Once you have entered all the required details, remember to click the Save Changes button in the header to save your configuration.

TradingView - How to create the alert

To create an alert in your TradingView account, you need to first open the desired chart. Once the chart is open, simply right-click and select the type of alert you want to create. Alerts are typically used in conjunction with specific strategies, which can be created using Pinecode or premium indicators. Many indicators in the market are pre-configured to place alerts based on their specific strategy conditions.

Enabling Webhooks

To enable Tradingview.com to send alerts over webhooks to your Gunbot, you'll have to check the Webhook URL checkbox and enter the following:

https://123.456.78.9:443

Where:

  • https:// - The secure http protocol, encrypted
  • 123.456.78.9 - The IP address of your Gunbot (change this to the appropriate value)
  • :443 - The port

In the message textbox you'll have to fill the contents of the webhook to send to Gunbot in case this specific condition from your Indicator/Script/... has been met:

  • The passcode for the webhook authorisation, which you've defined previously in the webhooks configuration step
  • The exchange you want Gunbot to execute the alert on (NOTE: this has to be one of your licensed exchanges)
  • The type of the trade (buy, sell, long, short, close)
  • The pair you would like to trade
  • The amount you would like per trade. Defined in quote (example: 0.02)
  • The price you would like to execute the alert. This can be used to place limit orders, however as alerts are meant to be used quite quickly, use 0 and Gunbot will execute market orders

The full structure of the message looks like this:

passcode exchange type pair amount price

info

You can find out more about the webhooks alert structure in the Gunbot Docs.

The alert will be executed as soon as Gunbot receives it.

Networking and Security Configuration

To ensure proper operation, it is necessary to enable port 443 in your computer's firewall/router. The specific steps may vary depending on the operating system or router interface you are using. Since port 443 is typically locked, it is essential to open it in both the firewall/router and the computer running Gunbot. If Gunbot is being used from home, you will also need to enable NAPT and route the WAN port 443 to the private IP of the computer.

For Windows

  • Open Windows Defender Firewall with Advanced Security
  • Click on Inbound Rules in the left panel - Add a new rule and select Port
  • Next, select TCP and type 443 for the port

  • Select Allow the connection and click Next
  • Give the newly created Rule a name and click Finish

For Linux

Linux systems depend on the firewall you're using, if you're using the common ufw you can modify it right from the terminal.

Since port 443 is commonly used, it is important to add some security measures to restrict who can connect to your Gunbot. To restrict which IPs are allowed to connect to the webhook listener, use the following command:

sudo ufw allow from 52.32.178.7 to any port 443

This is one of the public IPs from the tradingview.com which will send to your Gunbot the webhook alert. Currently, there are four servers from Tradingview.com that will communicate with your Gunbot to post alerts:

52.89.214.238 34.212.75.30 54.218.53.128 52.32.178.7

Run the command for each IP. Afterward, you can verify that it is correctly set up by checking the status using the following command:

sudo ufw status

Depending on the VPS provider, it is possible that you have to configure a 2nd tier firewall, for example amazon web service or google cloud, you will need to create another rule in their network configuration interfaces.

Which SSL Library to use

As tradingview enforces an https connection in order to be able to use Webhooks, you'll have to create one first.

Windows

Some Windows distributions may encounter issues with an outdated version of openssl, causing Gunbot to get stuck after an error. In this case, it is necessary to use LibreSSL 3.2.2 or a newer version.

You have two options: compile it yourself or use these simple steps.

Click the Start button, and type powershell - click the right mouse button & launch as Administrator

Then run this command first:

Set-ExecutionPolicy Bypass -Scope Process

Then without leaving powershell, the following command:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

Then in the same powershell window, copy and paste this code into the console

choco install -confirm libressl

It is possible that despite following the aforementioned steps, you may still encounter an error that causes Gunbot to become stuck. If this occurs, you can resolve the issue by downloading the LibreSSL Portable 3.3.3.

Linux

On Linux, using the openssl certification manager worked correctly and webhooks listener could be correctly started with the created certificate from openssl.

MacOS

On MacOS, you can issue the required certificate with openssl.

Confirming all is good

If everything has been configured properly, then you will see this on startup of your Gunbot