forked from jyap808/go-poloniex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lending.go
40 lines (37 loc) · 928 Bytes
/
lending.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
package poloniex
import (
"encoding/json"
"time"
)
type Lending struct {
Id uint64 `json:"id"`
Currency string `json:"currency"`
Rate float64 `json:"rate,string"`
Amount float64 `json:"amount,string"`
Duration float64 `json:"duration,string"`
Interest float64 `json:"interest,string"`
Fee float64 `json:"fee,string"`
Earned float64 `json:"earned,string"`
Open time.Time `json:"open,string"`
Close time.Time `json:"close,string"`
}
func (t *Lending) UnmarshalJSON(data []byte) error {
var err error
type Alias Lending
aux := &struct {
Open string `json:"open"`
Close string `json:"close"`
*Alias
}{
Alias: (*Alias)(t),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
t.Open, err = time.Parse("2006-01-02 15:04:05", aux.Open)
t.Close, err = time.Parse("2006-01-02 15:04:05", aux.Close)
if err != nil {
return err
}
return nil
}