forked from jyap808/go-poloniex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
withdrawal.go
38 lines (35 loc) · 895 Bytes
/
withdrawal.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
package poloniex
import (
"encoding/json"
"strings"
"time"
)
type Withdrawal struct {
WithdrawalNumber uint64 `json:"withdrawalNumber"`
Currency string `json:"currency"`
Address string `json:"address"`
Amount float64 `json:"amount,string"`
Date time.Time `json:"timestamp"`
Status string `json:"status"`
TxId string `json:"txid"`
IpAddress string `json:"ipAddress"`
}
func (t *Withdrawal) UnmarshalJSON(data []byte) error {
var err error
type Alias Withdrawal
aux := &struct {
Date int64 `json:"timestamp"`
*Alias
}{
Alias: (*Alias)(t),
}
if err = json.Unmarshal(data, &aux); err != nil {
return err
}
t.Date = time.Unix(aux.Date, 0)
if strings.HasPrefix(aux.Status, "COMPLETE") {
t.TxId = strings.TrimPrefix(t.Status, "COMPLETE: ")
t.Status = "COMPLETE"
}
return nil
}