From 9bd318567e2ba1350b47a42dc9b292a1eb0b9757 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 18 May 2026 21:14:18 +0800
Subject: [PATCH] 第二个版本
---
src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java | 29 ++++++++++++++++++++++++-----
1 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
index 825979d..86e4763 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateGridTradeService.java
@@ -1,5 +1,6 @@
package com.xcong.excoin.modules.gateApi;
+import cn.hutool.core.collection.CollUtil;
import io.gate.gateapi.ApiClient;
import io.gate.gateapi.ApiException;
import io.gate.gateapi.GateApiException;
@@ -432,6 +433,13 @@
tryGenerateQueues();
}else {
longPositionSize = size;
+ //取消多仓位线以上的开空仓挂单
+ List<GridElement> allShortOrders = GridElement.findAllShortOrders(longEntryPrice);
+ if (CollUtil.isNotEmpty(allShortOrders)){
+ for (GridElement e : allShortOrders) {
+ executor.cancelOrder(e.getShortOrderId());
+ }
+ }
}
} else {
longActive = false;
@@ -449,6 +457,13 @@
tryGenerateQueues();
}else {
shortPositionSize = size.abs();
+ //取消多仓位线以上的开空仓挂单
+ List<GridElement> allLongOrders = GridElement.findAllLongOrders(shortEntryPrice);
+ if (CollUtil.isNotEmpty(allLongOrders)){
+ for (GridElement e : allLongOrders) {
+ executor.cancelOrder(e.getShortOrderId());
+ }
+ }
}
} else {
shortActive = false;
@@ -791,9 +806,11 @@
List<GridElement> elements = new ArrayList<>();
int shortSize = shortPriceQueue.size();
int longSize = longPriceQueue.size();
- BigDecimal step = config.getStep().subtract(config.getContractMultiplier());
- String qty = config.getQuantity();
+ //根据精度转换成小数
int prec = config.getPriceScale();
+ BigDecimal minTick = BigDecimal.ONE.scaleByPowerOfTen(-prec);
+ BigDecimal step = config.getStep().subtract(minTick);
+ String qty = config.getQuantity();
// 空仓队列:id 从 -1 自减, shortPriceQueue[i] → id=-(i+1)
for (int i = 0; i < shortSize; i++) {
@@ -909,7 +926,7 @@
List<BigDecimal> matched = new ArrayList<>();
synchronized (shortPriceQueue) {
for (BigDecimal p : shortPriceQueue) {
- if (p.compareTo(currentPrice) > 0) {
+ if (p.compareTo(currentPrice) >= 0) {
matched.add(p);
} else {
break;
@@ -991,7 +1008,7 @@
if (downGridElement != null){
TraderParam downLongTraderParam = downGridElement.getLongTraderParam();
- if (!downGridElement.isHasShortOrder()){
+ if (!downGridElement.isHasLongOrder()){
executor.placeConditionalEntryOrder(
downLongTraderParam.getEntryPrice(),
FuturesPriceTrigger.RuleEnum.NUMBER_1,
@@ -1012,6 +1029,7 @@
BigDecimal downGridPrice = downGridElement.getGridPrice();
if (
!downGridElement.isHasShortOrder() &&
+ downGridPrice.compareTo(currentPrice) < 0 &&
downGridPrice.compareTo(longEntryPrice) <= 0 &&
downGridPrice.compareTo(shortEntryPrice) >= 0
){
@@ -1066,7 +1084,7 @@
List<BigDecimal> matched = new ArrayList<>();
synchronized (longPriceQueue) {
for (BigDecimal p : longPriceQueue) {
- if (p.compareTo(currentPrice) < 0) {
+ if (p.compareTo(currentPrice) <= 0) {
matched.add(p);
} else {
break;
@@ -1173,6 +1191,7 @@
BigDecimal downGridPrice = downGridElement.getGridPrice();
if (
!downGridElement.isHasLongOrder() &&
+ downGridPrice.compareTo(currentPrice) > 0 &&
downGridPrice.compareTo(longEntryPrice) <= 0 &&
downGridPrice.compareTo(shortEntryPrice) >= 0
){
--
Gitblit v1.9.1