{"id":24561898,"url":"https://github.com/toomore/grs","last_synced_at":"2025-04-04T11:13:43.269Z","repository":{"id":2872558,"uuid":"3878345","full_name":"toomore/grs","owner":"toomore","description":"📈 台灣上市上櫃股票價格擷取（Fetch Taiwan Stock Exchange data）含即時盤、台灣時間轉換、開休市判斷。","archived":false,"fork":false,"pushed_at":"2016-11-30T03:55:30.000Z","size":688,"stargazers_count":433,"open_issues_count":19,"forks_count":164,"subscribers_count":75,"default_branch":"master","last_synced_at":"2025-03-28T10:09:25.309Z","etag":null,"topics":["finance","python","stock","stock-data","taipei","taiwan","taiwan-stock-exchange","twse"],"latest_commit_sha":null,"homepage":"http://pypi.python.org/pypi/grs","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toomore.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-03-30T16:08:36.000Z","updated_at":"2025-03-04T22:36:01.000Z","dependencies_parsed_at":"2022-09-06T01:11:31.240Z","dependency_job_id":null,"html_url":"https://github.com/toomore/grs","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toomore%2Fgrs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toomore%2Fgrs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toomore%2Fgrs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toomore%2Fgrs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toomore","download_url":"https://codeload.github.com/toomore/grs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166168,"owners_count":20894654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["finance","python","stock","stock-data","taipei","taiwan","taiwan-stock-exchange","twse"],"created_at":"2025-01-23T08:46:28.839Z","updated_at":"2025-04-04T11:13:43.242Z","avatar_url":"https://github.com/toomore.png","language":"Python","readme":"===============================\ngrs 台灣上市上櫃股票價格擷取\n===============================\n\n.. image:: https://travis-ci.org/toomore/grs.svg?branch=master\n   :target: http://travis-ci.org/toomore/grs\n\n.. image:: https://img.shields.io/pypi/dm/grs.svg?maxAge=2592000\n   :target: https://pypi.python.org/pypi/grs\n\n.. image:: https://img.shields.io/pypi/v/grs.svg?maxAge=2592000\n   :target: https://pypi.python.org/pypi/grs\n\n.. image:: https://img.shields.io/pypi/wheel/grs.svg?maxAge=2592000\n   :target: https://pypi.python.org/pypi/grs\n\n.. image:: https://img.shields.io/pypi/l/grs.svg?maxAge=2592000\n   :target: https://pypi.python.org/pypi/grs\n\n主要開發擷取台灣股市（TWSE）股價資料\n\n- 資料來源 `證券交易所網站 \u003chttp://www.twse.com.tw/\u003e`_ 。\n- 資料來源 `證券櫃檯買賣中心 \u003chttp://www.otc.org.tw/\u003e`_ 。\n\n-----------------------------\n版本資訊\n-----------------------------\n\n:Authors: Toomore Chiang\n:Version: 0.7.0 of 2016/09/11\n:Python Version: Python 2.7\n:Docs: http://grs-docs.toomore.net/\n\n-----------------------------\nRequires\n-----------------------------\n\n- python-dateutil==1.5\n- ujson\n- urllib3\n\n-----------------------------\nReport Issue or get involved\n-----------------------------\n\n- Github: https://github.com/toomore/grs\n- Issues: https://github.com/toomore/grs/issues\n\n-----------------------------\nWeb Demo\n-----------------------------\n\n- grs Online: http://grs.toomore.net/\n\n-----------------------------\nQuick Start\n-----------------------------\n\n簡單計算\n\n::\n\n    from grs import Stock\n\n    stock = Stock('2618')                         # 擷取長榮航股價\n    print stock.moving_average(5)                 # 計算五日均價與持續天數\n    print stock.moving_average_value(5)           # 計算五日均量與持續天數\n    print stock.moving_average_bias_ratio(5, 10)  # 計算五日、十日乖離值與持續天數\n\n\n擷取 12 個月份資料\n\n::\n\n    stock = Stock('2618', 12)\n\n\n輸出 CSV 檔\n\n::\n\n    stock.out_putfile('/dev/shm/2618.csv')\n\n\n擷取上櫃股價資訊\n\n::\n\n    from grs import Stock\n\n    stock = Stock('8446')                         # 擷取華研股價\n    print stock.moving_average(5)                 # 計算五日均價與持續天數\n    print stock.moving_average_value(5)           # 計算五日均量與持續天數\n    print stock.moving_average_bias_ratio(5, 10)  # 計算五日、十日乖離值與持續天數\n\n\n如果已確定該代碼為上市或上櫃股票，可以直接指定參數跳過查表動作。\n\n::\n\n    stock = Stock('2618', twse=True) # 擷取長榮航股價\n    stock = Stock('8446', otc=True)  # 擷取華研股價\n\n\n-----------------------------\n其他功能\n-----------------------------\n\n顯示台灣時間：TWTime\n=============================\n\n適用於其他時區查詢台灣當地時間。\n\n::\n\n    from grs import TWTime\n\n    what_time = TWTime()\n    what_time.now()        # 顯示台灣此刻時間\n    what_time.localtime()  # 顯示當地此刻時間\n\n\n判斷台灣股市是否開市：TWSEOpen\n====================================\n\n::\n\n    from grs import TWSEOpen\n    from datetime import datetime\n\n    open_or_not = TWSEOpen()\n\n    open_or_not.d_day(datetime.today())        # 判斷今天是否開市\n                                               # 回傳 True or False\n    open_or_not.d_day(datetime(2012, 12, 22))  # 判斷 2012/12/22 是否開市\n\n\n各股即時盤資訊：RealtimeTWSE / RealtimeOTC\n---------------------------------------------\n\n上市即時資訊\n\n::\n\n    from grs import RealtimeTWSE\n\n    realtime_stock = RealtimeTWSE('2618')   # 擷取長榮航即時股價\n    realtime_stock.raw                      # 原始資料\n    realtime_stock.data                     # 回傳 type: dict\n\n\n上櫃即時資訊\n\n::\n\n    from grs import RealtimeOTC\n\n    realtime_stock = RealtimeOTC('8446')    # 擷取華研即時股價\n    realtime_stock.raw                      # 原始資料\n    realtime_stock.data                     # 回傳 type: dict\n\n\n大盤即時盤資訊：RealtimeWeight（加權指數、櫃檯指數、寶島指數）\n---------------------------------------------------------------\n\n::\n\n    from grs import RealtimeWeight\n\n    realtime_weight = RealtimeWeight()  # 擷取即時大盤資訊\n    realtime_weight.raw                 # 原始檔案\n    realtime_weight.data                # 回傳 type: dict\n\n\n上市股票代碼列表：TWSENo\n====================================\n\n回傳上市股票代碼與搜尋\n\n::\n\n    from grs import TWSENo\n\n\n    twse_no = TWSENo()\n    twse_no.all_stock       # 所有股票名稱、代碼 type: dict\n    twse_no.all_stock_no    # 所有股票代碼 type: list\n    twse_no.all_stock_name  # 所有股票名稱 type: list\n    twse_no.industry_code   # 回傳類別代碼 type: dict\n    twse_no.industry_comps  # 回傳類別所屬股票代碼 type: dict\n    twse_no.search(u'中')   # 搜尋股票名稱，回傳 type: dict\n    twse_no.searchbyno(23)  # 搜尋股票代碼，回傳 type: dict\n    twse_no.last_update     # 回傳列表最後更新時間（非同步）type: str\n\n\n單日倒數時間：Countdown\n====================================\n\n適用於設定 cache 時間。\n\n::\n\n    from grs import Countdown\n\n    countdown = Countdown(hour=14, minutes=30)  # 預設為 14:30\n    countdown.nextday    # 下一個 14:30 日期\n    countdown.countdown  # 到數秒數\n    countdown.exptime    # 下一個 14:30 日期時間（type: datetime）\n    countdown.lastmod    # 前一個 14:30 日期時間（type: datetime）\n\n\n判斷乖離轉折點：Stock(no).check_moving_average_bias_ratio\n================================================================\n\n判斷乖離轉折點\n\n::\n\n    from grs import Stock\n\n    stock = Stock('2618')\n    data = stock.moving_average_bias_ratio(3, 6)[0]  # 取得 3-6 乖離值 type: list\n\n    # 計算五個區間負乖離轉折點\n    check_data = stock.check_moving_average_bias_ratio(data, sample=5,\n                                                    positive_or_negative= False)\n    print check_data  # (T/F, 第幾轉折日, 乖離轉折點值) type: tuple\n\n\n四大買賣點判斷：BestFourPoint\n====================================\n\n判斷是否為技術分析的四大買賣點，條件成立，回傳條件結果，判斷結果僅供參考！\n\n::\n\n    from grs import BestFourPoint\n    from grs import Stock\n\n    stock = Stock('2618')\n    result = BestFourPoint(stock)\n    result.best_four_point_to_buy()       # 判斷是否為四大買點\n    result.best_four_point_to_sell()      # 判斷是否為四大賣點\n    result.best_four_point()              # 綜合判斷\n\n全部上市股票檢視\n\n::\n\n    from grs import BestFourPoint\n    from grs import Stock\n    from grs import TWSENo\n\n    stock_no_list = TWSENo().all_stock_no\n\n    for i in stock_no_list:\n        try:\n            best_point, info = BestFourPoint(Stock(i)).best_four_point()\n            if best_point:  # 買點\n                print 'Buy: {0} {1}'.format(i, info)\n            else:   # 賣點\n                print 'Sell: {0} {1}'.format(i, info)\n        except:     # 不作為或資料不足\n            print 'X: {0}'.format(i)\n\n\n擴充月份資料：Stock(no).plus_mons(month)\n============================================\n\n當原有的月份資料不夠時，不需要從頭抓取，只需要給予增額月份值即可。\n\n::\n\n    from grs import Stock\n\n    stock = Stock('2618')                # 預設為抓取３個月份資料\n    stock.moving_average(60)\n    IndexError: list index out of range  # 資料不足\n    len(stock.raw)                       # 回傳 51 個值\n    stock.plus_mons(1)                   # 在抓取一個月資料\n    len(stock.raw)                       # 回傳 66 個值\n    stock.moving_average(60)             # 計算成功\n\n\n-----------------------------\nChange Logs\n-----------------------------\n\n0.7.0 2016/09/11\n====================================\n\n- 修正：上市（TWSE）擷取連結\n\n0.6.2 2015/03/20\n====================================\n\n- 修正：上櫃（OTC）擷取連結\n\n0.6.1 2014/06/11\n====================================\n\n- 修正：安裝時錯誤的套件載入\n\n0.6.0 2014/06/10\n====================================\n\n- 修正：使用 urllib3 取代 urllib2\n- 新增：新格式的即時盤擷取資訊，包含加權指數、櫃檯指數、寶島指數\n\n0.5.6 2014/06/01\n====================================\n\n- 修正：tools 儲存路徑\n- 新增：日常交易的代碼與名稱（`grs.twseno.ImportCSV.get_stock_list`）\n- 新增：日常交易的類別代碼與名稱（`grs.twseno.ImportCSV.get_stock_comps_list`）\n- 已知問題：盤中即時資訊擷取無法使用 grs.RealtimeStock/RealtimeWeight\n\n0.5.5 2014/05/18\n====================================\n\n- 修正： `grs.fetch_data.SimpleAnalytics.CKMAO` to be classmethod.\n\n0.5.4 2014/05/12\n====================================\n\n- 新增：MA, MAO, MAV, CKMAO into grs.fetch_data.SimpleAnalytics.\n\n0.5.3 2014/04/17\n====================================\n\n- 修正：離線時的錯誤訊息\n- 修正：`realtime` str format.\n\n0.5.2 2014/04/12\n====================================\n\n- 修正：字串判斷使用 `basestring`.\n\n0.5.1 2014/04/08\n====================================\n\n- 修正：套件遺漏 csv 檔案\n\n0.5.0 2014/03/04\n====================================\n\n- 新增：上櫃資訊（ `櫃台買賣中心 \u003chttp://gretai.org.tw\u003e`_ ）\n- 修正：股票代碼列表回傳（TWSENo）代碼值改為 *string*.\n\n0.4.3 2014/01/22\n====================================\n\n- 新增： `grs 文件 \u003chttp://grs-docs.toomore.net\u003e`_.\n\n0.4.2 2014/01/11\n====================================\n\n- 修正：Stock ``stock_no``, RealtimeStock ``no`` 必須為 *string*.\n  `Issues #9 \u003chttps://github.com/toomore/grs/issues/9\u003e`_\n\n0.4.1 2014/01/02\n====================================\n\n- 修正：Countdown().countdown 秒數問題\n- 新增：twse_no, twse_open, twse_realtime, countdown into unittest\n- 移除：Support Python 2.6\n\n0.4.0 2013/12/30\n====================================\n\n- 修正：Naming Convention\n- 修正：Coding style to fit PEP8\n- 新增：For PyPy\n\n0.3.0 2013/12/18\n====================================\n\n- 更新：股票代碼列表\n- 更新：2014 年集中交易市場開（休）市日期表\n\n0.2.1 2013/12/16\n====================================\n\n- 修正：部分資料改用 tuple\n\n0.2.0 2012/04/13\n====================================\n\n- 修正：輸出中文統一使用 Unicode\n- 修正：需要套件 python-dateutil 調整為 1.5\n- 修正：Web Demo 網站網址\n- 新增：Stock.plusMons() 擴充月份資料\n\n0.1.4 2012/04/01\n====================================\n\n- 修正：每月首日無資料抓取問題\n\n0.1.3 2012/03/31\n====================================\n\n- 修正：Countdown 倒數時間計算錯誤（dateutil.relativedelta）\n\n0.1.2 2012/03/31\n====================================\n\n- 修正：grs 倒數時間計算錯誤（dateutil.relativedelta）\n","funding_links":[],"categories":["CLI/System Application"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoomore%2Fgrs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoomore%2Fgrs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoomore%2Fgrs/lists"}