-
Notifications
You must be signed in to change notification settings - Fork 8
/
get_order.go
90 lines (80 loc) · 1.63 KB
/
get_order.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
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
package indodax
import (
"encoding/json"
"strconv"
"strings"
"time"
)
type respGetOrders struct {
Success int
Return respGetOrder
Message string
}
type respGetOrder struct {
Order *GetOrder
}
//
// Get Order containt a status from order placed of user
//
type GetOrder struct {
OrderID int64
Price float64
Type string
OrderAmount float64
RemainAmount float64
SubmitTime time.Time
FinishTime time.Time
Status string
AssetName string
}
func (getOrder *GetOrder) UnmarshalJSON(b []byte) (err error) {
var kv map[string]string
err = json.Unmarshal(b, &kv)
if err != nil {
return err
}
for k, v := range kv {
k = strings.ToLower(k)
switch k {
case fieldNameOrderID:
getOrder.OrderID, err = strconv.ParseInt(v, 10, 64)
case fieldNameType:
getOrder.Type = v
case fieldNameStatus:
getOrder.Status = v
case fieldNameSubmitTime:
ts, err := strconv.ParseInt(v, 10, 64)
if err != nil {
return err
}
getOrder.SubmitTime = time.Unix(ts, 0)
case fieldNameFinishTime:
if v == "0" {
continue
}
ts, err := strconv.ParseInt(v, 10, 64)
if err != nil {
return err
}
getOrder.FinishTime = time.Unix(ts, 0)
case fieldNamePrice:
getOrder.Price, err = strconv.ParseFloat(v, 64)
default:
keyName := strings.Split(k, "_")
if len(keyName) < 2 {
continue
}
switch keyName[0] {
case fieldNameRemain:
getOrder.RemainAmount, err = strconv.ParseFloat(v, 64)
case fieldNameOrder:
getOrder.OrderAmount, err = strconv.ParseFloat(v, 64)
}
getOrder.AssetName = keyName[1]
}
if err != nil {
return err
}
}
return nil
}