Skip to content

Analytics

Methods related to querying information about database statistics or aggregating information.

Quick Reference

MethodDescription
aggregateTransfersAggregate Transfers using either a simple filter or queryBuilder
getStatisticsGet aggregated statistics about WAPI entities

aggregateTransfers

Aggregate Transfers using either a simple filter or queryBuilder

ts
await client
  .aggregateTransfers()
  .where({
    type: 'deposit',
    from_wallet: 'EUR',
    to_wallet: 'house',
  })
  .whereMetadata('example', 'test')
  .sum('to.amount as amount')
  .count()
  .groupBy('metadata.even as type', 'hour')
  .options({
    tracking_id: 'hello',
    return_all_intervals: {
      start_time: '2021-07-31 11:00:00',
      end_time: '2021-07-31 13:00:00',
    },
  });
ts
{
  rows: [
    {
      amount: 25,
      count: 5,
      type: 'even',
      hour: '2021-07-31 12'
    },
    {
      amount: 30,
      count: 5,
      type: 'odd',
      hour: '2021-07-31 12'
    },
    {
      amount: null,
      count: 0,
      type: null,
      hour: '2021-07-31 11'
    },
    {
      amount: null,
      count: 0,
      type: null,
      hour: '2021-07-31 13'
    }
  ],
  metadata: {
    aggregators: [
      {
        function: 'sum',
        field: 'to.amount',
        alias: 'amount'
      },
      {
        function: 'count',
        alias: 'count'
      }
    ],
    groups: [
      {
        type: 'metadata_field',
        field: 'even',
        alias: 'type'
      },
      {
        type: 'period',
        field: 'hour',
        alias: 'hour'
      }
    ]
  }
};

aggregateTransfersFnInput

Input for aggregateTransfers

AttributeTypeRequiredDescription
walletstring | numberForeign of the wallet connected to transfers
tokenstring | numberForeign of the token transferred
from_walletstring | numberForeign of the wallet transfers are made from
to_walletstring | numberForeign of the wallet transfers are made to
transfer_groupstring | numberForeign of the transfer_group the transfers are a part of
statusTransfersStatus Status of the transfers
metadata MetadataSearch Metadata filter
options{}Optional flags for input

aggregateTransfersFnOutput

Output of aggregateTransfers

AttributeTypeAlwaysDescription
rowsRows[]Results of the aggregation
metadata{}Metadata about the aggregation

getStatistics

Get aggregated statistics about WAPI entities

ts
await client.getStatistics(
  {
    model: 'Transfer',
    aggregator: 'count',
    group: 'month',
    timezone: 'Europe/Tallinn',
    filter: {
      end_time: new Date(
        `${new Date().getFullYear() + 1}-01-01`,
      ).toISOString(),
      start_time: new Date(
        `${new Date().getFullYear()}-01-01`,
      ).toISOString(),
    },
  },
  {
    // GENERALOPTIONS
  },
);
ts
{
  rows: [
    {
      aggregate: 4,
      period: '2026-01'
    }
  ]
};

getStatisticsFnInput

Input for getStatistics

AttributeTypeRequiredDescription
modelModel Model to return statistics about
aggregatorcount
groupGroup Time period rows should be grouped by
timezonestringTimezones allowed
filter{}
options{}Optional flags for input

getStatisticsFnOutput

Output of getStatistics

AttributeTypeAlwaysDescription
rows({})[]