twstock icon indicating copy to clipboard operation
twstock copied to clipboard

一次抓取多筆代號股票之31日交易資料?

Open chingwen823 opened this issue 6 years ago • 8 comments

有沒有一次抓取的方法? ex. restock.Stock(['2330','6515'])

try with list got en error back:

stock = twstock.Stock(stocknum) 2 stock

TypeError Traceback (most recent call last) in () ----> 1 stock = twstock.Stock(stocknum) 2 stock

~/Library/Python/3.6/lib/python/site-packages/twstock/stock.py in init(self, sid, initial_fetch) 133 def init(self, sid: str, initial_fetch: bool=True): 134 self.sid = sid --> 135 self.fetcher = TWSEFetcher() if codes[sid].market == '上市' else TPEXFetcher() 136 self.raw_data = [] 137 self.data = []

TypeError: unhashable type: 'list'

chingwen823 avatar Apr 20 '18 04:04 chingwen823

You can try this:

stocks = [Stock(symbol) for symbol in ['2330', '6515']]

I don't think it's a good idea to allow Stock(['2330', '6515']). Maybe you can elaborate more on your use case?

ianlini avatar Apr 20 '18 05:04 ianlini

thanks you are right what I trying to do is to compare a group of stocks with another

I will maintain a local dataset instead

by the way , the time limitation of connections of twes seems to be 3times/5sec

chingwen823 avatar Apr 20 '18 05:04 chingwen823

Yeah, it's very easy to be banned by TWSE. I always add a 1~5s random sleep between each request.

ianlini avatar Apr 20 '18 05:04 ianlini

我很好奇 一般限制是單位時間裡的連線數 如果不重建connection,連線的sesssion沒斷 應該可以一直無限去下查詢??(就不會被ban是嗎?)

chingwen823 avatar Apr 20 '18 05:04 chingwen823

我有想過這個問題,不過沒有測試過 另外 user agent 可能也有影響 不知道有沒有人測試過?

ianlini avatar Apr 20 '18 05:04 ianlini

@chingwen823

要如何作到不重建 connection 但是可以換查詢?

twmht avatar Mar 07 '19 12:03 twmht

我不知道 我後來自已寫了一套

Ming-Hsuan-Tu [email protected] 於 2019年3月7日 下午8:48 寫道:

@chingwen823 https://github.com/chingwen823 要如何作到不重建 connection 但是可以換查詢?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mlouielu/twstock/issues/41#issuecomment-470512531, or mute the thread https://github.com/notifications/unsubscribe-auth/APCdodOuldHZqYfXBEZ2g3M_2Ek2T3NOks5vUQqPgaJpZM4Tc3cG.

chingwen823 avatar Mar 07 '19 23:03 chingwen823

我不知道 我後來自已寫了一套

Ming-Hsuan-Tu [email protected] 於 2019年3月7日 下午8:48 寫道:

@chingwen823 https://github.com/chingwen823 要如何作到不重建 connection 但是可以換查詢?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mlouielu/twstock/issues/41#issuecomment-470512531, or mute the thread https://github.com/notifications/unsubscribe-auth/APCdodOuldHZqYfXBEZ2g3M_2Ek2T3NOks5vUQqPgaJpZM4Tc3cG.

那真的不重建連線就能一直查下去不被封嗎

TimLai666 avatar Dec 14 '23 17:12 TimLai666