| | |
| | | private List<String> longTakeProfitOrderIds = new ArrayList<>(); |
| | | /** 空仓止盈订单 ID 列表(支持一网格多笔止盈单:基础止盈 + 超额止盈并行挂单) */ |
| | | private List<String> shortTakeProfitOrderIds = new ArrayList<>(); |
| | | /** 多仓止盈订单 ID → 张数(仓位止盈补仓时取本次止盈单张数) */ |
| | | private final Map<String, Integer> longTakeProfitOrderSizes = new ConcurrentHashMap<>(); |
| | | /** 空仓止盈订单 ID → 张数 */ |
| | | private final Map<String, Integer> shortTakeProfitOrderSizes = new ConcurrentHashMap<>(); |
| | | /** 多仓止损订单 ID 列表(支持一个网格多个止损单) */ |
| | | private List<String> longStopLossOrderIds = new ArrayList<>(); |
| | | /** 空仓止损订单 ID 列表(支持一个网格多个止损单) */ |
| | | private List<String> shortStopLossOrderIds = new ArrayList<>(); |
| | | /** 多仓止损订单 ID → 张数(止损触发时统计该网格全部止损覆盖张数,修正追单的 REST 持仓时序竞态) */ |
| | | private final Map<String, Integer> longStopLossOrderSizes = new ConcurrentHashMap<>(); |
| | | /** 空仓止损订单 ID → 张数 */ |
| | | private final Map<String, Integer> shortStopLossOrderSizes = new ConcurrentHashMap<>(); |
| | | |
| | | /** |
| | | * 止损追单是否正在进行中(防重入标记)。 |
| | |
| | | |
| | | /** @return 多仓止盈订单 ID 列表 */ |
| | | public List<String> getLongTakeProfitOrderIds() { return longTakeProfitOrderIds; } |
| | | /** 添加多仓止盈订单 ID */ |
| | | public void addLongTakeProfitOrderId(String orderId) { if (orderId != null) longTakeProfitOrderIds.add(orderId); } |
| | | /** 移除多仓止盈订单 ID */ |
| | | public boolean removeLongTakeProfitOrderId(String orderId) { return longTakeProfitOrderIds.remove(orderId); } |
| | | /** 清空多仓止盈订单 ID */ |
| | | public void clearLongTakeProfitOrderIds() { longTakeProfitOrderIds.clear(); } |
| | | /** 添加多仓止盈订单 ID(不记录张数,仅兼容旧调用方) */ |
| | | public void addLongTakeProfitOrderId(String orderId) { addLongTakeProfitOrderId(orderId, 0); } |
| | | /** 添加多仓止盈订单 ID 并记录该单张数 */ |
| | | public void addLongTakeProfitOrderId(String orderId, int size) { |
| | | if (orderId == null) { |
| | | return; |
| | | } |
| | | longTakeProfitOrderIds.add(orderId); |
| | | longTakeProfitOrderSizes.put(orderId, size); |
| | | } |
| | | /** 移除多仓止盈订单 ID(同步清理张数记录) */ |
| | | public boolean removeLongTakeProfitOrderId(String orderId) { |
| | | longTakeProfitOrderSizes.remove(orderId); |
| | | return longTakeProfitOrderIds.remove(orderId); |
| | | } |
| | | /** 清空多仓止盈订单 ID(同步清理张数记录) */ |
| | | public void clearLongTakeProfitOrderIds() { |
| | | longTakeProfitOrderIds.clear(); |
| | | longTakeProfitOrderSizes.clear(); |
| | | } |
| | | /** @return 是否有止盈单 */ |
| | | public boolean hasLongTakeProfitOrders() { return !longTakeProfitOrderIds.isEmpty(); } |
| | | /** @return 指定多仓止盈单的张数,未记录返回 null */ |
| | | public Integer getLongTakeProfitOrderSize(String orderId) { return longTakeProfitOrderSizes.get(orderId); } |
| | | /** @deprecated 返回最后一个止盈订单ID,用于单订单场景的兼容 */ |
| | | @Deprecated |
| | | public String getLongTakeProfitOrderId() { return longTakeProfitOrderIds.isEmpty() ? null : longTakeProfitOrderIds.get(longTakeProfitOrderIds.size() - 1); } |
| | |
| | | |
| | | /** @return 空仓止盈订单 ID 列表 */ |
| | | public List<String> getShortTakeProfitOrderIds() { return shortTakeProfitOrderIds; } |
| | | /** 添加空仓止盈订单 ID */ |
| | | public void addShortTakeProfitOrderId(String orderId) { if (orderId != null) shortTakeProfitOrderIds.add(orderId); } |
| | | /** 移除空仓止盈订单 ID */ |
| | | public boolean removeShortTakeProfitOrderId(String orderId) { return shortTakeProfitOrderIds.remove(orderId); } |
| | | /** 清空空仓止盈订单 ID */ |
| | | public void clearShortTakeProfitOrderIds() { shortTakeProfitOrderIds.clear(); } |
| | | /** 添加空仓止盈订单 ID(不记录张数,仅兼容旧调用方) */ |
| | | public void addShortTakeProfitOrderId(String orderId) { addShortTakeProfitOrderId(orderId, 0); } |
| | | /** 添加空仓止盈订单 ID 并记录该单张数 */ |
| | | public void addShortTakeProfitOrderId(String orderId, int size) { |
| | | if (orderId == null) { |
| | | return; |
| | | } |
| | | shortTakeProfitOrderIds.add(orderId); |
| | | shortTakeProfitOrderSizes.put(orderId, size); |
| | | } |
| | | /** 移除空仓止盈订单 ID(同步清理张数记录) */ |
| | | public boolean removeShortTakeProfitOrderId(String orderId) { |
| | | shortTakeProfitOrderSizes.remove(orderId); |
| | | return shortTakeProfitOrderIds.remove(orderId); |
| | | } |
| | | /** 清空空仓止盈订单 ID(同步清理张数记录) */ |
| | | public void clearShortTakeProfitOrderIds() { |
| | | shortTakeProfitOrderIds.clear(); |
| | | shortTakeProfitOrderSizes.clear(); |
| | | } |
| | | /** @return 是否有止盈单 */ |
| | | public boolean hasShortTakeProfitOrders() { return !shortTakeProfitOrderIds.isEmpty(); } |
| | | /** @return 指定空仓止盈单的张数,未记录返回 null */ |
| | | public Integer getShortTakeProfitOrderSize(String orderId) { return shortTakeProfitOrderSizes.get(orderId); } |
| | | /** @deprecated 返回最后一个止盈订单ID,用于单订单场景的兼容 */ |
| | | @Deprecated |
| | | public String getShortTakeProfitOrderId() { return shortTakeProfitOrderIds.isEmpty() ? null : shortTakeProfitOrderIds.get(shortTakeProfitOrderIds.size() - 1); } |
| | |
| | | |
| | | /** @return 多仓止损订单 ID 列表 */ |
| | | public List<String> getLongStopLossOrderIds() { return longStopLossOrderIds; } |
| | | /** 添加一个多仓止损订单 ID */ |
| | | public void addLongStopLossOrderId(String orderId) { longStopLossOrderIds.add(orderId); } |
| | | /** 移除一个多仓止损订单 ID */ |
| | | public boolean removeLongStopLossOrderId(String orderId) { return longStopLossOrderIds.remove(orderId); } |
| | | /** 清空所有多仓止损订单 ID */ |
| | | public void clearLongStopLossOrderIds() { longStopLossOrderIds.clear(); } |
| | | /** 添加一个多仓止损订单 ID(不记录张数,仅兼容旧调用方) */ |
| | | public void addLongStopLossOrderId(String orderId) { addLongStopLossOrderId(orderId, 0); } |
| | | /** 添加一个多仓止损订单 ID 并记录该单张数 */ |
| | | public void addLongStopLossOrderId(String orderId, int size) { |
| | | if (orderId == null) { |
| | | return; |
| | | } |
| | | longStopLossOrderIds.add(orderId); |
| | | longStopLossOrderSizes.put(orderId, size); |
| | | } |
| | | /** 移除一个多仓止损订单 ID(同步清理张数记录) */ |
| | | public boolean removeLongStopLossOrderId(String orderId) { |
| | | longStopLossOrderSizes.remove(orderId); |
| | | return longStopLossOrderIds.remove(orderId); |
| | | } |
| | | /** 清空所有多仓止损订单 ID(同步清理张数记录) */ |
| | | public void clearLongStopLossOrderIds() { |
| | | longStopLossOrderIds.clear(); |
| | | longStopLossOrderSizes.clear(); |
| | | } |
| | | /** @return 是否有止损单 */ |
| | | public boolean hasLongStopLossOrders() { return !longStopLossOrderIds.isEmpty(); } |
| | | /** @return 该网格全部多仓止损单覆盖张数之和(用于止损触发时的追单量修正) */ |
| | | public int getLongStopLossTotalSize() { |
| | | int total = 0; |
| | | for (Integer size : longStopLossOrderSizes.values()) { |
| | | total += size; |
| | | } |
| | | return total; |
| | | } |
| | | |
| | | // ==================== 空仓止损订单 ID 列表 ==================== |
| | | |
| | | /** @return 空仓止损订单 ID 列表 */ |
| | | public List<String> getShortStopLossOrderIds() { return shortStopLossOrderIds; } |
| | | /** 添加一个空仓止损订单 ID */ |
| | | public void addShortStopLossOrderId(String orderId) { shortStopLossOrderIds.add(orderId); } |
| | | /** 移除一个空仓止损订单 ID */ |
| | | public boolean removeShortStopLossOrderId(String orderId) { return shortStopLossOrderIds.remove(orderId); } |
| | | /** 清空所有空仓止损订单 ID */ |
| | | public void clearShortStopLossOrderIds() { shortStopLossOrderIds.clear(); } |
| | | /** 添加一个空仓止损订单 ID(不记录张数,仅兼容旧调用方) */ |
| | | public void addShortStopLossOrderId(String orderId) { addShortStopLossOrderId(orderId, 0); } |
| | | /** 添加一个空仓止损订单 ID 并记录该单张数 */ |
| | | public void addShortStopLossOrderId(String orderId, int size) { |
| | | if (orderId == null) { |
| | | return; |
| | | } |
| | | shortStopLossOrderIds.add(orderId); |
| | | shortStopLossOrderSizes.put(orderId, size); |
| | | } |
| | | /** 移除一个空仓止损订单 ID(同步清理张数记录) */ |
| | | public boolean removeShortStopLossOrderId(String orderId) { |
| | | shortStopLossOrderSizes.remove(orderId); |
| | | return shortStopLossOrderIds.remove(orderId); |
| | | } |
| | | /** 清空所有空仓止损订单 ID(同步清理张数记录) */ |
| | | public void clearShortStopLossOrderIds() { |
| | | shortStopLossOrderIds.clear(); |
| | | shortStopLossOrderSizes.clear(); |
| | | } |
| | | /** @return 是否有止损单 */ |
| | | public boolean hasShortStopLossOrders() { return !shortStopLossOrderIds.isEmpty(); } |
| | | /** @return 该网格全部空仓止损单覆盖张数之和(用于止损触发时的追单量修正) */ |
| | | public int getShortStopLossTotalSize() { |
| | | int total = 0; |
| | | for (Integer size : shortStopLossOrderSizes.values()) { |
| | | total += size; |
| | | } |
| | | return total; |
| | | } |
| | | |
| | | // ==================== 止损追单防重入标记 ==================== |
| | | |