Rss & SiteMap

金字塔客服中心 - 专业程序化交易软件提供商 http://www.weistock.com/bbs/

专业程序化软件提供商
共3 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

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

1楼
hrrr 发表于: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



2楼
FireScript 发表于:2021/3/3 9:14:11
 python相关问题请在高级区发帖。 该贴会转移到高级区。
3楼
yukizzc 发表于:2021/3/3 9:25:03

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

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

共3 条记录, 每页显示 10 条, 页签: [1]


Powered By Dvbbs Version 8.3.0
Processed in .20313 s, 2 queries.