package com.xcong.excoin.modules.gateApi;
import java.math.BigDecimal;
/**
* 单笔挂单的完整参数,封装条件开仓单及止盈单的状态。
*
*
定位
* 每个 GridElement 内嵌两个 TraderParam(longTraderParam / shortTraderParam),
* 分别记录该价格层级上多仓和空仓的挂单参数。所有字段通过 getter/setter
* 在挂单/成交/止盈各阶段逐步填充。
*
* 字段分组
*
* | 类别 | 字段 | 生命周期 |
* | 开仓准备 | direction, entryPrice, quantity | updateGridElements() 预填充 |
* | 止盈预定 | takeProfitPrice | updateGridElements() 预填充(entryPrice ± (step - minTick)) |
* | 挂单确认 | entryOrderPlaced, entryOrderId | 条件单挂成功后由 longEntryTraderIdParam 等写入 |
* | 止盈确认 | takeProfitPlaced, takeProfitOrderId | 止盈单挂成功后由 longTakeProfitTraderIdParam 等写入 |
* | 定位 | entryGridPosition, takeProfitGridPosition | 当前策略中由 upId/downId 替代 |
*
*
* 盈利公式(正向合约)
*
* 多仓止盈盈利 = takeProfitPrice - entryPrice = (entryPrice + step - minTick) - entryPrice = step - minTick
* 空仓止盈盈利 = entryPrice - takeProfitPrice = entryPrice - (entryPrice - step + minTick) = step - minTick
*
*
* @author Administrator
*/
public class TraderParam {
/**
* 交易方向。
*
* - {@link #LONG} — 多头
* - {@link #SHORT} — 空头
*
*/
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 的流式构造器。
*
* 必填项
* {@code direction}、{@code entryPrice}、{@code takeProfitPrice} 必须设置。
*
* 默认值
* 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);
}
}
}