Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback to prevDay quote for polygon prices #22

Merged
merged 3 commits into from
Jul 8, 2024

Conversation

ebma
Copy link
Member

@ebma ebma commented Jul 5, 2024

Amends the changes made in #21.

  • Adds a fallback to the prevDay quote in case the lastQuote does not contain any non-zero values.
  • Does not return a quotation if the price is 0, so that the off-chain worker does not feed 'invalid' price data to the chain.

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 ebma requested a review from a team July 5, 2024 10:10
Copy link

@gianfra-t gianfra-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this 0 value can happen at any time ? I would worry that the previous day close would be much lower/higher than the previous non-zero fetched value for that day. WDTY?
We can also go for this solution but monitor the prices to check when this null entry happens during the day.

@ebma
Copy link
Member Author

ebma commented Jul 8, 2024

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
Copy link

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
Copy link
Member Author

ebma commented Jul 8, 2024

Added the logs and will merge now.

@ebma ebma merged commit ee50310 into master Jul 8, 2024
@ebma ebma deleted the 20-add-other-price-feed-providers-amend branch July 8, 2024 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants