Skip to main content

Account PnL Current

Get the current Profit and Loss (PnL) snapshot for an account, including equity value, net invested amount, and unrealized gains.

Query Structure​

query GetAccountPnlCurrent($input: GetAccountPnlCurrentInput!) {
getAccountPnlCurrent(input: $input) {
account_id
equity_value
net_invested
total_pnl
unrealized_pnl
pnl_pct
total_assets_in
total_assets_out
timestamp
}
}

Variables​

The query takes a single input object:

FieldTypeRequiredDescription
account_idStringYesAccount address to query
{
"input": {
"account_id": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
}
}

Response Fields​

FieldTypeDescription
account_idStringThe queried account address
equity_valueStringCurrent total equity value (shares_total * share_price / 1e18)
net_investedStringNet amount invested (total_assets_in - total_assets_out)
total_pnlStringTotal profit/loss (equity_value + total_assets_out - total_assets_in)
unrealized_pnlStringUnrealized profit/loss (equity_value - net_invested)
pnl_pctStringPnL as a percentage of net invested
total_assets_inStringTotal assets deposited
total_assets_outStringTotal assets redeemed
timestampDateTimeTimestamp of the snapshot

Expected Response​

{
"data": {
"getAccountPnlCurrent": {
"account_id": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
"equity_value": "15.234567890123456789",
"net_invested": "10.000000000000000000",
"total_pnl": "5.234567890123456789",
"unrealized_pnl": "5.234567890123456789",
"pnl_pct": "52.34",
"total_assets_in": "12.000000000000000000",
"total_assets_out": "2.000000000000000000",
"timestamp": "2024-01-15T10:30:00Z"
}
}
}

Interactive Example​

Query

query GetAccountPnlCurrent($input: GetAccountPnlCurrentInput!) {
  getAccountPnlCurrent(input: $input) {
    account_id
    equity_value
    net_invested
    total_pnl
    unrealized_pnl
    pnl_pct
    total_assets_in
    total_assets_out
    timestamp
  }
}

Variables

Click "Run Query" to execute the GraphQL query and see results

Use Cases​

Portfolio Dashboard Widget​

Display current portfolio performance:

import { GraphQLClient } from 'graphql-request'
import { API_URL_PROD } from '@0xintuition/graphql'

const client = new GraphQLClient(API_URL_PROD)

async function getPortfolioPnl(accountId: string) {
const query = `
query GetAccountPnlCurrent($input: GetAccountPnlCurrentInput!) {
getAccountPnlCurrent(input: $input) {
equity_value
net_invested
total_pnl
unrealized_pnl
pnl_pct
}
}
`

const data = await client.request(query, {
input: { account_id: accountId }
})
return data.getAccountPnlCurrent
}

// Usage
const pnl = await getPortfolioPnl('0x...')
console.log(`Equity Value: ${pnl.equity_value}`)
console.log(`Total PnL: ${pnl.total_pnl} (${pnl.pnl_pct}%)`)