> For the complete documentation index, see [llms.txt](https://docs.optswap.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.optswap.org/technical-reference/subgraphs/querying/example-queries.md).

# Example Queries

Assuming your address is `0xd8da6bf26964af9d7eed9e03e53415d37aa96045` (Hi Vitalik 👋), here are some sample GraphQL queries to get you quickly started with OptSwaps subgraphs. Feel free to explore all the other entities and fields available!

{% hint style="info" %}
Refer to the associated smart contracts documentation for full details about the various returned enumerated types and denominations.
{% endhint %}

### My Orders

```graphql
# All My Orders
query MyOrders {
  optSwapOrders(where: { user: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045" }) {
    id
    contract
    optionStyle
    optionType
    strike0
    strike1
    expiry
    lotSize
    orderType
    premium
    lots
    user
    timestamp
    blockNumber
  }
}

# Response:
{
  "data": {
    "optSwapOrders": [
      {
        "id": "0x18bb81e4153528cd8823857726b2ca6f994450ae010bd20a9bb5550436fb6498-2",
        "contract": "0xdbebcddf47ea77561ab5f98c40baf2f89a6770d4",
        "optionStyle": 0, # European Style Option
        "optionType": 1, # Call Option
        "strike0": "12000000", # in basis points of the cash token
        "strike1": "170141183460469231731687303715884105728", # 2^127 for Call Options
        "expiry": "1657267200", # Unix timestamp
        "lotSize": "10000", # in basis points
        "orderType": 1, # Buy Order
        "premium": "100", # in basis points of the cash token
        "lots": "10",
        "user": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
        "timestamp": "1656920647", # Unix timestamp
        "blockNumber": "27025991"
      },
      ...
    ]
  }
}
```

### My Positions

```graphql
# All My Positions for a given expiry timestamp
query MyPositionsForLastExpiry {
  optSwapPositions(where: { expiry: "1657267200",  user: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045" }) {
    id
    contract
    optionStyle
    optionType
    strike0
    strike1
    expiry
    lotSize
    orderType
    lots
    lotsLocked
    lotsSettled
    bookedProfitsOrLosses
    user
    createdAt
    timestamp
    blockNumber
  }
}

# Response:
{
  "data": {
    "optSwapPositions": [
      {
        "id": "0xaccd7b5f1adaab6f911d3a944adcb5966ee220cfbf104e5e3cdd6e4803fec876",
        "contract": "0xdbebcddf47ea77561ab5f98c40baf2f89a6770d4",
        "optionStyle": 1, # American Style Option
        "optionType": 0, # Put Option
        "strike0": "12000000", # in basis points of the cash token
        "strike1": "0", # in basis points
        "expiry": "1657267200", # Unix timestamp
        "lotSize": "10000", # in basis points (of the underlying token)
        "orderType": 0, # Sell Order
        "lots": "3",
        "lotsLocked": "0",
        "lotsSettled": "3",
        "bookedProfitsOrLosses": "-372000000", # Negative values mean losses; in subunits of the Cash Token
        "user": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
        "createdAt": "1656919724", # Unix timestamp
        "timestamp": "1656919724", # Unix timestamp
        "blockNumber": "27025831"
      },
      ...
    ]
  }
}
```

### Latest Blocks

```graphql
# The latest block indexed by the subgraph
query LastIndexedBlock {
  latestBlock(id: "latest") {
    id
    timestamp
    number
  }
}

# Response:
{
  "data": {
    "latestBlock": {
      "id": "latest",
      "timestamp": "1657379691", # Unix timestamp
      "number": "27097838"
    }
  }
}

# Latest blocks in which each contract was interacted with
query ContractInteractionLatestBlocks {
  latestBlocks {
    id
    timestamp
    number
  }
}

# Response:
{
  "data": {
    "latestBlocks": [
      {
        "id": "MetaOracle",
        "timestamp": "1657365133", # Unix timestamp
        "number": "27095701" # Block number
      },
      {
        "id": "OptSwap-0x83577b77c5a0a169883bc5cd5d7585cc77c94358",
        "timestamp": "1656862308",
        "number": "27017041"
      },
      ...
      {
        "id": "OptSwapDAOVeToken",
        "timestamp": "1656863802",
        "number": "27017299"
      },
      {
        "id": "latest",
        "timestamp": "1657386405",
        "number": "27099049"
      }
    ]
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.optswap.org/technical-reference/subgraphs/querying/example-queries.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
