Available translations

Webhook Notifications

foundations.png
Summary: Receive webhook notifications from other systems like Trading View, and use them as signals in your strategies.
Overview
Superalgos allows you to receive webhook notifications from TradingView or any other system supporting webhooks. You may use this feature to turn notifications into signals upon which you may act from within your strategies.
How does it Work?
  • Receiving Data: the Client receives via it's http interface notifications from external sources (like Trading View) and keep the data received in-memory. This happens independently of the Webhooks Sensor Bot, meaning that it does not matter if the Webhook Sensor Bot is running or not.
  • Retrieving Data: The Webhooks Sensor Bot, when it is running, queries the Client and ask it for the in-memory data it holds.
  • Saving Data: The Webhooks Sensor Bot saves this data to disk.
The rest of this page describes the set up process and how to use webhook notifications from within Superalgos.
Set-up the Client for Webhooks
There is nothing to configure in order for the Client to receive webhooks calls from external systems. The only thing you might need to do is to change the http interface port number at the Environment.js file if and only if your signals provider has any constraints regarding the port number it can send the notifications to.
Run a Quick Local Test
Before setting up the actual signal at the corresponding provider, you may run a quick local test that will help you familiarize with how Superalgos handles webhooks.
In the crypto ecosystem node menu, select Add Signals Providers. A structure of nodes is added with a signals provider node that allows you to run a little test. Select Configure Signals Provider on the menu.
 {
"webhookURL": "Webhook/New-Message/Trading-View/binance/BTC-USDT",
"testMessage": ""
}
  • webhookURL: This is the URL you need to use for testing purposes. Make sure you refer to the correct exchange and market. Something very similar to this, you will configure later at Trading View or other Signal Provider.
  • testMessage: Enter any message, for testing purposes. This message will be what you will use at your Trading System conditions to know which type of signal you received.
testMessage Examples
 BUY
 SELL
 TRIGGER ON
 TRIGGER OFF
 TAKE POSITION
Send the Test Message to the Client
Once the test message is configured, select Send Test Message on the menu.
The Client does not know you are sending a Test Message, and it does not know it is you and not the real Trading View. For the Client's point of view someone sent a Webhook message to it and it will do with it what it will do with any other message of this type. Store it in-memory waiting for the Webhook Sensor Bot to fetch the pending messages, in which case the Client will delete them upon delivery to the Sensor Bot.
The success logs looks like this:
 [INFO] httpInterface -> Webhook -> New-Message -> Exchange-Market = binance-BTC-USDT
[INFO] httpInterface -> Webhook -> New-Message -> messageReceived = Sell
[INFO] httpInterface -> Webhook -> New-Message -> Messages waiting to be Fetched by Webhooks Sensor Bot = 1
Set-up the Webhooks Sensor Bot Tasks
The Webhooks Data Mine features the definition of the Webhooks sensor bot used to monitor incoming notifications. You need to run an instance of this bot in the data mining section of the exchange and market of your choice.
The Getting-Started-Tutorials workspace does not have this Data Mine as a plugin so you will need to add it first. To do that locate the Plugins node, expand it and at the Plugins Data Mines add a New Plugin File. You can setup it's configuration like this:
 {
    "project": "Foundations",
    "fileName": "Webhooks",
    "folderName": "Data-Mines",
    "nodeType": "Data Mine",
    "saveWithWorkspace": false
}
The default workspace does not feature these tasks. To create a task for the Webhooks sensor bot, you need to uninstall and re-install the corresponding market. The process of installing a market adds all the tasks needed to run all the bots defined at all Data Mines present at the workspace.
Running the Webhooks Sensor Bot
Now that you have verified that the Client is receiving the signal messages and storing them for you, the next thing to do is to run the Webhooks Sensor Bot so that it fetches the signals from the Client and saves them on disk in the format that later can be consumed from strategies.
By default, this bot will run every 30 seconds. Each time it runs you will see logs entries at the Client's console similar to this:
 2021-03-10T09:57:40.111Z              Binance   BTC/USDT              Masters                       Webhooks                  Check-Webhook          Main Loop #        3
