Alert

Alert is a feature of Chainslake platform, it allows you to receive data alerts such as token price alerts, spike trading volume alerts… and can be customized according to your needs.

How to use

Just message Sonar bot on Telegram and you can start using it.

Create a Subscription

  • To receive alerts, you need to create a Subscription. Click the Menu button in the bottom right corner and select Create a new Subscription

Create subscription

  • Type cex/token_price_big_change and choose Finish button. With this subscription, you will receive an alert every time the price of a token changes by 10%.

Create subscription

Create Alert Channel

Using Data Builder, you can create Alert Channels according to your purpose. Channels are located in the alert folder of the Data Builder project. Each channel is a .sql file that you can call in the Sonar bot (remove the sql extension). For example cex/token_price_big_change.

{
    "name": "#PRICE CEX big change token price",
    "table": "binance_cex.trade_minute_agg_volume",
    "description": "Alerting when any coin in binance has price increase more than ${percent}%",
    "dashboard_url": "https://metabase.chainslake.io/public/dashboard/169d39da-25a0-484d-ad51-53ef13eda9de",
    "query_parameter": [
    {
            "name": "percent",
            "type": "number",
            "value": "10"
        }
    ],
    "transform_id": "binance_cex_price",
    "query": "ratio_change_price >= ${percent} and minute_max > minute_min",
    "message": "Price of $${base_asset} increase ${ratio_change_price} % with volume change ${change_volume} USD. [detail](https://metabase.chainslake.io/public/dashboard/13b762f3-91c3-40ec-b6c6-53c0775ceb12?coin=${base_asset})"
}

===

WITH
  trade_data AS (
    SELECT
      block_minute,
      base_asset,
      open_price,
      24h_volume
    FROM
      binance_cex.trade_minute_agg_volume
    WHERE
      block_minute > CURRENT_TIMESTAMP - interval '1' HOUR
  ),
  trade_filter AS (
    SELECT
      base_asset,
      max_by(24h_volume, open_price) - min_by(24h_volume, open_price) as change_volume,
      max_by(block_minute, open_price) AS minute_max,
      min_by(block_minute, open_price) AS minute_min,
      (max(open_price) - min(open_price)) / min(open_price) * 100 AS ratio_change_price
    FROM
      trade_data
    GROUP BY
      base_asset
  )
SELECT
  *
FROM
  trade_filter
WHERE
  minute_max >= cast(${from} AS timestamp)

Each channel consists of two parts: The SQL part defines the logic of the alert condition and the Properties part is the properties of the alert channel. The properties include:

  • name: Name of Alert Channel
  • table: Name of the table where the Alert will be placed on
  • query_parameter: User-customizable parameters on the Sonar bot
  • query: Filter data with user-passed parameters
  • message: Format of message sent to user if query condition is satisfied
  • transform_id: Query identifier used to reuse a written query.