欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件高级功能研发区 → 如何获得最新的不完整k线

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有1613人关注过本帖树形打印复制链接

主题:如何获得最新的不完整k线

帅哥哟,离线,有人找我吗?
hrrr
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:35 积分:0 威望:0 精华:0 注册:2021/2/24 11:38:50
如何获得最新的不完整k线  发帖心情 Post By:2021/3/2 22:15:21 [只看该作者]

请问要如何获得最新的(即不完整的)5分钟k线?
我尝试了以下的代码,可是每次打印出来的都是一样的完整的5分钟K线。
设置了include_now是True也没用。

from PythonApi import *

 

def init(context):

   """ Mandatory """

   settimer(auto_test, 1000)

   pass

 

def handle_bar(context):

   """ Mandatory """

   pass

 

def auto_test(context):

   contract_id = context.universe[0]

   bar_list = history_bars(order_book_id=contract_id,

                           bar_count=1,

                           frequency='5m',

                           fields=['open', 'close', 'high', 'low', 'datetime'],

                           include_now=True)

   write_logging(str(len(bar_list)))

   bar = bar_list[-1]

   text = contract_id + ' True'

   text += '\n- open: %s' % (bar[0])

   text += '\n- close: %s' % (bar[1])

   text += '\n- high: %s' % (bar[2])

   text += '\n- low: %s' % (bar[3])

   text += '\n- datetime: %s' % (bar[4])

   write_logging(text)

   bar_list = history_bars(order_book_id=contract_id,

                           bar_count=1,

                           frequency='5m',

                           fields=['open', 'close', 'high', 'low', 'datetime'],

                           include_now=False)

   bar = bar_list[-1]

   text = contract_id + ' False'

   text += '\n- open: %s' % (bar[0])

   text += '\n- close: %s' % (bar[1])

   text += '\n- high: %s' % (bar[2])

   text += '\n- low: %s' % (bar[3])

   text += '\n- datetime: %s' % (bar[4])

   write_logging(text)

   pass




 回到顶部
帅哥哟,离线,有人找我吗?
FireScript
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:14496 积分:0 威望:0 精华:0 注册:2017/7/4 13:40:18
  发帖心情 Post By:2021/3/3 9:14:11 [只看该作者]

 python相关问题请在高级区发帖。 该贴会转移到高级区。


命数如织,当如磐石。
 回到顶部
帅哥哟,离线,有人找我吗?
yukizzc
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:21598 积分:0 威望:0 精华:1 注册:2010/7/31 16:35:30
  发帖心情 Post By:2021/3/3 9:25:03 [只看该作者]


 回到顶部