Advanced Market Queries

When developers build their own marketplace on top of the Living Assets platform, whether within a video game, a web browser, or a mobile app, they often use the trading API to build their own custom databases, optimising the specific functionalities that they need.

The allMarketAssetData query provides an off-the-shelf entry point to some of the most common operations to all marketplaces, including pagination and filters, to help developers bootstrap a custom marketplace until they integrate their own specific needs.

Query

allMarketAssetData(
  first: Int
  last: Int
  offset: Int
  before: Cursor
  after: Cursor
  orderBy: [MarketAssetDataOrderBy!] = [NATURAL]
  condition: MarketAssetDatumCondition
  filter: MarketAssetDatumFilter
): MarketAssetDataConnection

This query returns a paginated list of asset data (more examples below). The parameters first, last, offset, before, and after are used for pagination. The orderBy parameter is used to specify the ordering of the results, and the condition and filter parameters are used to filter the results.

Query Input

Relevant query inputs are the MarketAssetDatumCondition and MarketAssetDatumFilter which allow filtering the received data.

MarketAssetDatumCondition

input MarketAssetDatumCondition {
  assetId: String
  buynowId: String
  props: JSON
  metadata: JSON
  assetCreatedAt: Datetime
  price: String
  currencyId: Int
  buynowCreatedAt: Datetime
  buynowUpdatedAt: Datetime
  validUntil: BigInt
  symbol: String
  isForSale: Boolean
  universeId: Int
  collectionId: Int
  lastSaleUpdatedAt: Datetime
  assetPropsFilter: AssetPropsFilterInput
  marketMetaDataFilter: MarketMetadataFilterInput
}

The MarketAssetDatumCondition input is used to specify the condition to be used in determining which MarketAssetDatum objects should be returned by the query. All fields are tested for equality and combined via the logical operatorAND. It also contains the assetPropsFilter and marketMetaDataFilter inputs for filtering assets based on the contents of the props and metadata fields.

AssetPropsFilterInput

input AssetPropsFilterInput {
  key: String!
  exactValue: String
  containedValue: String
}

The AssetPropsFilterInput input is used to filter assets based on the contents of the props field. The key field specifies which key to filter on, and the exactValue and containedValue fields specify exact and partial matches, respectively.

The filter will only apply to the properties at the root level of the props JSON object.

MarketMetadataFilterInput

input MarketMetadataFilterInput {
  key: String!
  exactValue: String
  containedValue: String
}

The MarketMetadataFilterInput input is used to filter assets based on the contents of the metadata field. The key field specifies which key to filter on, and the exactValue and containedValue fields specify exact and partial matches, respectively.

MarketAssetDatumFilter

input MarketAssetDatumFilter {
  assetId: StringFilter
  buynowId: StringFilter
  assetCreatedAt: DatetimeFilter
  price: StringFilter
  currencyId: IntFilter
  buynowCreatedAt: DatetimeFilter
  buynowUpdatedAt: DatetimeFilter
  validUntil: BigIntFilter
  symbol: StringFilter
  isForSale: BooleanFilter
  universeId: IntFilter
  collectionId: IntFilter
  lastSaleUpdatedAt: DatetimeFilter
  and: [MarketAssetDatumFilter!]
  or: [MarketAssetDatumFilter!]
  not: MarketAssetDatumFilter
}

The MarketAssetDatumFilter input is used to filter MarketAssetDatum objects based on their fields. All fields are combined via the logical operator AND. It also contains the AND, OR, and NOT inputs for combining and negating filter expressions.

Available filters are: equalTo, in, lessThan, isNull and greaterThan.

Query Response

type MarketAssetDataConnection {
  nodes: [MarketAssetDatum]!
  edges: [MarketAssetDataEdge!]!
  pageInfo: PageInfo!
  totalCount: Int!
}

