Exchange rate canister's caching mechanism

Hello everyone, can someone explain about exchange rate canister’s caching mechanism, in my case I have to get the price of two crypto currencies on a 1 min interval. In the docs I read that every request should attach 1 billion cycles and if the response comes from the cache, only 20 million cycles will be consumed.
Can someone clarify the process?

1 Like

Note: The cycles cost of these requests are expected to be decreased in the next upgrade of the XRC.

Also I saw this in the documentation, what is the status of the next upgrade?

1 Like

Let me give it a try.

If you use a timestamp in your request (UNIX timestamp in seconds), then the time stamp is rounded down to a minute. If you don’t provide a timestamp is provided, then the start of the current minute based on subnet time is used.

If there is an entry for your currency pair and this timestamp in a local datastructure of the canister, then the stored value is returned (and the low amount of cycles is consumed).

If there is no entry for your currency pair and this timestamp, then the canister will make outcalls to several exchange rate providers and compute the median for your pair. Since this is costs more resources, a higher amount in cycles is consumed, depending on the number of outcalls that were made.

Is this more clear?
Sources:

1 Like

Regarding the costs, I don’t see any changes to the canister repo GitHub - dfinity/exchange-rate-canister: The exchange rate canister (XRC) makes use of the HTTP requests feature to provide exchange rates as a service to the IC. since the developer docs article was changed. Therefore I assume this hasn’t happened yet and as long as the code is not in the repo it won’t happen either. I don’t know when this is planned.

1 Like

Thanks for clarification

Hi @asjn3e

The documentation for the cycles price reduction is out of date (we will fix this asap). The cost reduction occurred in this PR: Update cycle pricing by THLO · Pull Request #232 · dfinity/exchange-rate-canister · GitHub.

2 Likes