efinance icon indicating copy to clipboard operation
efinance copied to clipboard

取得股票历史数据时,若是klt为分钟的分时数据,能否加入时间段参数?

Open six7ths opened this issue 4 years ago • 3 comments
trafficstars

def get_quote_history(stock_codes: Union[str, List[str]], beg: str = '19000101', end: str = '20500101', klt: int = 101, fqt: int = 1) -> Union[pd.DataFrame, Dict[str, pd.DataFrame]]:

比如klt=30,那每天也就8条数据,但获取数据时,比如,我仅想获取10:30的数据,其他条暂时不要,可否再加入时间Time的beg和end参数?

six7ths avatar Aug 11 '21 08:08 six7ths

以日期为时间段的数据会更好。如果你想仅获取多日的的指定时间点的数据,那么可以使用 pandas 的筛选功能(返回的数据绝大多数是 pandas.DataFrame 或者 pandas.Series)。以获取 2021年7月10:30 这个时间点的数据为例,示例代码如下

import efinance as ef
df = ef.stock.get_quote_history('600519',
                                beg='20210701',
                                end='20210731',
                                klt=30)
# 从日期里面取出时间
df['时间段'] = df['日期'].apply(lambda x: x.split()[-1])
# 筛选出 时间点为 10:30 的数据
target_df = df.query('时间段 == "10:30"')
print(target_df)

image

Micro-sheep avatar Aug 11 '21 11:08 Micro-sheep

好的,收到,我来试试。

不过,若我只需要一个时点数据,却取回来整体数据,会不会增加网页接口负担呢?我担心的是这个

six7ths avatar Aug 12 '21 01:08 six7ths

好的,收到,我来试试。

不过,若我只需要一个时点数据,却取回来整体数据,会不会增加网页接口负担呢?我担心的是这个

这个不需要担心。接口很稳定,并发量大。

Micro-sheep avatar Aug 31 '21 11:08 Micro-sheep