hydrosquall / tiingo-python

Python client for interacting with the Tiingo Financial Data API (stock ticker and news data)
https://pypi.org/project/tiingo/
MIT License
251 stars 52 forks source link

Server limit messages are not handled gracefully #45

Open pmularien opened 6 years ago

pmularien commented 6 years ago

Description

API limits enforced at the free tier are not handled gracefully (i.e. error / exception thrown).

What I Did

As expected, once I passed an API limit (not yet a paying customer, though I intend to pay shortly), I received an error because the Tiingo response is not JSON in this case:

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The offending line:

C:\anaconda3-4.2.0\lib\site-packages\tiingo\api.py in get_ticker_price(self, ticker, startDate, endDate, fmt, frequency)
    137         response = self._request('GET', url, params=params)
    138         if fmt == "json":
--> 139             return response.json()
    140         elif fmt == "object":
    141             data = response.json()

This is because the response from the Tiingo API is:

You have run over your 500 symbol look up for this month. Please upgrade at https://api.tiingo.com/pricing to have your limits increased.

... although the HTTP status is still 200 OK (not great API design). Happy to submit a PR if you feel this should be fixed!

hydrosquall commented 6 years ago

@pmularien : appreciate you trying out this library, and the detailed bug report! At the very least, we could do a better job of providing a more informative error message, if not having designated logic to handle this rate limiting case.

If you file a PR, I'd be happy to pull it in for the next release :)

For the longer term, @Rishi, perhaps usage of a 429 status code might be appropriate: https://softwareengineering.stackexchange.com/questions/128512/suggested-http-rest-status-code-for-request-limit-reached

hydrosquall commented 6 years ago

Hi @pmularien - just wanted to ping back to see if you were still interested in picking up this issue :)