package com.xcong.excoin.modules.gateApi;
|
|
import java.math.BigDecimal;
|
|
/**
|
* 网格交易单参数,封装单笔条件开仓单及其止盈单的完整状态。
|
*
|
* <p>每笔挂单对应的参数独立存储为一个 TraderParam 实例,
|
* 用于追踪条件开仓单和止盈条件单的挂单状态、价格位置及订单 ID。
|
*
|
* <h3>关键字段</h3>
|
* <ul>
|
* <li><b>方向</b>:多 / 空,决定挂单和止盈的触发方向</li>
|
* <li><b>价格</b>:挂单价(条件开仓触发价)、止盈价(止盈触发价)</li>
|
* <li><b>挂单状态</b>:挂单价是否挂成功、止盈价是否挂成功</li>
|
* <li><b>网格位置</b>:挂单价网格位置、止盈价网格位置(用于定位在价格队列中的索引)</li>
|
* <li><b>订单ID</b>:挂单订单 ID、止盈订单 ID(用于取消和匹配)</li>
|
* </ul>
|
*
|
* <h3>使用示例</h3>
|
* <pre>
|
* TraderParam param = TraderParam.builder()
|
* .direction(Direction.LONG)
|
* .entryPrice(new BigDecimal("2293.7"))
|
* .takeProfitPrice(new BigDecimal("2301.6"))
|
* .quantity("1")
|
* .entryGridPosition(3)
|
* .takeProfitGridPosition(4)
|
* .build();
|
*
|
* // 挂单成功后更新
|
* param.setEntryOrderPlaced(true);
|
* param.setEntryOrderId("12345");
|
*
|
* // 止盈单挂成功后更新
|
* param.setTakeProfitPlaced(true);
|
* param.setTakeProfitOrderId("12346");
|
* </pre>
|
*
|
* @author Administrator
|
*/
|
public class TraderParam {
|
|
/**
|
* 交易方向。
|
* <ul>
|
* <li>{@link #LONG} — 多头</li>
|
* <li>{@link #SHORT} — 空头</li>
|
* </ul>
|
*/
|
public enum Direction {
|
/** 多头方向 */
|
LONG,
|
/** 空头方向 */
|
SHORT
|
}
|
|
/** 交易方向(多 / 空) */
|
private Direction direction;
|
/** 下单数量(合约张数) */
|
private String quantity;
|
/** 挂单价在网格队列中的位置(索引,-1 表示未定位) */
|
private int entryGridPosition;
|
/** 条件开仓触发价 */
|
private BigDecimal entryPrice;
|
/** 挂单(条件开仓单)订单 ID */
|
private String entryOrderId;
|
/** 挂单价(条件开仓单)是否挂成功 */
|
private boolean entryOrderPlaced;
|
/** 止盈价在网格队列中的位置(索引,-1 表示未定位) */
|
private int takeProfitGridPosition;
|
/** 止盈触发价 */
|
private BigDecimal takeProfitPrice;
|
/** 止盈条件单订单 ID */
|
private String takeProfitOrderId;
|
/** 止盈价是否挂成功 */
|
private boolean takeProfitPlaced;
|
|
private TraderParam(Builder builder) {
|
this.direction = builder.direction;
|
this.entryPrice = builder.entryPrice;
|
this.takeProfitPrice = builder.takeProfitPrice;
|
this.quantity = builder.quantity;
|
this.takeProfitPlaced = builder.takeProfitPlaced;
|
this.entryOrderPlaced = builder.entryOrderPlaced;
|
this.entryGridPosition = builder.entryGridPosition;
|
this.takeProfitGridPosition = builder.takeProfitGridPosition;
|
this.takeProfitOrderId = builder.takeProfitOrderId;
|
this.entryOrderId = builder.entryOrderId;
|
}
|
|
// ==================== 交易方向 ====================
|
|
/** @return 交易方向(多 / 空) */
|
public Direction getDirection() { return direction; }
|
/** 设置交易方向 */
|
public void setDirection(Direction direction) { this.direction = direction; }
|
|
// ==================== 条件开仓触发价 ====================
|
|
/** @return 条件开仓触发价 */
|
public BigDecimal getEntryPrice() { return entryPrice; }
|
/** 设置条件开仓触发价 */
|
public void setEntryPrice(BigDecimal entryPrice) { this.entryPrice = entryPrice; }
|
|
// ==================== 止盈触发价 ====================
|
|
/** @return 止盈触发价 */
|
public BigDecimal getTakeProfitPrice() { return takeProfitPrice; }
|
/** 设置止盈触发价 */
|
public void setTakeProfitPrice(BigDecimal takeProfitPrice) { this.takeProfitPrice = takeProfitPrice; }
|
|
// ==================== 下单数量 ====================
|
|
/** @return 下单数量(合约张数) */
|
public String getQuantity() { return quantity; }
|
/** 设置下单数量 */
|
public void setQuantity(String quantity) { this.quantity = quantity; }
|
|
// ==================== 挂单价网格位置 ====================
|
|
/** @return 挂单价在网格队列中的索引位置,-1 表示未定位 */
|
public int getEntryGridPosition() { return entryGridPosition; }
|
/** 设置挂单价在网格队列中的索引位置 */
|
public void setEntryGridPosition(int entryGridPosition) { this.entryGridPosition = entryGridPosition; }
|
|
// ==================== 止盈价网格位置 ====================
|
|
/** @return 止盈价在网格队列中的索引位置,-1 表示未定位 */
|
public int getTakeProfitGridPosition() { return takeProfitGridPosition; }
|
/** 设置止盈价在网格队列中的索引位置 */
|
public void setTakeProfitGridPosition(int takeProfitGridPosition) { this.takeProfitGridPosition = takeProfitGridPosition; }
|
|
// ==================== 止盈价是否挂成功 ====================
|
|
/** @return 止盈条件单是否已挂成功 */
|
public boolean isTakeProfitPlaced() { return takeProfitPlaced; }
|
/** 标记止盈条件单已挂成功 */
|
public void setTakeProfitPlaced(boolean takeProfitPlaced) { this.takeProfitPlaced = takeProfitPlaced; }
|
|
// ==================== 挂单价是否挂成功 ====================
|
|
/** @return 条件开仓单是否已挂成功 */
|
public boolean isEntryOrderPlaced() { return entryOrderPlaced; }
|
/** 标记条件开仓单已挂成功 */
|
public void setEntryOrderPlaced(boolean entryOrderPlaced) { this.entryOrderPlaced = entryOrderPlaced; }
|
|
// ==================== 止盈订单 ID ====================
|
|
/** @return 止盈条件单订单 ID(挂成功后由交易所返回) */
|
public String getTakeProfitOrderId() { return takeProfitOrderId; }
|
/** 记录止盈条件单订单 ID */
|
public void setTakeProfitOrderId(String takeProfitOrderId) { this.takeProfitOrderId = takeProfitOrderId; }
|
|
// ==================== 挂单订单 ID ====================
|
|
/** @return 挂单(条件开仓单)订单 ID(挂成功后由交易所返回) */
|
public String getEntryOrderId() { return entryOrderId; }
|
/** 记录条件开仓单订单 ID */
|
public void setEntryOrderId(String entryOrderId) { this.entryOrderId = entryOrderId; }
|
|
public static Builder builder() {
|
return new Builder();
|
}
|
|
/**
|
* TraderParam 的流式构造器。
|
*
|
* <h3>必填项</h3>
|
* {@code direction}、{@code entryPrice}、{@code takeProfitPrice} 必须设置。
|
*
|
* <h3>默认值</h3>
|
* quantity=1 / entryGridPosition=-1 / takeProfitGridPosition=-1 / 挂单状态均为 false
|
*/
|
public static class Builder {
|
/** 交易方向(必填) */
|
private Direction direction;
|
/** 条件开仓触发价(必填) */
|
private BigDecimal entryPrice;
|
/** 止盈触发价(必填) */
|
private BigDecimal takeProfitPrice;
|
/** 下单数量,默认 "1" */
|
private String quantity = "1";
|
/** 止盈价是否挂成功,默认 false */
|
private boolean takeProfitPlaced = false;
|
/** 挂单价是否挂成功,默认 false */
|
private boolean entryOrderPlaced = false;
|
/** 挂单价网格位置,默认 -1(未定位) */
|
private int entryGridPosition = -1;
|
/** 止盈价网格位置,默认 -1(未定位) */
|
private int takeProfitGridPosition = -1;
|
/** 止盈订单 ID */
|
private String takeProfitOrderId;
|
/** 挂单订单 ID */
|
private String entryOrderId;
|
|
/** 设置交易方向(多 / 空) */
|
public Builder direction(Direction direction) { this.direction = direction; return this; }
|
/** 设置条件开仓触发价 */
|
public Builder entryPrice(BigDecimal entryPrice) { this.entryPrice = entryPrice; return this; }
|
/** 设置止盈触发价 */
|
public Builder takeProfitPrice(BigDecimal takeProfitPrice) { this.takeProfitPrice = takeProfitPrice; return this; }
|
/** 设置下单数量(合约张数) */
|
public Builder quantity(String quantity) { this.quantity = quantity; return this; }
|
/** 设置止盈价是否已挂成功 */
|
public Builder takeProfitPlaced(boolean takeProfitPlaced) { this.takeProfitPlaced = takeProfitPlaced; return this; }
|
/** 设置挂单价是否已挂成功 */
|
public Builder entryOrderPlaced(boolean entryOrderPlaced) { this.entryOrderPlaced = entryOrderPlaced; return this; }
|
/** 设置挂单价在网格队列中的索引位置 */
|
public Builder entryGridPosition(int entryGridPosition) { this.entryGridPosition = entryGridPosition; return this; }
|
/** 设置止盈价在网格队列中的索引位置 */
|
public Builder takeProfitGridPosition(int takeProfitGridPosition) { this.takeProfitGridPosition = takeProfitGridPosition; return this; }
|
/** 设置止盈条件单订单 ID */
|
public Builder takeProfitOrderId(String takeProfitOrderId) { this.takeProfitOrderId = takeProfitOrderId; return this; }
|
/** 设置挂单(条件开仓单)订单 ID */
|
public Builder entryOrderId(String entryOrderId) { this.entryOrderId = entryOrderId; return this; }
|
|
public TraderParam build() {
|
return new TraderParam(this);
|
}
|
}
|
}
|