toomore / grs Goto Github PK
View Code? Open in Web Editor NEW📈 台灣上市上櫃股票價格擷取(Fetch Taiwan Stock Exchange data)含即時盤、台灣時間轉換、開休市判斷。
Home Page: http://pypi.python.org/pypi/grs
License: MIT License
📈 台灣上市上櫃股票價格擷取(Fetch Taiwan Stock Exchange data)含即時盤、台灣時間轉換、開休市判斷。
Home Page: http://pypi.python.org/pypi/grs
License: MIT License
Dear Toomore,
I run test_unittest.py by the following command
python test_unittest.py
But the following error occurred.
Traceback (most recent call last):
File "test_unittest.py", line 3, in
import grs
ImportError: No module named grs
Do you have any suggestion?
Thanks in advance!
snowuyl
驗證資料時發現資料裡有時候會混雜著
94/08/29,1085.0,65851.0,59.4,62.5,59.4,60.2,0.80,478.0
94/08/30,906.0,52032.0,60.3,60.5,56.0,56.0,-4.20,364.0
94/08/31,1266.0,68393.0,55.8,57.5,52.1,52.6,-3.40,478.0
¦@18µ§
1.¡u¡¯¡vªí¥Ü¸Ó¤é¬°¸ÓªÑ²¼¤WÂd±¾µPº¤é¡A¨ä±¾µPº¤é¤§º¦¶^«Y¥H·í¤é¦¬½L»ù´î©Ó¾P»ùpºâ¦Ó±o¡C
94/09/02,827.0,46129.0,53.8,56.2,53.7,56.2,3.60,244.0
94/09/05,512.0,28293.0,56.9,56.9,54.1,54.1,-2.10,268.0
94/09/06,1029.0,55870.0,54.1,56.2,52.5,56.0,1.90,372.0
之類的一行亂碼,不知道是什麼東西~
Collecting grs
Using cached grs-0.7.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/y8/04ps3r3d52q3mz7wfy_mgc8m0000gn/T/pip-build-og6hoafl/grs/setup.py", line 4, in <module>
import grs
File "/private/var/folders/y8/04ps3r3d52q3mz7wfy_mgc8m0000gn/T/pip-build-og6hoafl/grs/grs/__init__.py", line 33, in <module>
from .fetch_data import Stock
File "/private/var/folders/y8/04ps3r3d52q3mz7wfy_mgc8m0000gn/T/pip-build-og6hoafl/grs/grs/fetch_data.py", line 497
raise ConnectionError(), u'IN OFFLINE, NO DATA FETCH.'
^
SyntaxError: invalid syntax
I am running it on macOS Sierra & Python 2.7 virtual environment.
Even I got your repository in local environment and run setup.py, it still failed anyway.
Please help out how to install this package successfully.
Thanks for all help.
不知道有沒有可能利用 selenium 執行 網頁程式下單
當我嘗試增加月份時,使用 plus_mons 出現了下列錯誤
File "../A/B.py", line 33, in queryPrice
stock.plus_mons(1)
File "/Library/Python/2.7/site-packages/grs-0.6.2-py2.7.egg/grs/fetch_data.py", line 121, in plus_mons
oldraw = list(self.__raw_data)
AttributeError: 'Stock' object has no attribute '_FetchData__raw_data'
我使用pycharm+django+python2.7
在使用grs模塊的時候一直出現此錯誤:HTTPConnectionPool(host='mis.tse.com.tw', port=None): Max retries exceeded with url: /stock/api/getStockInfo.jsp?ex_ch=otc_070279.tw_20141118&json=1&delay=0&_=1416282457 (Caused by ProtocolError('Connection aborted.', error(10060, '')))
我不知道什麼原因,應該怎麼解決?
1.cvs資料檔停留在2013/12/18,可否要更新,或建立自動上網更新機制
2.TWSENo().industry_code.keys()與TWSENo().industry_comps.keys()兩者資料不盡相同,可否更改一下!
3.有些股票如果抓太多資料(24月) stock('xxxx',24),無法讀取
4.遇到剛剛下市的股票,會出現錯誤,,無法讀取
ex:<2015.2.4>代號:2384 --> AttributeError: 'Stock' object has no attribute '_SimpleAnalytics__raw_data'
感謝你!你的程式很好用。
我已經安裝 python-dateutil 1.5、ujson、urllib3,但是經常出現不能連接上的問題。
例如Stock導入的時候也報錯,我看了錯誤報告,是缺少dateutil的庫,於是我安裝了之後可以導入。但很不穩定,經常會報錯,錯誤是:WARNING:urllib3.connectionpool:Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(10060, ''))': /ch/trading/exchange/STOCK_DAY/STOCK_DAY_print.php?genpage=genpage/Report201411/201411_F3_1_8_2618.php&type=csv&r=859600
<grs.fetch_data.Stock object at 0x01C69D50>;
還有其他的功能也不能使用,例如:RealtimeTWSE,報:WARNING:urllib3.connectionpool:Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(10060, ''))': /stock/api/getStockInfo.jsp?ex_ch=tse_2618.tw_20141118&json=1&delay=0&=1416278929
WARNING:urllib3.connectionpool:Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(10060, ''))': /stock/api/getStockInfo.jsp?ex_ch=tse_2618.tw_20141118&json=1&delay=0&=1416278929
WARNING:urllib3.connectionpool:Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(10060, ''))': /stock/api/getStockInfo.jsp?ex_ch=tse_2618.tw_20141118&json=1&delay=0&_=1416278929
Traceback (most recent call last):
File "<pyshell#2>", line 1, in
realtime_stock = RealtimeTWSE('2618')
File "C:\Python27\lib\site-packages\grs-0.6.1-py2.7.egg\grs\realtime2.py", line 132, in init
super(RealtimeTWSE, self).init(no, date)
File "C:\Python27\lib\site-packages\grs-0.6.1-py2.7.egg\grs\realtime2.py", line 35, in init
self.result = URL.request('GET', STOCKPATH % params)
File "build\bdist.win32\egg\urllib3\request.py", line 68, in request
*_urlopen_kw)
File "build\bdist.win32\egg\urllib3\request.py", line 81, in request_encode_url
return self.urlopen(method, url, *_urlopen_kw)
File "build\bdist.win32\egg\urllib3\connectionpool.py", line 579, in urlopen
release_conn=release_conn, *_response_kw)
File "build\bdist.win32\egg\urllib3\connectionpool.py", line 579, in urlopen
release_conn=release_conn, *_response_kw)
File "build\bdist.win32\egg\urllib3\connectionpool.py", line 579, in urlopen
release_conn=release_conn, **response_kw)
File "build\bdist.win32\egg\urllib3\connectionpool.py", line 559, in urlopen
_pool=self, _stacktrace=stacktrace)
File "build\bdist.win32\egg\urllib3\util\retry.py", line 265, in increment
raise MaxRetryError(pool, url, error)
MaxRetryError: HTTPConnectionPool(host='mis.tse.com.tw', port=None): Max retries exceeded with url: /stock/api/getStockInfo.jsp?ex_ch=tse_2618.tw_20141118&json=1&delay=0&=1416278929 (Caused by ProtocolError('Connection aborted.', error(10060, '')));
我不知道是什麼原因導致這個錯誤,有時候是可以使用的,另外還有RealtimeOTC,錯誤:WARNING:urllib3.connectionpool:Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(10060, ''))': /stock/api/getStockInfo.jsp?ex_ch=otc_2618.tw_20141118&json=1&delay=0&=1416279071
WARNING:urllib3.connectionpool:Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(10060, ''))': /stock/api/getStockInfo.jsp?ex_ch=otc_2618.tw_20141118&json=1&delay=0&=1416279071
WARNING:urllib3.connectionpool:Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(10060, ''))': /stock/api/getStockInfo.jsp?ex_ch=otc_2618.tw_20141118&json=1&delay=0&_=1416279071
Traceback (most recent call last):
File "<pyshell#3>", line 1, in
RealtimeOTC('2618')
File "C:\Python27\lib\site-packages\grs-0.6.1-py2.7.egg\grs\realtime2.py", line 146, in init
super(RealtimeOTC, self).init(no, date)
File "C:\Python27\lib\site-packages\grs-0.6.1-py2.7.egg\grs\realtime2.py", line 35, in init
self.result = URL.request('GET', STOCKPATH % params)
File "build\bdist.win32\egg\urllib3\request.py", line 68, in request
*_urlopen_kw)
File "build\bdist.win32\egg\urllib3\request.py", line 81, in request_encode_url
return self.urlopen(method, url, *_urlopen_kw)
File "build\bdist.win32\egg\urllib3\connectionpool.py", line 579, in urlopen
release_conn=release_conn, *_response_kw)
File "build\bdist.win32\egg\urllib3\connectionpool.py", line 579, in urlopen
release_conn=release_conn, *_response_kw)
File "build\bdist.win32\egg\urllib3\connectionpool.py", line 579, in urlopen
release_conn=release_conn, **response_kw)
File "build\bdist.win32\egg\urllib3\connectionpool.py", line 559, in urlopen
_pool=self, _stacktrace=stacktrace)
File "build\bdist.win32\egg\urllib3\util\retry.py", line 265, in increment
raise MaxRetryError(pool, url, error)
MaxRetryError: HTTPConnectionPool(host='mis.tse.com.tw', port=None): Max retries exceeded with url: /stock/api/getStockInfo.jsp?ex_ch=otc_2618.tw_20141118&json=1&delay=0&=1416279071 (Caused by ProtocolError('Connection aborted.', error(10060, '')));
而TWSENo().all_stock 得到所有號碼及名稱是一直可以使用的。
我應該如何解決這些問題?
可以問一下這部分的錯誤訊息嗎 ??
>>> from grs import RealtimeTWSE
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name RealtimeTWSE
謝謝
Traceback (most recent call last):
File "E:/git/stock/stockgrs.py", line 118, in
realtime_stock = RealtimeOTC('8446') # 擷取華研即時股價
File "C:\Python27\lib\site-packages\grs\realtime2.py", line 146, in init
super(RealtimeOTC, self).init(no, date)
File "C:\Python27\lib\site-packages\grs\realtime2.py", line 35, in init
self.result = URL.request('GET', STOCKPATH % params)
File "C:\Python27\lib\site-packages\urllib3\request.py", line 66, in request
**urlopen_kw)
File "C:\Python27\lib\site-packages\urllib3\request.py", line 87, in request_encode_url
return self.urlopen(method, url, **extra_kw)
File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
release_conn=release_conn, **response_kw)
File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 549, in urlopen
raise HostChangedError(self, url, retries)
urllib3.exceptions.HostChangedError: HTTPConnectionPool(host='mis.tse.com.tw', port=80): Tried to open a foreign host with url: http://1.1.1.8
Hi Sir,
Could I use grs get EPS of 2330?
Thanks in advance!
snowuyl
大約從 6 月開始,都會丟出 exception :Tried to open a foreign host with url: http://1.1.1.1
使用 wget/curl 也同樣會有一樣的問題,我想這是 mis.tse.com.tw 問題。
不知道有沒有方法可以避過。
試著編 pkgbuild for arch linux, 但發現你的 github tag 和 https://pypi.python.org/pypi/grs 不一致. 建議標記一下 0.4.1
ticker = '2317'
month =12
stock = Stock(ticker, month)
print stock.price
Traceback (most recent call last):
File "<pyshell#21>", line 1, in
print stock.price
File "C:\Python27\lib\site-packages\grs\fetch_data.py", line 391, in price
return self.__serial_price()
File "C:\Python27\lib\site-packages\grs\fetch_data.py", line 291, in __serial_price
return list(result)
File "C:\Python27\lib\site-packages\grs\fetch_data.py", line 290, in
result = (float(i[rows]) for i in self.__raw_data)
ValueError: could not convert string to float: --
Traceback (most recent call last):
File "realtime2.py", line 235, in
realtime_data = RealtimeTWSE(1201)
File "realtime2.py", line 132, in init
super(RealtimeTWSE, self).init(no, date)
File "realtime2.py", line 35, in init
self.result = URL.request('GET', STOCKPATH % params)
File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 69, in request
*_urlopen_kw)
File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 90, in request_encode_url
return self.urlopen(method, url, *_extra_kw)
File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 652, in urlopen
release_conn=release_conn, **response_kw)
File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 529, in urlopen
raise HostChangedError(self, url, retries)
urllib3.exceptions.HostChangedError: HTTPConnectionPool(host='mis.tse.com.tw', port=None): Tried to open a foreign host with url: http://1.1.1.2
可以問一下在手冊裡,moving_average_bias_ratio 是 "計算乖離率(均價)",可以實際上看起來是價差,而不是百分比,是不是字面上有一些 ambiguous
謝謝
櫃台買賣中心
http://www.otc.org.tw/
從 GITHUB 下載了 grs 0.7.0, 執行起來一切都好唯獨無法取得即時盤的股價資訊. 查閱了歷史資料, 以前似乎也曾發生過類似的問題 (如 issue #39 擷取華研即時股價出現錯誤)
不知即時盤的資訊是只在 2016/11 月底的時候無法取得呢? 抑或是從此以後再也無法取得了呢?
請問這是因為台灣證劵交易所不提供即時的資訊嗎?
煩請不吝告知, 謝謝!
stock.out_putfile('/dev/shm/2618.csv') do not return right data
stock = Stock("2618')
stock.plus_mons(1)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/site-packages/grs/fetch_data.py", line 121, in plus_mons
oldraw = list(self.__raw_data)
AttributeError: 'Stock' object has no attribute '_FetchData__raw_data'
unittest
File "grsTry.py", line 8, in
print stock.moving_average(3) # 閮?鈭???蝥予??
File "C:\Python27\lib\site-packages\grs\fetch_data.py", line 334, in moving_average
return self.__calculate_moving_average(date, 6)
File "C:\Python27\lib\site-packages\grs\fetch_data.py", line 298, in __calculate_moving_average
cal_data = self.__serial_price(row)
File "C:\Python27\lib\site-packages\grs\fetch_data.py", line 290, in __serial_price
return list(result)
File "C:\Python27\lib\site-packages\grs\fetch_data.py", line 289, in
result = (float(i[rows]) for i in self.__raw_data)
IndexError: list index out of range
步驟:
Python 2.7.4 (default, May 17 2013, 17:07:08)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.24)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from grs import Stock
>>> s = Stock('2330')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/grs/fetch_data.py", line 452, in __new__
elif stock_no in TWSENo().all_stock_no:
File "/usr/local/lib/python2.7/site-packages/grs/twseno.py", line 160, in __init__
super(TWSENo, self).__init__('stock_no.csv', 'industry_code.csv')
File "/usr/local/lib/python2.7/site-packages/grs/twseno.py", line 37, in __init__
self.__allstockno = self.importcsv()
File "/usr/local/lib/python2.7/site-packages/grs/twseno.py", line 42, in importcsv
with open(csv_path) as csv_file:
IOError: [Errno 2] No such file or directory: '/usr/local/lib/python2.7/site-packages/grs/stock_no.csv'
臺灣股票應該會有含英文字母. 建議改以文字當 key,
eg.
03236C 元牛Y1
股票代碼表以相當舊
作者你好
有關twse_list.csv
證期會代碼,公司簡稱,分類代碼,分類名稱
UPDATE,2013/12/18,x,x
1312,國喬,03,塑膠工業
關於分類代碼,分類名稱你是去哪邊找的?
整個csv是你自己整理的嗎?
Dear Toomore,
I run the following command on Windows 8.1
pip install -U grs
But the following error occurred.
Collecting grs
Downloading grs-0.7.0.tar.gz (96kB)
42% |█████████████▋ | 40kB 91kB/s eta 0:00:01
53% |█████████████████ | 51kB 112kB/s eta 0:0
63% |████████████████████▌ | 61kB 134kB/s eta
74% |███████████████████████▉ | 71kB 119kB/s
85% |███████████████████████████▎ | 81kB 136k
95% |██████████████████████████████▊ | 92kB 1
100% |████████████████████████████████| 102k
B 166kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\snowuyl\AppData\Local\Temp\pip-build-mcrgjp54\grs\setup.py",
line 4, in
import grs
File "C:\Users\snowuyl\AppData\Local\Temp\pip-build-mcrgjp54\grs\grs__init
_.py", line 33, in
from .fetch_data import Stock
File "C:\Users\snowuyl\AppData\Local\Temp\pip-build-mcrgjp54\grs\grs\fetch
data.py", line 497
raise ConnectionError(), u'IN OFFLINE, NO DATA FETCH.'
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\snowuyl\A
ppData\Local\Temp\pip-build-mcrgjp54\grs\
Do you have any suggestion?
Thanks in advance!
snowuyl
中華民國103年有價證券集中交易市場開(休)市日期表
http://www.twse.com.tw/ch/trading/trading_days.php
Hi toomore,
這個module很好用!
但是我在抓一些股的時候,當他在漲停(跌停)時,沒有委賣/買,亦沒有量。
所以在realtime2.py中, 93行開始best_ask_pirce 等等,因抓不到值的問題,導致在Assign過程中,list index out of range.
我自己是加了一些簡單的判斷避開(len(best_ask_*) is not 0才做assign...),不知道toomore大是否要做一些修改XD
感謝!!
vaal
Dear toomore,
I added test.py to get real time stock price of 2618.
from grs import RealtimeTWSE
realtime_stock = RealtimeTWSE('2618')
realtime_stock.raw
realtime_stock.data
But when I type the following on terminal of Ubuntu 16.04. The following error occurred.
Traceback (most recent call last):
File "test.py", line 3, in
realtime_stock = RealtimeTWSE('2618')
File "/home/snowuyl/samba/grs-master/grs/realtime2.py", line 132, in init
super(RealtimeTWSE, self).init(no, date)
File "/home/snowuyl/samba/grs-master/grs/realtime2.py", line 35, in init
self.result = URL.request('GET', STOCKPATH % params)
File "/usr/lib/python2.7/dist-packages/urllib3/request.py", line 69, in request
*_urlopen_kw)
File "/usr/lib/python2.7/dist-packages/urllib3/request.py", line 90, in request_encode_url
return self.urlopen(method, url, *_extra_kw)
File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 654, in urlopen
release_conn=release_conn, **response_kw)
File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 531, in urlopen
raise HostChangedError(self, url, retries)
urllib3.exceptions.HostChangedError: HTTPConnectionPool(host='mis.tse.com.tw', port=None): Tried to open a foreign host with url: http://1.1.1.8
Do you have any suggestion to solve this issue?
Thanks in advance!
snowuyl
with sphinx.
Dear Toomore,
My startup.py is as follows.
from grs import Stock
stock = Stock('6278')
print stock.moving_average(5)
print stock.moving_average_value(5)
print stock.moving_average_bias_ratio(5, 10)
I run startup.py as follows.
python startup.py
But the following error occurred
Traceback (most recent call last):
File "startup.py", line 3, in
from grs import Stock
ImportError: cannot import name Stock
Do you have any suggestion?
Thanks in advance!
snowuyl
我輸入
open_or_not.d_day(datetime(2017, 02, 06)) #西元年 2017/02/06是否開市
True
顯示為有開市
但當我輸入
open_or_not.d_day(datetime(106, 02, 06))#民國年
False
顯示為未開市
原始資料內容
2454聯發科
[u'106/02/06', 10439845.0, 2200855430.0, 208.0, 214.0, 206.0, 212.0, u'+5.00', 5853.0, u'']
有這個天的資料的
最近上市股票資料抓不到!上櫃都沒問題。
Hi,
it seems that twse changed the form of the table, so grs cannnot crawl any stock data.
Hope new version would be push soon.
Thank you.
No response output for the following call:
twse_no.last_update # 回傳列表最後更新時間(非同步)type: str
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.