Skip to main content
All queries target the subgraph’s GraphQL endpoint. See Overview for endpoint URLs.

Position Queries

Open Positions for an Account

query OpenPositions($account: ID!) {
  positions(
    where: { account: $account, status: "OPEN" }
    orderBy: openTimestamp
    orderDirection: desc
    first: 25
  ) {
    id
    pairId
    side
    tenor
    notional
    entryStrike
    fixingTimestamp
    imLocked
    mmThreshold
    openTimestamp
  }
}

Position History with PnL

query ClosedPositions($account: ID!, $first: Int!, $skip: Int!) {
  positions(
    where: { account: $account, status_not: "OPEN" }
    orderBy: closeTimestamp
    orderDirection: desc
    first: $first
    skip: $skip
  ) {
    id
    side
    tenor
    notional
    entryStrike
    status
    closeReason
    closedPrice
    realizedPnl
    marketPnl
    openTimestamp
    closeTimestamp
  }
}

Single Position by ID

query Position($id: ID!) {
  position(id: $id) {
    id
    account { id }
    pairId
    side
    tenor
    notional
    entryStrike
    fixingTimestamp
    imLocked
    mmThreshold
    snapshotImBps
    snapshotMmBps
    status
    closeReason
    closedPrice
    realizedPnl
    marketPnl
    openTxHash
    closeTxHash
    openTimestamp
    closeTimestamp
  }
}

Account Queries

Account Overview

query Account($id: ID!) {
  account(id: $id) {
    collateralBalance
    imLockedTotal
    availableBalance
    positionCount
    openPositionCount
    totalRealizedPnl
    lpShares
    lpAssetsDeposited
  }
}

Top Accounts by Realized PnL

query TopTraders {
  accounts(
    orderBy: totalRealizedPnl
    orderDirection: desc
    first: 10
    where: { positionCount_gt: 0 }
  ) {
    id
    totalRealizedPnl
    positionCount
    openPositionCount
  }
}

Pool State

Current Pool Snapshot

query PoolState {
  poolState(id: "pool") {
    totalAssets
    totalShares
    netExposure
    grossNotional
    sharePrice
    totalPnlApplied
    totalFeesCollected
    tradingFeesCollected
    liquidationFeesCollected
    terminationFeesCollected
    oracleFeesCollected
    depositCount
    withdrawCount
  }
}

Vault Events

LP Deposit/Withdraw History

query VaultHistory($first: Int!, $skip: Int!) {
  vaultEvents(
    orderBy: timestamp
    orderDirection: desc
    first: $first
    skip: $skip
  ) {
    id
    type
    sender
    owner
    assets
    shares
    timestamp
    txHash
  }
}

Deposits Only

query Deposits($first: Int!) {
  vaultEvents(
    where: { type: "DEPOSIT" }
    orderBy: timestamp
    orderDirection: desc
    first: $first
  ) {
    sender
    assets
    shares
    timestamp
  }
}

Oracle Queries

Latest Forward Rounds

query LatestForwardRounds {
  oracleRounds(
    where: { isLatest: true }
    orderBy: publishTime
    orderDirection: desc
    first: 10
  ) {
    id
    fixingTimestamp
    forwardPrice
    roundId
    publishTime
  }
}

Forward Price History for a Fixing Timestamp

query ForwardHistory($fixingTs: BigInt!) {
  oracleRounds(
    where: { fixingTimestamp: $fixingTs }
    orderBy: roundId
    orderDirection: asc
    first: 100
  ) {
    roundId
    forwardPrice
    publishTime
  }
}

Fixing Prices

query FixingPrices($first: Int!) {
  fixingPrices(
    orderBy: fixingTimestamp
    orderDirection: desc
    first: $first
  ) {
    pairId
    fixingTimestamp
    price
    timestamp
    txHash
  }
}

Activity Feed

Unified Pool Transactions

The PoolTransaction entity provides a single timeline of all position-related activity.
query ActivityFeed($first: Int!, $skip: Int!) {
  poolTransactions(
    orderBy: timestamp
    orderDirection: desc
    first: $first
    skip: $skip
  ) {
    id
    type
    positionId
    account
    notional
    pnl
    tradingFee
    oracleFee
    timestamp
    txHash
  }
}

Activity by Account

query AccountActivity($account: Bytes!, $first: Int!) {
  poolTransactions(
    where: { account: $account }
    orderBy: timestamp
    orderDirection: desc
    first: $first
  ) {
    type
    positionId
    notional
    pnl
    tradingFee
    timestamp
    txHash
  }
}

Analytics

Daily Stats

query DailyStats($first: Int!) {
  dailyStats_collection(
    orderBy: id
    orderDirection: desc
    first: $first
  ) {
    id
    date
    positionsOpened
    positionsClosed
    totalVolume
    totalPnl
    totalFees
    forwardRounds
  }
}

Protocol State

Current Mode and Transition History

query ProtocolState {
  protocolState(id: "protocol") {
    currentMode
    modeTransitionCount
    oracleInvalidatedCount
    lastModeTransition {
      fromMode
      toMode
      reasonCode
      actor
      timestamp
    }
  }
}
query ModeHistory($first: Int!) {
  modeTransitions(
    orderBy: timestamp
    orderDirection: desc
    first: $first
  ) {
    fromMode
    toMode
    reasonCode
    actor
    timestamp
    txHash
  }
}

Position Reductions

query Reductions($positionId: ID!, $first: Int!) {
  positionReductions(
    where: { position: $positionId }
    orderBy: timestamp
    orderDirection: desc
    first: $first
  ) {
    reductionNotional
    remainingNotional
    settledPnl
    fee
    timestamp
    txHash
  }
}

Pagination

Cursor-based pagination and advanced filtering.

Schema Reference

Complete entity and field definitions.

Data Source Guide

When to query the subgraph vs RPC.