Exchange Rate Canister: ForexInvalidTimestamp

Greetings,

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

git@github.com:THLO/xrc_demo.git

1 Like

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!

@icplonger do you mean a workaround to make the XRC work? Or a workaround just by not using the XRC and fetching the exchange rate in other ways? Could you share more details about the workaround you found?

1 Like

@THLO so, what’s the solution to this when running the XRC locally?

1 Like

Hi ilbert,

I just ended up writing my own endpoints to get fx/token prices as a workaround

GitHub - janusdotai/supercartd_shim: netlify functions for supercartd and call them via HTTPS outcalls

1 Like

Hi @ilbert .

What version of dfx are you using? IIRC, there were issues in prior versions when connecting to IPv4 addresses with HTTPS outcalls. The vast majority of foreign exchange sources use only IPv4.

When the XRC canister is initially installed, it should reach out to all foreign exchanges and update the internal store. This should allow you to successfully retrieve a rate. There is one potential issue remaining. There is a time zone check in the XRC.

At the moment, the only way to turn off the time zone check is with a feature flag when compiling the wasm. Setting this value to yes will disable the timezone check. You could compile and then install the wasm.

It’s not ideal, but I hope that is helpful.

2 Likes