mlouielu / twstock

台灣股市股票價格擷取 (含即時股票資訊) - Taiwan Stock Opendata with realtime
http://twstock.readthedocs.io/
MIT License
1.13k stars 350 forks source link

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

Open chingwen823 opened 6 years ago

chingwen823 commented 6 years ago

有沒有一次抓取的方法? 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'
ianlini commented 6 years ago

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?

chingwen823 commented 6 years ago

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

ianlini commented 6 years ago

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

chingwen823 commented 6 years ago

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

ianlini commented 6 years ago

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

twmht commented 5 years ago

@chingwen823

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

chingwen823 commented 5 years ago

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

Ming-Hsuan-Tu notifications@github.com 於 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 commented 9 months ago

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

Ming-Hsuan-Tu notifications@github.com 於 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.

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