VeighNa量化社区
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 42
声望: 0

在收到on_order回调的时候,根据order: OrderData读取到订单已经成交,记录入下:

20230417_09:49:28.957018:('order触发,trading值:', True)
20230417_09:49:28.957018:(OrderData(gateway_name='ROHON', extra=None, symbol='SPD CF307&CF309', exchange=<Exchange.CZCE: 'CZCE'>, orderid='1681689782_151_4', type=<OrderType.LIMIT: '限价'>, direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=-130.0, volume=2, traded=2, status=<Status.ALLTRADED: '全部成交'>, datetime=datetime.datetime(2023, 4, 17, 9, 3, tzinfo=zoneinfo.ZoneInfo(key='Asia/Shanghai')), reference=''),)

然后我根据全部成交状态,发出一个平多订单:

20230417_09:49:28.957018:('order触发,trading值:', True)
20230417_09:49:28.957018:(OrderData(gateway_name='ROHON', extra=None, symbol='SPD CF307&CF309', exchange=<Exchange.CZCE: 'CZCE'>, orderid='1681689782_151_49', type=<OrderType.LIMIT: '限价'>, direction=<Direction.SHORT: '空'>, offset=<Offset.CLOSE: '平'>, price=-120.0, volume=2.0, traded=0, status=<Status.SUBMITTING: '提交中'>, datetime=None, reference='CtaStrategy_CF307309_ren_02'),)
20230417_09:49:28.957018:('trade触发,trading值:', True)
20230417_09:49:28.957018:(TradeData(gateway_name='ROHON', extra=None, symbol='CF309', exchange=<Exchange.CZCE: 'CZCE'>, orderid='1681689782_151_4', tradeid=' 3182', direction=<Direction.SHORT: '空'>, offset=<Offset.OPEN: '开'>, price=15080.0, volume=2, datetime=datetime.datetime(2023, 4, 17, 9, 49, 29, tzinfo=zoneinfo.ZoneInfo(key='Asia/Shanghai'))),)
20230417_09:49:28.957018:('trade触发,trading值:', True)
20230417_09:49:28.957018:(TradeData(gateway_name='ROHON', extra=None, symbol='CF307', exchange=<Exchange.CZCE: 'CZCE'>, orderid='1681689782_151_4', tradeid=' 3183', direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=14950.0, volume=1, datetime=datetime.datetime(2023, 4, 17, 9, 49, 29, tzinfo=zoneinfo.ZoneInfo(key='Asia/Shanghai'))),)

然后这个订单被拒了:
20230417_09:49:28.988440:('order触发,trading值:', True)
20230417_09:49:28.988440:(OrderData(gateway_name='ROHON', extra=None, symbol='SPD CF307&CF309', exchange=<Exchange.CZCE: 'CZCE'>, orderid='1681689782_151_49', type=<OrderType.LIMIT: '限价'>, direction=<Direction.SHORT: '空'>, offset=<Offset.CLOSE: '平'>, price=-120.0, volume=2, traded=0, status=<Status.REJECTED: '拒单'>, datetime=None, reference=''),)
20230417_09:49:28.988440:('平多委托失败,订单号:', '1681689782_151_49', ',数量:', 2, ',价格:', -120.0)

在错误信息那边提示:交易委托失败,代码:30,信息:多仓不足,无法平仓[投机][卖][平仓][SPD CF307&CF309][2][-120.000][1 < 2]

请问这是咋回事?根据最后的错误信息[1 < 2],也就是仓位只有1,不足2,所以下单失败.

可是on_order过来的数据是显示已全部成交了呀?

Member
avatar
加入于:
帖子: 42
声望: 0

在收到on_order回调的时候,根据order: OrderData读取到订单已经成交(判断依据:volume=2, traded=2, status=<Status.ALLTRADED: '全部成交'>)
我根据成交状态,发出一个平多订单,然后这个订单被拒了,
在错误信息那边提示:交易委托失败,代码:30,信息:多仓不足,无法平仓[投机][卖][平仓][SPD CF307&CF309][2][-120.000][1 < 2]
根据最后的错误信息[1 < 2],好像是说仓位只有1,不足2,所以下单失败.
请问我这个下单流程错了吗?

这种错误也不是每次都发生,有的也能成功.

Member
avatar
加入于:
帖子: 42
声望: 0

是不是底层那边,需要等待trade数据,更新仓位才行?

order数据显示 已全部成交还不够?

Member
avatar
加入于:
帖子: 42
声望: 0

下面是完整的LOG记录:
我下的是套利单,先收到ORDER回调,显示已完全成交,然后我发单,发单的时候,收到TRADE回调,TRADE信息显示品种1成交了2手,品种2成交了1手,然后被拒单,拒单完后,才收到品种2成交第2手的信息

完全成交的ORDER信息,是柜台那边推送过来的,还是VNPY后台根据TRADE信息推算出来的?如果是VNPY来推算的,是不是只根据品种1的成交就推算全部成交了?

20230417_09:03:00.843838:('order触发,trading值:', True)
20230417_09:03:00.843838:(OrderData(gateway_name='ROHON', extra=None, symbol='SPD CF307&CF309', exchange=<Exchange.CZCE: 'CZCE'>, orderid='1681689782_151_4', type=<OrderType.LIMIT: '限价'>, direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=-130.0, volume=2.0, traded=0, status=<Status.SUBMITTING: '提交中'>, datetime=None, reference='CtaStrategy_CF307309_ren_02'),)

