Exchange Rate Canister: ForexInvalidTimestamp


I’m calling XRC locally in development… when I call it using #Cryptocurrency it works fine, even with no timestamp given:

2024-01-29 20:07:34.119499609 UTC: [Canister bkyz2-fmaaa-aaaaa-qaaaq-cai] #Ok({base_asset = {class_ = #Cryptocurrency; symbol = "BTC"}; metadata = {base_asset_num_queried_sources = 3; base_asset_num_received_rates = 2; decimals = 9; forex_timestamp = null; quote_asset_num_queried_sources = 0; quote_asset_num_received_rates = 0; standard_deviation = 5_586_143_571}; quote_asset = {class_ = #Cryptocurrency; symbol = "USDT"}; rate = 43_116_950_000_000; timestamp = 1_706_558_820})

However, when I try to call it to get a USD/EUR exchange rate it fails saying this:

2024-01-29 20:10:42.851090773 UTC: [Canister b77ix-eeaaa-aaaaa-qaada-cai] [xrc] Caller: bkyz2-fmaaa-aaaaa-qaaaq-cai Timestamp: 1706559000 Request: GetExchangeRateRequest { base_asset: Asset { symbol: "USD", class: FiatCurrency }, quote_asset: Asset { symbol: "EUR", class: FiatCurrency }, timestamp: None } Error: ForexInvalidTimestamp
2024-01-29 20:10:42.851090773 UTC: [Canister bkyz2-fmaaa-aaaaa-qaaaq-cai] #Err(#ForexInvalidTimestamp)

In both cases I’m setting the timestamp variable to null …which to my understanding means I should get the latest price yes? Is this true for both crypto and forex?

I’ve also tried using timestamps now and recently but still get errors. I’ve made sure my environment is timesync’ed to the correct time. Any ideas?

I’m using the code/wasm from

I just ran the xrc_demo project with a hardcoded USD/EUR asset pair against the exchange rate canister running on mainnet (uf6dk-hyaaa-aaaaq-qaaaq-cai) and everything worked fine.

When you say that you’re “calling XRC locally in development”, does that mean that you have your own instance of the XRC running? In that case, it is possible that you see this error because the XRC fetches daily forex only a few times a day, so a freshly installed XRC simply doesn’t have any forex rates yet.

Let me know if this helps!

Yeah that’s exactly what’s happening I’m running it locally and its not showing recent rates because of it being out of sync.

All good, I’ve found a workaround, thanks!