mlouielu / twstock

台灣股市股票價格擷取 (含即時股票資訊) - Taiwan Stock Opendata with realtime

Home Page:http://twstock.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Raise error when stat is not 'OK' in Stock.fetch()

ianlini opened this issue · comments

In TWSEFetcher.fetch(), we currently catch the JSONDecodeError (or ValueError in Python 2) and let the return value to be:

{
    'stat': '',
    'data': []
}

stat may also be other values return by TWSE / TPEX, and we don't check the stat in Stock.fetch().

This is bad because when using Stock, users won't know what happens unless they look into the Stock.raw_data.

I propose 2 solutions:

  1. raise error when 'stat' is not 'OK' in Stock.fetch()
  2. Stock.fetch() gives a better return value to let users know what happens

I prefer 1. because Stock.fetch() should be a high-level function that is always successful, so users should always deal with the non-OK stat.