mango-explorer/ShowAllAccounts.ipynb

164 lines
5.0 KiB
Plaintext
Raw Normal View History

2021-04-14 08:51:39 -07:00
{
"cells": [
{
"cell_type": "markdown",
"id": "preceding-cisco",
2021-04-15 02:59:04 -07:00
"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",
2021-04-23 01:28:09 -07:00
"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gl/OpinionatedGeek%2Fmango-explorer/HEAD?filepath=ShowAllAccounts.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)"
2021-04-15 02:59:04 -07:00
]
},
{
"cell_type": "markdown",
"id": "experienced-drive",
2021-04-14 08:51:39 -07:00
"metadata": {},
"source": [
"# 🥭 Show All Accounts\n",
2021-04-15 02:59:04 -07:00
"\n",
2021-04-14 08:51:39 -07:00
"This notebook tries to display information about all Mango margin accounts.\n",
"\n",
"It fetches the data from Solana, parses it, and then prints it.\n"
]
},
{
"cell_type": "markdown",
"id": "banned-vitamin",
2021-04-14 08:51:39 -07:00
"metadata": {},
"source": [
"## How To Use This Page\n",
"\n",
"Theo code should be runnable as-is. Just click the >> button in the toolbar above, and you should see output appear below the code."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "numeric-routine",
"metadata": {
"jupyter": {
"source_hidden": true
}
},
2021-04-14 08:51:39 -07:00
"outputs": [],
"source": [
"import logging\n",
"logging.getLogger().setLevel(logging.ERROR)\n",
"\n",
2021-04-14 08:51:39 -07:00
"from pyserum.market import Market\n",
"\n",
"from BaseModel import AccountInfo, Group, MarginAccount, OpenOrders, TokenAccount\n",
"from Context import default_context\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "national-argentina",
"metadata": {},
"outputs": [],
"source": [
2021-04-14 08:51:39 -07:00
"def show_all_accounts():\n",
" print(\"Context:\", default_context)\n",
2021-04-14 08:51:39 -07:00
"\n",
" group = Group.load(default_context)\n",
" print(\"Group:\", group)\n",
"\n",
" markets = list(map(lambda market: Market.load(default_context.client, market.spot), group.markets))\n",
" print(\"Markets:\", markets)\n",
"\n",
" vaults = AccountInfo.load_multiple(default_context, [token.vault for token in group.basket_tokens])\n",
2021-04-14 08:51:39 -07:00
" print(\"Vaults:\", vaults)\n",
"\n",
" for index, vault in enumerate(vaults):\n",
" token = TokenAccount.parse(vault)\n",
" decimals = group.basket_tokens[index].token.decimals\n",
2021-04-14 08:51:39 -07:00
" amount = token.amount / (10 ** decimals)\n",
" print(f\"Vault token amount[{index}]: {amount:,.8f}\")\n",
"\n",
" import time\n",
" start_time = time.time()\n",
" print(\"Loading margin accounts...\")\n",
" margin_accounts = MarginAccount.load_all_for_group_with_open_orders(default_context, default_context.program_id, group)\n",
2021-04-14 08:51:39 -07:00
" print(f\"Done. Time taken: {time.time() - start_time}\")\n",
"\n",
" print(margin_accounts)\n",
2021-04-14 08:51:39 -07:00
"\n",
"\n",
"show_all_accounts()\n",
"# import cProfile\n",
"# import pstats\n",
"# cProfile.run(\"show_all_accounts()\", sort=pstats.SortKey.TIME)\n"
2021-04-14 08:51:39 -07:00
]
}
],
"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
2021-04-14 08:51:39 -07:00
}
},
"nbformat": 4,
"nbformat_minor": 5
2021-04-15 02:59:04 -07:00
}