-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.java
More file actions
41 lines (33 loc) · 1.47 KB
/
Copy pathOrder.java
File metadata and controls
41 lines (33 loc) · 1.47 KB
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
import java.io.Serializable;
public class Order implements Serializable {
private static final long serialVersionUID = 1L;
public enum Side { BUY, SELL, CANCEL }
public static final Order POISON_PILL = new Order(-1, Side.BUY, 0, 0, -1);
private final int sequenceId;
private final Side side;
private final double price;
private int quantity;
private final long timestamp;
private final int cancelTargetId;
public Order(int sequenceId, Side side, double price, int quantity, int cancelTargetId) {
this.sequenceId = sequenceId;
this.side = side;
this.price = price;
this.quantity = quantity;
this.cancelTargetId = cancelTargetId;
this.timestamp = System.nanoTime();
}
public int getSequenceId() { return sequenceId; }
public Side getSide() { return side; }
public double getPrice() { return price; }
public int getQuantity() { return quantity; }
public long getTimestamp() { return timestamp; }
public int getCancelTargetId(){ return cancelTargetId; }
public void setQuantity(int quantity) { this.quantity = quantity; }
@Override
public String toString() {
if (side == Side.CANCEL)
return String.format("[#%d] CANCEL target=#%d", sequenceId, cancelTargetId);
return String.format("[#%d] %s $%.2f x %d qty", sequenceId, side, price, quantity);
}
}