Morpho Markets
How to query Morpho Markets Data thanks to the API?
Select the query you are interested in in the list below, and paste it into the GraphQL Playground: https://api.morpho.org/graphql
By default, the Morpho API returns only the 100 first results and retrieve informations on the Ethereum network.
Discovery and Listing
Markets List
query {
markets {
items {
uniqueKey
lltv
oracleAddress
irmAddress
loanAsset {
address
symbol
decimals
}
collateralAsset {
address
symbol
decimals
}
state {
borrowAssets
supplyAssets
fee
utilization
}
}
}
}Market Parameters
query {
markets(
first: 100
orderBy: SupplyAssetsUsd
orderDirection: Desc
where: { chainId_in: [1, 8453] }
) {
items {
uniqueKey
loanAsset { address }
collateralAsset { address }
lltv
irmAddress
oracleAddress
}
}
}Market Metrics
Total Collateral, Borrow & Supply
query {
markets(
first: 100
orderBy: SupplyAssetsUsd
orderDirection: Desc
where: { chainId_in: [1, 8453] }
) {
items {
uniqueKey
state {
collateralAssets
collateralAssetsUsd
borrowAssets
borrowAssetsUsd
supplyAssets
supplyAssetsUsd
liquidityAssets
liquidityAssetsUsd
}
}
}
}Market APY (Native & Rewards)
query {
markets(
first: 100
orderBy: SupplyAssetsUsd
orderDirection: Desc
where: { chainId_in: [1, 8453] }
) {
items {
uniqueKey
state {
borrowApy
avgBorrowApy
avgNetBorrowApy
supplyApy
avgSupplyApy
avgNetSupplyApy
rewards {
asset {
address
chain {
id
}
}
supplyApr
borrowApr
}
}
}
}
}Asset Information
Assets (Price & Yield)
query GetAssetsWithPrice {
assets(where: { symbol_in: ["wstETH", "WETH"], chainId_in: [1] }) {
items {
symbol
address
priceUsd
chain {
id
network
}
}
}
}priceUsdis the current price of the asset in USD.oraclePriceUsdis a deprecated field, please use priceUsd instead.
Position Tracking
User Positions
User All Markets Position
query {
marketPositions(
first: 10,
orderBy: BorrowAssetsUsd,
orderDirection: Desc
where: {
marketUniqueKey_in: ["0x698fe98247a40c5771537b5786b2f3f9d78eb487b4ce4d75533cd0e94d88a115"]
}
) {
items {
user { address }
state {
collateral
borrowAssets
borrowAssetsUsd
}
}
}
}User Account Overview
query {
userByAddress(
chainId: 1
address: "0x821880a3E2bac432d67E5155e72BB655Ef65fa5E"
) {
address
marketPositions {
market {
uniqueKey
}
borrowAssets
borrowAssetsUsd
supplyAssets
supplyAssetsUsd
}
vaultPositions {
vault {
address
name
}
assets
assetsUsd
shares
}
transactions {
hash
timestamp
type
}
}
}All Market Positions
query {
marketPositions(
first: 10
orderBy: SupplyShares
orderDirection: Desc
where: {
marketUniqueKey_in: [
"0x698fe98247a40c5771537b5786b2f3f9d78eb487b4ce4d75533cd0e94d88a115"
]
}
) {
items {
market {
uniqueKey
loanAsset {
address
symbol
}
collateralAsset {
address
symbol
}
}
user {
address
}
state {
supplyShares
supplyAssets
supplyAssetsUsd
borrowShares
borrowAssets
borrowAssetsUsd
collateral
collateralUsd
}
}
}
}Risk & Oracle Data
Oracle Data
All Markets
query MARKETS_PARAMS {
markets(
first: 100
orderBy: SupplyAssetsUsd
orderDirection: Desc
where: { chainId_in: [1, 8453] }
) {
items {
uniqueKey
oracleAddress
oracle {
address
type
creationEvent {
txHash
timestamp
blockNumber
}
data {
... on MorphoChainlinkOracleV2Data {
baseFeedOne {
address
description
vendor
pair
}
baseFeedTwo {
address
}
baseVaultConversionSample
quoteFeedOne {
address
}
quoteFeedTwo {
address
}
quoteVaultConversionSample
}
... on MorphoChainlinkOracleData {
baseFeedOne {
address
description
vendor
pair
}
baseOracleVault {
address
}
}
}
}
oracleInfo {
type
}
}
}
}Specific Market
query {
marketByUniqueKey(
uniqueKey: "0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836"
chainId: 8453
) {
uniqueKey
oracleAddress
oracle {
address
type
creationEvent {
txHash
timestamp
blockNumber
}
data {
... on MorphoChainlinkOracleV2Data {
baseFeedOne {
address
description
vendor
pair
}
baseFeedTwo {
address
}
baseVaultConversionSample
quoteFeedOne {
address
}
quoteFeedTwo {
address
}
quoteVaultConversionSample
}
... on MorphoChainlinkOracleData {
baseFeedOne {
address
description
vendor
pair
}
baseOracleVault {
address
}
}
}
}
oracleInfo {
type
}
}
}Liquidations
query {
transactions(
where: {
marketUniqueKey_in: [
"0x49bb2d114be9041a787432952927f6f144f05ad3e83196a7d062f374ee11d0ee"
"0x093d5b432aace8bf6c4d67494f4ac2542a499571ff7a1bcc9f8778f3200d457d"
]
type_in: [MarketLiquidation]
}
) {
items {
blockNumber
hash
type
user {
address
}
data {
... on MarketLiquidationTransactionData {
seizedAssets
repaidAssets
seizedAssetsUsd
repaidAssetsUsd
badDebtAssetsUsd
liquidator
market {
uniqueKey
}
}
}
}
}
}Market Warnings
query {
markets {
items {
uniqueKey
warnings {
type
level
}
}
}
}Integration
Vault Listing
query {
marketByUniqueKey(
uniqueKey: "0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836"
chainId: 8453
) {
uniqueKey
supplyingVaults {
address
symbol
metadata {
description
}
}
}
}Historical Data
The historicalState allows to get historical data for certain queries. The queries need to be backfilled to return proper data (i.e. the historical data needs to be indexed and stored). Some queries are not backfilled and are flagged as deprecated in the Morpho API sandbox.
How to use the historicalState variables
Here are the available variables when using an historicalState query:
startTimestamp: beginning of the historical data in UNIX timestamp format,endTimestamp: end of the historical data in UNIX timestamp format,interval: interval of the historical data points (YEAR,QUARTER,MONTH,WEEK,DAY,HOUR). Inputting these variables is not mandatory but it is advised to specify them to control the specific data returned.
If no variables are specified, the default values will be:
startTimestamp: 0,endTimestamp: infinity,interval: will adjust according tostartTimestampandendTimestampto return around 50 data points.
Note that the historicalState field is not accessible through the (multiple) markets(...) and vaults(...) list queries. Historical data is only available through individual market or vault queries like market(id: ""), marketByUniqueKey, vault(id: "") or vaultByAddress.
Below you will find examples of historicalData queries.
Historical APYs
query MarketByUniqueKey($uniqueKey: String!, $options: TimeseriesOptions) {
marketByUniqueKey(uniqueKey: $uniqueKey) {
historicalState {
supplyApy(options: $options) {
x
y
}
borrowApy(options: $options) {
x
y
}
}
}
}With the following variables:
{
"variables": {
"startTimestamp": 1707749700,
"endTimestamp": 1708354500,
"interval": HOUR,
}
}Historical Market States
query MarketApys($options: TimeseriesOptions) {
marketByUniqueKey(
uniqueKey: "0x608929d6de2a10bacf1046ff157ae38df5b9f466fb89413211efb8f63c63833a"
) {
uniqueKey
historicalState {
supplyAssetsUsd(options: $options) {
x
y
}
borrowAssetsUsd(options: $options) {
x
y
}
}
}
}With the following variables:
"variables": {
"startTimestamp": 1707749700,
"endTimestamp": 1708354500,
"interval": HOUR,
}Historical Asset Price
query {
wstETHWeeklyPriceUsd: assetByAddress(
address: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
chainId: 1
) {
historicalPriceUsd(
options: {
startTimestamp: 1707749700
endTimestamp: 1708354500
interval: HOUR
}
) {
x
y
}
}
}All queries sent for assetByAddress, marketByUniqueKey and vaultByAddress should include the chainId parameter.
Advanced Features
Paging, Ordering & Filtering
query {
markets(
first: 3
skip: 1
orderBy: Lltv
orderDirection: Desc
where: {
collateralAssetAddress_in: ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]
}
) {
pageInfo {
count
countTotal
}
items {
uniqueKey
lltv
collateralAsset {
symbol
}
loanAsset {
symbol
}
}
}
}