掘金社区

请加下关于股票数据获取问题Pinned highlighted

mfk80 发表在问题反馈 2021-03-29 16:43:39

问题反馈
716
5
0

请问怎么筛选出涨停的股票作为数据来源呢,具体代码的那种,谢谢阿

用get_history_instruments获取所有股票的数据后,为什么一直提示没有upper_limit字段呢,实际上看是有所有字段内容的,但无法调取出来显示加工

评论: 5
  • get_history_instruments(symbols='SZSE.000001,SZSE.000002', start_date='2017-09-19', end_date='2017-09-19', df=True)
    0_1617153461457_d7e6f2ce-7dc0-43d3-aa1f-4b73ac2513d2-image.png
    官网示例代码有upper_limit字段,如何调取请查询pandas 的 DataFrame对象相关文档,例如df['upper_limit']

    2021-03-31 09:19:18
  • 是的,按理说都可以提取的,是不是有股票数量限制,
    all_stock1 = get_instruments(exchanges='SHSE, SZSE', sec_types=[1], fields='symbol, listed_date, delisted_date', df=True)
    all_stock = list(all_stock1.symbol)
    for i in range(len(all_stock)):
    data = history(symbol=all_stock[i], frequency='1d', start_time='2021-01-04 09:00:00',
    end_time='2021-1-15 16:00:00',
    fields='symbol,bob,eob,open,high,low,close', df=True)
    data1 = get_history_instruments(symbols=all_stock[i], start_date='2021-01-04',end_date='2021-01-05', df=True)
    data2=data1['upper_limit']

    运行结果提示40行就是说明最后一行的KeyError: 'upper_limit'

    2021-03-31 22:41:12
  • @mfk80 你这个代码all_stock没有过滤已经退市的,导致退市票无法使用get_history_instruments获取数据,返回空的df,就无法获取upper_limit字段。

    2021-04-06 09:18:46
  • code = all_stock[ (all_stock['delisted_date'] > date2) &
    (all_stock['symbol'].str[5] != '9') & (all_stock['symbol'].str[5] != '2')]
    for i in range(len(code)):
    data = history(symbol=code['symbol'][i], frequency='1d', start_time='2021-01-04 09:00:00',
    end_time='2021-1-15 16:00:00',
    fields='symbol,bob,eob,open,high,low,close', df=True)
    data1 = get_history_instruments(symbols=code['symbol'][i], start_date='2021-01-04',end_date='2021-01-05',
    df=True)

    非常感谢,确实是包含退市的,剔出后又出现如下错误,还劳烦请教下

    Traceback (most recent call last):
    File "C:/Users/caspa/.PyCharmCE2019.3/config/scratches/hs300.py", line 33, in <module>
    data = history(symbol=code['symbol'][i], frequency='1d', start_time='2021-01-04 09:00:00',
    File "D:\vnstudio\lib\site-packages\pandas\core\series.py", line 868, in getitem
    result = self.index.get_value(self, key)
    File "D:\vnstudio\lib\site-packages\pandas\core\indexes\base.py", line 4375, in get_value
    tz=getattr(series.dtype, 'tz', None))
    File "pandas_libs\index.pyx", line 81, in pandas._libs.index.IndexEngine.get_value
    File "pandas_libs\index.pyx", line 89, in pandas._libs.index.IndexEngine.get_value
    File "pandas_libs\index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc
    File "pandas_libs\hashtable_class_helper.pxi", line 987, in pandas._libs.hashtable.Int64HashTable.get_item
    File "pandas_libs\hashtable_class_helper.pxi", line 993, in pandas._libs.hashtable.Int64HashTable.get_item
    KeyError: 197

    2021-04-10 22:37:27
  • @Charkong 谢谢

    2021-04-10 22:44:02
相关阅读
  • 问题反馈history提取数据有问题?
  • Looks like your connection to 掘金量化社区 - 量化交易者的交流社区 was lost, please wait while we try to reconnect.