获取股票当前的价格与状态(附聚宽一函数的翻译方法)

用户头像mx_*716bsb
2023-10-19 发布

只需要调用get_security_info()以及get_price()即可。需注意get_price()中参数fields的类型。

实际上,聚宽中最常用的获取股票状态的函数get_current_data()(简单来说)就是上面两个函数的叠加。翻译时需注意把get_current_data()拆开。

# 获取当前对应价格

def handle_data(context):
    current_info=get_security_info(context.security)
    current_price=get_price('300033.SZ',end_date='20230808', fre_step='1d', fields=['open'], skip_paused = True, fq = 'pre', bar_count = 5, is_panel = 0)
  
    #获取股票所有信息、停牌时间以及开盘价
    print(current_info)
    print(current_info.end_date)
    print(current_price['open'])

评论

需要帮助?

试试AI小助手吧