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

fetch_historical_prices_by_epic_and_num_points exception during exception handling #33

Closed
M1ntcraft3r opened this issue Dec 21, 2016 · 5 comments

Comments

@M1ntcraft3r
Copy link

M1ntcraft3r commented Dec 21, 2016

response = ig_service.fetch_historical_prices_by_epic_and_num_points(epic, resolution, num_points)
  File "C:\Python35-32\lib\site-packages\trading_ig-0.0.6-py3.5.egg\trading_ig\rest.py", line 837, in fetch_historical_prices_by_epic_and_num_points
  File "C:\Python35-32\lib\site-packages\trading_ig-0.0.6-py3.5.egg\trading_ig\rest.py", line 754, in format_prices
  File "C:\Python35-32\lib\site-packages\pandas\core\frame.py", line 2917, in set_index
    level = frame[col]._values
  File "C:\Python35-32\lib\site-packages\pandas\core\frame.py", line 2059, in __getitem__
    return self._getitem_column(key)
  File "C:\Python35-32\lib\site-packages\pandas\core\frame.py", line 2066, in _getitem_column
    return self._get_item_cache(key)
  File "C:\Python35-32\lib\site-packages\pandas\core\generic.py", line 1386, in _get_item_cache
    values = self._data.get(item)
  File "C:\Python35-32\lib\site-packages\pandas\core\internals.py", line 3541, in get
    loc = self.items.get_loc(item)
  File "C:\Python35-32\lib\site-packages\pandas\indexes\base.py", line 2136, in get_loc
    return self._engine.get_loc(self._maybe_cast_indexer(key))
  File "pandas\index.pyx", line 139, in pandas.index.IndexEngine.get_loc (pandas\index.c:4443)
  File "pandas\index.pyx", line 161, in pandas.index.IndexEngine.get_loc (pandas\index.c:4289)
  File "pandas\src\hashtable_class_helper.pxi", line 732, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13733)
  File "pandas\src\hashtable_class_helper.pxi", line 740, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13687)
KeyError: 'snapshotTimeUTC'
@redbullpeter
Copy link
Contributor

I get this error too when I run the test_ig_service function.

A cursory check shows that

IG returns a key called snapshotTime but not snapshotTimeUTC. Changing the expected key to snapshotTime (rest.py:line757) seems to solve the basic issue but then datetime doesn't seem to recognise the date format at (rest.py: line 758).

So it seems IG changed something since this piece of code was written...

I'll dig a little deeper later and see if I can fix it. It seems relatively simple.... (watch me eat my words!)

@redbullpeter
Copy link
Contributor

redbullpeter commented Feb 2, 2017

OK here's a fix:

line 757: df = df.set_index('snapshotTime')
line 758: df.index = pd.to_datetime(df.index, format="%Y:%m:%d-%H:%M:%S")

Be aware that the time index will be local time (timezone of the account) and not UTC. As part of the config we could require a timezone to use. But I'll leave that for another iteration.

@redbullpeter
Copy link
Contributor

@femtotrader Can you give me rights to open a pull request.

@femtotrader
Copy link
Member

You don't need any rights to open a PR.

You just need to first fork this repository.
capture d ecran 2017-02-02 a 20 49 06

Clone your fork.

$ git clone https://github.com/YOU/REPOS

Define this repository as upstream.

$ git remote add upstream https://github.com/ORIGINAL_USER/REPOS

Create a branch

$ git checkout -b fix_issue_33

Modify code to fix issue (or add enhancement)

Commit your changes

$ git commit

Push to your repository

$ git push

Open a Pull request (from your repository)
https://help.github.com/articles/creating-a-pull-request/
https://help.github.com/articles/about-pull-requests/

@femtotrader
Copy link
Member

Thanks @M1ntcraft3r and @redbullpeter

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

No branches or pull requests

3 participants