PTrade生命周期、调度与策略设置
get_business_type
该接口用于返回当前策略的业务类型。
原型
get_business_type()
适用环境
该函数在回测、交易模块可用
释义
该接口用于返回当前策略的业务类型。
注意事项
无
参数
无
返回值
策略业务类型(str):
stock -- 股票
rzrq -- 融资融券
future -- 期货
示例
def initialize(context):
# 初始化策略
g.security = "600570.SS"
set_universe(g.security)
def before_trading_start(context, data):
g.flag = False
g.business_type = get_business_type()
log.info("当前策略的业务类型为:%s" % g.business_type)
def handle_data(context, data):
if g.flag is False:
if g.business_type == "stock":
order("600570.SS", 100)
elif g.business_type == "future":
buy_open("IF2309.CCFX", 1, 3816.0)
g.flag = True