#!/usr/bin/env python # coding: utf-8 # [🥭 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) # # [![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. # # _🏃‍♀️ To run this notebook press the ⏩ icon in the toolbar above._ # # 🥭 Show Account DataFrame # # This notebook shows `pandas` `DataFrame` for each Mango Account belonging to a specified `Keypair`. # # It fetches the data from Solana, parses it, runs the calculations, and then displays it. # # In[ ]: import mango from IPython.display import display from solana.publickey import PublicKey with mango.ContextBuilder.build(cluster_name="devnet") as context: group = mango.Group.load(context) cache: mango.Cache = mango.Cache.load(context, group.cache) account = mango.Account.load(context, PublicKey("HhepjyhSzvVP7kivdgJH9bj32tZFncqKUwWidS1ja4xL"), group) open_orders = account.load_all_spot_open_orders(context) frame = account.to_dataframe(group, open_orders, cache) display(frame) print(f"Init Health: {account.init_health(frame)}") print(f"Maint Health: {account.maint_health(frame)}") print(f"Total Value: {account.total_value(frame)}") print(f"Leverage: {account.leverage(frame):,.2f}x") print("Example complete.")