| | |
| | | return; |
| | | } |
| | | |
| | | checkProfitAndReset(); |
| | | // 异步检查盈亏,避免 REST 调用阻塞 WS 心跳导致 Socket closed |
| | | executor.submitTask(this::checkProfitAndReset); |
| | | |
| | | if (state == StrategyState.ACTIVE && |
| | | longActive == false && |
| | |
| | | for (int i = 0; i < shortTpCount; i++) { |
| | | int tpGridId = shortGridElement.getId() - 2 * (i + 1); |
| | | GridElement tpElem = GridElement.findById(tpGridId); |
| | | if (tpElem == null || tpElem.getShortTakeProfitOrderId() != null) { |
| | | // 用 takeProfitPlaced 做同步标记,避免异步回调未执行时重复挂单 |
| | | if (tpElem == null || tpElem.getShortTraderParam().isTakeProfitPlaced()) { |
| | | continue; |
| | | } |
| | | tpElem.getShortTraderParam().setTakeProfitPlaced(true); |
| | | BigDecimal tpPrice = tpElem.getGridPrice(); |
| | | int finalTpGridId = tpGridId; |
| | | executor.placeTakeProfit( |
| | |
| | | for (int i = 0; i < longTpCount; i++) { |
| | | int tpGridId = longGridElement.getId() + 2 * (i + 1); |
| | | GridElement tpElem = GridElement.findById(tpGridId); |
| | | if (tpElem == null || tpElem.getLongTakeProfitOrderId() != null) { |
| | | // 用 takeProfitPlaced 做同步标记,避免异步回调未执行时重复挂单 |
| | | if (tpElem == null || tpElem.getLongTraderParam().isTakeProfitPlaced()) { |
| | | continue; |
| | | } |
| | | tpElem.getLongTraderParam().setTakeProfitPlaced(true); |
| | | BigDecimal tpPrice = tpElem.getGridPrice(); |
| | | int finalTpGridId = tpGridId; |
| | | executor.placeTakeProfit( |
| | |
| | | }); |
| | | } |
| | | } |
| | | cancelCursor = GridElement.findById(cancelCursor.getUpId()); |
| | | Integer nextUpId = cancelCursor.getUpId(); |
| | | cancelCursor = nextUpId != null ? GridElement.findById(nextUpId) : null; |
| | | } |
| | | // log.info("[Gate-2] 多仓仓位归零 空仓队列触发, 匹配:{},当前价:{}", matched, currentPrice); |
| | | if (!newEntryGrid.isHasLongOrder()) { |
| | |
| | | }); |
| | | } |
| | | } |
| | | cancelCursor = GridElement.findById(cancelCursor.getDownId()); |
| | | Integer nextDownId = cancelCursor.getDownId(); |
| | | cancelCursor = nextDownId != null ? GridElement.findById(nextDownId) : null; |
| | | } |
| | | // log.info("[Gate-4] 空仓仓位归零 多仓队列触发, 匹配:{},当前价:{}", matched, currentPrice); |
| | | if (!newEntryGrid.isHasShortOrder()){ |
| | |
| | | for (GridElement e : config.getGridElements()) { |
| | | String tpId = e.getLongTakeProfitOrderId(); |
| | | if (tpId != null) { |
| | | e.getLongTraderParam().setTakeProfitPlaced(false); |
| | | e.setLongTakeProfitOrderId(null); |
| | | executor.cancelConditionalOrder(tpId, oid -> {}); |
| | | } |
| | |
| | | for (GridElement e : config.getGridElements()) { |
| | | String tpId = e.getShortTakeProfitOrderId(); |
| | | if (tpId != null) { |
| | | e.getShortTraderParam().setTakeProfitPlaced(false); |
| | | e.setShortTakeProfitOrderId(null); |
| | | executor.cancelConditionalOrder(tpId, oid -> {}); |
| | | } |