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

Fix issue #223 #231

Merged
merged 1 commit into from
Aug 27, 2022
Merged

Fix issue #223 #231

merged 1 commit into from
Aug 27, 2022

Conversation

deroshkin
Copy link
Contributor

Force currency code to be upper case to compensate for Yahoo improperly formatting some foreign currencies (at least GBP), which confused currency conversion.

Not sure whether the place I chose to force the upper case conversion is the best location, but it works.

Force currency code to be upper case to compensate for Yahoo improperly formatting some foreign currencies (at least GBP), which confused currency conversion.
@achannarasappa
Copy link
Owner

Great find! Thank you for contributing this fix

I was able to replicate the issue and the root cause seems be as you've said that Yahoo returns non-uppercase characters for some currency quotes but the currency conversion pair is always uppercase.

❯  http "https://query1.finance.yahoo.com/v7/finance/quote?lang=en-US&region=EU&corsDomain=finance.yahoo.com&symbols=GBPUSD=X" | jq '.quoteResponse.result[0].symbol'
"GBPUSD=X"

❯  http "https://query1.finance.yahoo.com/v7/finance/quote?lang=en-US&region=EU&corsDomain=finance.yahoo.com&symbols=BATS.L" | jq '.quoteResponse.result[0].currency'
"GBp"

@achannarasappa achannarasappa merged commit 76fee90 into achannarasappa:master Aug 27, 2022
@RichTeaMan
Copy link

RichTeaMan commented Sep 14, 2022

Sorry to comment on a merged issue, but I don't think is correct.

For instance, GBP is not the same as GBp. GBP is British Pounds while GBp is British pennies (see https://en.wiktionary.org/wiki/GBP, https://en.wiktionary.org/wiki/GBp & this for a real example: https://finance.yahoo.com/quote/0P00013P6I.L). Some of my holdings are showing me being £10000s up but unfortunately this is not actually the case.

@deroshkin
Copy link
Contributor Author

@RichTeaMan is right, I just checked yahoo finance site listings for some London stocks, and they are in fact in terms of pennies. Unfortunately, the yahoo exchange rate API if queried with GBp will return the exchange rate for GBP.
IMO there are 2 ways of addressing this without changing the API used, and both are far from ideal:

  1. Convert all stock quotes from GBp to GBP when creating assetQuote in transformResponseQuote (quote.go)
  2. Hard code a 2-step conversion from GBp to any target currency in 2 steps (GBp -> GBP -> USD/EUR/...) somewhere in the currency conversion code.

If you are willing to switch APIs, there are some currency converters that do allow British pennies (some use GBX instead of GBp)

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.

3 participants