pendulum-chain / oracle-pallet

The Unlicense
0 stars 0 forks source link

Add fallback to prevDay quote for polygon prices #22

Closed ebma closed 4 months ago

ebma commented 4 months ago

Amends the changes made in #21.

I noticed that the batching server returns a price of 0 for the TZS and NGN currencies. This is because the lastQuote returned by the 'all-tickers' endpoint returns 0 values for all fields of those currencies. I suppose this is either because there is not much activity or maybe they were not traded on that day yet, see https://api.polygon.io/v2/snapshot/locale/global/markets/forex/tickers?tickers=C:TZSUSD&apiKey={apiKey}.

image

In case the lastQuote is empty we will now fall back to the prevDay values instead.

I compared them to the response of the currency-conversion endpoint here https://api.polygon.io/v1/conversion/TZS/USD?amount=1&precision=5&apiKey={apiKey}

and I think using the c (-> 'close') value of the previous day makes the most sense in this case. It also matches the result of the conversion (though to be fair, all values seem to do in this example due to the low precision).

image
ebma commented 4 months ago

So this 0 value can happen at any time ?

I think it shouldn't but for some reason it seemed to happen on that day for TZS and BRL. So we should assume that it can happen any time, yes.

I would worry that the previous day close would be much lower/higher than the previous non-zero fetched value for that day.

I don't think this should be the case because I would assume that in the cases where the lastQuote for the current day is 0, I would assume that the close of the previous day would then be equal to the previous non-zero fetched value. At least I would understand the problem to be such that the lastQuote is only empty because there is no trade yet for that new day.

We can also go for this solution but monitor the prices to check when this null entry happens during the day.

I can add a log statement, should I?

gianfra-t commented 4 months ago

I would understand the problem to be such that the lastQuote is only empty because there is no trade yet for that new day.

That would make the most sense to be honest, especially since it is not mentioned on the docs. So let's go for it. Yeah let's add just a println for when the 0 value happens to confirm our theory.

ebma commented 4 months ago

Added the logs and will merge now.