[INFO] httpInterface -> Webhook -> Fetch-Messages -> Exchange-Market = binance-BTC-USDT
[INFO] httpInterface -> Webhook -> Fetch-Messages -> Messages Fetched by Webhooks Sensor Bot = 0
Send Test Messages while Sensor Bot is Running
Now that you know how to send test messages, try doing that while the Sensor Bot is running. By looking at the Client's console you will be able to see what is going on:
  • The Client accumulates the signals received.
  • The Sensor Bot fetches all the accumulated signals every time it runs.
In the example below I sent 3 signal messages from the UI to the Client, and then the Sensor Bot fetch them all.
 [INFO] httpInterface -> Webhook -> New-Message -> Exchange-Market = binance-BTC-USDT
[INFO] httpInterface -> Webhook -> New-Message -> messageReceived = Sell
[INFO] httpInterface -> Webhook -> New-Message -> Messages waiting to be Fetched by Webhooks Sensor Bot = 1
[INFO] httpInterface -> Webhook -> New-Message -> Exchange-Market = binance-BTC-USDT
[INFO] httpInterface -> Webhook -> New-Message -> messageReceived = Sell
[INFO] httpInterface -> Webhook -> New-Message -> Messeges waiting to be Fetched by Webhooks Sensor Bot = 2
[INFO] httpInterface -> Webhook -> New-Message -> Exchange-Market = binance-BTC-USDT
[INFO] httpInterface -> Webhook -> New-Message -> messageReceived = Sell
[INFO] httpInterface -> Webhook -> New-Message -> Messeges waiting to be Fetched by Webhooks Sensor Bot = 3
2021-03-10T10:04:40.472Z              Binance   BTC/USDT              Masters                       Webhooks                  Check-Webhook          Main Loop #       17
[INFO] httpInterface -> Webhook -> Fetch-Messages -> Exchange-Market = binance-BTC-USDT
[INFO] httpInterface -> Webhook -> Fetch-Messages -> Messeges Fetched by Webhooks Sensor Bot = 3
Webhooks Sensor Bot Output
The Webhooks sensor bot outputs a single file, Data.json, in the following location:
  Data-Storage\Project\Superalgos\Data-Mine\Masters\Webhooks\Exchange-Id\Market\Output\External-Signals\Single-File
Based on our tests, the location you would find the file would be:
 Data-Storage\Project\Superalgos\Data-Mine\Masters\Webhooks\binance\BTC-USDT\Output\External-Signals\Single-File
You may open the file and see if the content corresponds to what is expected.
This is what the file may look like after the 3 test messages we sent:
 [[1615370665064,"Trading-View","Sell"],[1615370665655,"Trading-View","Sell"],[1615370666472,"Trading-View","Sell"]]
As per the record definition of the Webhooks sensor bot in the Masters data mine, each record in the file features three fields:
  • timestamp: the Unix datetime of the message. This is the moment in time the Client received the signal from the external Signals provider.
  • source: the name of the Signal Provider. This comes as part of the message sent by the provider, because is part of the URL you will specify later at the Signal Provider's system. In our example we used Trading View, but in fact it could be any other provider. You will have this property available at your Trading System, meaning that you will be able to write conditions that distinguish the signal by Signal Provider.
  • message: the message set up at the provider’s system (BUY, SELL, etc.).
Using Webhooks Signals from within Strategies
You may use each of the three available properties with the following syntax:
 chart.atAnyTimeFrame.externalSignal.timestamp
 chart.atAnyTimeFrame.externalSignal.source
 chart.atAnyTimeFrame.externalSignal.message
For example, a simple condition evaluating to true when a the last message received is a buy signal from TradingView would look like this:
 chart.atAnyTimeFrame.externalSignal.source === "Trading-View" && 
chart.atAnyTimeFrame.externalSignal.message === "BUY"
You may also use the previous property to check the previous message, as follows:
 chart.atAnyTimeFrame.externalSignal.previous.message === "BUY"
It may be wise to verify the date of the message, or to check if the message corresponds to a certain time frame. To do that, you may use the isItInside function as follows:
 isItInside(chart.atAnyTimeFrame.externalSignal, chart.at01hs.candle)
