在定义了这开盘时的运行函数以后,止损部分如何时限分钟级别的运行,并实时止损,可以多指导
run_daily(market_open, time='open', reference_security='000300.XSHG')
止损部分
for stock in context.portfolio.positions.keys():
cost = context.portfolio.positions[stock].avg_cost
price = context.portfolio.positions[stock].price
ret = price/cost-1
if ret <= -0.03:
log.info("止损卖出并计入日志")
order_target(stock, 0)
print "\n%s 触发止损ret" % ret