From 6e4499000b79c1848824a217af84ee51cba36274 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 18 May 2026 17:15:43 +0800
Subject: [PATCH] 第二个版本
---
src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java | 37 ++++++++++++++++++++++++++++++++++++-
1 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
index 094eaab..a7ccf86 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfig.java
@@ -1,6 +1,8 @@
package com.xcong.excoin.modules.gateApi;
import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
/**
* Gate 模块统一配置。
@@ -88,10 +90,18 @@
private final BigDecimal marginRatioLimit;
/** 合约乘数(单张合约代表的基础资产数量,如 BTC_USDT=0.001, ETH_USDT=0.01) */
private final BigDecimal contractMultiplier;
+ /** 价格精度(根据合约乘数自动计算的小数位数,如 0.001 → 3,0.01 → 2) */
+ private final int pricePrecision;
/** 未实现盈亏计价模式:最新价 / 标记价格 */
private final PnLPriceMode unrealizedPnlPriceMode;
/** 网格绝对步长(shortBaseEntryPrice × gridRate),运行时由队列生成逻辑设置 */
private BigDecimal step;
+ /** 网格元素列表,由队列初始化时同步填充,包含完整的多空仓挂单状态 */
+ private volatile List<GridElement> gridElements = new ArrayList<>();
+ /** 基座多头挂单参数,在基座成交后由 tryGenerateQueues 填充 */
+ private TraderParam baseLongTraderParam;
+ /** 基座空头挂单参数,在基座成交后由 tryGenerateQueues 填充 */
+ private TraderParam baseShortTraderParam;
private GateConfig(Builder builder) {
this.apiKey = builder.apiKey;
@@ -109,6 +119,7 @@
this.gridQueueSize = builder.gridQueueSize;
this.marginRatioLimit = builder.marginRatioLimit;
this.contractMultiplier = builder.contractMultiplier;
+ this.pricePrecision = builder.contractMultiplier.stripTrailingZeros().scale();
this.unrealizedPnlPriceMode = builder.unrealizedPnlPriceMode;
}
@@ -185,6 +196,8 @@
/** @return 合约乘数(单张合约代表的基础资产数量,如 ETH_USDT=0.01) */
public BigDecimal getContractMultiplier() { return contractMultiplier; }
+ /** @return 价格精度(根据合约乘数自动计算的小数位数,如 0.001→3,0.01→2),用于价格四舍五入 */
+ public int getPricePrecision() { return pricePrecision; }
/** @return 未实现盈亏计价模式:LAST_PRICE(最新成交价)/ MARK_PRICE(标记价格) */
public PnLPriceMode getUnrealizedPnlPriceMode() { return unrealizedPnlPriceMode; }
@@ -194,6 +207,28 @@
public BigDecimal getStep() { return step; }
/** 设置网格绝对步长(由 generateShortQueue 在运行时计算并注入) */
public void setStep(BigDecimal step) { this.step = step; }
+
+ // ==================== 网格元素列表 ====================
+
+ /** @return 网格元素列表(队列初始化后填充),线程不安全,仅由策略线程单线程写入 */
+ public List<GridElement> getGridElements() { return gridElements; }
+ /** 设置网格元素列表(由队列生成逻辑写入),同时重建全局 ID 索引 */
+ public void setGridElements(List<GridElement> gridElements) {
+ this.gridElements = gridElements;
+ GridElement.rebuildIndex(gridElements);
+ }
+
+ // ==================== 基座挂单参数 ====================
+
+ /** @return 基座多头挂单参数 */
+ public TraderParam getBaseLongTraderParam() { return baseLongTraderParam; }
+ /** 设置基座多头挂单参数(由 tryGenerateQueues 在基座成交后填充) */
+ public void setBaseLongTraderParam(TraderParam baseLongTraderParam) { this.baseLongTraderParam = baseLongTraderParam; }
+
+ /** @return 基座空头挂单参数 */
+ public TraderParam getBaseShortTraderParam() { return baseShortTraderParam; }
+ /** 设置基座空头挂单参数(由 tryGenerateQueues 在基座成交后填充) */
+ public void setBaseShortTraderParam(TraderParam baseShortTraderParam) { this.baseShortTraderParam = baseShortTraderParam; }
// ==================== 环境 ====================
@@ -240,7 +275,7 @@
/** 补仓最大重试次数,默认 3 */
private int reopenMaxRetries = 3;
/** 网格队列容量,默认 50 */
- private int gridQueueSize = 50;
+ private int gridQueueSize = 300;
/** 保证金占初始本金比例上限,默认 0.2(20%) */
private BigDecimal marginRatioLimit = new BigDecimal("0.2");
/** 合约乘数,默认 0.001 */
--
Gitblit v1.9.1