forked from bitsoex/bitso-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitsoOrderBook.java
More file actions
54 lines (44 loc) · 1.75 KB
/
Copy pathBitsoOrderBook.java
File metadata and controls
54 lines (44 loc) · 1.75 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
package com.bitso;
import java.math.BigDecimal;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONObject;
import com.bitso.exchange.BookOrder;
import com.bitso.exchange.OrderBook;
import com.bitso.helpers.Helpers;
public class BitsoOrderBook extends OrderBook {
public BitsoOrderBook(JSONObject obj) {
if (obj.has("timestamp")) {
timestamp = obj.getLong("timestamp");
} else {
System.err.println("No timestamp: " + obj);
Helpers.printStackTrace();
}
if (obj.has("bids")) {
JSONArray bidsJSON = obj.getJSONArray("bids");
bids = new ArrayList<BookOrder>(bidsJSON.length());
for (int i = 0; i < bidsJSON.length(); i++) {
JSONArray bid = bidsJSON.getJSONArray(i);
BigDecimal price = new BigDecimal(bid.getString(0));
BigDecimal amount = new BigDecimal(bid.getString(1));
bids.add(new BookOrder(price, amount, BookOrder.TYPE.BUY));
}
} else {
System.err.println("No bids: " + obj);
Helpers.printStackTrace();
}
if (obj.has("asks")) {
JSONArray asksJSON = obj.getJSONArray("asks");
asks = new ArrayList<BookOrder>(asksJSON.length());
for (int i = 0; i < asksJSON.length(); i++) {
JSONArray ask = asksJSON.getJSONArray(i);
BigDecimal price = new BigDecimal(ask.getString(0));
BigDecimal amount = new BigDecimal(ask.getString(1));
asks.add(new BookOrder(price, amount, BookOrder.TYPE.SELL));
}
} else {
System.err.println("No asks: " + obj);
Helpers.printStackTrace();
}
}
}