In the above example, the first parameter chart.atAnyTimeFrame.externalSignal is the signal object you wish to check, and the second parameter chart.at01hs.candle is any other object that is delimited in time. In this case, the condition validates true if the last message falls within the last 1-hour candle.
Test that the Signal is Taken by your Strategy
We will make ourselves sure that from within a strategy we can react to an external Signal. To test this, please take the following steps. All of the following goes into the current Lighting Strike Backtesting Session / Task.
Paper Trading Session
Right click over the Backtesting Session node and select switch to Paper Trading so that we can simulate live trading without connecting to the exchange.
Set-up Session Parameters
Since you have reinstalled the market in order for the task of the Webhooks bot to appear at the Master Trading Mine Tasks, the setup for the Lighting Strike strategy needs to be fixed. (Assuming you are at the Getting Started Workspace). This is what we are going to do:
Apply this config to your Session Base Asset
 {
    "initialBalance": 0
}
Apply this config to the Session Quoted Asset
 {
    "initialBalance": 1
}
Apply this config to the Time Range
 {
    "initialDatetime": "2020-09-01",
    "finalDatetime": "2030-09-02"
}
The initialDatetime will be ignored because we are running a Paper Trading Session. The important thing is that the finalDatetime is in the future.
Apply this config to the Time Frame
 {
    "label": "01-min"
}
Set-up the Strategy for Webhooks Signals
Inside the Lighting Strike trading system locate the Trigger On Event, and paste the following into the Javascript Node of the only condition it has.
 chart.atAnyTimeFrame.externalSignal.message === "TRIGGER ON"
What we are doing here is setting the strategy to be triggered once an external signal with the message TRIGGER ON is received via the Webhook Sensor Bot.
Run the Data Mining Tasks
For this test, since we are Paper Trading, we will need a live stream of data from the exchange. We don't need to run all the Task of Mater Data Mining, only the ones needed by the Lighting Strike strategy:
  • Candles Volumes
  • Resistances and Supports
  • Webhooks
Run Task and Session
Run Task and the Session, and monitor the chart that was called Backtesting (now that is our Papertrading session), at the end of the market at the 1 minute time frame. Turn on the Episodes layer and wait for a few minutes until you see the Episode icons appear at the charts.
Before running the task and session, delete the data at
 Data-Storage\Project\Superalgos\Data-Mine\Masters\Webhooks
Set-up the Signals Provider
At the Crypto Ecosystem, paste the following config to the Signals Provider.
 {
    "webhookURL": "Webhook/New-Message/Trading-View/binance/BTC-USDT",
    "testMessage": "TRIGGER ON"
}
This means that when you send this test message, you will be delivering the TRIGGER ON signal expected by the strategy.
Ready to Send the Test Message TRIGGER ON
Go to the charts again an turn on the Strategies layer. You should not see anything at the charts since no strategy has been triggered.
After you see the confirmation at the UI that the message was sent, check the Client's console to verify the message was received. Then wait until the message is picked up by the Webhooks Sensor Bot. Then wait until the Trading Bot runs again.
Go to the charts and wait until it plots the icons of the strategy, confirming that the strategy was triggered by the test message you sent.
Set-up your Firewall / Router to accept Incoming Connections
As you might have imagined, you will need to open a port at your router / firewall to accept incoming connections from the signal provider's servers (like Trading View for instance). This is what allows that server to connect to the server where the Client is running, enabling the Client to receive those signals.
What we can tell you regarding this, is that the Superalgos Client is running a very simple http server at the port configured at the Environment.js file.
Set-up Alerts / Messages at the Signals Provider
You will use the following syntax to craft the URL you need to configure for the webhooks at the provider:
 http://YourIPAddress:Port/Webhook/New-Message/Provider-Name/Exchange/Market
For example:
 http://182.45.73.1:34247/Webhook/New-Message/Trading-View/binance/BTC-USDT
Previous
Telegram Announcements

Integrations — TOC

You just read page 2 in the topic.

1. Telegram Announcements

2. Webhook Notifications