以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://222.73.7.161/bbs/index.asp)
--  高级功能研发区  (http://222.73.7.161/bbs/list.asp?boardid=5)
----  如何获得最新的不完整k线  (http://222.73.7.161/bbs/dispbbs.asp?boardid=5&id=184475)

--  作者:hrrr
--  发布时间:2021/3/2 22:15:21
--  如何获得最新的不完整k线
请问要如何获得最新的(即不完整的)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
--  发布时间:2021/3/3 9:14:11
--  
 python相关问题请在高级区发帖。 该贴会转移到高级区。

--  作者:yukizzc
--  发布时间:2021/3/3 9:25:03
--  

http://www.weistock.com/bbs/dispbbs.asp?boardid=5&Id=175333

这个是在夸周期时候起作用