Administrator
2026-06-05 2fede14ef1191ecd8738af4be3808c087131d8a5
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
package com.xcong.excoin.modules.okxNewPrice;
 
import java.math.BigDecimal;
 
/**
 * 单笔挂单的完整参数,封装条件开仓单及止盈单的状态。
 *
 * <h3>定位</h3>
 * 每个 OkxGridElement 内嵌两个 OkxTraderParam(longTraderParam / shortTraderParam),
 * 分别记录该价格层级上多仓和空仓的挂单参数。
 *
 * <h3>字段分组</h3>
 * <table>
 *   <tr><th>类别</th><th>字段</th><th>生命周期</th></tr>
 *   <tr><td>开仓准备</td><td>direction, entryPrice, quantity</td><td>updateGridElements() 预填充</td></tr>
 *   <tr><td>止盈预定</td><td>takeProfitPrice</td><td>updateGridElements() 预填充</td></tr>
 *   <tr><td>挂单确认</td><td>entryOrderPlaced, entryOrderId</td><td>条件单挂成功后写入</td></tr>
 *   <tr><td>止盈确认</td><td>takeProfitPlaced, takeProfitOrderId</td><td>止盈单挂成功后写入</td></tr>
 * </table>
 *
 * @author Administrator
 */
public class OkxTraderParam {
 
    public enum Direction {
        LONG,
        SHORT
    }
 
    /** 交易方向 */
    private Direction direction;
    /** 下单数量(合约张数) */
    private String quantity;
    /** 条件开仓触发价 */
    private BigDecimal entryPrice;
    /** 挂单(条件开仓单)订单 ID */
    private String entryOrderId;
    /** 挂单价是否挂成功 */
    private boolean entryOrderPlaced;
    /** 止盈触发价 */
    private BigDecimal takeProfitPrice;
    /** 止盈条件单(算法单)订单 ID(OKX 用 algoId) */
    private String takeProfitOrderId;
    /** 止盈价是否挂成功 */
    private boolean takeProfitPlaced;
 
    private OkxTraderParam(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.takeProfitOrderId = builder.takeProfitOrderId;
        this.entryOrderId = builder.entryOrderId;
    }
 
    public Direction getDirection() { return direction; }
    public void setDirection(Direction direction) { this.direction = direction; }
    public BigDecimal getEntryPrice() { return entryPrice; }
    public void setEntryPrice(BigDecimal entryPrice) { this.entryPrice = entryPrice; }
    public BigDecimal getTakeProfitPrice() { return takeProfitPrice; }
    public void setTakeProfitPrice(BigDecimal takeProfitPrice) { this.takeProfitPrice = takeProfitPrice; }
    public String getQuantity() { return quantity; }
    public void setQuantity(String quantity) { this.quantity = quantity; }
    public String getEntryOrderId() { return entryOrderId; }
    public void setEntryOrderId(String entryOrderId) { this.entryOrderId = entryOrderId; }
    public boolean isEntryOrderPlaced() { return entryOrderPlaced; }
    public void setEntryOrderPlaced(boolean entryOrderPlaced) { this.entryOrderPlaced = entryOrderPlaced; }
    public boolean isTakeProfitPlaced() { return takeProfitPlaced; }
    public void setTakeProfitPlaced(boolean takeProfitPlaced) { this.takeProfitPlaced = takeProfitPlaced; }
    public String getTakeProfitOrderId() { return takeProfitOrderId; }
    public void setTakeProfitOrderId(String takeProfitOrderId) { this.takeProfitOrderId = takeProfitOrderId; }
 
    public static Builder builder() {
        return new Builder();
    }
 
    public static class Builder {
        private Direction direction;
        private BigDecimal entryPrice;
        private BigDecimal takeProfitPrice;
        private String quantity = "1";
        private boolean takeProfitPlaced = false;
        private boolean entryOrderPlaced = false;
        private String takeProfitOrderId;
        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 takeProfitOrderId(String takeProfitOrderId) { this.takeProfitOrderId = takeProfitOrderId; return this; }
        public Builder entryOrderId(String entryOrderId) { this.entryOrderId = entryOrderId; return this; }
 
        public OkxTraderParam build() {
            return new OkxTraderParam(this);
        }
    }
}