Administrator
2026-05-19 2af15077fb2e66500e955ffebc44ecad42e2dd66
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
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);
        }
    }
}