Skip to main content

Account PnL Chart

Get historical Profit and Loss (PnL) time-series data for an account, suitable for charting portfolio performance over configurable intervals.

Query Structure​

query GetAccountPnlChart($input: GetAccountPnlChartInput!) {
getAccountPnlChart(input: $input) {
account_id
count
data
interval
}
}

Variables​

The query takes a single input object:

FieldTypeRequiredDescription
account_idStringYesAccount address to query
intervalStringYesTime interval for data points (e.g. "1h", "1d", "1w", "1M")
start_timeStringYesStart of the time range (ISO 8601 timestamp)
end_timeStringYesEnd of the time range (ISO 8601 timestamp)
{
"input": {
"account_id": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
"interval": "1d",
"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
dataJSONArray of PnL data points for the time range
intervalStringThe interval used for aggregation

Expected Response​

{
"data": {
"getAccountPnlChart": {
"account_id": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
"count": 31,
"data": [
{
"timestamp": "2024-01-01T00:00:00Z",
"equity_value": "10.000000000000000000",
"net_invested": "10.000000000000000000",
"total_pnl": "0.000000000000000000",
"pnl_pct": 0.0
},
{
"timestamp": "2024-01-02T00:00:00Z",
"equity_value": "10.500000000000000000",
"net_invested": "10.000000000000000000",
"total_pnl": "0.500000000000000000",
"pnl_pct": 5.0
}
],
"interval": "1d"
}
}
}

Interactive Example​

Query

query GetAccountPnlChart($input: GetAccountPnlChartInput!) {
  getAccountPnlChart(input: $input) {
    account_id
    count
    data
    interval
  }
}

Variables

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

Use Cases​

Portfolio Performance Chart​

Build a line chart showing portfolio value over time:

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

const client = new GraphQLClient(API_URL_PROD)

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

const query = `
query GetAccountPnlChart($input: GetAccountPnlChartInput!) {
getAccountPnlChart(input: $input) {
account_id
count
data
interval
}
}
`

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

return data.getAccountPnlChart
}

Best Practices​

  1. Choose appropriate intervals - Use "1h" for recent data, "1d" for weekly/monthly views, "1w" or "1M" for longer periods
  2. Limit date ranges - Request only the data needed; smaller ranges return faster
  3. Handle empty data - Display an appropriate message when count is 0