alvarobartt / investiny

🀏🏻 `investpy` but made tiny
https://alvarobartt.github.io/investiny
MIT License
324 stars 36 forks source link

some stock id's give an error #25

Open andresrogers opened 2 years ago

andresrogers commented 2 years ago

For some ids, historical_data gives this error:

historical_data(investing_id=40654,from_date=start_date_1, to_date=end_date_1)

also

historical_data(investing_id=26490,from_date=start_date_1, to_date=end_date_1)

for dates: start_date_1 = '04/27/2000' end_date_1 = '04/26/2012'

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/tmp/ipykernel_16762/3915976534.py in <module>
----> 1 historical_data(investing_id=26490,from_date=start_date_1, to_date=end_date_1)

~/.local/lib/python3.10/site-packages/investiny/historical.py in historical_data(investing_id, from_date, to_date, interval)
     46     time_format = "%H:%M %m/%d/%Y" if isinstance(interval, int) else "%m/%d/%Y"
     47     output = {
---> 48         "date": [datetime.fromtimestamp(t).strftime(time_format) for t in data["t"]],  # type: ignore
     49         "open": data["o"],  # type: ignore
     50         "high": data["h"],  # type: ignore

KeyError: 't'
alvarobartt commented 2 years ago

Hi @andresrogers, where are you retrieving those IDs from? If those are being retrieved from investpy static files, just to let you know that those files are not consistent as those were statically generated some time ago, and have potentially changed. So the available data there may not be the actual one.

Anyway, let me know the Investing.com URL of the asserts corresponding to the investing_id=29490 and investing_id=40654IDs so as to explore the issue further.

Thanks! πŸ‘πŸ»

andresrogers commented 2 years ago

The ones that gave me an error are:

investing_id=26490 is META

search_assets(query="META", limit=1) {'symbol': 'META', 'full_name': 'NASDAQ:META', 'description': 'Meta Platforms Inc', 'type': 'Stock', 'ticker': '26490', 'exchange': 'NASDAQ'}

investing_id=40654 is TLT

search_assets(query="TLT", limit=1) {'symbol': 'TLT', 'full_name': 'NASDAQ:TLT', 'description': 'iShares 20+ Year Treasury Bond ETF', 'type': 'ETF', 'ticker': '40654', 'exchange': 'NASDAQ'},

It only gave me that error if I used '04/27/2000' as starting date, didn't get the error for less than 10 years difference to current date.

alvarobartt commented 2 years ago

Ok @andresrogers let me try and I'll come back to you with a response πŸ‘πŸ» But I assume it may have something to do with #24 as it just happens whenever you use too distant dates.

ramakrishnamekala129 commented 2 years ago
              open        high         low       close

date 2012-05-18 42.049999 45.000000 38.000000 38.230000 2012-05-21 36.529999 36.660000 33.000000 34.029999 2012-05-22 32.610001 33.590000 30.940001 31.000000 2012-05-23 31.370001 32.500000 31.360001 32.000000 2012-05-24 32.950001 33.209999 31.770000 33.029999 ... ... ... ... ... 2022-10-04 140.490005 142.390106 139.339996 140.279999 2022-10-05 138.240005 140.210007 134.779999 138.979996 2022-10-06 137.714996 141.449997 136.600006 139.070007 2022-10-07 136.759995 138.289993 132.440002 133.449997 2022-10-10 133.550003 135.940002 132.800003 134.100006

ramakrishnamekala129 commented 2 years ago

it gave error because this api doesnt have 2012-05-18 before data this stock

andresrogers commented 2 years ago

it gave error because this api doesnt have 2012-05-18 before data this stock

I thought something of the sort, but I believe the expected behaviour should be to return the earliest possible data without giving an error.

alvarobartt commented 2 years ago

Thanks for posting that @ramakrishnamekala129, and yes, @andresrogers, the expected behavior is not to fail, so I'll check it and come back with a response ASAP :+1:

alvarobartt commented 2 years ago

it gave error because this api doesnt have 2012-05-18 before data this stock

I thought something of the sort, but I believe the expected behaviour should be to return the earliest possible data without giving an error.

We should be creating a separate issue for this once the new version is released! πŸ˜„