Skip to main content

Position Changes

Track individual position changes and view pre-aggregated daily/hourly summaries. Position changes record every deposit and redemption event that modifies a position.

Individual Changes​

Query Structure​

query GetPositionChanges(
$accountId: String!
$termId: String!
$limit: Int!
) {
position_changes(
where: {
account_id: { _eq: $accountId }
term_id: { _eq: $termId }
}
order_by: { created_at: desc }
limit: $limit
) {
id
account_id
term_id
curve_id
event_type
assets_in
assets_out
shares_delta
block_number
created_at
transaction_hash
}
}

Response Fields (position_changes)​

FieldTypeNullableDescription
idbigintNoChange record ID
account_idStringNoAccount that made the change
term_idStringNoTerm ID
curve_idnumericNoBonding curve ID
event_idStringNoAssociated event ID
event_typeStringNoType of event (deposit/redemption)
assets_innumericNoAssets deposited
assets_outnumericNoAssets redeemed
shares_deltanumericNoChange in shares (positive for deposits, negative for redemptions)
block_numbernumericNoBlock number
log_indexbigintNoLog index within block
created_attimestamptzNoEvent timestamp
transaction_hashStringNoTransaction hash

Relationships​

FieldTypeDescription
accountaccountsAccount that made the change
termtermsAssociated term
vaultvaultsAssociated vault

Daily Aggregates​

Pre-computed daily summaries of position changes, bucketed by day.

query GetDailyPositionChanges(
$accountId: String!
$termId: String!
$limit: Int!
) {
position_change_daily(
where: {
account_id: { _eq: $accountId }
term_id: { _eq: $termId }
}
order_by: { bucket: desc }
limit: $limit
) {
bucket
account_id
term_id
curve_id
assets_in_period
assets_out_period
shares_delta_period
transaction_count
}
}

Response Fields (position_change_daily)​

FieldTypeDescription
buckettimestamptzDay bucket timestamp
account_idStringAccount ID
term_idStringTerm ID
curve_idnumericBonding curve ID
assets_in_periodnumericTotal assets deposited in this day
assets_out_periodnumericTotal assets redeemed in this day
shares_delta_periodnumericNet share change for the day
transaction_countnumericNumber of transactions in this day

Hourly Aggregates​

Same structure as daily, bucketed by hour.

query GetHourlyPositionChanges(
$accountId: String!
$termId: String!
$limit: Int!
) {
position_change_hourly(
where: {
account_id: { _eq: $accountId }
term_id: { _eq: $termId }
}
order_by: { bucket: desc }
limit: $limit
) {
bucket
account_id
term_id
curve_id
assets_in_period
assets_out_period
shares_delta_period
transaction_count
}
}

The hourly view has the same fields as daily. The transaction_count type is bigint (vs numeric for daily).

Interactive Example​

Query

query GetPositionChanges($accountId: String!, $limit: Int!) {
  position_changes(
    where: { account_id: { _eq: $accountId } }
    order_by: { created_at: desc }
    limit: $limit
  ) {
    id
    term_id
    event_type
    assets_in
    assets_out
    shares_delta
    created_at
    transaction_hash
  }
}

Variables

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

Use Cases​

Activity Timeline​

async function getPositionActivity(accountId: string, termId: string) {
const query = `
query GetActivity($accountId: String!, $termId: String!) {
position_changes(
where: {
account_id: { _eq: $accountId }
term_id: { _eq: $termId }
}
order_by: { created_at: desc }
limit: 50
) {
event_type
assets_in
assets_out
shares_delta
created_at
transaction_hash
}
position_changes_aggregate(
where: {
account_id: { _eq: $accountId }
term_id: { _eq: $termId }
}
) {
aggregate {
count
sum {
assets_in
assets_out
}
}
}
}
`

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