| | |
| | | state = StrategyState.OPENING; |
| | | log.info("[Gate] 首根K线到达,开基底仓位..."); |
| | | executor.openLong(config.getQuantity(), () -> { |
| | | baseLongOpened = true; |
| | | longActive = true; |
| | | log.info("[Gate] 基底多已开"); |
| | | log.info("[Gate] 基底多单已提交"); |
| | | }, null); |
| | | executor.openShort(negate(config.getQuantity()), () -> { |
| | | baseShortOpened = true; |
| | | shortActive = true; |
| | | log.info("[Gate] 基底空已开"); |
| | | log.info("[Gate] 基底空单已提交"); |
| | | }, null); |
| | | return; |
| | | } |
| | |
| | | log.info("[Gate] 基底多成交价: {}", longBaseEntryPrice); |
| | | tryGenerateQueues(); |
| | | } else { |
| | | executor.placeTakeProfit(entryPrice.add(config.getGridRate()).setScale(1, RoundingMode.HALF_UP), |
| | | BigDecimal tpPrice = entryPrice.multiply(BigDecimal.ONE.add(config.getGridRate())).setScale(1, RoundingMode.HALF_UP); |
| | | executor.placeTakeProfit(tpPrice, |
| | | FuturesPriceTrigger.RuleEnum.NUMBER_1, ORDER_TYPE_CLOSE_LONG, AUTO_SIZE_LONG); |
| | | log.info("[Gate] 多单止盈已设, entry:{}, tp:{}", entryPrice, |
| | | entryPrice.add(config.getGridRate()).setScale(1, RoundingMode.HALF_UP)); |
| | | log.info("[Gate] 多单止盈已设, entry:{}, tp:{}", entryPrice, tpPrice); |
| | | } |
| | | } else { |
| | | longActive = false; |
| | |
| | | log.info("[Gate] 基底空成交价: {}", shortBaseEntryPrice); |
| | | tryGenerateQueues(); |
| | | } else { |
| | | executor.placeTakeProfit(entryPrice.subtract(config.getGridRate()).setScale(1, RoundingMode.HALF_UP), |
| | | BigDecimal tpPrice = entryPrice.multiply(BigDecimal.ONE.subtract(config.getGridRate())).setScale(1, RoundingMode.HALF_UP); |
| | | executor.placeTakeProfit(tpPrice, |
| | | FuturesPriceTrigger.RuleEnum.NUMBER_2, ORDER_TYPE_CLOSE_SHORT, AUTO_SIZE_SHORT); |
| | | log.info("[Gate] 空单止盈已设, entry:{}, tp:{}", entryPrice, |
| | | entryPrice.subtract(config.getGridRate()).setScale(1, RoundingMode.HALF_UP)); |
| | | log.info("[Gate] 空单止盈已设, entry:{}, tp:{}", entryPrice, tpPrice); |
| | | } |
| | | } else { |
| | | shortActive = false; |
| | |
| | | shortPriceQueue.clear(); |
| | | BigDecimal step = config.getGridRate(); |
| | | for (int i = 1; i <= config.getGridQueueSize(); i++) { |
| | | shortPriceQueue.add(shortBaseEntryPrice.subtract(step.multiply(BigDecimal.valueOf(i))).setScale(1, RoundingMode.HALF_UP)); |
| | | shortPriceQueue.add(shortBaseEntryPrice.multiply(BigDecimal.ONE.subtract(step.multiply(BigDecimal.valueOf(i)))).setScale(1, RoundingMode.HALF_UP)); |
| | | } |
| | | shortPriceQueue.sort((a, b) -> b.compareTo(a)); |
| | | //输出队列:shortPriceQueue; |
| | |
| | | longPriceQueue.clear(); |
| | | BigDecimal step = config.getGridRate(); |
| | | for (int i = 1; i <= config.getGridQueueSize(); i++) { |
| | | longPriceQueue.add(longBaseEntryPrice.add(step.multiply(BigDecimal.valueOf(i))).setScale(1, RoundingMode.HALF_UP)); |
| | | longPriceQueue.add(longBaseEntryPrice.multiply(BigDecimal.ONE.add(step.multiply(BigDecimal.valueOf(i)))).setScale(1, RoundingMode.HALF_UP)); |
| | | } |
| | | longPriceQueue.sort(BigDecimal::compareTo); |
| | | log.info("[Gate] 多队列:{}", longPriceQueue); |
| | |
| | | BigDecimal min = shortPriceQueue.isEmpty() ? matched.get(matched.size() - 1) : shortPriceQueue.get(shortPriceQueue.size() - 1); |
| | | BigDecimal step = config.getGridRate(); |
| | | for (int i = 0; i < matched.size(); i++) { |
| | | min = min.subtract(step).setScale(1, RoundingMode.HALF_UP); |
| | | min = min.multiply(BigDecimal.ONE.subtract(step)).setScale(1, RoundingMode.HALF_UP); |
| | | shortPriceQueue.add(min); |
| | | } |
| | | shortPriceQueue.sort((a, b) -> b.compareTo(a)); |
| | |
| | | BigDecimal max = longPriceQueue.isEmpty() ? matched.get(matched.size() - 1) : longPriceQueue.get(longPriceQueue.size() - 1); |
| | | BigDecimal step = config.getGridRate(); |
| | | for (int i = 0; i < matched.size(); i++) { |
| | | max = max.add(step).setScale(1, RoundingMode.HALF_UP); |
| | | max = max.multiply(BigDecimal.ONE.add(step)).setScale(1, RoundingMode.HALF_UP); |
| | | longPriceQueue.add(max); |
| | | } |
| | | longPriceQueue.sort(BigDecimal::compareTo); |
| | |
| | | shortPnl = shortPositionSize.multiply(multiplier).multiply(shortEntryPrice.subtract(price)); |
| | | } |
| | | unrealizedPnl = longPnl.add(shortPnl); |
| | | |
| | | log.info("[Gate] 未实现盈亏: {}", unrealizedPnl); |
| | | } |
| | | |
| | | /** |