等级: 免费版
- 注册:
- 2022-4-2
- 曾用名:
|
请问老师,我的报单代码如下;为什么一直出现这个提示
#有未成交单时,判断是否需要撤单
if orderlist!=None: #如果有挂单,这里增加撤单重开代码
#撤单代码
cancelorder(context,orderlist,strategy_hold,tbuyhold,tsellhold)
if portfolio_change>0: #如果仓差大于0执行后面的报单
#获取买1价和卖1价
lastprice=get_dynainf(code,7) #获取最新价
upperprice=get_dynainf(code,54) #获取涨停价
lowerprice=get_dynainf(code,55) #获取跌停价
nbuy1=get_dynainf(code,28) #获取buy1买1价
nsell1=get_dynainf(code,34) #获取sell1卖1价
mindiff=get_dynainf(code,208) #获取合约最小变动价
trading_day = get_dynainf(code,229) #获取合约日期
split_date = get_split(code,2)[-1].ex_dividend_date #获取合约换月日期
today_split = split_date.date == trading_day and strategy_hold==Y_strategy_hold #判断是否换月
#如果涨跌停或者换月时间不交易
if not(today_split):
#如果买一价卖一价差距过大,用中间价
if nsell1-nbuy1>mindiff:
n_mindiff=mindiff*round((nsell1-nbuy1)/mindiff/2)
nbuy1 = nbuy1+n_mindiff
nsell1 = nsell1-n_mindiff
canuse=get_account(19) #获取账户可用资金
codeinfo=get_instruments(code) #获取合约单位和保证金比例
#计算账户实际资金能开仓手数
canopen=canuse//(lastprice*codeinfo.multipliter*codeinfo.buy_margin_rate) # 可开仓手数
closelots = random.randint(1,max(portfolio_change,1)) #随机下单手数与可用取最小
openlots = min(canopen, closelots) #随机下单手数与可用取最小
#根据信号下单:
if strategy_hold>=0 and tsellhold>0:
buy_close(code, "Limit", price=nsell1,volume = closelots, account = accounts,serial_id = 1) # 用卖1价平空
elif strategy_hold<=0 and tbuyhold>0:
sell_close(code, "Limit", price=nbuy1,volume = closelots, account = accounts,serial_id = 2) # 用买1价平多
elif strategy_hold>0 and strategy_hold<tbuyhold :
sell_close(code, "Limit", price=nbuy1,volume = closelots,account = accounts,serial_id = 3) # 用卖1价减多
elif strategy_hold<0 and abs(strategy_hold)<abs(tsellhold):
buy_close(code, "Limit", price=nsell1,volume = closelots, account = accounts,serial_id = 4) # 用买1价减空
if not(lastprice>upperprice-5*mindiff or lastprice<lowerprice+5*mindiff or canuse<20000):
if strategy_hold>0 and tbuyhold==0 and canopen>0:
buy_open(code, "Limit", price=nsell1,volume = openlots,account = accounts,serial_id = 5) # 用卖1价开多
if strategy_hold<0 and tsellhold==0 and canopen>0:
sell_open(code, "Limit", price=nbuy1,volume = openlots,account = accounts,serial_id = 6) # 用买1价开空
if tbuyhold>0 and strategy_hold>tbuyhold and canopen>0:
buy_open(code, "Limit", price=nsell1,volume = openlots,account = accounts,serial_id = 7) # 用卖1价加多
if strategy_hold<0 and abs(strategy_hold)>tsellhold and canopen>0:
sell_open(code, "Limit", price=nbuy1,volume = openlots,account = accounts,serial_id = 8) # 用买1价加空
else:
return
|
|