| | |
| | | .entryOrderId(orderId) |
| | | .build(); |
| | | config.setBaseLongTraderParam(baseLongTp); |
| | | baseLongOpened = true; |
| | | }, null); |
| | | executor.openShort(size, (orderId) -> { |
| | | TraderParam baseShortTp = TraderParam.builder() |
| | | .entryOrderId(orderId) |
| | | .build(); |
| | | config.setBaseShortTraderParam(baseShortTp); |
| | | baseShortOpened = true; |
| | | }, null); |
| | | return; |
| | | } |
| | |
| | | boolean isLong = (direction == TraderParam.Direction.LONG); |
| | | |
| | | if (state == StrategyState.OPENING) { |
| | | if (isLong && hasPosition && !baseLongOpened) { |
| | | // 基底成交通知仅记录价格/数量,flag 在 REST 回调中设置 |
| | | if (isLong && hasPosition) { |
| | | longActive = true; |
| | | longPositionSize = size; |
| | | longEntryPrice = entryPrice; |
| | | longBaseEntryPrice = entryPrice; |
| | | baseLongOpened = true; |
| | | log.info("[OKX] 基底多成交价: {}", longBaseEntryPrice); |
| | | tryGenerateQueues(); |
| | | } else if (!isLong && hasPosition && !baseShortOpened) { |
| | | } else if (!isLong && hasPosition) { |
| | | shortActive = true; |
| | | shortPositionSize = size.abs(); |
| | | shortEntryPrice = entryPrice; |
| | | shortBaseEntryPrice = entryPrice; |
| | | baseShortOpened = true; |
| | | log.info("[OKX] 基底空成交价: {}", shortBaseEntryPrice); |
| | | tryGenerateQueues(); |
| | | } |
| | |
| | | // ---- 自动订单(条件单)状态变更回调 ---- |
| | | |
| | | /** |
| | | * 自动订单状态变更回调。由 OrderAlgoOkxChannelHandler 调用。 |
| | | * 自动订单状态变更回调。由 OrdersOkxChannelHandler 调用。 |
| | | */ |
| | | public void onAutoOrder(String orderId, String status, String reason, String orderType, String tradeId) { |
| | | if (state == StrategyState.STOPPED) { |
| | |
| | | int posSize = queryPositionSize(OkxPosMode.SHORT); |
| | | extendShortStopLoss(posSize, shortGridElement.getId()); |
| | | accumulatedShortLossCount = 0; |
| | | log.info("[OKX] 空单成交 gridId:{}, 当前持仓:{}张", filledQty, posSize); |
| | | log.info("[OKX] 空单成交 gridId:{}, 成交{}张, 当前持仓:{}张", |
| | | shortGridElement.getId(), filledQty, posSize); |
| | | |
| | | BigDecimal shortBaseQty = new BigDecimal(config.getBaseQuantity()); |
| | | BigDecimal shortGridQty = new BigDecimal(config.getQuantity()); |
| | |
| | | int posSize = queryPositionSize(OkxPosMode.LONG); |
| | | extendLongStopLoss(posSize, longGridElement.getId()); |
| | | accumulatedLongLossCount = 0; |
| | | log.info("[OKX] 多单成交 gridId:{}, 当前持仓:{}张", filledQty, posSize); |
| | | log.info("[OKX] 多单成交 gridId:{}, 成交{}张, 当前持仓:{}张", |
| | | longGridElement.getId(), filledQty, posSize); |
| | | |
| | | BigDecimal longBaseQty = new BigDecimal(config.getBaseQuantity()); |
| | | BigDecimal longGridQty = new BigDecimal(config.getQuantity()); |