This commit is contained in:
tony 2026-07-08 22:19:52 +08:00
parent 82c85dfade
commit 3aa332a210
3 changed files with 26 additions and 29 deletions

View File

@ -16,13 +16,13 @@
<dependency> <dependency>
<groupId>vip.uuquant</groupId> <groupId>vip.uuquant</groupId>
<artifactId>uuquant-java-runner</artifactId> <artifactId>uuquant-java-runner</artifactId>
<version>20260329.1811</version> <version>20260707.1453</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>vip.uuquant</groupId> <groupId>vip.uuquant</groupId>
<artifactId>uuquant-exchange-api</artifactId> <artifactId>uuquant-exchange-api</artifactId>
<version>20260327.1656</version> <version>20260619.0130</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -11,8 +11,8 @@ public class StrategyApplication {
// 调试模式 // 调试模式
DebugConfig debugConfig = new DebugConfig(); DebugConfig debugConfig = new DebugConfig();
debugConfig.setAgentHost("192.168.0.105"); debugConfig.setAgentHost("192.168.0.105");
debugConfig.setRobotId(2038210296263434242L); debugConfig.setRobotId(2074501096701927426L);
debugConfig.setRobotApiKey("454d7146f092fdbbcfdef0ff554d9aa4"); debugConfig.setRobotApiKey("be7520970034b54cb7f2bccab0d546ca");
StrategyRunner strategyRunner = StrategyRunner.getInstance(); StrategyRunner strategyRunner = StrategyRunner.getInstance();
strategyRunner.setDebugConfig(debugConfig); strategyRunner.setDebugConfig(debugConfig);

View File

@ -10,19 +10,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import vip.uuquant.exhangeapi.core.WebSocketConnectionStatus; import vip.uuquant.exhangeapi.core.WebSocketConnectionStatus;
import vip.uuquant.exhangeapi.core.WebSocketMessageHandler; import vip.uuquant.exhangeapi.core.WebSocketMessageHandler;
import vip.uuquant.exhangeapi.enums.ExchangeType; import vip.uuquant.exhangeapi.enums.*;
import vip.uuquant.exhangeapi.enums.MarginType;
import vip.uuquant.exhangeapi.enums.OrderSide;
import vip.uuquant.exhangeapi.enums.OrderStatus;
import vip.uuquant.exhangeapi.enums.PositionSide;
import vip.uuquant.exhangeapi.enums.PositionStatus;
import vip.uuquant.exhangeapi.enums.QtyUnitType;
import vip.uuquant.exhangeapi.impl.bitget.BitGetClient; import vip.uuquant.exhangeapi.impl.bitget.BitGetClient;
import vip.uuquant.tradesystem.runner.enums.AlarmLevel; import vip.uuquant.tradesystem.runner.enums.AlarmLevel;
import vip.uuquant.tradesystem.runner.enums.RobotChartType; import vip.uuquant.tradesystem.runner.enums.RobotChartType;
import vip.uuquant.tradesystem.runner.strategy.BaseStrategy; import vip.uuquant.tradesystem.runner.strategy.BaseStrategy;
import vip.uuquant.tradesystem.runner.vo.AccountVO; import vip.uuquant.tradesystem.runner.vo.AccountVO;
import vip.uuquant.tradesystem.runner.vo.RobotVO;
import vip.uuquant.tradesystem.runner.vo.SymbolVO; import vip.uuquant.tradesystem.runner.vo.SymbolVO;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -60,7 +53,9 @@ public class AutoGridStrategy extends BaseStrategy {
private BigDecimal lowerBound; private BigDecimal lowerBound;
private boolean testMode; private boolean testMode;
private int leverage; private int leverage;
/** 最大待成交买单数量 */ /**
* 最大待成交买单数量
*/
private int gridCount; private int gridCount;
// 精度 // 精度
@ -78,11 +73,17 @@ public class AutoGridStrategy extends BaseStrategy {
private volatile boolean upperBoundPaused; private volatile boolean upperBoundPaused;
private volatile boolean lowerBoundPaused; private volatile boolean lowerBoundPaused;
/** 待成交买单:key = 网格价格字符串 */ /**
* 待成交买单:key = 网格价格字符串
*/
private final Map<String, GridBuyOrder> pendingBuyOrders = new ConcurrentHashMap<>(); private final Map<String, GridBuyOrder> pendingBuyOrders = new ConcurrentHashMap<>();
/** 已成交待止盈的多头仓位 */ /**
* 已成交待止盈的多头仓位
*/
private final List<GridPosition> openPositions = new CopyOnWriteArrayList<>(); private final List<GridPosition> openPositions = new CopyOnWriteArrayList<>();
/** 正在平仓中的仓位,防止重复触发 */ /**
* 正在平仓中的仓位,防止重复触发
*/
private final Map<String, Boolean> closingPositions = new ConcurrentHashMap<>(); private final Map<String, Boolean> closingPositions = new ConcurrentHashMap<>();
private final Object tradeLock = new Object(); private final Object tradeLock = new Object();
@ -204,7 +205,7 @@ public class AutoGridStrategy extends BaseStrategy {
tryParams("base_quantity", "atr_multiplier", "kline_interval", "kline_period", tryParams("base_quantity", "atr_multiplier", "kline_interval", "kline_period",
"grid_adjust_interval", "min_gap", "max_gap", "upper_bound", "lower_bound", "grid_adjust_interval", "min_gap", "max_gap", "upper_bound", "lower_bound",
"grid_count", "testMode"); "grid_count", "test_mode");
baseQuantity = getRunParams().getBigDecimal("base_quantity"); baseQuantity = getRunParams().getBigDecimal("base_quantity");
atrMultiplier = getRunParams().getBigDecimal("atr_multiplier"); atrMultiplier = getRunParams().getBigDecimal("atr_multiplier");
@ -215,7 +216,7 @@ public class AutoGridStrategy extends BaseStrategy {
maxGap = getRunParams().getBigDecimal("max_gap"); maxGap = getRunParams().getBigDecimal("max_gap");
upperBound = getRunParams().getBigDecimal("upper_bound"); upperBound = getRunParams().getBigDecimal("upper_bound");
lowerBound = getRunParams().getBigDecimal("lower_bound"); lowerBound = getRunParams().getBigDecimal("lower_bound");
testMode = getRunParams().getBooleanValue("testMode"); testMode = getRunParams().getBooleanValue("test_mode");
leverage = getRunParams().getIntValue("leverage"); leverage = getRunParams().getIntValue("leverage");
if (leverage <= 0) { if (leverage <= 0) {
leverage = 10; leverage = 10;
@ -239,11 +240,7 @@ public class AutoGridStrategy extends BaseStrategy {
} }
} }
RobotVO robotInfo = getRobotInfo(); robotId = getRobotConfig().getRobotId();
if (robotInfo != null) {
robotId = robotInfo.getRobotId();
}
initBitGetClient(); initBitGetClient();
initCharts(); initCharts();
@ -303,11 +300,11 @@ public class AutoGridStrategy extends BaseStrategy {
AccountVO account = getAccount(); AccountVO account = getAccount();
bitGetClient.init(account.getApiKey(), account.getSecretKey(), account.getPassphrase(), bitGetClient.init(account.getApiKey(), account.getSecretKey(), account.getPassphrase(),
null, CommonConstant.webSocketManager); null, CommonConstant.webSocketManager);
try { // try {
bitGetClient.setLeverage(getSymbol(), leverage); // bitGetClient.setLeverage(getSymbol(), leverage);
} catch (Exception e) { // } catch (Exception e) {
logger.warn("设置杠杆失败:{}", e.getMessage()); // logger.warn("设置杠杆失败:{}", e.getMessage());
} // }
try { try {
bitGetClient.createPublicWebsocket(webSocketMessageHandler); bitGetClient.createPublicWebsocket(webSocketMessageHandler);
bitGetClient.createPrivateWebsocket(webSocketMessageHandler); bitGetClient.createPrivateWebsocket(webSocketMessageHandler);
@ -844,7 +841,7 @@ public class AutoGridStrategy extends BaseStrategy {
// ======================== 工具方法 ======================== // ======================== 工具方法 ========================
private JSONObject buildOrderRequest(String side, String tradeSide, String orderType, private JSONObject buildOrderRequest(String side, String tradeSide, String orderType,
BigDecimal price, BigDecimal size, boolean reduceOnly) { BigDecimal price, BigDecimal size, boolean reduceOnly) {
JSONObject orderInfo = new JSONObject(); JSONObject orderInfo = new JSONObject();
orderInfo.put("symbol", getPlainSymbol()); orderInfo.put("symbol", getPlainSymbol());
orderInfo.put("marginMode", MARGIN_MODE); orderInfo.put("marginMode", MARGIN_MODE);