| | |
| | | * .contract("XAU_USDT") |
| | | * .leverage("100") |
| | | * .gridRate(new BigDecimal("0.0035")) |
| | | * .contractMultiplier("0.001") |
| | | * .isProduction(false) |
| | | * .build(); |
| | | * |
| | |
| | | * <h3>默认值</h3> |
| | | * <ul> |
| | | * <li>合约: BTC_USDT, 杠杆: 10x, 全仓, 双向持仓</li> |
| | | * <li>网格: 0.35%, 止盈: 0.5 USDT, 亏损: 7.5 USDT</li> |
| | | * <li>数量: 1 张, 环境: 测试网, 重试: 3 次</li> |
| | | * <li>网格间距: 0.35%, 队列容量: 50, 保证金比例上限: 20%</li> |
| | | * <li>止盈: 0.5 USDT, 亏损上限: 7.5 USDT</li> |
| | | * <li>数量: 1 张, 合约乘数: 0.001, 环境: 测试网</li> |
| | | * </ul> |
| | | * |
| | | * @author Administrator |
| | | */ |
| | | public class GateConfig { |
| | | |
| | | /** 未实现盈亏计价模式 */ |
| | | public enum PnLPriceMode { |
| | | /** 按最新成交价计算 */ |
| | | LAST_PRICE, |
| | | /** 按标记价格计算 */ |
| | | MARK_PRICE |
| | | } |
| | | |
| | | /** 账号标签(用于日志区分多账号) */ |
| | | private final String label; |
| | | /** Gate API v4 密钥 */ |
| | | private final String apiKey; |
| | | /** Gate API v4 签名密钥 */ |
| | |
| | | private final boolean isProduction; |
| | | /** 补仓最大重试次数 */ |
| | | private final int reopenMaxRetries; |
| | | /** 网格队列容量 */ |
| | | private final int gridQueueSize; |
| | | /** 保证金占初始本金比例上限 */ |
| | | private final BigDecimal marginRatioLimit; |
| | | /** 合约乘数(单张合约代表的基础资产数量,如 BTC_USDT=0.001, ETH_USDT=0.01) */ |
| | | private final BigDecimal contractMultiplier; |
| | | /** 未实现盈亏计价模式:最新价 / 标记价格 */ |
| | | private final PnLPriceMode unrealizedPnlPriceMode; |
| | | |
| | | private GateConfig(Builder builder) { |
| | | this.label = builder.label; |
| | | this.apiKey = builder.apiKey; |
| | | this.apiSecret = builder.apiSecret; |
| | | this.contract = builder.contract; |
| | |
| | | this.quantity = builder.quantity; |
| | | this.isProduction = builder.isProduction; |
| | | this.reopenMaxRetries = builder.reopenMaxRetries; |
| | | this.gridQueueSize = builder.gridQueueSize; |
| | | this.marginRatioLimit = builder.marginRatioLimit; |
| | | this.contractMultiplier = builder.contractMultiplier; |
| | | this.unrealizedPnlPriceMode = builder.unrealizedPnlPriceMode; |
| | | } |
| | | |
| | | /** |
| | |
| | | : "wss://ws-testnet.gate.com/v4/ws/futures/usdt"; |
| | | } |
| | | |
| | | public String getLabel() { return label; } |
| | | public String getApiKey() { return apiKey; } |
| | | public String getApiSecret() { return apiSecret; } |
| | | public String getContract() { return contract; } |
| | |
| | | public String getQuantity() { return quantity; } |
| | | public boolean isProduction() { return isProduction; } |
| | | public int getReopenMaxRetries() { return reopenMaxRetries; } |
| | | public int getGridQueueSize() { return gridQueueSize; } |
| | | public BigDecimal getMarginRatioLimit() { return marginRatioLimit; } |
| | | public BigDecimal getContractMultiplier() { return contractMultiplier; } |
| | | public PnLPriceMode getUnrealizedPnlPriceMode() { return unrealizedPnlPriceMode; } |
| | | |
| | | public static Builder builder() { |
| | | return new Builder(); |
| | |
| | | * GateConfig 的流式构造器,提供合理的默认值。 |
| | | */ |
| | | public static class Builder { |
| | | private String label = "default"; |
| | | private String apiKey; |
| | | private String apiSecret; |
| | | private String contract = "BTC_USDT"; |
| | |
| | | private String quantity = "1"; |
| | | private boolean isProduction = false; |
| | | private int reopenMaxRetries = 3; |
| | | private int gridQueueSize = 50; |
| | | private BigDecimal marginRatioLimit = new BigDecimal("0.2"); |
| | | private BigDecimal contractMultiplier = new BigDecimal("0.001"); |
| | | private PnLPriceMode unrealizedPnlPriceMode = PnLPriceMode.LAST_PRICE; |
| | | |
| | | public Builder label(String label) { this.label = label; return this; } |
| | | public Builder apiKey(String apiKey) { this.apiKey = apiKey; return this; } |
| | | public Builder apiSecret(String apiSecret) { this.apiSecret = apiSecret; return this; } |
| | | public Builder contract(String contract) { this.contract = contract; return this; } |
| | |
| | | public Builder quantity(String quantity) { this.quantity = quantity; return this; } |
| | | public Builder isProduction(boolean isProduction) { this.isProduction = isProduction; return this; } |
| | | public Builder reopenMaxRetries(int reopenMaxRetries) { this.reopenMaxRetries = reopenMaxRetries; return this; } |
| | | public Builder contractMultiplier(BigDecimal contractMultiplier) { this.contractMultiplier = contractMultiplier; return this; } |
| | | public Builder unrealizedPnlPriceMode(PnLPriceMode mode) { this.unrealizedPnlPriceMode = mode; return this; } |
| | | |
| | | public GateConfig build() { |
| | | return new GateConfig(this); |