> For the complete documentation index, see [llms.txt](https://docs.mysticfinance.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mysticfinance.xyz/api/mystic-morpho-graphql-api.md).

# Mystic Morpho GraphQL API

### Introduction

The Mystic Morpho API lets you read all kinds of Morpho data in real-time on the chains Morpho is on. Track your positions, liquidate, manage risk or build your own Morpho-powered app using Mystic's Morpho API. Note that to use it, you will need your own API Key. Please contact us to get an API Key and get started -> [**Contact us**](mailto:joao.moreira@mysticfinance.xyz)**.**

### Base URL

{% tabs %}
{% tab title="Production" %}

```
https://api.mysticfinance.xyz/graphql
```

{% endtab %}

{% tab title="Staging" %}

```
https://staging-api.mysticfinance.xyz/graphql
```

{% endtab %}
{% endtabs %}

### Authentication

To call the API, you need to an API Key. API Key usage is billed monthly and the Key will expire if payment fails. An expired key returns `401`.&#x20;

#### Making a Request

GraphQL is **`POST` +** a JSON body, you must send `Content-Type: application/json` and a body containing `query` (and optionally `variables`).&#x20;

```
curl "https://api.mysticfinance.xyz/graphql" \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "query": "query Markets($ids: [ChainId!]) { morphoMarkets(where: { chainId_in: $ids }, limit: 2) { items { marketId name supplyApy { total } } } }",
    "variables": { "ids": [98866] }
  }'
```

#### What you can Query

| Query                                   | Returns                                                                                     |
| --------------------------------------- | ------------------------------------------------------------------------------------------- |
| `morphoMarkets(where, limit, skip)`     | Returns Data for Markets                                                                    |
| `morphoVaults(where, limit, skip)`      | Returns Data for Vaults                                                                     |
| `marketHistory(marketId!, chainId)`     | Daily history for one market                                                                |
| `vaultHistory(vaultAddress!, chainId)`  | Daily history for one vault                                                                 |
| `openPositions(chainId, …, page)`       | Paginated list of open borrow positions and their risk of liquidation (LTVs, HFs and more). |
| `liquidatedPositions(chainId, …, page)` | Past liquidations, newest first (paginated).                                                |

#### Example Queries

**Markets**

```graphql
query Markets {
  morphoMarkets(where: { chainId_in: [98866] }, limit: 50, skip: 0) {
    pageInfo { countTotal hasNextPage }
    items {
      marketId
      name
      isIdle
      lltv { formatted }
      utilization
      liquidationPenalty
      collateralAsset { symbol address priceUsd decimals }
      loanAsset { symbol address priceUsd decimals }
      totalSupplied { formatted usd }
      totalBorrowed { formatted usd }
      liquidityInMarket { formatted usd }
      supplyApy { base rewards { asset { symbol } apr } total }
      borrowApy { base total }
      chain { id name }
    }
  }
}
```

**Vaults**

```graphql
query Vaults {
  morphoVaults(where: { chainId_in: [98866] }, limit: 50, skip: 0) {
    pageInfo { countTotal hasNextPage }
    items {
      vaultAddress
      name
      decimals
      asset { symbol address priceUsd }
      metadata { curators { name } }
      totalSupplied { formatted usd }
      totalLiquidity { formatted usd }
      supplyApy { base rewards { asset { symbol } apr } total fee }
      supplyApy7d { total }
      supplyApy30d { total }
      performanceFee
      curatorAddress
      marketAllocations {
        market { marketId name }
        supplyCap { usd }
      }
    }
  }
}
```

**Market and Vaults History**

```graphql
query History {
  marketHistory(marketId: "0x…", chainId: 98866) {
    daily {
      bucketTimestamp
      totalSupplied { usd }
      totalBorrowed { usd }
      supplyApy30d { total }
      borrowApy30d { total }
    }
  }
  vaultHistory(vaultAddress: "0x…", chainId: 98866) {
    daily {
      bucketTimestamp
      totalSupplied { usd }
      supplyApy30d { total }
    }
  }
}
```

**Open Positions**

```graphql
query OpenPositions {
  openPositions(
    chainId: 98866
    minHealthFactor: 0.9
    maxHealthFactor: 1.1
    page: 0
  ) {
    totalItems
    page
    limit
    totalPages
    data {
      marketId
      borrower
      healthFactor
      liquidatablePosition
      positionWithBadDebt
      badDebt
      collateralToBeSeized
      debtToBeRepaid
      openPremium
      liquidationPenalty
    }
  }
}
```

**Liquidated Positions**

```graphql
query LiquidatedPositions {
  liquidatedPositions(chainId: 98866, page: 0) {
    totalItems
    totalPages
    data {
      marketId
      liquidator
      liquidatee
      collateralSeized
      debtRepaid
      premium
      profit
      timestamp
      transactionHash
    }
  }
}
```
