-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlist_trades.go
57 lines (49 loc) · 949 Bytes
/
list_trades.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 indodax
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
)
//
// List Trade containt all match order from user
//
type ListTrade struct {
ID int64
Type string
Date time.Time
Amount float64
Price float64
}
func (listTrade *ListTrade) 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 fieldNameTID:
listTrade.ID, err = strconv.ParseInt(v, 10, 64)
case fieldNameType:
listTrade.Type = v
case fieldNameDate:
ts, err := strconv.ParseInt(v, 10, 64)
if err != nil {
return err
}
listTrade.Date = time.Unix(ts, 0)
case fieldNameAmount:
listTrade.Amount, err = strconv.ParseFloat(v, 64)
case fieldNamePrice:
listTrade.Price, err = strconv.ParseFloat(v, 64)
}
if err != nil {
fmt.Println(k)
return err
}
}
return nil
}