ricequant / rqalpha-mod-vnpy

RQAlpha 对接 vnpy 的扩展 Mod。通过启用该 Mod 来实现期货策略的实盘交易
Apache License 2.0
298 stars 59 forks source link

测试发单时候系统报错退出 #21

Closed handsomu closed 7 years ago

handsomu commented 7 years ago

image

RQA设置的LimitOrder在发出时实际变成了MarketOrder,并且一发单就自动撤单了。

合约 测试代码如下:

`def init(context): context.s1 = "IF1705"

subscribe(context.s1)

subscribe(context.s1)
logger.info("Interested in: " + str(context.s1))
context.counter = 0
context.order = None
context.vwap = 0
context.multiplier = instruments(context.s1).contract_multiplier

def before_trading(context): print('** BEFORE TRADING') print('GET OPEN ORDERS {}'.format(get_open_orders())) p_print(context)

def p_print(context): print('PORTFOLIO TOTAL VALUE{}, UAV {}, CASH{}, COST{}'.format(context.portfolio.total_value, context.portfolio.unit_net_value, context.portfolio.cash, context.portfolio.transaction_cost)) print('ACCOUNT CASH{}, HOLDING PNL{}, REALIZED PNL{}, BUY MARGIN{}, ' 'SELL MARGIN{}, MARGIN{}, FROZEN_CASH{}, TOTAL_VALUE {}'.format(context.portfolio.future_account.cash, context.portfolio.future_account.holding_pnl, context.portfolio.future_account.realized_pnl, context.portfolio.future_account.buy_margin, context.portfolio.future_account.sell_margin, context.portfolio.future_account.margin, context.portfolio.future_account.frozen_cash, context.portfolio.future_account.total_value))

def handle_tick(context, tick): context.counter += 1 if tick.volume != 0: context.vwap = tick.total_turnover / (tick.volume * context.multiplier) else: context.vwap = tick.last

if context.counter % 100 == 0:

    print('COUNTER {},  VWAP {}, LAST {}, VOLUME {}, TURNOVER {}'.format(
          context.counter,  context.vwap, tick.last, tick.volume, tick.total_turnover))
    print('*******************BUY OPEN NOW****************')

    p_print(context)
    context.order = buy_open(context.s1, 1, LimitOrder(3500))

if context.counter % 150 == 0:

    print('COUNTER {},  VWAP {}, LAST {}, VOLUME {}, TURNOVER {}'.format(
          context.counter,  context.vwap, tick.last, tick.volume, tick.total_turnover))
    print('SELL CLOSE NOW *****************')
    sell_close(context.s1, 1, LimitOrder(3300))
    p_print(context)

`

Cuizi7 commented 7 years ago

发单类型错误和报错的问题已在 feature/abandon-vnpy-gateway 分支修复。 另外使用 CTP 发市价单始终会被撤,不知道是不是 CTP 对市价单有限制。

Cuizi7 commented 7 years ago

master 分支已修复。