> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gtfo.vc/llms.txt
> Use this file to discover all available pages before exploring further.

# Query the subgraph

> Exact schema and working queries for books, depth, and your orders.

The subgraph exposes typed entities. Below are working examples aligned with the schema.

<Note>
  Use `openOrders` for active orders. Use `orders` for complete history.
</Note>

### Books (paginate)

```graphql theme={null}
query Books($first: Int!, $skip: Int!) {
  books(first: $first, skip: $skip, orderBy: id) {
    id
    base {
      id
      symbol
      decimals
    }
    quote {
      id
      symbol
      decimals
    }
    unitSize
    makerPolicy {
      fee
      isFeeInQuote
    }
    takerPolicy {
      fee
      isFeeInQuote
    }
  }
}
```

### Depth by price level

```graphql theme={null}
query Depth($book: ID!, $first: Int!) {
  book(id: $book) {
    id
    depths(first: $first, orderBy: tick, orderDirection: desc) {
      tick
      unitAmount
      baseAmount
      quoteAmount
    }
  }
}
```

### Active orders for a user

```graphql theme={null}
query MyOpenOrders($owner: Bytes!, $book: ID!) {
  openOrders(
    where: { owner: $owner, book: $book }
    orderBy: tick
    orderDirection: desc
  ) {
    id
    tick
    unitAmount
    pendingUnitAmount
    claimableUnitAmount
    cancelableUnitAmount
    timestamp
  }
}
```

### Recent taker trades (takes) in a book

```graphql theme={null}
query RecentTakes($book: ID!, $first: Int!) {
  takes(
    where: { book: $book }
    first: $first
    orderBy: timestamp
    orderDirection: desc
  ) {
    id
    timestamp
    trader
    inputToken {
      id
      symbol
    }
    outputToken {
      id
      symbol
    }
    inputAmount
    outputAmount
    amountUSD
    transaction {
      id
    }
  }
}
```

### Order history with fills, claims, and cancels

```graphql theme={null}
query OrderHistory($orderId: ID!) {
  order(id: $orderId) {
    id
    tick
    price
    unitAmount
    pendingUnitAmount
    fills(orderBy: timestamp, orderDirection: asc) {
      id
      timestamp
      inputAmount
      outputAmount
      transaction {
        id
      }
    }
    claims(orderBy: timestamp, orderDirection: asc) {
      id
      timestamp
      claimedUnitAmount
      transaction {
        id
      }
    }
    cancels(orderBy: timestamp, orderDirection: asc) {
      id
      timestamp
      canceledUnitAmount
      transaction {
        id
      }
    }
  }
}
```

### Maker fills for a user across all books

```graphql theme={null}
query MakerFillsByUser($maker: Bytes!, $first: Int!) {
  makerFills(
    where: { maker: $maker }
    first: $first
    orderBy: timestamp
    orderDirection: desc
  ) {
    id
    timestamp
    book {
      id
      base {
        symbol
      }
      quote {
        symbol
      }
    }
    tick
    price
    inputAmount
    outputAmount
    amountUSD
    orderIdString
  }
}
```

### All trades for a given user in a book

```graphql theme={null}
query UserTradesInBook($user: Bytes!, $book: ID!, $first: Int!) {
  trades(
    where: { trader: $user, book: $book }
    first: $first
    orderBy: timestamp
    orderDirection: desc
  ) {
    id
    type
    timestamp
    trader
    book {
      id
    }
    inputToken {
      id
      symbol
    }
    outputToken {
      id
      symbol
    }
    inputAmount
    outputAmount
    amountUSD
    logIndex
    transaction {
      id
    }
  }
}
```

### Cancels for a specific order

```graphql theme={null}
query OrderCancels($orderId: ID!) {
  order(id: $orderId) {
    id
    tick
    price
    cancels(orderBy: timestamp, orderDirection: asc) {
      id
      timestamp
      canceller
      owner
      canceledUnitAmount
      canceledBaseAmount
      canceledQuoteAmount
      canceledAmountUSD
      remainingClaimableUnitAmount
      remainingCancelableUnitAmount
      transaction {
        id
      }
    }
  }
}
```

### Claims by owner across all books

```graphql theme={null}
query ClaimsByOwner($owner: Bytes!, $first: Int!) {
  claims(
    where: { owner: $owner }
    first: $first
    orderBy: timestamp
    orderDirection: desc
  ) {
    id
    timestamp
    book {
      id
      base {
        symbol
      }
      quote {
        symbol
      }
    }
    claimer
    orderIdString
    tick
    price
    claimedUnitAmount
    claimedBaseAmount
    claimedQuoteAmount
    claimedAmountUSD
    transaction {
      id
    }
  }
}
```

### Cancels by owner across all books

```graphql theme={null}
query CancelsByOwner($owner: Bytes!, $first: Int!) {
  cancels(
    where: { owner: $owner }
    first: $first
    orderBy: timestamp
    orderDirection: desc
  ) {
    id
    timestamp
    book {
      id
      base {
        symbol
      }
      quote {
        symbol
      }
    }
    canceller
    orderIdString
    tick
    price
    canceledUnitAmount
    canceledBaseAmount
    canceledQuoteAmount
    canceledAmountUSD
    transaction {
      id
    }
  }
}
```

### All order movements (takes, claims, cancels) for a user

Using the `OrderMovement` interface to query all order movements:

```graphql theme={null}
query UserOrderMovements($trader: Bytes!, $book: ID!, $first: Int!) {
  orderMovements(
    where: { trader: $trader, book: $book }
    first: $first
    orderBy: timestamp
    orderDirection: desc
  ) {
    id
    type
    timestamp
    trader
    book {
      id
    }
    logIndex
    transaction {
      id
    }
    ... on Take {
      inputToken {
        symbol
      }
      outputToken {
        symbol
      }
      inputAmount
      outputAmount
    }
    ... on Claim {
      orderIdString
      claimedUnitAmount
      claimedQuoteAmount
    }
    ... on Cancel {
      orderIdString
      canceledUnitAmount
      canceledQuoteAmount
    }
  }
}
```
