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
169 lines (132 loc) · 4.16 KB
/
Copy pathBitsoOrder.java
File metadata and controls
169 lines (132 loc) · 4.16 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
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
package com.bitso;
import java.math.BigDecimal;
import java.util.Date;
import org.json.JSONObject;
import com.bitso.helpers.Helpers;
public class BitsoOrder {
public static enum SIDE {
BUY, SELL;
public String toString() {
return this.name().toLowerCase();
}
}
public static enum TYPE {
MARKET, LIMIT;
public String toString() {
return this.name().toLowerCase();
}
}
public static enum STATUS {
OPEN, PARTIALLY_FILLED, QUEUED, COMPLETED, CANCELLED, UNKNOWN
}
private String book;
private BigDecimal originalAmount;
private BigDecimal unfilledAmount;
private BigDecimal originalValue;
private Date orderDate;
private Date updateDate;
private BigDecimal price;
private String oid;
private SIDE side;
// open || partially filled || completed || cancelled || queuedis
private STATUS status;
private TYPE type;
public BitsoOrder(JSONObject o) {
book = 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 = retrieveSide(Helpers.getString(o, "side"));
status = retrieveStatus(Helpers.getString(o, "status"));
type = retrieveType(Helpers.getString(o, "type"));
}
private BitsoOrder.SIDE retrieveSide(String side) {
return BitsoOrder.SIDE.valueOf(side.toUpperCase());
}
private BitsoOrder.STATUS retrieveStatus(String status) {
if (status.equals("open")) return BitsoOrder.STATUS.OPEN;
if (status.equals("partially filled")) return BitsoOrder.STATUS.PARTIALLY_FILLED;
if (status.equals("completed")) return BitsoOrder.STATUS.COMPLETED;
if (status.equals("cancelled")) return BitsoOrder.STATUS.CANCELLED;
if (status.equals("queued")) return BitsoOrder.STATUS.QUEUED;
System.err.println(status + " is not a supported order status");
return BitsoOrder.STATUS.UNKNOWN;
}
private BitsoOrder.TYPE retrieveType(String type) {
return BitsoOrder.TYPE.valueOf(type.toUpperCase());
}
public String getBook() {
return book;
}
public void setBook(String book) {
this.book = book;
}
public BigDecimal getOriginalAmount() {
return originalAmount;
}
public void setOriginalAmount(BigDecimal originalAmount) {
this.originalAmount = originalAmount;
}
public BigDecimal getUnfilledAmount() {
return unfilledAmount;
}
public void setUnfilledAmount(BigDecimal unfilledAmount) {
this.unfilledAmount = unfilledAmount;
}
public BigDecimal getOriginalValue() {
return originalValue;
}
public void setOriginalValue(BigDecimal originalValue) {
this.originalValue = originalValue;
}
public Date getOrderDate() {
return orderDate;
}
public void setOrderDate(Date orderDate) {
this.orderDate = orderDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public String getOid() {
return oid;
}
public void setOid(String oid) {
this.oid = oid;
}
public SIDE getSide() {
return side;
}
public void setSide(SIDE side) {
this.side = side;
}
public STATUS getStatus() {
return status;
}
public void setStatus(STATUS status) {
this.status = status;
}
public TYPE getType() {
return type;
}
public void setType(TYPE type) {
this.type = type;
}
@Override
public String toString() {
return Helpers.fieldPrinter(this, BitsoOrder.class);
}
}