-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrows.go
57 lines (46 loc) · 1.08 KB
/
rows.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
package bittrex
type BookRow struct {
Quantity float64
Price float64 `json:"Rate"`
}
type BookRowUpdate struct {
Quantity float64
Price float64 `json:"Rate"`
Type int //0, 1, 2 means ADD, REMOVE, UPDATE
}
type BookRowsAscending []BookRow
func (r BookRowsAscending) Len() int {
return len(r)
}
func (r BookRowsAscending) Less(i, j int) bool {
return r[i].Price < r[j].Price
}
func (r BookRowsAscending) Swap(i, j int) {
r[i], r[j] = r[j], r[i]
}
type BookRowsDescending []BookRow
func (r BookRowsDescending) Len() int {
return len(r)
}
func (r BookRowsDescending) Less(i, j int) bool {
return r[i].Price > r[j].Price
}
func (r BookRowsDescending) Swap(i, j int) {
r[i], r[j] = r[j], r[i]
}
func separateRowUpdates(rows []BookRowUpdate) ([]BookRowUpdate, []BookRowUpdate, []BookRowUpdate) {
add := []BookRowUpdate{}
remove := []BookRowUpdate{}
update := []BookRowUpdate{}
for _, r := range rows {
switch r.Type {
case 0:
add = append(add, r)
case 1:
remove = append(remove, r)
case 2:
update = append(update, r)
}
}
return add, remove, update
}