stable/docs/webhook-config.md

291 lines
8.4 KiB
Markdown
Raw Permalink Normal View History

2018-07-07 12:13:49 +00:00
# Webhook usage
## Configuration
Enable webhooks by adding a webhook-section to your configuration file, and setting `webhook.enabled` to `true`.
Sample configuration (tested using IFTTT).
```json
"webhook": {
"enabled": true,
"url": "https://maker.ifttt.com/trigger/<YOUREVENT>/with/key/<YOURKEY>/",
2022-04-04 17:32:27 +00:00
"webhookentry": {
2018-07-07 12:13:49 +00:00
"value1": "Buying {pair}",
"value2": "limit {limit:8f}",
"value3": "{stake_amount:8f} {stake_currency}"
},
2022-04-04 17:32:27 +00:00
"webhookentrycancel": {
2020-02-11 14:58:40 +00:00
"value1": "Cancelling Open Buy Order for {pair}",
2020-02-08 20:02:52 +00:00
"value2": "limit {limit:8f}",
"value3": "{stake_amount:8f} {stake_currency}"
},
2022-04-04 17:32:27 +00:00
"webhookentryfill": {
"value1": "Buy Order for {pair} filled",
"value2": "at {open_rate:8f}",
"value3": ""
2020-02-08 20:02:52 +00:00
},
2022-04-04 17:05:36 +00:00
"webhookexit": {
"value1": "Exiting {pair}",
2018-07-07 12:13:49 +00:00
"value2": "limit {limit:8f}",
2020-03-05 14:44:38 +00:00
"value3": "profit: {profit_amount:8f} {stake_currency} ({profit_ratio})"
2018-07-07 12:13:49 +00:00
},
2022-04-04 17:05:36 +00:00
"webhookexitcancel": {
"value1": "Cancelling Open Exit Order for {pair}",
2020-02-08 20:02:52 +00:00
"value2": "limit {limit:8f}",
2020-03-05 14:44:38 +00:00
"value3": "profit: {profit_amount:8f} {stake_currency} ({profit_ratio})"
2020-02-08 20:02:52 +00:00
},
2022-04-04 17:05:36 +00:00
"webhookexitfill": {
"value1": "Exit Order for {pair} filled",
"value2": "at {close_rate:8f}.",
"value3": ""
},
2018-07-07 12:13:49 +00:00
"webhookstatus": {
"value1": "Status: {status}",
"value2": "",
"value3": ""
}
},
```
2021-11-02 19:26:38 +00:00
The url in `webhook.url` should point to the correct url for your webhook. If you're using [IFTTT](https://ifttt.com) (as shown in the sample above) please insert your event and key to the url.
2018-07-07 12:13:49 +00:00
You can set the POST body format to Form-Encoded (default), JSON-Encoded, or raw data. Use `"format": "form"`, `"format": "json"`, or `"format": "raw"` respectively. Example configuration for Mattermost Cloud integration:
```json
"webhook": {
"enabled": true,
"url": "https://<YOURSUBDOMAIN>.cloud.mattermost.com/hooks/<YOURHOOK>",
"format": "json",
"webhookstatus": {
"text": "Status: {status}"
}
},
```
The result would be a POST request with e.g. `{"text":"Status: running"}` body and `Content-Type: application/json` header which results `Status: running` message in the Mattermost channel.
When using the Form-Encoded or JSON-Encoded configuration you can configure any number of payload values, and both the key and value will be ouput in the POST request. However, when using the raw data format you can only configure one value and it **must** be named `"data"`. In this instance the data key will not be output in the POST request, only the value. For example:
```json
"webhook": {
"enabled": true,
"url": "https://<YOURHOOKURL>",
"format": "raw",
"webhookstatus": {
"data": "Status: {status}"
}
},
```
The result would be a POST request with e.g. `Status: running` body and `Content-Type: text/plain` header.
Optional parameters are available to enable automatic retries for webhook messages. The `webhook.retries` parameter can be set for the maximum number of retries the webhook request should attempt if it is unsuccessful (i.e. HTTP response status is not 200). By default this is set to `0` which is disabled. An additional `webhook.retry_delay` parameter can be set to specify the time in seconds between retry attempts. By default this is set to `0.1` (i.e. 100ms). Note that increasing the number of retries or retry delay may slow down the trader if there are connectivity issues with the webhook. Example configuration for retries:
```json
"webhook": {
"enabled": true,
"url": "https://<YOURHOOKURL>",
"retries": 3,
"retry_delay": 0.2,
"webhookstatus": {
"status": "Status: {status}"
}
},
```
2018-07-07 12:13:49 +00:00
Different payloads can be configured for different events. Not all fields are necessary, but you should configure at least one of the dicts, otherwise the webhook will never be called.
2022-04-04 17:32:27 +00:00
### Webhookentry
2018-07-07 12:13:49 +00:00
2022-04-04 17:32:27 +00:00
The fields in `webhook.webhookentry` are filled when the bot executes a long/short. Parameters are filled using string.format.
2018-07-07 12:13:49 +00:00
Possible parameters are:
* `trade_id`
2019-04-05 04:47:03 +00:00
* `exchange`
* `pair`
2021-12-29 13:24:12 +00:00
* `direction`
2021-12-19 15:24:46 +00:00
* `leverage`
* ~~`limit` # Deprecated - should no longer be used.~~
* `open_rate`
2020-02-08 20:02:52 +00:00
* `amount`
2020-02-08 20:19:07 +00:00
* `open_date`
2019-04-05 04:47:03 +00:00
* `stake_amount`
* `stake_currency`
* `base_currency`
2019-04-05 04:47:03 +00:00
* `fiat_currency`
2019-06-17 05:03:33 +00:00
* `order_type`
2020-02-08 20:02:52 +00:00
* `current_rate`
2021-11-21 08:24:20 +00:00
* `enter_tag`
2020-02-08 20:02:52 +00:00
2022-04-04 17:32:27 +00:00
### Webhookentrycancel
2020-02-08 20:02:52 +00:00
2022-04-04 17:32:27 +00:00
The fields in `webhook.webhookentrycancel` are filled when the bot cancels a long/short order. Parameters are filled using string.format.
2020-02-08 20:02:52 +00:00
Possible parameters are:
* `trade_id`
2020-02-08 20:02:52 +00:00
* `exchange`
* `pair`
2021-12-29 13:24:12 +00:00
* `direction`
* `leverage`
2020-02-08 20:02:52 +00:00
* `limit`
* `amount`
2020-02-08 20:19:07 +00:00
* `open_date`
2020-02-08 20:02:52 +00:00
* `stake_amount`
* `stake_currency`
* `base_currency`
2020-02-08 20:02:52 +00:00
* `fiat_currency`
* `order_type`
* `current_rate`
2021-11-21 08:24:20 +00:00
* `enter_tag`
2018-07-07 12:13:49 +00:00
2022-04-04 17:32:27 +00:00
### Webhookentryfill
2022-04-04 17:32:27 +00:00
The fields in `webhook.webhookentryfill` are filled when the bot filled a long/short order. Parameters are filled using string.format.
Possible parameters are:
* `trade_id`
* `exchange`
* `pair`
2021-12-29 13:24:12 +00:00
* `direction`
2021-12-19 15:24:46 +00:00
* `leverage`
* `open_rate`
* `amount`
* `open_date`
* `stake_amount`
* `stake_currency`
* `base_currency`
* `fiat_currency`
* `order_type`
* `current_rate`
2021-11-21 08:24:20 +00:00
* `enter_tag`
2022-04-04 17:05:36 +00:00
### Webhookexit
The fields in `webhook.webhookexit` are filled when the bot exits a trade. Parameters are filled using string.format.
2018-07-07 12:13:49 +00:00
Possible parameters are:
* `trade_id`
2019-04-05 04:47:03 +00:00
* `exchange`
* `pair`
2021-12-29 13:24:12 +00:00
* `direction`
2021-12-19 15:24:46 +00:00
* `leverage`
2019-04-05 04:47:03 +00:00
* `gain`
* `limit`
* `amount`
* `open_rate`
* `profit_amount`
* `profit_ratio`
* `stake_currency`
* `base_currency`
* `fiat_currency`
2022-03-24 19:33:47 +00:00
* `exit_reason`
* `order_type`
* `open_date`
* `close_date`
2022-04-04 17:05:36 +00:00
### Webhookexitfill
2022-04-04 17:05:36 +00:00
The fields in `webhook.webhookexitfill` are filled when the bot fills a exit order (closes a Trade). Parameters are filled using string.format.
Possible parameters are:
* `trade_id`
* `exchange`
* `pair`
2021-12-29 13:24:12 +00:00
* `direction`
2021-12-19 15:58:58 +00:00
* `leverage`
* `gain`
* `close_rate`
* `amount`
* `open_rate`
2019-04-05 04:47:03 +00:00
* `current_rate`
* `profit_amount`
2020-03-05 14:44:38 +00:00
* `profit_ratio`
2019-04-05 04:47:03 +00:00
* `stake_currency`
* `base_currency`
2019-04-05 04:47:03 +00:00
* `fiat_currency`
2022-03-24 19:33:47 +00:00
* `exit_reason`
2019-06-17 05:03:33 +00:00
* `order_type`
2019-12-08 13:10:26 +00:00
* `open_date`
* `close_date`
2018-07-07 12:13:49 +00:00
2022-04-04 17:05:36 +00:00
### Webhookexitcancel
2020-02-08 20:02:52 +00:00
2022-04-04 17:05:36 +00:00
The fields in `webhook.webhookexitcancel` are filled when the bot cancels a exit order. Parameters are filled using string.format.
2020-02-08 20:02:52 +00:00
Possible parameters are:
* `trade_id`
2020-02-08 20:02:52 +00:00
* `exchange`
* `pair`
2021-12-29 13:24:12 +00:00
* `direction`
* `leverage`
2020-02-08 20:02:52 +00:00
* `gain`
* `limit`
* `amount`
* `open_rate`
* `current_rate`
* `profit_amount`
2020-03-05 14:44:38 +00:00
* `profit_ratio`
2020-02-08 20:02:52 +00:00
* `stake_currency`
* `base_currency`
2020-02-08 20:02:52 +00:00
* `fiat_currency`
2022-03-24 19:33:47 +00:00
* `exit_reason`
2020-02-08 20:02:52 +00:00
* `order_type`
* `open_date`
2020-02-08 20:19:07 +00:00
* `close_date`
2020-02-08 20:02:52 +00:00
2018-07-07 12:13:49 +00:00
### Webhookstatus
The fields in `webhook.webhookstatus` are used for regular status messages (Started / Stopped / ...). Parameters are filled using string.format.
The only possible value here is `{status}`.
## Discord
A special form of webhooks is available for discord.
You can configure this as follows:
```json
"discord": {
"enabled": true,
"webhook_url": "https://discord.com/api/webhooks/<Your webhook URL ...>",
"exit_fill": [
{"Trade ID": "{trade_id}"},
{"Exchange": "{exchange}"},
{"Pair": "{pair}"},
{"Direction": "{direction}"},
{"Open rate": "{open_rate}"},
{"Close rate": "{close_rate}"},
{"Amount": "{amount}"},
{"Open date": "{open_date:%Y-%m-%d %H:%M:%S}"},
{"Close date": "{close_date:%Y-%m-%d %H:%M:%S}"},
{"Profit": "{profit_amount} {stake_currency}"},
{"Profitability": "{profit_ratio:.2%}"},
{"Enter tag": "{enter_tag}"},
{"Exit Reason": "{exit_reason}"},
{"Strategy": "{strategy}"},
{"Timeframe": "{timeframe}"},
],
"entry_fill": [
{"Trade ID": "{trade_id}"},
{"Exchange": "{exchange}"},
{"Pair": "{pair}"},
{"Direction": "{direction}"},
{"Open rate": "{open_rate}"},
{"Amount": "{amount}"},
{"Open date": "{open_date:%Y-%m-%d %H:%M:%S}"},
{"Enter tag": "{enter_tag}"},
{"Strategy": "{strategy} {timeframe}"},
]
}
```
The above represents the default (`exit_fill` and `entry_fill` are optional and will default to the above configuration) - modifications are obviously possible.
Available fields correspond to the fields for webhooks and are documented in the corresponding webhook sections.
The notifications will look as follows by default.
![discord-notification](assets/discord_notification.png)