-
Notifications
You must be signed in to change notification settings - Fork 3
/
wallet_service.go
200 lines (179 loc) · 5.2 KB
/
wallet_service.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package phemex
import (
"context"
"encoding/json"
)
// GetUserWalletService get account info
type GetUserWalletService struct {
c *Client
offset *int64
limit *int64
withCount *int64
}
// Offset set offset
func (s *GetUserWalletService) Offset(offset int64) *GetUserWalletService {
s.offset = &offset
return s
}
// Limit set limit
func (s *GetUserWalletService) Limit(limit int64) *GetUserWalletService {
s.limit = &limit
return s
}
// WithCount set with count
func (s *GetUserWalletService) WithCount(withCount int64) *GetUserWalletService {
s.withCount = &withCount
return s
}
// Do send request
func (s *GetUserWalletService) Do(ctx context.Context, opts ...RequestOption) ([]*UserWallet, error) {
r := &request{
method: "GET",
endpoint: "/phemex-user/users/children",
secType: secTypeSigned,
}
if s.offset != nil {
r.setParam("offset", s.offset)
}
if s.limit != nil {
r.setParam("limit", s.limit)
}
if s.withCount != nil {
r.setParam("withCount", s.withCount)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
resp := new(BaseResponse)
resp.Data = new([]*UserWallet)
err = json.Unmarshal(data, resp)
if err != nil {
return nil, err
}
return *resp.Data.(*[]*UserWallet), nil
}
// UserWallet user wallet
type UserWallet struct {
UserID int `json:"userId"`
Email string `json:"email"`
NickName string `json:"nickName"`
PasswordState float64 `json:"passwordState"`
ClientCnt float64 `json:"clientCnt"`
Totp float64 `json:"totp"`
Logon float64 `json:"logon"`
ParentID float64 `json:"parentId"`
ParentEmail string `json:"parentEmail"`
Status float64 `json:"status"`
Wallet *WalletUserWallet `json:"wallet"`
UserMarginVo []*UserMarginUserWalletVo `json:"userMarginVo"`
}
// WalletUserWallet wallet user wallet
type WalletUserWallet struct {
TotalBalance string `json:"totalBalance"`
TotalBalanceEv float64 `json:"totalBalanceEv"`
AvailBalance string `json:"availBalance"`
AvailBalanceEv float64 `json:"availBalanceEv"`
FreezeBalance string `json:"freezeBalance"`
FreezeBalanceEv float64 `json:"freezeBalanceEv"`
Currency string `json:"currency"`
CurrencyCode float64 `json:"currencyCode"`
}
// UserMarginUserWalletVo user margin UserWalletvo
type UserMarginUserWalletVo struct {
Currency string `json:"currency"`
AccountBalance string `json:"accountBalance"`
TotalUsedBalance string `json:"totalUsedBalance"`
AccountBalanceEv float64 `json:"accountBalanceEv"`
TotalUsedBalanceEv float64 `json:"totalUsedBalanceEv"`
BonusBalanceEv float64 `json:"bonusBalanceEv"`
BonusBalance string `json:"bonusBalance"`
}
// ExchangeMarginService get account info
type ExchangeMarginService struct {
c *Client
btcAmount *float64
btcAmountEv *int64
linkKey *string
moveOp ExchangeMarginType
usdAmount *float64
usdAmountEv *int64
}
// BtcAmount set btcAmount
func (s *ExchangeMarginService) BtcAmount(btcAmount float64) *ExchangeMarginService {
s.btcAmount = &btcAmount
return s
}
// BtcAmountEv set btcAmountEv
func (s *ExchangeMarginService) BtcAmountEv(btcAmountEv int64) *ExchangeMarginService {
s.btcAmountEv = &btcAmountEv
return s
}
// LinkKey set linkKey
func (s *ExchangeMarginService) LinkKey(linkKey string) *ExchangeMarginService {
s.linkKey = &linkKey
return s
}
// MoveOp set moveOp
func (s *ExchangeMarginService) MoveOp(moveOp ExchangeMarginType) *ExchangeMarginService {
s.moveOp = moveOp
return s
}
// UsdAmount set usdAmount
func (s *ExchangeMarginService) UsdAmount(usdAmount float64) *ExchangeMarginService {
s.usdAmount = &usdAmount
return s
}
// UsdAmountEv set usdAmountEv
func (s *ExchangeMarginService) UsdAmountEv(usdAmountEv int64) *ExchangeMarginService {
s.usdAmountEv = &usdAmountEv
return s
}
// Do send request
func (s *ExchangeMarginService) Do(ctx context.Context, opts ...RequestOption) (*ExchangeMargin, error) {
r := &request{
method: "POST",
endpoint: "/exchange/margins",
secType: secTypeSigned,
}
m := params{
"moveOp": s.moveOp,
}
if s.btcAmount != nil {
m["btcAmount"] = *s.btcAmount
}
if s.btcAmountEv != nil {
m["btcAmountEv"] = *s.btcAmountEv
}
if s.linkKey != nil {
m["linkKey"] = *s.linkKey
}
if s.usdAmount != nil {
m["usdAmount"] = *s.usdAmount
}
if s.usdAmountEv != nil {
m["usdAmountEv"] = *s.usdAmountEv
}
r.setFormParams(m)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
resp := new(BaseResponse)
resp.Data = new(ExchangeMargin)
err = json.Unmarshal(data, resp)
if err != nil {
return nil, err
}
return resp.Data.(*ExchangeMargin), nil
}
// ExchangeMargin exchange margin
type ExchangeMargin struct {
MoveOp int `json:"moveOp"`
FromCurrencyName string `json:"fromCurrencyName"`
ToCurrencyName string `json:"toCurrencyName"`
FromAmount string `json:"fromAmount"`
ToAmount string `json:"toAmount"`
LinkKey string `json:"linkKey"`
Status int64 `json:"status"`
}