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)β
| Field | Type | Nullable | Description |
|---|---|---|---|
id | bigint | No | Change record ID |
account_id | String | No | Account that made the change |
term_id | String | No | Term ID |
curve_id | numeric | No | Bonding curve ID |
event_id | String | No | Associated event ID |
event_type | String | No | Type of event (deposit/redemption) |
assets_in | numeric | No | Assets deposited |
assets_out | numeric | No | Assets redeemed |
shares_delta | numeric | No | Change in shares (positive for deposits, negative for redemptions) |
block_number | numeric | No | Block number |
log_index | bigint | No | Log index within block |
created_at | timestamptz | No | Event timestamp |
transaction_hash | String | No | Transaction hash |
Relationshipsβ
| Field | Type | Description |
|---|---|---|
account | accounts | Account that made the change |
term | terms | Associated term |
vault | vaults | Associated 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)β
| Field | Type | Description |
|---|---|---|
bucket | timestamptz | Day bucket timestamp |
account_id | String | Account ID |
term_id | String | Term ID |
curve_id | numeric | Bonding curve ID |
assets_in_period | numeric | Total assets deposited in this day |
assets_out_period | numeric | Total assets redeemed in this day |
shares_delta_period | numeric | Net share change for the day |
transaction_count | numeric | Number 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 })
}
Relatedβ
- Positions with Value - Enriched position data
- User Positions - Basic position queries
- Deposits & Redemptions - Transaction history