Skip to main content

Positions with Value

Query positions enriched with computed value fields including PnL, redeemable assets, and theoretical value. This is a view that extends the base positions table with real-time calculations.

Query Structure​

query GetPositionsWithValue($accountId: String!, $limit: Int!) {
positions_with_value(
where: { account_id: { _eq: $accountId } }
order_by: { redeemable_assets: desc }
limit: $limit
) {
id
account_id
term_id
curve_id
shares
redeemable_assets
theoretical_value
pnl
pnl_pct
total_deposit_assets_after_total_fees
total_redeem_assets_for_receiver
created_at
updated_at
}
}

Response Fields​

FieldTypeDescription
idStringPosition identifier
account_idStringAccount holding the position
term_idStringTerm ID for the vault
curve_idnumericBonding curve ID
sharesnumericNumber of shares held
redeemable_assetsnumericCurrent redeemable value in assets
theoretical_valuenumericTheoretical position value
pnlnumericProfit and loss (assets)
pnl_pctnumericPnL as percentage
total_deposit_assets_after_total_feesnumericTotal deposited (after fees)
total_redeem_assets_for_receivernumericTotal redeemed
block_numberbigintBlock number of last update
log_indexbigintLog index
transaction_hashStringLast transaction hash
created_attimestamptzPosition creation time
updated_attimestamptzLast update time

Relationships​

FieldTypeDescription
accountaccountsAccount that holds this position
termtermsAssociated term entity
vaultvaultsAssociated vault

Interactive Example​

Query

query GetPositionsWithValue($accountId: String!, $limit: Int!) {
  positions_with_value(
    where: { account_id: { _eq: $accountId } }
    order_by: { redeemable_assets: desc }
    limit: $limit
  ) {
    id
    term_id
    curve_id
    shares
    redeemable_assets
    pnl
    pnl_pct
    account {
      label
    }
  }
}

Variables

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

Use Cases​

Portfolio Dashboard​

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

const client = new GraphQLClient(API_URL_PROD)

async function getPortfolio(accountId: string) {
const query = `
query GetPortfolio($accountId: String!) {
positions_with_value(
where: {
account_id: { _eq: $accountId }
shares: { _gt: "0" }
}
order_by: { redeemable_assets: desc }
) {
term_id
curve_id
shares
redeemable_assets
pnl
pnl_pct
vault {
current_share_price
market_cap
}
}
positions_with_value_aggregate(
where: {
account_id: { _eq: $accountId }
shares: { _gt: "0" }
}
) {
aggregate {
count
sum {
redeemable_assets
pnl
}
}
}
}
`

return client.request(query, { accountId })
}

Compared to positions​

Featurepositionspositions_with_value
Base fieldsid, shares, account_id, term_id, curve_idSame
PnL fieldsNopnl, pnl_pct
Value fieldsNoredeemable_assets, theoretical_value
Deposit/redeem totalsNototal_deposit_assets_after_total_fees, total_redeem_assets_for_receiver