-
-
Notifications
You must be signed in to change notification settings - Fork 296
/
deposit.go
83 lines (63 loc) · 1.97 KB
/
deposit.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
package types
import (
"fmt"
"strconv"
"strings"
"time"
"github.com/c9s/bbgo/pkg/fixedpoint"
)
type DepositStatus string
const (
// EMPTY string means not supported
DepositPending = DepositStatus("pending")
DepositRejected = DepositStatus("rejected")
DepositSuccess = DepositStatus("success")
DepositCancelled = DepositStatus("canceled")
// created but can not withdraw
DepositCredited = DepositStatus("credited")
)
type Deposit struct {
GID int64 `json:"gid" db:"gid"`
Exchange ExchangeName `json:"exchange" db:"exchange"`
Time Time `json:"time" db:"time"`
Amount fixedpoint.Value `json:"amount" db:"amount"`
Asset string `json:"asset" db:"asset"`
Address string `json:"address" db:"address"`
AddressTag string `json:"addressTag"`
TransactionID string `json:"transactionID" db:"txn_id"`
Status DepositStatus `json:"status"`
// Required confirm for unlock balance
UnlockConfirm int `json:"unlockConfirm"`
// Confirmation format = "current/required", for example: "7/16"
Confirmation string `json:"confirmation"`
}
func (d Deposit) GetCurrentConfirmation() (current int, required int) {
if len(d.Confirmation) == 0 {
return 0, 0
}
strs := strings.Split(d.Confirmation, "/")
if len(strs) < 2 {
return 0, 0
}
current, _ = strconv.Atoi(strs[0])
required, _ = strconv.Atoi(strs[1])
return current, required
}
func (d Deposit) EffectiveTime() time.Time {
return d.Time.Time()
}
func (d Deposit) String() (o string) {
o = fmt.Sprintf("%s deposit %s %v <- ", d.Exchange, d.Asset, d.Amount)
if len(d.AddressTag) > 0 {
o += fmt.Sprintf("%s (tag: %s) at %s", d.Address, d.AddressTag, d.Time.Time())
} else {
o += fmt.Sprintf("%s at %s", d.Address, d.Time.Time())
}
if len(d.TransactionID) > 0 {
o += fmt.Sprintf("txID: %s", cutstr(d.TransactionID, 12, 4, 4))
}
if len(d.Status) > 0 {
o += "status: " + string(d.Status)
}
return o
}