Including CSPR rates

Often, when looking at the fiat value of a native token amount, we want it to be converted using the rate that was relevant at the moment when the corresponding action happened. CSPR.cloud REST API provides the possibility to do so when requesting data having the timestamp property and when it's semantically acceptable To learn more, visit the CSPR rate page.

In the example below, we include the USD to CSPR rate in the account delegation rewards response by calling the rate function with the USD currency ID as the argument in the includes query param:

curl -X 'GET' \
  'https://api.testnet.cspr.cloud/accounts/019aa4adcd6f58f92eb4c98c0245e5d86b61de4919245c23ae9e906a6df5d41b0c/delegation-rewards?includes=rate(1)' \
  -H 'accept: application/json' \
  -H 'authorization: 55f79117-fc4d-4d60-9956-65423f39a06a'
{
  "item_count": 38490,
  "page_count": 3849,
  "data": [
    {
      "amount": "139319",
      "era_id": 11774,
      "public_key": "019aa4adcd6f58f92eb4c98c0245e5d86b61de4919245c23ae9e906a6df5d41b0c",
      "rate": 0.04051209,
      "timestamp": "2023-12-20T12:55:54Z",
      "validator_public_key": "0106ca7c39cd272dbf21a86eeb3b36b7c26e2e9b94af64292419f7862936bca2ca"
    },
    {
      "amount": "186761050",
      "era_id": 11774,
      "public_key": "019aa4adcd6f58f92eb4c98c0245e5d86b61de4919245c23ae9e906a6df5d41b0c",
      "rate": 0.04051209,
      "timestamp": "2023-12-20T12:55:54Z",
      "validator_public_key": "017d96b9a63abcb61c870a4f55187a0a7ac24096bdb5fc585c12a686a4d892009e"
    },
    ...
    {
      "amount": "139010",
      "era_id": 11771,
      "public_key": "019aa4adcd6f58f92eb4c98c0245e5d86b61de4919245c23ae9e906a6df5d41b0c",
      "rate": 0.0403257,
      "timestamp": "2023-12-20T06:55:27Z",
      "validator_public_key": "0106ca7c39cd272dbf21a86eeb3b36b7c26e2e9b94af64292419f7862936bca2ca"
    }
  ]
}

Last updated