mango-explorer/ShowMyAccounts.ipynb

101 lines
3.3 KiB
Plaintext
Raw Normal View History

2021-04-14 08:51:39 -07:00
{
"cells": [
{
"cell_type": "markdown",
"id": "wicked-wichita",
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"
]
},
{
"cell_type": "markdown",
"id": "polished-journalist",
2021-04-14 08:51:39 -07:00
"metadata": {},
"source": [
"# 🥭 Show My Accounts [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gl/OpinionatedGeek%2Fmango-explorer/HEAD?filepath=ShowMyAccounts.ipynb)\n",
2021-04-14 08:51:39 -07:00
"\n",
2021-04-15 02:59:04 -07:00
"_🏃 To run this notebook press the ⏩ icon in the toolbar above._\n",
"\n",
2021-04-14 08:51:39 -07:00
"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": "naked-transportation",
2021-04-14 08:51:39 -07:00
"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": "insured-surveillance",
2021-04-14 08:51:39 -07:00
"metadata": {},
"outputs": [],
"source": [
"ACCOUNT_TO_LOOK_UP = \"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "surrounded-vocabulary",
2021-04-14 08:51:39 -07:00
"metadata": {},
"outputs": [],
"source": [
"from solana.publickey import PublicKey\n",
"from Context import default_context\n",
"from Classes import AccountInfo, Group, MarginAccount\n",
"\n",
2021-04-15 02:59:04 -07:00
"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",
2021-04-14 08:51:39 -07:00
"print(\"Context:\", default_context);\n",
"\n",
"root_account_key = PublicKey(ACCOUNT_TO_LOOK_UP)\n",
"root_account = AccountInfo.load(default_context, root_account_key)\n",
"print(\"My account:\", root_account)\n",
"\n",
"group = Group.load(default_context)\n",
"# print(\"Group:\", group)\n",
"\n",
"prices = group.get_prices()\n",
"\n",
"my_margin_accounts = MarginAccount.load_all_for_owner(default_context, default_context.program_id, group, root_account_key)\n",
"for my_margin_account in my_margin_accounts:\n",
" print(\"My margin account:\", my_margin_account)\n",
" print(my_margin_account.get_balance_sheet(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"
}
},
"nbformat": 4,
"nbformat_minor": 5
}