# 本Python代码主要用于策略交易
# 可以自己import我们平台支持的第三方python模块,比如pandas、numpy等。
from PythonApi import *
from datetime import datetime
def init(context):
context.hh = 0
# 你选择的品种的数据更新将会触发此段逻辑,例如日或分钟历史数据切片或者是实时数据切片更新。--(必须实现)
def handle_bar(context):
year = context.now.year
month = context.now.month
day = context.now.day
#print((year,month,day))
if year==2018 and month==12 and day==3:
buy_open("SQRB00", "Market",0 ,1)
portfolio = get_portfolio ("RB00", 2)
bar_close = history_bars('SQRB00',1,'1d','CLOSE')
if portfolio.buy_quantity>0 and bar_close>context.hh:
context.hh = bar_close
#print((context.hh,bar_close))
if portfolio.buy_quantity>0 and (context.hh - bar_close)/context.hh >0.1:
sell_close("SQRB00", "Market",0 ,1)
context.hh = 0