Administrator
4 days ago 795ed86a6f3623f0a11e0e2f4edadc1b94008c4a
refactor(gateApi): 止盈都严格保持 2 个 grid 间距

- 简化了做空仓位止盈订单ID的计算公式,消除条件判断
- 简化了做多仓位止盈订单ID的计算公式,消除条件判断
- 提高了代码可读性和维护性
- 减少了循环中的条件分支判断
1 files modified
6 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/okxApi/OkxGridTradeService.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/okxApi/OkxGridTradeService.java
@@ -476,8 +476,7 @@
                    BigDecimal shortExcess = BigDecimal.valueOf(posSize).subtract(shortBaseQty);
                    int shortExcessCount = shortExcess.divide(shortGridQty, 0, RoundingMode.DOWN).intValue();
                    for (int i = 0; i < shortExcessCount; i++) {
                        int tpGridId = shortGridElement.getId() - 2 - i;
                        if (i > 0) { tpGridId = tpGridId - 1; }
                        int tpGridId = shortGridElement.getId() - 2 * (i + 1);
                        GridElement tpElem = GridElement.findById(tpGridId);
                        if (tpElem == null || tpElem.getShortTakeProfitOrderId() != null) {
                            continue;
@@ -517,8 +516,7 @@
                    BigDecimal longExcess = BigDecimal.valueOf(posSize).subtract(longBaseQty);
                    int longExcessCount = longExcess.divide(longGridQty, 0, RoundingMode.DOWN).intValue();
                    for (int i = 0; i < longExcessCount; i++) {
                        int tpGridId = longGridElement.getId() + 2 + i;
                        if (i > 0) { tpGridId = tpGridId + 1; }
                        int tpGridId = longGridElement.getId() + 2 * (i + 1);
                        GridElement tpElem = GridElement.findById(tpGridId);
                        if (tpElem == null || tpElem.getLongTakeProfitOrderId() != null) {
                            continue;