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:
| Field | Type | Required | Description |
|---|---|---|---|
account_id | String | Yes | Account address to query |
start_time | String | Yes | Start of the time range (ISO 8601 timestamp) |
end_time | String | Yes | End 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β
| Field | Type | Description |
|---|---|---|
account_id | String | The queried account address |
count | Int | Number of data points returned |
data | JSON | Realized 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β
- Use appropriate time ranges - Narrow ranges return faster and produce more focused results
- Combine with current PnL - Use alongside
getAccountPnlCurrentfor a complete picture of realized + unrealized gains
Relatedβ
- Account PnL Current - Current PnL including unrealized
- Account PnL Chart - Historical PnL trends
- User Positions - Active positions