Skip to main content

Account PnL Realized

Get realized Profit and Loss (PnL) data for an account over a specified time range.

Query Structure​

query GetAccountPnlRealized($input: GetAccountPnlRealizedInput!) {
getAccountPnlRealized(input: $input) {
account_id
count
data
}
}

Variables​

The query takes a single input object:

FieldTypeRequiredDescription
account_idStringYesAccount address to query
start_timeStringYesStart of the time range (ISO 8601 timestamp)
end_timeStringYesEnd of the time range (ISO 8601 timestamp)
{
"input": {
"account_id": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
"start_time": "2024-01-01T00:00:00Z",
"end_time": "2024-01-31T23:59:59Z"
}
}

Response Fields​

FieldTypeDescription
account_idStringThe queried account address
countIntNumber of data points returned
dataJSONRealized PnL data for the time range

Expected Response​

{
"data": {
"getAccountPnlRealized": {
"account_id": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
"count": 5,
"data": [
{
"timestamp": "2024-01-05T12:00:00Z",
"realized_pnl": "0.750000000000000000"
},
{
"timestamp": "2024-01-15T08:30:00Z",
"realized_pnl": "1.250000000000000000"
}
]
}
}
}

Interactive Example​

Query

query GetAccountPnlRealized($input: GetAccountPnlRealizedInput!) {
  getAccountPnlRealized(input: $input) {
    account_id
    count
    data
  }
}

Variables

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

Use Cases​

Realized Gains Report​

Generate a report of realized gains over a period:

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

const client = new GraphQLClient(API_URL_PROD)

async function getRealizedPnl(accountId: string, days: number = 30) {
const endTime = new Date()
const startTime = new Date()
startTime.setDate(startTime.getDate() - days)

const query = `
query GetAccountPnlRealized($input: GetAccountPnlRealizedInput!) {
getAccountPnlRealized(input: $input) {
account_id
count
data
}
}
`

const data = await client.request(query, {
input: {
account_id: accountId,
start_time: startTime.toISOString(),
end_time: endTime.toISOString()
}
})

return data.getAccountPnlRealized
}

Best Practices​

  1. Use appropriate time ranges - Narrow ranges return faster and produce more focused results
  2. Combine with current PnL - Use alongside getAccountPnlCurrent for a complete picture of realized + unrealized gains