Queries

This page provides example queries for the Predy subgraph, you can try any of these queries or write your own on the Predy subgraph playground. Refer to The Graph - GraphQL API documentation to learn how subgraph queries are structured.

Asset

Returns a list of all contracts that generated entities for the subgraph.

{
  assets {
    id
  }
}

VaultEntity

Gets the 5 most recently created vaults and returns their owner address (account) and a history of their trading/margin actions.

{
  vaultEntities(
    first: 5
    orderBy: vaultId
    orderDirection: desc
  ) {
    vaultId
    account
    history {
      txid
      subVaultIndex
      timestamp
      productId
      action
      tradeAmount
      tradePrice
      marginAmount
    }
  }
}

SubVaultEntity

Gets the subvaults for vault number XX and returns the subvault ID and metadata.

{
  subVaultEntities(
    where: { vault: "XX" }
  ) {
    subVaultId
    metadata
  }
}

TradeHistoryEntity

Gets all trade/margin events between timestamps 1655272800 (June 15 2022 00:00:00) and 1655359200 (June 16 2022 00:00:00).

{
  tradeHistoryEntities(
    where: { timestamp_gte: 1655272800, timestamp_lt: 1655359200 }
  ) {
    txid
    action
    productId
    tradeAmount
    tradePrice
    fundingFeePerPosition
    marginAmount
  }
}

PoolDepositedEntity

Gets pool deposits over $10,000, ordered largest to smallest, return the USDC deposited and the amount of LP tokens minted.

{
  poolDepositedEntities(
    where: { depositAmount_gt: 10000000 }
    orderBy: depositAmount
    orderDirection: desc
  ) {
    id
    mintAmount
    depositAmount
  }
}

PoolWithdrawnEntity

Get the 10 most recent pool withdrawals and return the amount of LP token burned and the USDC withdrawn.

{
  poolWithdrawnEntities(
    first: 10
    orderBy: timestamp
    orderDirection: desc
  ) {
      id
      burnAmount
      withdrawAmount
  }
}

HedgedEntity

Get the hedging actions performed, ordered oldest to most recent, and returns the amount of USDC and ETH traded and the direction of the trade.

{
  hedgedEntities(
    orderBy: timestamp
  ) {
    timestamp
    isBuyingUnderlying
    usdcAmount
    underlyingAmount
  }
}

FundingPaymentEntity

Get the highest 10 funding rates since timestamp 1655272800 (June 15 2022 00:00:00), returning the timestamp and rate.

{
  fundingPaymentEntities(
    first: 10
    where: { timestamp_gte: 1655272800 }
    orderBy: fundingRate
    orderDirection: desc
  ) {
    timestamp
    fundingRate
  }
}

VarianceUpdatedEntity

Gets the 10 most recent variance updates and returns the timestamp, ETH price, and variance for those updates.

{
  varianceUpdatedEntities(
    first: 10
    orderBy: timestamp
    orderDirection: desc
  ) {
    timestamp
    price
    variance
  }
}

MetricsEntity

Gets the metrics entities for the current PerpetualMarket contract (0xadbaee9665c101413ebff07e20520bdb67c71ab6).

{
  metricsEntities(
    where: { asset: "0xadbaee9665c101413ebff07e20520bdb67c71ab6" }
  ) {
    id
    openLong
    openShort
    notionalVolume
  }
}

AggregatedVolume

Gets all WEEKLY aggregated volume statistics for product ID 1 (ETH²)

{
  aggregatedVolumes(
    where: { interval: WEEKLY, productId: 1 }
  ) {
    interval
    openTimestamp
    closeTimestamp
    productId
    volume
    notionalVolume
  }
}

AggregatedFundingPayment

Gets the aggregated DAILY funding statistics since timestamp 1655078400 (June 13 2022 00:00:00) for product ID 0 (ETH).

{
  aggregatedFundingPayments(
    where: { interval: DAILY, openTimestamp_gt: 1655078400, productId: 0 }
  ) {
    openTimestamp
    openFundingRate
    poolReceived
  }
}

LPTokenPriceEntity

Gets the first 100 LP token price updates since timestamp 1655078400 (June 13 2022 00:00:00).

{
  lpTokenPriceEntities(
    first: 100
    orderBy: timestamp
    orderDirection: asc
    where: {timestamp_gt: 1655078400}
  ) {
    id
    timestamp
    price
  }
}

AggregatedLpTokenPriceEntity

Gets the aggregated WEEKLY LP token price details (open, close, high, low) ordered by most recent to oldest.

{
  aggregatedLpTokenPriceEntities(
    orderDirection: desc
    where: { interval: WEEKLY }
  ) {
    openTimestamp
    open
    close
    high
    low
  }
}

OpenInterestEntity

Gets the latest 50 open interest updates for product ID 1 (ETH²).

{
  openInterestEntities(
    first: 50
    orderBy: timestamp
    orderDirection: desc
    where: { productId: 1 }
  ) {
    timestamp
    openLong
    openShort
  }
}

AggregatedOpenInterestEntity

Gets the aggregated HOURLY open interest details (open, close, high, low) for the past 24 hours, ordered by most recent to oldest.

{
  aggregatedOpenInterestEntities(
    first: 24
    orderBy: openTimestamp
    orderDirection: desc
    where: { interval: HOURLY }
  ) {
    openTimestamp
    open
    close
    high
    low
  }
}

Last updated