{ "cells": [ { "cell_type": "markdown", "id": "1c81447d", "metadata": {}, "source": [ "[🥭 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)\n", "\n", "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/blockworks-foundation/mango-explorer-examples/HEAD?labpath=ShowAccountDataFrame.ipynb) [Run this code](https://mybinder.org/v2/gh/blockworks-foundation/mango-explorer-examples/HEAD?labpath=ShowAccountDataFrame.ipynb) on Binder.\n", "\n", "_🏃‍♀️ To run this notebook press the ⏩ icon in the toolbar above._" ] }, { "cell_type": "markdown", "id": "055fbf67", "metadata": {}, "source": [ "# 🥭 Show Account DataFrame\n", "\n", "This notebook shows `pandas` `DataFrame` for each Mango Account belonging to a specified `Keypair`.\n", "\n", "It fetches the data from Solana, parses it, runs the calculations, and then displays it.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "88779eaa", "metadata": {}, "outputs": [], "source": [ "import mango\n", "\n", "from IPython.display import display\n", "\n", "from solana.publickey import PublicKey\n", "\n", "with mango.ContextBuilder.build(cluster_name=\"devnet\") as context:\n", " group = mango.Group.load(context)\n", " cache: mango.Cache = mango.Cache.load(context, group.cache)\n", "\n", " account = mango.Account.load(context, PublicKey(\"HhepjyhSzvVP7kivdgJH9bj32tZFncqKUwWidS1ja4xL\"), group)\n", " open_orders = account.load_all_spot_open_orders(context)\n", " frame = account.to_dataframe(group, open_orders, cache)\n", " display(frame)\n", " print(f\"Init Health: {account.init_health(frame)}\")\n", " print(f\"Maint Health: {account.maint_health(frame)}\")\n", " print(f\"Total Value: {account.total_value(frame)}\")\n", " print(f\"Leverage: {account.leverage(frame):,.2f}x\")\n", "\n", "print(\"Example complete.\")" ] } ], "metadata": { "interpreter": { "hash": "ac2eaa0ea0ebeafcc7822e65e46aa9d4f966f30b695406963e145ea4a91cd4fc" }, "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.9.10" }, "metadata": { "interpreter": { "hash": "ac2eaa0ea0ebeafcc7822e65e46aa9d4f966f30b695406963e145ea4a91cd4fc" } }, "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 }