-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_utils.go
65 lines (53 loc) · 1.19 KB
/
test_utils.go
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
package orderbook
// level provides a struct for transversing both orderbook's treemaps
type level struct {
bidPrice Price
bidSize Volume
askPrice Price
askSize Volume
}
// Iterates through bids and asks and returns each bid leveled up with an ask in the same position.
func levels(orderBook *OrderBook) []level {
var levels []level
var bids []Price
var asks []Price
itb := orderBook.bids.Iterator()
for itb.Next() {
key := itb.Key().(Price)
bids = append(bids, key)
}
ita := orderBook.asks.Iterator()
for ita.Next() {
key := ita.Key().(Price)
asks = append(asks, key)
}
maxItems := 0
if len(bids) > len(asks) {
maxItems = len(bids)
} else {
maxItems = len(asks)
}
for i := 0; i < maxItems; i++ {
bidPrice := Price(0)
askPrice := Price(0)
if bids == nil || i >= len(bids) {
bidPrice = Price(0)
} else {
bidPrice = bids[i]
}
if asks == nil || i >= len(asks) {
askPrice = Price(0)
} else {
askPrice = asks[i]
}
bidSize := orderBook.GetBidSize(bidPrice)
askSize := orderBook.GetAskSize(askPrice)
levels = append(levels, level{
bidPrice: bidPrice,
bidSize: bidSize,
askPrice: askPrice,
askSize: askSize,
})
}
return levels
}