mango-explorer/ShowMyAccounts.ipynb

174 lines
5.5 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "markdown",
"id": "significant-spanish",
"metadata": {},
"source": [
"# ⚠ Warning\n",
"\n",
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"\n",
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gl/OpinionatedGeek%2Fmango-explorer/HEAD?filepath=ShowMyAccounts.ipynb) _🏃 To run this notebook press the ⏩ icon in the toolbar above._\n",
"\n",
"[🥭 Mango Markets](https://mango.markets/) support is available at: [Docs](https://docs.mango.markets/) | [Discord](https://discord.gg/67jySBhxrg) | [Twitter](https://twitter.com/mangomarkets) | [Github](https://github.com/blockworks-foundation) | [Email](mailto:hello@blockworks.foundation)"
]
},
{
"cell_type": "markdown",
"id": "raising-orchestra",
"metadata": {},
"source": [
"# 🥭 Show My Accounts\n",
"\n",
"This notebook tries to display information about all Mango margin accounts that belong to a specified account.\n",
"\n",
"It fetches the data from Solana, parses it, and then prints it.\n"
]
},
{
"cell_type": "markdown",
"id": "ordered-kenya",
"metadata": {},
"source": [
"## How To Use This Page\n",
"\n",
"Enter the public key of the account you want to check in the value for `ACCOUNT_TO_LOOK_UP` in the box below, between the double-quote marks. Then run the notebook by choosing 'Run > Run All Cells' from the notebook menu at the top of the page."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "beneficial-guidance",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
"outputs": [],
"source": [
"import logging\n",
"logging.getLogger().setLevel(logging.ERROR)\n",
"\n",
"from solana.publickey import PublicKey\n",
"\n",
"from BaseModel import Group, MarginAccount\n",
"from Constants import SYSTEM_PROGRAM_ADDRESS\n",
"from Context import default_context\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "distinct-economy",
"metadata": {},
"outputs": [],
"source": [
"ACCOUNT_TO_LOOK_UP = \"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "transsexual-opening",
"metadata": {},
"outputs": [],
"source": [
"if ACCOUNT_TO_LOOK_UP == \"\":\n",
" raise Exception(\"No account to look up - try setting the variable ACCOUNT_TO_LOOK_UP to an account public key.\")\n",
"\n",
"print(\"Context:\", default_context)\n",
"\n",
"root_account_key = PublicKey(ACCOUNT_TO_LOOK_UP)\n",
"root_account = default_context.load_account(root_account_key)\n",
"if root_account is None:\n",
" raise Exception(f\"Account '{root_account_key}' could not be found.\")\n",
"\n",
"print(\"My account:\", root_account)\n",
"if root_account.owner != SYSTEM_PROGRAM_ADDRESS:\n",
" raise Exception(f\"Account '{root_account_key}' is not a root user account.\")\n",
"\n",
"group = Group.load(default_context)\n",
"# print(\"Group:\", group)\n",
"\n",
"print(\"Balances:\")\n",
"print(f\" SOL balance: {default_context.fetch_sol_balance(root_account_key):>18,.8f}\")\n",
"group = Group.load(default_context)\n",
"for basket_token in group.basket_tokens:\n",
" print(f\"{basket_token.token.name:>7} balance: {default_context.fetch_token_balance(root_account_key, basket_token.token.mint):>18,.8f}\")\n",
"\n",
"prices = group.fetch_token_prices()\n",
"print(prices)\n",
"\n",
"my_margin_accounts = MarginAccount.load_all_for_owner(default_context, root_account_key, group)\n",
"for my_margin_account in my_margin_accounts:\n",
" print(\"My margin account:\", my_margin_account)\n",
" print(\"Balance sheet totals\", my_margin_account.get_balance_sheet_totals(group, prices))\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": true
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}