Micro-sheep / efinance

efinance 是一个可以快速获取基金、股票、债券、期货数据的 Python 库,回测以及量化交易的好帮手!🚀🚀🚀
MIT License
1.82k stars 463 forks source link

get_quote_history 获取多个标的时不稳定 #102

Open vensentzhou opened 1 year ago

vensentzhou commented 1 year ago

在日常使用中,使用get_quote_history获取多个标的时,(最近)出现多次获取失败,无响应的的情况,请问大佬有什么改善的方法?

截屏2022-11-12 11 45 13
vensentzhou commented 1 year ago
截屏2022-11-12 11 31 03
Micro-sheep commented 1 year ago

在日常使用中,使用get_quote_history获取多个标的时,(最近)出现多次获取失败,无响应的的情况,请问大佬有什么改善的方法? 截屏2022-11-12 11 45 13

我今天试了一下,也是会遇到这个问题,有时候会卡在某一只股票上面,但是我单独获取这只股票之后,后面再和其他的放在一起获取,就不会再卡住。具体原因待我调试之后再说。

vensentzhou commented 1 year ago

我测试情况也是这样,所以现在临时采用for循环 单票取数据,期待大佬的研究成果。

six7ths commented 1 year ago

我最近也经常卡,有时获取个位数股票时,总是卡在最后几个,更别说几十只股票的情况了。

Micro-sheep commented 1 year ago

我最近也经常卡,有时获取个位数股票时,总是卡在最后几个,更别说几十只股票的情况了。

把源代码的这一段改为下面这一段测试看看呢?我这边改了之后测试几次大量获取也没有发现卡住。 https://github.com/Micro-sheep/efinance/blob/b88696fd31911da27f62c2e365930508a2c93bac/efinance/common/getter.py#L97

改为

url = 'http://7.push2his.eastmoney.com/api/qt/stock/kline/get'

具体更新方法是

# 下载代码
git clone https://github.com/Micro-sheep/efinance
# 本地安装
cd efinance
pip install -e .

之后按我说的修改文件 efinance/common/getter.py 中的对应部分再进行测试。

tyewu commented 1 year ago

这个问题目前还存在,改了URL还是卡住,不知道是什么问题

nrliangxy commented 1 year ago

我最近也经常卡,有时获取个位数股票时,总是卡在最后几个,更别说几十只股票的情况了。

把源代码的这一段改为下面这一段测试看看呢?我这边改了之后测试几次大量获取也没有发现卡住。

https://github.com/Micro-sheep/efinance/blob/b88696fd31911da27f62c2e365930508a2c93bac/efinance/common/getter.py#L97

改为

url = 'http://7.push2his.eastmoney.com/api/qt/stock/kline/get'

具体更新方法是

# 下载代码
git clone https://github.com/Micro-sheep/efinance
# 本地安装
cd efinance
pip install -e .

之后按我说的修改文件 efinance/common/getter.py 中的对应部分再进行测试。

将多进程直接改为gevent 来进行协成请求就可以解决问题了

Micro-sheep commented 1 year ago

我尝试替换了一下,用几天看看情况如何。

nrliangxy commented 1 year ago

我尝试替换了一下,用几天看看情况如何。

def get_quote_history_multi( codes: List[str], beg: str = '19000101', end: str = '20500101', klt: int = 101, fqt: int = 1, tries: int = 3, **kwargs, ) -> Dict[str, pd.DataFrame]: """ 获取多只股票、债券历史行情信息 """

dfs: Dict[str, pd.DataFrame] = {}

total = len(codes)
pool = Pool(total)
coroutine_list = [pool.spawn(get_quote_history_single, x) for x in codes]
gevent.joinall(coroutine_list)
df_value = [_.value for _ in coroutine_list]
dfs = dict(zip(codes, df_value))
return dfs

跑跑这个,应该就可以了