How does multiple sorting work?

Hello, how does the multiple sort works when you query for dex trades.

Example: desc: [“baseAmount”, “tradeIndex”]

I tried to run a few tests but I still don’t understand how the double sorting is happening compared to a regular simple sort like this desc: “baseAmount” for example.

Thank you

Multiple sort works on the principle that the GraphQL query sorts according to the first argument passed (in your case “baseAmount”) and in a condition where the first argument fails, then the second argument is taken into consideration while sorting (in your case “tradeAmount”).

Notice that in the following GraphQL query, the count has been passed as the first argument.

{
  ethereum(network: bsc) {
    dexTrades(
      options: {limit: 1, desc: ["count", "tradeAmount"]}
      baseCurrency: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}
      quoteCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}
      date: {since: "2021-01-01"}
    ) {
      date{
        month
        year
      }
      tradeAmount(in: USD)
      count
      baseCurrency {
        symbol
      }
    }
  }
}

the result generated is as follows

{
  "ethereum": {
    "dexTrades": [
      {
        "date": {
          "month": 11,
          "year": 2021
        },
        "tradeAmount": 8965247890.779522,
        "count": 10601645,
        "baseCurrency": {
          "symbol": "WBNB"
        }
      }
    ]
  }
}

Observe that the data returned is of November 2021 and the count value is 10601645 and the tradeAmount being 8965247890.779522 USD . And in the GraphQL query below, the first argument has been kept as tradeAmount

{
  ethereum(network: bsc) {
    dexTrades(
      options: {limit: 1, desc: ["tradeAmount", "count"]}
      baseCurrency: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}
      quoteCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}
      date: {since: "2021-01-01"}
    ) {
      date{
        month
        year
      }
      tradeAmount(in: USD)
      count
      baseCurrency {
        symbol
      }
    }
  }
}

and the count value returned by this query is of the month of May 2021 and is 7540199 and the tradeAmount being 17364799391.899685 USD as shown below.

{
  "ethereum": {
    "dexTrades": [
      {
        "date": {
          "month": 5,
          "year": 2021
        },
        "tradeAmount": 17364799391.899685,
        "count": 7540199,
        "baseCurrency": {
          "symbol": "WBNB"
        }
      }
    ]
  }
}

I hope this helps :100: