| | |
| | | package com.xcong.excoin.modules.gateApi; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Gate 模块统一配置。 |
| | |
| | | private final BigDecimal marginRatioLimit; |
| | | /** 合约乘数(单张合约代表的基础资产数量,如 BTC_USDT=0.001, ETH_USDT=0.01) */ |
| | | private final BigDecimal contractMultiplier; |
| | | /** 价格精度(交易所价格的最小小数位数,如 XAU_USDT=1 表示 0.1 精度,ETH_USDT=2 表示 0.01 精度) */ |
| | | private final int priceScale; |
| | | /** 未实现盈亏计价模式:最新价 / 标记价格 */ |
| | | 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; |
| | |
| | | this.gridQueueSize = builder.gridQueueSize; |
| | | this.marginRatioLimit = builder.marginRatioLimit; |
| | | this.contractMultiplier = builder.contractMultiplier; |
| | | this.priceScale = builder.priceScale; |
| | | this.unrealizedPnlPriceMode = builder.unrealizedPnlPriceMode; |
| | | } |
| | | |
| | |
| | | |
| | | /** @return 合约乘数(单张合约代表的基础资产数量,如 ETH_USDT=0.01) */ |
| | | public BigDecimal getContractMultiplier() { return contractMultiplier; } |
| | | /** @return 价格精度(交易所价格的小数位数,如 1=0.1精度,2=0.01精度),用于价格四舍五入 */ |
| | | public int getPriceScale() { return priceScale; } |
| | | /** @return 未实现盈亏计价模式:LAST_PRICE(最新成交价)/ MARK_PRICE(标记价格) */ |
| | | public PnLPriceMode getUnrealizedPnlPriceMode() { return unrealizedPnlPriceMode; } |
| | | |
| | |
| | | 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; } |
| | | |
| | | // ==================== 环境 ==================== |
| | | |
| | |
| | | /** 补仓最大重试次数,默认 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 */ |
| | | private BigDecimal contractMultiplier = new BigDecimal("0.001"); |
| | | /** 价格精度(交易所价格的小数位数),默认 1(0.1 精度) */ |
| | | private int priceScale = 1; |
| | | /** 未实现盈亏计价模式,默认 LAST_PRICE(最新成交价) */ |
| | | private PnLPriceMode unrealizedPnlPriceMode = PnLPriceMode.LAST_PRICE; |
| | | |
| | |
| | | public Builder reopenMaxRetries(int reopenMaxRetries) { this.reopenMaxRetries = reopenMaxRetries; return this; } |
| | | /** 设置合约乘数(单张合约代表的基础资产数量) */ |
| | | public Builder contractMultiplier(BigDecimal contractMultiplier) { this.contractMultiplier = contractMultiplier; return this; } |
| | | /** 设置价格精度(交易所价格的小数位数,如 1=0.1精度,2=0.01精度) */ |
| | | public Builder priceScale(int priceScale) { this.priceScale = priceScale; return this; } |
| | | /** 设置未实现盈亏计价模式 */ |
| | | public Builder unrealizedPnlPriceMode(PnLPriceMode mode) { this.unrealizedPnlPriceMode = mode; return this; } |
| | | |