feat(gateApi): 添加交易ID参数支持自动订单处理
- 在AutoOrdersChannelHandler中添加trade_id字段解析和传递
- 更新GateGridTradeService中的onAutoOrder方法签名以接收tradeId参数
- 添加对做空止盈订单的取消逻辑处理
- 添加对做多止盈订单的取消逻辑处理
- 在订单状态更新时验证tradeId不为"0"才执行止盈订单创建
- 修复长订单和短订单的止盈参数设置方法调用错误
| | |
| | | ); |
| | | } |
| | | ); |
| | | |
| | | if (e.getShortTakeProfitOrderId() != null){ |
| | | executor.cancelConditionalOrder( |
| | | e.getShortTakeProfitOrderId(), |
| | | orderId -> { |
| | | shortTakeProfitTraderIdParam( |
| | | e, |
| | | null, |
| | | false |
| | | ); |
| | | } |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | executor.cancelConditionalOrder( |
| | | e.getLongOrderId(), |
| | | orderId -> { |
| | | shortEntryTraderIdParam( |
| | | longEntryTraderIdParam( |
| | | e, |
| | | null, |
| | | false |
| | | ); |
| | | } |
| | | ); |
| | | if (e.getLongTakeProfitOrderId() != null){ |
| | | executor.cancelConditionalOrder( |
| | | e.getLongTakeProfitOrderId(), |
| | | orderId -> { |
| | | longTakeProfitTraderIdParam( |
| | | e, |
| | | null, |
| | | false |
| | | ); |
| | | } |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | * @param reason 变更原因 |
| | | * @param orderType 订单类型(plan-close-long-position 等) |
| | | */ |
| | | public void onAutoOrder(String orderId, String status, String reason, String orderType) { |
| | | public void onAutoOrder(String orderId, String status, String reason, String orderType, String tradeId) { |
| | | if (state == StrategyState.STOPPED) { |
| | | return; |
| | | } |
| | |
| | | */ |
| | | GridElement longGridElement = GridElement.findByLongOrderId(orderId); |
| | | if (longGridElement != null) { |
| | | if (longGridElement.isHasLongOrder()){ |
| | | if (longGridElement.isHasLongOrder() && !tradeId.equals("0")){ |
| | | if (longGridElement.getLongTakeProfitOrderId() == null){ |
| | | BigDecimal longTp = longGridElement.getLongTraderParam().getTakeProfitPrice(); |
| | | if (longTp != null) { |
| | |
| | | } |
| | | GridElement shortGridElement = GridElement.findByShortOrderId(orderId); |
| | | if (shortGridElement != null) { |
| | | if (shortGridElement.isHasShortOrder()){ |
| | | if (shortGridElement.isHasShortOrder() && !tradeId.equals("0")){ |
| | | if (shortGridElement.getShortTakeProfitOrderId() == null){ |
| | | BigDecimal shortTp = shortGridElement.getShortTraderParam().getTakeProfitPrice(); |
| | | if (shortTp != null) { |
| | |
| | | String status = autoOrder.getString("status"); |
| | | String reason = autoOrder.getString("reason"); |
| | | String orderType = autoOrder.getString("order_type"); |
| | | String tradeId = autoOrder.getString("trade_id"); |
| | | JSONObject trigger = autoOrder.getJSONObject("trigger"); |
| | | String triggerPrice = trigger != null ? trigger.getString("price") : null; |
| | | log.info("[{}] 自动订单更新, id:{}, status:{}, reason:{}, order_type:{}, trigger_price:{}, trade_id:{}", |
| | | CHANNEL_NAME, orderId, status, reason, orderType, triggerPrice, |
| | | autoOrder.get("trade_id")); |
| | | tradeId); |
| | | if (getGridTradeService() != null) { |
| | | getGridTradeService().onAutoOrder(orderId, status, reason, orderType); |
| | | getGridTradeService().onAutoOrder(orderId, status, reason, orderType, tradeId); |
| | | } |
| | | } |
| | | } catch (Exception e) { |