# DEX Bot 监控

### Dex Bot 监控是什么？

DEX Bot 监控是针对 DEX 的需求场景而设计的监控类型。该主要功能是监控各去中心化交易所的相关事件。

### Dex Bot 监控典型场景

1. Dex 上大额成交监控
2. Dex 上流动性大额移除监控
3. Dex 上流动性大额百分比监控
4. Dex 上流动性阈值监控
5. Dex 上币价波动监控

#### 支持的数据源

| 数据源         | 类型       | 稳定性 |
| ----------- | -------- | --- |
| Ethereum    | on chain | 极高  |
| BSC         | on chain | 高   |
| Avalanche   | on chain | 高   |
| Polygon PoS | on chain | 高   |
| Arbitrum    | on chain | 高   |
| Optimism    | on chain | 高   |
| Base        | on chain | 高   |
| ZKFair      | on chain | 高   |
| Blast       | on chain | 高   |

#### 支持的 Swap

| Chain       | Dex                                  |
| ----------- | ------------------------------------ |
| Ethereum    | UniswapV2, UniswapV3, Sushiswap      |
| BSC         | Pancakeswap V2                       |
| Avalanche   | TraderJoe, Pangolin                  |
| Polygon PoS | UniswapV2, UniswapV3, MMF, Quickswap |
| Arbitrum    | UniswapV3, Sushiswap, Chronos        |
| Optimism    | UniswapV3                            |
| Base        | UniswapV3                            |
| ZKFair      | SideSwap                             |
| Blast       | Thruster                             |

### 如何配置 Dex Bot 监控？

登录 ChainBot 平台后，右上角 "Create Bot" -> "Dex Monitor"。

<figure><img src="/files/stFHqjLFzTVuZEEuXJiF" alt=""><figcaption><p>Create Dex Monitor</p></figcaption></figure>

**Info 说明**

| 字段名      | 说明               | 是否必填 |
| -------- | ---------------- | ---- |
| Name     | Bot 监控名          | 是    |
| Chain    | 选定的 Chain        | 是    |
| Contract | 选定的智能合约地址        | 是    |
| Function | 选定的智能合约的方法       | 是    |
| Tags     | Bot 监控 tags，利于搜索 | 是    |

#### Conditions 说明

| Price     | Below                | dex 中指定 token ​的价格低于设置的阈值          |
| --------- | -------------------- | ---------------------------------- |
|           | Above                | dex 中指定 token ​的​​价格高于设置的阈值        |
|           | ChangeRisesRate      | dex 中指定 token ​价格上涨百分率             |
|           | ChangeDropsRate      | dex 中指定 token ​价格下跌百分率             |
|           | ChangeRisesDropsRate | dex 中指定 token ​价格上涨或者下跌百分率，两个同时都监控 |
| Liquidity | Below                | 流动性低于设置的阈值                         |
|           | Above                | 流动性高于设置的阈值                         |
|           | ChangeRisesRate      | dex 中指定 pair 的流动性上涨百分率             |
|           | ChangeDropsRate      | dex 中指定 pair 的流动性下跌百分率             |
|           | ChangeRisesDropsRate | dex 中指定 pair 的流动性上涨或下跌百分率          |
|           | WhaleAdd             | 大额流动性添加                            |
|           | WhaleRemove          | 大额流动性移除                            |
|           | WhaleAddRemove       | 大额流动性添加或者移除                        |
| Swap      | WhaleSell            | 大额卖出                               |
|           | WhaleBuy             | 大额买入                               |
|           | WhaleBuySell         | 大额买卖                               |

**模板变量说明**

| $tokenBase.symbol    | tokenBase 的 symbol，比如 WBTC                   |
| -------------------- | -------------------------------------------- |
| $tokenBase.decimals  | ​tokenBase 的 decimals，比如 18                  |
| $tokenBase.address   | ​tokenBase 的链上地址                             |
| $tokenQuote.symbol   | ​tokenQuote 的 symbol，比如 WETH                 |
| $tokenQuote.decimals | ​tokenQuote 的 decimals，比如 18                 |
| $tokenQuote.address  | tokenQuote 的链上地址                             |
| $tokenQuote.balance  | tokenQuote 的余额（只在流动性变化的时候支持）                 |
| $tokenIn.symbol      | ​tokenIn 的 symbol，比如 wbtc                    |
| $tokenIn.decimals    | ​tokenIn 的 decimals，比如 18                    |
| $tokenIn.address     | ​tokenIn 的链上地址                               |
| $tokenOut.symbol     | ​​tokenOut 的 symbol，比如 weth                  |
| $tokenOut.decimals   | ​​tokenOut 的 decimals，比如 18                  |
| $tokenOut.address    | ​​tokenOut 的链上地址                             |
| ​$dex.name           | DEX 的名字，比如 uniswap                           |
| $value               | 目标 token 在 dex 兑换的数量                         |
| $price               | 目标 token 兑换的价格，以 base token wei 计价单位         |
| $priceUSD            | 目标 token 兑换成 U 的价格，以 U 计价                    |
| $changed.duration    | ​指标变动时间范围                                    |
| $changed.rate        | ​指标变动百分率                                     |
| $action              | 监控指标的行为，add（添加）/ remove（移除）/ buy（买）/ sell（卖） |

#### 术语说明

