| | |
| | | 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; |
| | | } |
| | | GridElement tpElem = GridElement.findById(tpGridId); |
| | | if (tpElem == null || tpElem.getShortTakeProfitOrderId() != null) { |
| | | continue; |
| | |
| | | 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; |
| | | } |
| | | |
| | | GridElement tpElem = GridElement.findById(tpGridId); |
| | | if (tpElem == null || tpElem.getLongTakeProfitOrderId() != null) { |
| | | continue; |
| | |
| | | String reason = ""; |
| | | |
| | | if (hasLong && hasShort) { |
| | | // 多空双边持仓:多均价 − 空均价 > span × step |
| | | BigDecimal gap = longAvgPrice.subtract(shortAvgPrice); |
| | | // 多空双边持仓:|多均价 − 空均价| > span × step |
| | | BigDecimal gap = shortAvgPrice.subtract(longAvgPrice); |
| | | if (gap.compareTo(threshold) >= 0) { |
| | | shouldRestart = true; |
| | | reason = StrUtil.format("双边跨度 多均价:{} − 空均价:{} = {} > {} (span:{}×step:{})", |
| | | reason = StrUtil.format("双边跨度 |多均价:{} − 空均价:{}| = {} >= {} (span:{}×step:{})", |
| | | longAvgPrice, shortAvgPrice, gap, threshold, span, step); |
| | | } |
| | | } else if (hasLong) { |