addisonlynch / iexfinance

Python SDK for IEX Cloud
https://addisonlynch.github.io/iexfinance
Apache License 2.0
648 stars 136 forks source link

IEXQueryError... #228

Closed mkemper999999 closed 3 years ago

mkemper999999 commented 4 years ago

Just now (16/11 @ 2pm in London) is the first time I try to access IEX through Python and am no doubt making a silly mistake. I get this error [raise IEXQueryError("The query could not be completed. " iexfinance.utils.exceptions.IEXQueryError: An error occurred while making the query.] whereas (see code below) I expected to get a latest price (note that I am using my sandbox secret key, and have sandbox switched on online). The error appears on the 3rd line.

from iexfinance.stocks import Stock aapl = Stock("AAPL", token="Tsk_xxxxxxxxxxxxxxxxxxxxx") price = aapl.get_price() print(price)

Should I use my Sandbox publishable key? What anyway is the difference between a secret and publishable key??

Many thanks in advance - Michael

NexVeridian commented 4 years ago

The difference between secret and publishable keys https://github.com/iexg/IEX-API/issues/706#issuecomment-466552762

And you can create Signed Requests with your private key

Make sure that sandbox testing is off All of my keys are in the format pk_xxxxxxx or sk_xxxxxxx and I get them from https://iexcloud.io/console/tokens

maybe try get_tops, it dose almost the same thing as get_price get_price has a data weighting of 1 a call, get_tops has a data weighting of 0 a call

from iexfinance.iexdata import get_tops import pandas as pd df = pd.DataFrame(get_tops(["SPY"], token="pk_xxxxxxxxx")) print(df)

mkemper999999 commented 4 years ago

Thanks for helping out - I'm not usually stuck on a 4 line snippet of code ;-)

Thanks for pointing out the difference between publishable and secret keys (basically, normally use the publishable key).

You then have the link to "And you can create Signed Requests with your private key", Some questions:

In my code example I had sandbox on and used my sandbox secret key. I get the same error with my sandbox publishable key (which makes sense). Then I switched sandbox off and tried both my 'real' secret and publishable keys (which indeed start with sk and pk respectively) and still I get the same error. Note though that all these tokens are correct, for if I corrupt one by replacing a character in the middle with "^", I get: iexfinance.utils.exceptions.IEXAuthenticationError: The query could not be completed. Invalid auth token.

Then (!!) I tried your get_tops code snippet, and now ... I do get the data just fine!!?

With all this info can you determine what goes wrong with my code snippet?

Again, many thanks - much appreciated - Michael

NexVeridian commented 4 years ago

Signed Requests uses SK_xxxx, it's only available for Grow and Scale users, so don't worry about it for now, I'm not sure if it's been add to this package yet

I tried running your code again and it seems that the iex api changed, so that get_price got changed from being free to using Price Only, which is only available on paid accounts, so try to use get_tops for now I guess?

IEXQueryError: An error occurred while making the query (402): The requested data is not available to free tier accounts. Please upgrade for access to this data.

mkemper999999 commented 4 years ago

Thanks again

I just now upgraded to a paid account (I thought, incorrectly apparently, that that was not needed for the sandbox), but ... my error still persists? In other words, I just paid $108 and still I cant get the data I want!!

What do I do now? Any suggestions?

Michael

mkemper999999 commented 4 years ago

Correction: I paid succesfully, and ran my code - result the same error, hence my message above Then a few minutes later a re-ran exactly the same code, and now I do get a proper result. Clearly it took time for some register to be updated. Anyway, it now all works, so ... case closed. Many thanks!

Michael

addisonlynch commented 3 years ago

Going to close this issue. Please re-open if there are any outstanding issues!