forked from bitsoex/bitso-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitsoOrder.java
More file actions
101 lines (86 loc) · 2.93 KB
/
Copy pathBitsoOrder.java
File metadata and controls
101 lines (86 loc) · 2.93 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
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
package com.bitso;
import java.math.BigDecimal;
import java.util.Date;
import org.json.JSONObject;
import com.bitso.exceptions.BitsoExceptionNotExpectedValue;
import com.bitso.helpers.Helpers;
public class BitsoOrder {
public static enum SIDE {
BUY, SELL;
public String toString() {
return this.name().toLowerCase();
}
}
public static enum STATUS {
OPEN, PARTIALLY_FILLED, COMPLETED, CANCELLED;
public String toString() {
return this.name().toLowerCase();
}
}
public static enum TYPE {
MARKET, LIMIT;
public String toString() {
return this.name().toLowerCase();
}
}
public BitsoBook book;
public BigDecimal originalAmount;
public BigDecimal unfilledAmount;
public BigDecimal originalValue;
public Date orderDate;
public Date updateDate;
public BigDecimal price;
public String oid;
public SIDE side;
public STATUS status;
public TYPE type;
public BitsoOrder(JSONObject o) {
book = Helpers.getBook(Helpers.getString(o, "book"));
originalAmount = Helpers.getBD(o, "original_amount");
unfilledAmount = Helpers.getBD(o, "unfilled_amount");
originalValue = Helpers.getBD(o, "original_value");
orderDate = Helpers.getZonedDatetime(o, "created_at");
updateDate = Helpers.getZonedDatetime(o, "updated_at");
price = Helpers.getBD(o, "price");
oid = Helpers.getString(o, "oid");
side = getSide(Helpers.getString(o, "side"));
status = getStatus(Helpers.getString(o, "status"));
type = getType(Helpers.getString(o, "type"));
}
public BitsoOrder.SIDE getSide(String side) {
if (side.equals("buy")) {
return BitsoOrder.SIDE.BUY;
}
return BitsoOrder.SIDE.SELL;
}
public BitsoOrder.STATUS getStatus(String status) {
switch (status) {
case "open":
return BitsoOrder.STATUS.OPEN;
case "partially filled":
return BitsoOrder.STATUS.PARTIALLY_FILLED;
case "completed":
return BitsoOrder.STATUS.COMPLETED;
case "cancelled":
return BitsoOrder.STATUS.CANCELLED;
default:
String exceptionMessage = status + "is not a supported order status";
throw new BitsoExceptionNotExpectedValue(exceptionMessage);
}
}
public BitsoOrder.TYPE getType(String type) {
switch (type) {
case "limit":
return BitsoOrder.TYPE.LIMIT;
case "market":
return BitsoOrder.TYPE.MARKET;
default:
String exceptionMessage = type + "is not a supported order type";
throw new BitsoExceptionNotExpectedValue(exceptionMessage);
}
}
@Override
public String toString() {
return Helpers.fieldPrinter(this);
}
}