Added Notication documentation.

This commit is contained in:
Geoff Taylor 2021-07-22 11:38:32 +01:00
parent 2f6c3088ef
commit bf258ef103
2 changed files with 132 additions and 18 deletions

View File

@ -11,7 +11,7 @@ Run these notebooks on Binder: [![Binder](https://mybinder.org/badge_logo.svg)](
**I am not yet confident in the figures and calculations. Please don't rely on this code yet!**
This is the start of a project to explore and provide useful code for [Mango Markets](https://mango.markets/).
This is a project to explore and provide useful code for [Mango Markets](https://mango.markets/).
There are some notebook pages to explore Mango account structures for your own accounts.
@ -41,8 +41,6 @@ Most notebooks are currently 'runnable' - if you open them in your browser and p
Mango Markets should set up your account automatically for trading, but the requirements for running a liquidator can be a bit more extensive. For instance, for trading you need token accounts for both tokens in the trade but to run a liquidator you need token accounts for all tokens in the `Group`.
The [AccountScout](AccountScout.ipynb) notebook can verify any user's root account to make sure it meets the requirements of the liquidator.
## Show your Mango margin accounts
@ -51,7 +49,12 @@ To try this out, go to the [Show Account](ShowAccount.ipynb) page and enter your
## Show all Mango margin accounts
To try this out, go to the [Show All Accounts](ShowAllAccounts.ipynb) page and run the code.
To try this out, go to the [Show All Margin Accounts](ShowAllMarginAccounts.ipynb) page and run the code.
## Show details of the current Mango gorup
You can use the [Show Group](ShowGroup.ipynb) page to inspect the details of the current Mango group.
## Load all margin accounts into a Pandas `DataFrame`
@ -67,20 +70,6 @@ The [Pandas](Pandas.ipynb) page can currently show you:
* The top ten margin accounts with the lowest collateralisation.
## Structure of this project
The code is (nearly) all Python in Jupyter Notebooks.
Some notebooks are more code files than useful notebooks themselves (although being able to easily run the code is still a boon):
* The [Layouts](Layouts.ipynb) notebook contains the low-level Python data structures for interpreting raw Solana program data.
* The [BaseModel](BaseModel.ipynb) notebook contains higher-level classes for loading and working with that data.
Other notebooks are more user-oriented:
* [Show Account](ShowAccount.ipynb) to show data pertaining to a single Mango Markets margin account.
* [Show All Accounts](ShowAllAccounts.ipynb) to show data for all Mango Markets margin accounts.
* [Pandas](Pandas.ipynb) to load data into a [Pandas](https://pandas.pydata.org/) `DataFrame` to allow for further manipulation and analysis.
## References
* [🥭 Mango Markets](https://mango.markets/)

125
docs/Notifications.md Normal file
View File

@ -0,0 +1,125 @@
# 🥭 Mango Explorer
# 🛎️ Notifications
Sometimes you want to be notified when something happens. For instance, you might want to get an alert when your `liquidator` successfully performs a liquidation.
🥭 Mango Explorer has a consistent approach to notifications across its commands, allowing you to send notifications to:
* Telegram
* Discord
* Mailjet
* CSV files
Configuring all of these 'notification targets' in a command-line could be tricky, so:
> Each notification target parameter starts with a handler name, a colon, and then handler-specific configuration.
For example, to record liquidations to a CSV file `/var/mango-explorer/liquidations.csv`, you'd pass the following additional parameters to your `liquidator`:
```
--notify-successful-liquidations csvfile:/var/mango-explorer/liquidations.csv
```
Available notifications varies by program (you can always use the `--help` parameter to see what parameters a given command accepts), but here are the possible notification parameters for the `liquidator` command:
* --notify-liquidations
* --notify-successful-liquidations
* --notify-failed-liquidations
* --notify-errors
# 💌 Telegram
The `TelegramNotificationTarget` sends messages to [Telegram](https://telegram.org/).
The format for configuring the telegram notification is:
1. The word 'telegram'
2. A colon ':'
3. The chat ID
4. An '@' symbol
5. The bot token
So:
telegram:<CHAT-ID>@<BOT-TOKEN>
For example:
```
telegram:012345678@9876543210:ABCDEFGHijklmnop-qrstuvwxyzABCDEFGH
```
The [Telegram instructions to create a bot](https://core.telegram.org/bots#creating-a-new-bot) show you how to create the bot token.
# 💬 Discord
The `DiscordNotificationTarget` sends messages to [Discord](https://discord.com/).
The format for configuring the discord notification target is:
1. The word 'discord'
2. A colon ':'
3. The Discord webhook URL for the channel you want to show the notifications.
So:
discord:<DISCORD-WEBHOOK_URL>
For example:
```
discord:https://discord.com/api/webhooks/012345678901234567/ABCDE_fghij-KLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN
```
These [Discord instructions](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) show you how to create a webhook.
# 📧 Mailjet
The `MailjetNotificationTarget` sends an email through [Mailjet](https://mailjet.com).
This is the most complicated configuration, because it involves so many different parameters.
In order to pass everything in to the notifier as a single string (needed to stop command-line parameters form getting messy), `MailjetNotificationTarget` requires a long compound string, separated by colons.
The format for configuring the mailjet notification is:
1. The word 'mailjet'
2. A colon ':'
3. The chat ID
4. An '@' symbol
5. The bot token
So:
mailjet:<MAILJET-API-KEY>:<MAILJET-API-SECRET>:FROM-NAME:FROM-ADDRESS:TO-NAME:TO-ADDRESS
For example:
```
mailjet:user:secret:subject:from%20name:from@address:to%20name%20with%20colon%3A:to@address
```
Individual components are URL-encoded (so, for example, spaces are replaces with %20,
colons are replaced with %3A).
* `<MAILJET-API-KEY>` and `<MAILJET-API-SECRET>` are from your [Mailjet](https://mailjet.com) count.
* `FROM-NAME` and `TO-NAME` are just text fields that are used as descriptors in the email messages.
* `FROM-ADDRESS` is the address the email appears to come from. This must be validated with ailjet](https://mailjet.com).
* `TO-ADDRESS` is the destination address - the email account to which the email is being sent.
Mailjet provides a client library, but really we don't need or want more dependencies.
# 📃 CSV Files
The `CsvFileNotificationTarget` writes liquidation events to a CSV file.
The `CsvFileNotificationTarget` is reserved for `LiquidationEvent`s - nothing is written if the item is not a `LiquidationEvent`.
The format for configuring the CSV file notification target is:
1. The word 'csvfile'
2. A colon ':'
3. The full or relative pathname to the desired CSV file (bearing in mind this filename may be in the context of the docker container, not the native filesystem).
So:
csvfile:<CSV-FILENAME>
For example:
```
csvfile:/path/to/filename.csv
```
The following headers should be automatically added to new CSV files:
```
"Timestamp","Liquidator Name","Group","Succeeded","Signature","Wallet","Margin Account","Token Changes"
```
Token changes are listed as pairs of value plus symbol, so each token change adds two columns to the output. Token changes may arrive in different orders, so ordering of token changes is not guaranteed to be consistent from transaction to transaction.