V3 Technical Docs
  • Deployed Contracts
    • Notional V3
      • Ethereum Mainnet
      • Arbitrum
  • Security
    • Audits
    • Bug Bounty
  • Currency Ids & Precision
    • Currency Ids
    • Market Indexes
    • Notional Internal Precision
  • Contract interaction guides
    • Intro
    • Trading guide
      • Deposit (Prime Lend)
      • Trade fCash (Borrow & Lend Fixed)
      • Add liquidity (Mint nTokens)
      • Withdraw liquidity (Redeem nTokens)
      • Withdraw (Prime Cash)
      • Settle Account
      • Enter Leveraged Vaults
      • Exit Leveraged Vaults
    • Accounts
    • Prime Cash Markets
    • fCash Markets
    • nTokens
    • Leveraged Vaults
    • Oracles
    • Governance parameters
  • Subgraph guides
    • Notional V3 Subgraphs
      • Fetch Notional Accounts
      • Fetch Notional's reserves
      • Fetch Notional nToken accounts
      • Fetch Historical Trades
      • Fetch an Account's P&L
      • Fetch current fCash and Prime Cash Rates
      • Fetch Historical Prime Cash & Prime Debt Exchange Rates
      • Fetch Prime Cash Market Balances
      • Fetch fCash Market Balances
      • Fetch Outstanding Debt
      • Fetch Historical nToken Exchange Rates
      • Fetch ETH Oracle Exchange Rates
      • Fetch Annual Incentive Rates
      • Fetch Interest Rate Models
      • Fetch Governance Parameters
  • Dune Dashboard
  • Notional Risk Docs
  • Notional V3 Docs
  • Notional Blog
Powered by GitBook
On this page
  • Get an account's balances
  • Fetch an account's positions in readable format
  • Get an account's free collateral
  • Get an account's Leveraged Vaults positions
  1. Contract interaction guides

Accounts

PreviousExit Leveraged VaultsNextPrime Cash Markets

Last updated 11 months ago

To get a list of Notional users, one can use this or use this .

Get an account's balances

account = notional.getAccount(accountAddress)

Fetch an account's positions in readable format

The following function can be used to make an account's balances more readable. This is especially useful when comparing an account's state before and after trading.

from datetime import datetime

# CurrencyId to Symbol Mapping
CURRENCY_ID_TO_SYMBOL = {
    1: "ETH",
    2: "DAI",
    3: "USDC",
    4: "WBTC",
    5: "wstETH",
    6: "FRAX",
    7: "rETH",
    8: "USDT",
}

# This function can be used to make an account's positions readable.
def getAccountPositions(address):
        account = notional.getAccount(address)
        dict = {}
        dict['Account Address'] = address
        dict['Free collateral (ETH)'] = notional.getFreeCollateral(address)[0] / 1e8

        for i in account[1]:
            if i[0] != 0:
                symbol = CURRENCY_ID_TO_SYMBOL[i[0]]
                dict[symbol] = {
                    'p{} Balance'.format(symbol): i[1]/1e8,
                    'n{} Balance'.format(symbol): i[2]/1e8} 

        for j in account[2]:
            symbol = CURRENCY_ID_TO_SYMBOL[j[0]]
            if j[2] == 1:
                dict[symbol].update({'f{} {} {}'.format(symbol, j[1], datetime.fromtimestamp(j[1]).date()): j[3] / 1e8})
        return dict

Get an account's free collateral

If a user's free collateral is negative, then the user is eligible to get liquidated. If the user's free collateral figure is positive the account is sufficiently collateralized.

notional.getFreeCollateral(accountAddress)

Get an account's Leveraged Vaults positions

Users can use the getVaultAccount methord to fetch an account's leveraged vault positions:

leveragedVaultAccount = notional.getVaultAccount(accountAddress, vaultAdderes)
accountVaultShares = leveragedVaultAccount["vaultShares"]/1e8
accountDebtInUnderlying = leveragedVaultAccount["accountDebtUnderlying"]/1e8

subgraph query
Dune query