1. tokenBase：为基准 token，例如：WBTC/WETH 交易对中，其中 WBTC 为 tokenBase。
2. tokenQuote：为基准 token 定价的 token，例如：WBTC/WETH 交易对中，其中 WETH 为 tokenQuote。
3. tokenIn：在 dex 中使用 swap 功能使用 a 换 b时，其中 a 为 tokenIn，b 为 tokenOut。即：将 a token 放进流动性池子中，从流动性池子中拿出 b token 的行为。例如：swap WBTC/WETH 时，此时 WBTC 为 tokenIn，WETH 则为 tokenOut。
4. tokenBase, tokenQuote, tokenIn, tokenOut 均为 ERC20 的 Token，因此都有 name, symbol, decimals, address 等标准 ERC20 的方法。

#### 默认告警模板

大额成交 Swap-WhaleSwap

{% code overflow="wrap" lineNumbers="true" %}

```shell
[ 🐳 {$bot.name} ]
Pair: {$dex.tokenBase.symbol}/{$dex.tokenQuote.symbol} on {$dex.name}
Value: {$dex.value} USD
Action: {$dex.tokenIn.amount} {$dex.tokenIn.symbol} -> {$dex.tokenOut.amount} {$dex.tokenOut.symbol} at price {$dex.price} USD
Explore: {$chain.explore}/tx/{$tx.hash}
```

{% endcode %}

流动性大额 Liquidity-WhaleAdd/WhaleRemove/WhaleAdRemove

{% code overflow="wrap" lineNumbers="true" %}

```shell
[ 🐳 {$bot.name} ]
Pair: {$dex.tokenBase.symbol}/{$dex.tokenQuote.symbol} on {$dex.name}
Value: {$dex.value} USD
Action: {$dex.tokenIn.amount} {$dex.tokenIn.symbol} -> {$dex.tokenOut.amount} {$dex.tokenOut.symbol} at price {$dex.price} USD
Explore: {$chain.explore}/tx/{$tx.hash}
Created By ChainBot.org
```

{% endcode %}

流动性大额百分比 Liquidity-WhaleAddPercent/WhaleRemovePercent/WhaleAddRemovePercent

{% code overflow="wrap" lineNumbers="true" %}

```shell
[ 🐳 {$bot.name} ]
Pair: {$dex.tokenBase.symbol}/{$dex.tokenQuote.symbol} on {$dex.name}
Value: {$dex.value} USD
Action: {$dex.action} more than {$dex.changed.rate}% liquidity to pool
Explore: {$chain.explore}/tx/{$tx.hash}
Created By ChainBot.org
```

{% endcode %}

流动性阈值 Liquidity-Above/Below

{% code overflow="wrap" lineNumbers="true" %}

```shell
[ {$bot.name}  ]
📉📈 {$dex.tokenBase.symbol}/{$dex.tokenQuote.symbol} liquidity on {$dex.name} above/below {$dex.changed.rate} in the past {$dex.changed.duration}
current liquidity is {$dex.tokenQuote.balance} {$dex.tokenQuote.symbol}
```

{% endcode %}

流动性波动比率 Liquidity-ChangeRisesRate/ChangeDropsRate/ChangeRisesDropsRate

{% code overflow="wrap" lineNumbers="true" %}

```shell
[ {$bot.name}  ]
📉📈 {$dex.tokenBase.symbol}/{$dex.tokenQuote.symbol} liquidity on {$dex.name} {$dex.direction} {$dex.changed.rate} in the past {$dex.changed.duration}
current liquidity is {$dex.tokenQuote.balance} {$dex.tokenQuote.symbol}
```

{% endcode %}

币价波动 Price-ChangeRisesRate/ChangeDropsRate/ChangeRisesDropsRate

{% code overflow="wrap" lineNumbers="true" %}

```shell
[ {$bot.name} ]
📉📈 {$dex.tokenBase.symbol}/{$dex.tokenQuote.symbol} price on {$dex.name} {$dex.direction} {$dex.changed.rate} in the past {$dex.changed.duration}
current price is {$dex.price} {$dex.tokenQuote.symbol}
```

{% endcode %}

币价阈值监控 Price-Above/Below

{% code overflow="wrap" lineNumbers="true" %}

```shell
[ {$bot.name} ]
📉📈 {$dex.tokenBase.symbol}/{$dex.tokenQuote.symbol} price on {$dex.name} {$dex.direction} {$dex.setPrice}. 
current price {$dex.price} USD.
```

{% endcode %}

[了解告警通知模板？](/zh/advanced-features/alarm-notification-template.md)

#### 通知消息示例

> \[ 🐳 Whale swap on Uniswap ETH/USDT pool ]\
> Pair: WETH/USDT on UniswapV3\
> Value: 51.237884 USD\
> Action: 0.0404716445741972 WETH -> 51.237884 USDT at price 1266.019321405753878 USD\
> Explore: <https://etherscan.io/tx/0xef1cd8f1edfbfa7fc2efe74b814c3535c333921cedae9aaad66a9d969ab885b8>\
> Created By [ChainBot.io](https://www.chainbot.io)

#### Dex Bot 监控案例

[Dex Bot 案例](/zh/bot-case/dex-bot-demo.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chainbot.io/zh/basic-usage/bots/dex-bot.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