The MarketAssetDataConnection type represents a connection to a list of MarketAssetDatum objects. The nodes field is a list of the actual MarketAssetDatum objects, the edges field contains the MarketAssetDatum objects and cursors for pagination, the pageInfo field provides information about the current page, and the totalCount field provides the total number of MarketAssetDatum objects that match the query.

Query Response Fields

The relevant response field is MarketAssetDatum, which contains the returned information about the assets and their trades.

MarketAssetDatum type

type MarketAssetDatum {
  assetId: String
  buynowId: String
  props: JSON
  metadata: JSON
  assetCreatedAt: Datetime
  price: String
  currencyId: Int
  buynowCreatedAt: Datetime
  buynowUpdatedAt: Datetime
  validUntil: BigInt
  symbol: String
  isForSale: Boolean
  universeId: Int
  collectionId: Int
  lastSaleUpdatedAt: Datetime
}

Examples

Please find below some examples of allMarketAssetData GraphQL queries:

Filter by isForSale
query {
  allMarketAssetData(
    condition: {
      isForSale: true
    }
  ) {
    nodes {
      assetId
      price
      isForSale
    }
  }
}

This query will return all assets that are currently for sale.

Filter by Price
query {
  allMarketAssetData(
    filter: {
      price: { greaterThan: "100" }
    }
  ) {
    nodes {
      assetId
      price
    }
  }
}

This query will return all assets with a price greater than or equal to 100.

Order by Price
query {
  allMarketAssetData(
    orderBy: [PRICE_ASC]
  ) {
    nodes {
      assetId
      price
    }
  }
}

This query will return all assets sorted in ascending order by price.

Filter by Currency
query {
  allMarketAssetData(condition: { currencyId: 1 }) {
    nodes {
      assetId
      price
      currencyId
    }
  }
}

This query will return all assets with currency id equal to 1.

Filter by Time
query {
  allMarketAssetData(
    filter: {
      assetCreatedAt: { greaterThan: "2022-01-01T00:00:00Z" }
    }
  ) {
    nodes {
      assetId
      assetCreatedAt
    }
  }
}

This query will return all assets created after January 1st, 2022.

Filter by Asset Name Property
query {
  allMarketAssetData(
    condition: {
      assetPropsFilter: {
        key: "name"
        containedValue: "sword"
      }
    }
  ) {
    nodes {
      assetId
      props
    }
  }
}

This query will return all assets with the property "name" containing the word "sword".

Filter by Metadata
query {
  allMarketAssetData(
    condition: {
      marketMetaDataFilter: {
        key: "category"
        exactValue: "weapons"
      }
    }
  ) {
    nodes {
      assetId
      metadata
    }
  }
}

This query will return all assets with metadata containing the key "category" and value "weapons".

Filter by Collection and Universe
query {
  allMarketAssetData(
    condition: {
      collectionId: 633
      universeId: 123
    }
  ) {
    nodes {
      assetId
      universeId
    }
  }
}

This query will return all assets belonging collection id 633 and the universe with id 123.

Filter by Asset Creation Date and Update Date
query {
  allMarketAssetData(
    filter: {
      and: [
        { assetCreatedAt: { greaterThan: "2022-01-01T00:00:00Z" } },
        { buynowUpdatedAt: { greaterThan: "2022-02-01T00:00:00Z" } }
      ]
    }
  ) {
    nodes {
      assetId
      assetCreatedAt
      buynowUpdatedAt
    }
  }
}

This query will return all assets created after January 1st, 2022, and updated after February 1st, 2022.

Filter by Latest Sold
query {
  allMarketAssetData(
    filter: {
      lastSaleUpdatedAt: { isNull: false }
    }
    orderBy: [LAST_SALE_UPDATED_AT_DESC]
    first: 10
  ) {
    nodes {
      assetId
      lastSaleUpdatedAt
    }
  }
}

This query will return the 10 most recently sold assets, sorted by the date they were last sold. It filters by the lastSaleUpdatedAt field to only include assets that have been sold at least once.

Last updated

freeverse.io