| | |
| | | WAITING_KLINE, OPENING, ACTIVE, STOPPED |
| | | } |
| | | |
| | | private static final String ORDER_TYPE_CLOSE_LONG = "close-long-position"; |
| | | private static final String ORDER_TYPE_CLOSE_SHORT = "close-short-position"; |
| | | private static final String ORDER_TYPE_CLOSE_LONG = "plan-close-long-position"; |
| | | private static final String ORDER_TYPE_CLOSE_SHORT = "plan-close-short-position"; |
| | | |
| | | private final GateConfig config; |
| | | private final GateTradeExecutor executor; |
| | |
| | | } |
| | | } |
| | | } |
| | | log.info("[Gate] 空队列:{}", shortPriceQueue); |
| | | log.info("[Gate] 原空队列:{}", shortPriceQueue); |
| | | if (matched.isEmpty()) { |
| | | log.info("[Gate] 空仓队列未触发, 当前价:{}", currentPrice); |
| | | return; |
| | |
| | | } |
| | | shortPriceQueue.sort(BigDecimal::compareTo); |
| | | |
| | | log.info("[Gate] 空队列:{}", shortPriceQueue); |
| | | log.info("[Gate] 现空队列:{}", shortPriceQueue); |
| | | } |
| | | |
| | | synchronized (longPriceQueue) { |
| | | longPriceQueue.addAll(matched); |
| | | BigDecimal first = longPriceQueue.isEmpty() ? matched.get(matched.size() - 1) : longPriceQueue.get(0); |
| | | BigDecimal step = config.getGridRate(); |
| | | int added = 0; |
| | | for (int i = 1; i <= matched.size(); i++) { |
| | | BigDecimal elem = first.multiply(BigDecimal.ONE.subtract(step.multiply(BigDecimal.valueOf(i)))).setScale(1, RoundingMode.HALF_UP); |
| | | if (longEntryPrice.compareTo(BigDecimal.ZERO) > 0 |
| | | && elem.subtract(longEntryPrice).abs().compareTo(longEntryPrice.multiply(step)) < 0) { |
| | | continue; |
| | | } |
| | | longPriceQueue.add(elem); |
| | | added++; |
| | | } |
| | | longPriceQueue.sort(BigDecimal::compareTo); |
| | | while (longPriceQueue.size() > config.getGridQueueSize()) { |
| | | longPriceQueue.remove(longPriceQueue.size() - 1); |
| | | } |
| | | |
| | | log.info("[Gate] 多队列:{}", shortPriceQueue); |
| | | log.info("[Gate] 现多队列:{}, 跳过{}个(贴近多仓均价)", longPriceQueue, matched.size() - added); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | } |
| | | log.info("[Gate] 多队列:{}", longPriceQueue); |
| | | log.info("[Gate] 原多队列:{}", longPriceQueue); |
| | | if (matched.isEmpty()) { |
| | | log.info("[Gate] 多仓队列未触发, 当前价:{}", currentPrice); |
| | | return; |
| | |
| | | } |
| | | longPriceQueue.sort(BigDecimal::compareTo); |
| | | |
| | | log.info("[Gate] 多队列:{}", longPriceQueue); |
| | | log.info("[Gate] 现多队列:{}", longPriceQueue); |
| | | } |
| | | |
| | | synchronized (shortPriceQueue) { |
| | | shortPriceQueue.addAll(matched); |
| | | BigDecimal first = shortPriceQueue.isEmpty() ? matched.get(0) : shortPriceQueue.get(0); |
| | | BigDecimal step = config.getGridRate(); |
| | | int added = 0; |
| | | for (int i = 1; i <= matched.size(); i++) { |
| | | BigDecimal elem = first.multiply(BigDecimal.ONE.add(step.multiply(BigDecimal.valueOf(i)))).setScale(1, RoundingMode.HALF_UP); |
| | | if (shortEntryPrice.compareTo(BigDecimal.ZERO) > 0 |
| | | && elem.subtract(shortEntryPrice).abs().compareTo(shortEntryPrice.multiply(step)) < 0) { |
| | | continue; |
| | | } |
| | | shortPriceQueue.add(elem); |
| | | added++; |
| | | } |
| | | shortPriceQueue.sort((a, b) -> b.compareTo(a)); |
| | | while (shortPriceQueue.size() > config.getGridQueueSize()) { |
| | | shortPriceQueue.remove(shortPriceQueue.size() - 1); |
| | | } |
| | | |
| | | log.info("[Gate] 空队列:{}", shortPriceQueue); |
| | | log.info("[Gate] 现空队列:{}, 跳过{}个(贴近空仓均价)", shortPriceQueue, matched.size() - added); |
| | | } |
| | | } |
| | | |