代码如下:
from vnpy_ctastrategy.template import CtaTemplate
from vnpy.trader.object import TickData,BarData,OrderData,TradeData
from vnpy_ctastrategy.base import StopOrder
from vnpy.trader.utility import BarGenerator,ArrayManager
from vnpy.trader.constant import Interval
class TickTest(CtaTemplate):
author=""
tick_last_price:float=0.0
tick_hour:int=0
tick_minute:int=0
tick_second:int=0
tick_up_limit:float=0
tick_down_limit:float=0
parameters=[]
variables=[
"tick_last_price",
"tick_hour",
"tick_minute",
"tick_second",
"tick_up_limit",
"tick_down_limit"
]
def __init__(self, cta_engine, strategy_name, vt_symbol, setting):
super().__init__(cta_engine, strategy_name, vt_symbol, setting)
pass
def on_init(self):
"""策略初始化"""
print("on_init")
self.put_event()
def on_start(self):
"""策略启动"""
print("on_start")
self.put_event()
def on_stop(self):
"""策略停止"""
self.put_event()
def on_tick(self,tick:TickData):
"""收到tick时调用该函数"""
print("on_tick")
self.tick_last_price=tick.last_price
self.tick_hour=tick.datetime.hour
self.tick_minute=tick.datetime.minute
self.tick_second=tick.datetime.second
self.tick_up_limit=tick.limit_up
self.tick_down_limit=tick.limit_down
self.put_event()
def on_order(self,order:OrderData):
"""交易所委托出现变化时调用该函数"""
pass
def on_stop_order(self, stop_order: StopOrder):
"""本地的停止单委托发生变化时调用该函数"""
pass
def on_trade(self, trade: TradeData):
"""成交时调用该函数"""
pass