algorithmic-trading-python icon indicating copy to clipboard operation
algorithmic-trading-python copied to clipboard

Testing Sandbox Deprecated

Open Indianapolis-Jones opened this issue 2 years ago • 12 comments

I am getting a 403 error when making API call for AAPL around minute 41 of the video. Is this because it is deprecated? Is there a work around?

Indianapolis-Jones avatar Jan 06 '23 06:01 Indianapolis-Jones

The sandbox is on more unfortunately. Also you will find part 3 of the course requires a paid version of the api sadly. But you can do the first two for free, just use base_url = 'https://cloud.iexapis.com'

npomfret avatar Jan 06 '23 15:01 npomfret

@npomfret @nickmccullum Love the course!! Unfortunately even when I use a new base_url = 'https://cloud.iexapis.com' I still get errors shown below. Anything I could try next? image image image This just happened - this section was working two days ago.

christianperera avatar Jan 08 '23 21:01 christianperera

Can you print out the http status code? Change your request to something like:

response = requests.get(api_url)
print(response.status_code).  <-- need to see this
data = response.json()

It should be 200.

npomfret avatar Jan 09 '23 16:01 npomfret

403 means Forbidden. You are making a request that is in one way not authorised. I think it's because you are using the sandbox which isn't allowed any more.

npomfret avatar Jan 17 '23 19:01 npomfret

Found a solution to this issue. I had the same issue also with the 403 code.

It seems like IEX Cloud has abandoned the system of API's mentioned in the video (docs also call it old now). You can find the new documentation at https://iexcloud.io/docs/. What I did was make an account with IEX Cloud (for free). This will give you access for 30 days to their API platform, should be enough for the course. On the upside: the data will be actual data and not the random data like in the old sandbox.

The new api-url looks like this:

api_url = f'https://api.iex.cloud/v1/data/core/quote/{symbol}?token={IEX_CLOUD_API_TOKEN}'

And you have to replace the token in the secrets.py file with the private key from your account you just made.

My final code block looks like this:

api_url = f'https://api.iex.cloud/v1/data/core/quote/{symbol}?token={IEX_CLOUD_API_TOKEN}'
response = requests.get(api_url)
print(response.status_code)
data = response.json()[0]
print(data)```

Now it gives a 200 code for me, hopefully it'll work for you too!
Edit: Also note that the data is now returned in a list, if you place [0] after the .json() you get the normal dictionary like in the code.

djangovanderplas avatar Feb 11 '23 00:02 djangovanderplas

@djangovanderplas have you made it to the Batch API Calls section yet? image I am able to print my batchApiCallUrl but when I run a .status_code on the url the response I get back is a 404 response. did you have this problem? or could there be something wrong with my url?

itsmarcotime avatar Feb 16 '23 23:02 itsmarcotime

Having issues making batch url. Tried playing around a little. Tried the below as docs mention

Format: GET /data/WORKSPACE/DATASET_A,DATASET_B/KEY_1,KEY_2

Tried doing this

payment_needed

402

which apparently is payment needed!!!

This sucks!!!

Someone suggest a hack if they have.

senile-optimist avatar Feb 19 '23 14:02 senile-optimist

Found a solution to this issue. I had the same issue also with the 403 code.

It seems like IEX Cloud has abandoned the system of API's mentioned in the video (docs also call it old now). You can find the new documentation at https://iexcloud.io/docs/. What I did was make an account with IEX Cloud (for free). This will give you access for 30 days to their API platform, should be enough for the course. On the upside: the data will be actual data and not the random data like in the old sandbox.

The new api-url looks like this:

api_url = f'https://api.iex.cloud/v1/data/core/quote/{symbol}?token={IEX_CLOUD_API_TOKEN}'

And you have to replace the token in the secrets.py file with the private key from your account you just made.

My final code block looks like this:

api_url = f'https://api.iex.cloud/v1/data/core/quote/{symbol}?token={IEX_CLOUD_API_TOKEN}'
response = requests.get(api_url)
print(response.status_code)
data = response.json()[0]
print(data)```

Now it gives a 200 code for me, hopefully it'll work for you too!
Edit: Also note that the data is now returned in a list, if you place [0] after the .json() you get the normal dictionary like in the code.

thanks for the tip regarding the json()[0] my code now works with data = requests.get(api_url).json()[0]

johnpd avatar Feb 23 '23 18:02 johnpd

batch api url?

inaG17 avatar Mar 16 '23 20:03 inaG17

@inaG17 batch api url mentioned in the pic in my comment throws 402 which says payment needed to make the api call

senile-optimist avatar Mar 18 '23 22:03 senile-optimist

For those who are stuck on the batch call, here's my code. (Definitely could be better, but i'm still a beginner)

#Parsing function shown on the video
def chunks(lst, n):
    for i in range(0, len(lst), n):
        yield lst[i:i+n]

#The actual batch call
symbol_groups = list(chunks(stocks['Ticker'], 100))
symbol_strings = []
for i in range(0, len(symbol_groups)):
    symbol_strings.append(','.join(symbol_groups[i]))

final_dataframe = pd.DataFrame(columns = my_columns)      
for symb_str in symbol_strings:
    batch_api_call_url = f'https://api.iex.cloud/v1/data/core/quote/{symb_str}?token={IEX_CLOUD_API_TOKEN}'
    data = requests.get(batch_api_call_url).json()
    
    for symb in symb_str.split(','):
        for d in data :
            if d['symbol'] == symb:
            	new_row = pd.Series([symb, d['latestPrice'], d['marketCap'], 'N/A'], index = my_columns)
        final_dataframe = pd.concat([final_dataframe,new_row.to_frame().T], ignore_index=True)
        
final_dataframe

Smogryd avatar Apr 02 '23 13:04 Smogryd

Found a solution to this issue. I had the same issue also with the 403 code.

It seems like IEX Cloud has abandoned the system of API's mentioned in the video (docs also call it old now). You can find the new documentation at https://iexcloud.io/docs/. What I did was make an account with IEX Cloud (for free). This will give you access for 30 days to their API platform, should be enough for the course. On the upside: the data will be actual data and not the random data like in the old sandbox.

The new api-url looks like this:

api_url = f'https://api.iex.cloud/v1/data/core/quote/{symbol}?token={IEX_CLOUD_API_TOKEN}'

And you have to replace the token in the secrets.py file with the private key from your account you just made.

My final code block looks like this:

api_url = f'https://api.iex.cloud/v1/data/core/quote/{symbol}?token={IEX_CLOUD_API_TOKEN}'
response = requests.get(api_url)
print(response.status_code)
data = response.json()[0]
print(data)```

Now it gives a 200 code for me, hopefully it'll work for you too!
Edit: Also note that the data is now returned in a list, if you place [0] after the .json() you get the normal dictionary like in the code.

Just want to add that Public token of my new account also works.

Hongyac avatar Apr 04 '23 20:04 Hongyac