20230417_09:03:05.437649:('order触发,trading值:', True)
20230417_09:03:05.437649:(OrderData(gateway_name='ROHON', extra=None, symbol='SPD CF307&CF309', exchange=<Exchange.CZCE: 'CZCE'>, orderid='1681689782_151_4', type=<OrderType.LIMIT: '限价'>, direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=-130.0, volume=2, traded=0, status=<Status.NOTTRADED: '未成交'>, datetime=datetime.datetime(2023, 4, 17, 9, 3, tzinfo=zoneinfo.ZoneInfo(key='Asia/Shanghai')), reference=''),)

20230417_09:49:28.957018:('order触发,trading值:', True)
20230417_09:49:28.957018:(OrderData(gateway_name='ROHON', extra=None, symbol='SPD CF307&CF309', exchange=<Exchange.CZCE: 'CZCE'>, orderid='1681689782_151_4', type=<OrderType.LIMIT: '限价'>, direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=-130.0, volume=2, traded=2, status=<Status.ALLTRADED: '全部成交'>, datetime=datetime.datetime(2023, 4, 17, 9, 3, tzinfo=zoneinfo.ZoneInfo(key='Asia/Shanghai')), reference=''),)

20230417_09:49:28.957018:('开多全部成交,订单号:', '1681689782_151_4', ',数量:', 2, ',价格:', -130.0)
20230417_09:49:28.957018:('定单号:ROHON.1681689782_151_49,合约:SPD CF307&CF309,卖出平仓数量:2,价格:-120.000000\n',)

20230417_09:49:28.957018:('order触发,trading值:', True)
20230417_09:49:28.957018:(OrderData(gateway_name='ROHON', extra=None, symbol='SPD CF307&CF309', exchange=<Exchange.CZCE: 'CZCE'>, orderid='1681689782_151_49', type=<OrderType.LIMIT: '限价'>, direction=<Direction.SHORT: '空'>, offset=<Offset.CLOSE: '平'>, price=-120.0, volume=2.0, traded=0, status=<Status.SUBMITTING: '提交中'>, datetime=None, reference='CtaStrategy_CF307309_ren_02'),)

20230417_09:49:28.957018:('trade触发,trading值:', True)
20230417_09:49:28.957018:(TradeData(gateway_name='ROHON', extra=None, symbol='CF309', exchange=<Exchange.CZCE: 'CZCE'>, orderid='1681689782_151_4', tradeid=' 3182', direction=<Direction.SHORT: '空'>, offset=<Offset.OPEN: '开'>, price=15080.0, volume=2, datetime=datetime.datetime(2023, 4, 17, 9, 49, 29, tzinfo=zoneinfo.ZoneInfo(key='Asia/Shanghai'))),)
20230417_09:49:28.957018:('trade触发,trading值:', True)
20230417_09:49:28.957018:(TradeData(gateway_name='ROHON', extra=None, symbol='CF307', exchange=<Exchange.CZCE: 'CZCE'>, orderid='1681689782_151_4', tradeid=' 3183', direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=14950.0, volume=1, datetime=datetime.datetime(2023, 4, 17, 9, 49, 29, tzinfo=zoneinfo.ZoneInfo(key='Asia/Shanghai'))),)

20230417_09:49:28.988440:('order触发,trading值:', True)
20230417_09:49:28.988440:(OrderData(gateway_name='ROHON', extra=None, symbol='SPD CF307&CF309', exchange=<Exchange.CZCE: 'CZCE'>, orderid='1681689782_151_49', type=<OrderType.LIMIT: '限价'>, direction=<Direction.SHORT: '空'>, offset=<Offset.CLOSE: '平'>, price=-120.0, volume=2, traded=0, status=<Status.REJECTED: '拒单'>, datetime=None, reference=''),)

20230417_09:49:28.988440:('平多委托失败,订单号:', '1681689782_151_49', ',数量:', 2, ',价格:', -120.0)

20230417_09:49:28.988440:('trade触发,trading值:', True)
20230417_09:49:28.988440:(TradeData(gateway_name='ROHON', extra=None, symbol='CF307', exchange=<Exchange.CZCE: 'CZCE'>, orderid='1681689782_151_4', tradeid=' 3184', direction=<Direction.LONG: '多'>, offset=<Offset.OPEN: '开'>, price=14950.0, volume=1, datetime=datetime.datetime(2023, 4, 17, 9, 49, 29, tzinfo=zoneinfo.ZoneInfo(key='Asia/Shanghai'))),)

LLM学员
avatar
加入于:
帖子: 1546
声望: 112

18650802653 wrote:

是不是底层那边,需要等待trade数据,更新仓位才行?

order数据显示 已全部成交还不够?

对的,这里涉及到融航内部的仓位维护逻辑,根据你这里反馈猜测也是基于on_trade来计算,所以你在收到on_trade之前(一般延时很低很低,但也不排除特殊情况慢个百毫秒到几秒)就去下平仓委托,自然可能出现仓位不足了。

Member
avatar
加入于:
帖子: 42
声望: 0

MTF wrote:

18650802653 wrote:

是不是底层那边,需要等待trade数据,更新仓位才行?

order数据显示 已全部成交还不够?

对的,这里涉及到融航内部的仓位维护逻辑,根据你这里反馈猜测也是基于on_trade来计算,所以你在收到on_trade之前(一般延时很低很低,但也不排除特殊情况慢个百毫秒到几秒)就去下平仓委托,自然可能出现仓位不足了。

意思是说,这个仓位不足的拒单,是融航那边拒绝的.而不是VNPY这边本地拒绝的,是吧?

VNPY这边发单,有进行仓位判断吗?还是直接就发出去?

Member
avatar
加入于:
帖子: 4883
声望: 293

单纯发单没有进行判断的

© 2015-2022 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】