# 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](https://thegraph.com/hosted-service/subgraph/predy-dev/predy-v202-arbitrum). Refer to The Graph - [GraphQL API documentation](https://thegraph.com/docs/en/developer/graphql-api/) to learn how subgraph queries are structured.

### Asset

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

```graphql
{
  assets {
    id
  }
}
```

### VaultEntity

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

```graphql
{
  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.

```graphql
{
  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).

```graphql
{
  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.

```graphql
{
  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.

```graphql
{
  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.

```graphql
{
  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.

```graphql
{
  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.

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

### MetricsEntity

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

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

### AggregatedVolume

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

```graphql
{
  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).

```graphql
{
  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).

```graphql
{
  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.

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

### OpenInterestEntity

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

```graphql
{
  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.

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.predy.finance/predy-v2-documentation/developer/subgraph/queries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
