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 currency to ETF/Funds #172

Closed
typhoon71 opened this issue Jun 6, 2020 · 13 comments
Closed

Add currency to ETF/Funds #172

typhoon71 opened this issue Jun 6, 2020 · 13 comments
Assignees
Labels
improvement Something needs to be improved

Comments

@typhoon71
Copy link

I'd like to suggest to add the currency to search result, as the same financial instrument can be present on the same exchange with 2 differenct currencies; i.e. in the case of London, you have quotations in USD and GBP too.

Comparing instruments with different currency it would be something useful to know, so you coud apply the relevant cross.

It would be a great addition to the To the investpy.search_quotes() too.

What do you think about it?

@alvarobartt
Copy link
Owner

Hi again @typhoon71! This feature seems perfect to me, but since investpy internally uses the Investing.com Search Engine I need to do some research before telling you if it is or it is not possible.

Additionally, if the original search results do not provide the currency I think I can develop a method to retrieve the currency once the search results are retrieved. For example, you search Apple and you just want to retrieve the stock AAPL, so once you select the search result you want you should be able to call a function so as to retrieve the currency such as search_result.retrieve_currency or something like that.

Let me do more research over this feature and I will let you know as soon as possible if I can implement it or not.

Thank you! Remember to star the repo if you found it useful and follow me at GitHub so as to get notified of all the updates!

@alvarobartt alvarobartt self-assigned this Jun 7, 2020
@alvarobartt alvarobartt added the enhancement New feature or request label Jun 7, 2020
@typhoon71
Copy link
Author

A method like search_result.retrieve_currency would be neat.

That way one could retrieve the list of instruments with on investpy.search_quotes() and then retrieve the currency cross, only if needed.

@RamonGuixa
Copy link

HY,
I also have find problems with ETFs.
My opinion is that with only Symbol, and also stock exhange, currency and name are not needed and also we will avoid fetching failures and etfs duplicated.
For instance: Name: Xtrackers Stoxx Europe 600 UCITS ETF 1C, stock_exchange= Xetra, we got error not found and also this name has two currencies: But Xetra is always in EUR and London is always GBP for that Symbol.
Symbol has another advantage is short typing.
Thanks for your Investpy.
Ramón Guixá Arderiu

@typhoon71
Copy link
Author

typhoon71 commented Jun 7, 2020

@RamonGuixa: one may want to check all the quotes for an etf given in un currency, even in different nations (say, to find the best execution exchange).

I suppose you can say that given the exchange one knows the currency used, but I'm not too sure if assuming that is good in general (i.e.: IE00BJQTJ848).

That's one of the reasons I second that addition to investpy.search_quotes(), as it would be helpful
to have the currency generalized as possible between all financial instruments.

@typhoon71
Copy link
Author

Also, if you don't add the currency and "go by echange" the user will need a method to link currency to exchange. It would then make sense to include it in investpy (but if the currency is added in investpy.search_quotes() results it would be even better).

Side note: investpy.search_quotes() works nicely and the issues I had with dates are fixed in the dev branch. Thanks a lot alvarobartt.

@Fetix
Copy link

Fetix commented Jun 22, 2020

Hi all,
I strongly second this request.

Ran into an ETF where I couldn't poll information via get_etf_historical_data which would have provided a currency. I then resorted the workaround proposed in #148 to get the data but they are lacking currency information.

I really like .search_quotes() as it allows you to poll data for various instruments in a unified way and would love it to provide currency information.

@Fetix
Copy link

Fetix commented Jun 25, 2020

Hi all,
hi @typhoon71,

I really wantend to have access to the currency information right now and found a dirty hack:

  • Get the tag field from the .search_qoutes() result
  • Grab the content of the investing.com/tag [1]
  • Look for the currency. It's in there in the clear. [2]

Cheers,
Fetix

--
[1] https://medium.com/@speedforcerun/python-crawler-http-error-403-forbidden-1623ae9ba0f
[2]
currency_def = html.find('Currency in <span class=\'bold\'>') + 33 # 33 = len(Currency in <span class=\'bold\'>)
currency = html[currency_def : currency_def+3]

@alvarobartt
Copy link
Owner

alvarobartt commented Jun 9, 2021

Hi @typhoon71, @RamonGuixa and @Fetix 🤗

I'll release investpy v1.0.7 later this week including the currency while retrieving the information of any financial products while investpy.search_quotes as also proposed in #390

Make sure to watch the current milestone https://github.com/alvarobartt/investpy/milestone/2 so as to keep an eye on all the investpy.search_quotes functions that will come for the next release!

I may also post information about the release on my Twitter account, feel free to follow if you want/need more information about investpy 🔥

@alvarobartt alvarobartt added improvement Something needs to be improved and removed enhancement New feature or request labels Jun 9, 2021
@alvarobartt alvarobartt added this to the investpy v1.0.7 milestone Jun 9, 2021
@alvarobartt
Copy link
Owner

Hi again @typhoon71, @RamonGuixa and @Fetix! 🤗

I've already implemented a function to retrieve the default currency of every SearchObj after calling investpy.search_quotes so that you can just use the following piece of code:

>>> import investpy
>>> search_result = investpy.search_quotes(text='apple', n_results=1)
>>> print(search_result)
{"id_": 6408, "name": "Apple Inc", "symbol": "AAPL", "country": "united states", "tag": "/equities/apple-computer-inc", "pair_type": "stocks", "exchange": "NASDAQ"}
>>> currency = search_result.retrieve_currency()
>>> print(currency)
USD
>>> print(search_result.default_currency)
USD

Also see below that it's pretty simple but efficient and the elapsed time to retrieve the currency is less than 300ms, which is something nice too!

/workspace/investpy $ time python -c "import investpy;data = investpy.search_quotes('apple', n_results=1);curr = data.retrieve_currency()"

real    0m1.384s
user    0m0.841s
sys     0m0.736s
/workspace/investpy $ time python -c "import investpy;data = investpy.search_quotes('apple', n_results=1)"

real    0m1.094s
user    0m0.824s
sys     0m0.871s

@alvarobartt
Copy link
Owner

Reopened this issue since I still need to include some more tests and fix the current build as it failed in the previous commits... 😖

@alvarobartt
Copy link
Owner

It seems that as it happened before with SearchObj.retrieve_information, as described in #395, Investing.com has different HTML templates for the stocks, since the stocks/equities pages are already using the new templates, all the other financial products are still using the old one, so we need to define a way to either use one parser or another based on the product type 😖

Hopefully the current version I developed for SearchObj.retrieve_information can be re-used as it should be consistent to new changes and easy to update to adapt to the new changes on the different financial product HTMLs 👍

@alvarobartt
Copy link
Owner

Hi @typhoon71, @RamonGuixa and @Fetix, the new release is already out! 🔥

You can already install it using either pip install investpy==1.0.7 or just update the current version that you are using with pip install investpy --upgrade. Thanks a lot for your support! 👍

For more information about this new release, you should check investpy v1.0.7 Release 🎈

@typhoon71
Copy link
Author

I will definitely be checking this. thanks a lot in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Something needs to be improved
Projects
None yet
Development

No branches or pull requests

4 participants