-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.go
249 lines (209 loc) · 7.25 KB
/
account.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package goswyftx
import "net/http"
type AccountService service
type AccountSettings struct {
// Used only for Account Profile request, might be a bug with the api?
FavouriteAssets struct {
AssetID bool `json:"assetId,omitempty"`
} `json:"favouriteAssets"`
// Used only for updating account settings, might be a bug with the api?
FavouriteAsset struct {
AssetID bool `json:"assetId,omitempty"`
FavStatus bool `json:"favStatus,omitempty"`
} `json:"favouriteAsset,omitempty"`
AnalyticsOptOut bool `json:"analyticsOptOut,omitempty"`
ActiveAffiliation bool `json:"activeAffil,omitempty"`
DisableSMSRecovery bool `json:"disableSMSRecovery,omitempty"`
}
type AccountProfile struct {
DOB SwyftxTime `json:"dob,omitempty"`
Name struct {
First string `json:"first,omitempty"`
Last string `json:"last,omitempty"`
} `json:"name,omitempty"`
Email string `json:"email,omitempty"`
Phone string `json:"phone,omitempty"`
Currency struct {
ID int `json:"id,omitempty"`
Code string `json:"code,omitempty"`
} `json:"currency,omitempty"`
UserHash string `json:"user_hash,omitempty"`
MetaData struct {
MFAEnabled bool `json:"mfa_enabled,omitempty"`
MFAEnrolled bool `json:"mfa_enrolled,omitempty"`
} `json:"metadata,omitempty"`
UserSettings struct {
} `json:"userSettings,omitempty"`
}
type AccountVerification struct {
Status string `json:"status,omitempty"`
Email string `json:"email,omitempty"`
MFA string `json:"mfa,omitempty"`
Phone string `json:"phone,omitempty"`
Identity string `json:"identity,omitempty"`
}
type AccountUserVerification struct {
Success bool `json:"success,omitempty"`
EmailVerified bool `json:"emailVerified,omitempty"`
PhoneVerified bool `json:"phoneVerified,omitempty"`
Msg string `json:"msg,omitempty"`
}
type AccountAffiliation struct {
ReferralLink string `json:"referral_link,omitempty"`
ReferredUsers int `json:"referred_users"`
}
type AccountBalance struct {
AssetID int `json:"assetId,omitempty"`
// TODO: Convert to float
AvailableBalance string `json:"availableBalance,omitempty"`
}
type AccountStatistics struct {
Orders int `json:"orders,omitempty"`
Traded float32 `json:"traded,omitempty"`
Deposited float32 `json:"deposited,omitempty"`
Withdrawn float32 `json:"withdrawn,omitempty"`
}
type AccountMilestones struct {
SignUp bool `json:"signUp,omitempty"`
Verified bool `json:"verified,omitempty"`
Deposit bool `json:"deposit,omitempty"`
Trade bool `json:"trade,omitempty"`
Refer bool `json:"refer,omitempty"`
Completed bool `json:"completed,omitempty"`
}
// Account returns an account service that holds methods that can interact
// with account endpoints
func (c *Client) Account() *AccountService {
return (*AccountService)(&service{c})
}
// Profile will get a users profile
func (as *AccountService) Profile() (*AccountProfile, error) {
var account struct {
Profile AccountProfile `json:"profile"`
}
if err := as.client.Get("user/", &account); err != nil {
return nil, err
}
return &account.Profile, nil
}
// Settings will update a users account settings
func (as *AccountService) Settings(accSett *AccountSettings) (*AccountProfile, error) {
var (
account struct {
Profile AccountProfile `json:"profile"`
}
body struct {
Data AccountSettings `json:"data"`
}
)
body.Data = *accSett
if err := as.client.Post("user/settings/", &body, &account); err != nil {
return nil, err
}
return &account.Profile, nil
}
// Verification will get all user verification information
func (as *AccountService) VerificationInfo() (*AccountVerification, error) {
var account struct {
Verification AccountVerification `json:"verification"`
}
if err := as.client.Get("user/verification/", &account); err != nil {
return nil, err
}
return &account.Verification, nil
}
// VerificationGreenID will save GreenID verification info
func (as *AccountService) VerificationGreenID(greenID string) error {
var body struct {
Verification struct {
ID string `json:"id"`
} `json:"verification"`
}
body.Verification.ID = greenID
if err := as.client.Request(http.MethodGet, "user/verification/storeGreenId/", &body, nil); err != nil {
return err
}
return nil
}
// StartEmailVerification will send an email to verify access to an email account
func (as *AccountService) StartEmailVerification() (*AccountUserVerification, error) {
return as.startVerification("email", "")
}
// CheckEmailVerification will check the verification status of an email account
func (as *AccountService) CheckEmailVerification() (*AccountUserVerification, error) {
return as.checkVerification("email", "")
}
// CheckPhoneVerification will send an SMS to a phone number containing a verification token
func (as *AccountService) CheckPhoneVerification(phone string) (*AccountUserVerification, error) {
return as.checkVerification("phone", phone)
}
// StartPhoneVerification will try and verify access to a phone given a token
func (as *AccountService) StartPhoneVerification(token string) (*AccountUserVerification, error) {
return as.startVerification("phone", token)
}
func (as *AccountService) startVerification(verifyType, token string) (*AccountUserVerification, error) {
var accUserVerif AccountUserVerification
if err := as.client.Post(buildString("user/verification/", verifyType, "/", token), nil,
&accUserVerif); err != nil {
return nil, err
}
return &accUserVerif, nil
}
func (as *AccountService) checkVerification(verifyType, phone string) (*AccountUserVerification, error) {
var accUserVerif AccountUserVerification
if err := as.client.Get(buildString("user/verification/", verifyType, "/", phone),
&accUserVerif); err != nil {
return nil, err
}
return &accUserVerif, nil
}
// Affiliation will get a user's affiliation link and statistics
func (as *AccountService) Affiliation() (*AccountAffiliation, error) {
var accAffil AccountAffiliation
if err := as.client.Get("user/affiliations/", &accAffil); err != nil {
return nil, err
}
return &accAffil, nil
}
// Balance will get a user's account balance
func (as *AccountService) Balance() ([]*AccountBalance, error) {
var balances []*AccountBalance
if err := as.client.Get("user/balance/", &balances); err != nil {
return nil, err
}
return balances, nil
}
// SetCurrency will update a user's default currency given the asset ID of the new currency
func (as *AccountService) SetCurrency(assetID int) (*AccountProfile, error) {
var (
body struct {
Profile struct {
DefaultAsset int `json:"defaultAsset"`
} `json:"profile"`
}
account struct {
Profile AccountProfile `json:"profile"`
}
)
body.Profile.DefaultAsset = assetID
if err := as.client.Post("user/currency/", &body, &account); err != nil {
return nil, err
}
return &account.Profile, nil
}
// Statistics for the user's account and usage
func (as *AccountService) Statistics() (*AccountStatistics, error) {
var stats AccountStatistics
if err := as.client.Get("user/statistics/", &stats); err != nil {
return nil, err
}
return &stats, nil
}
// Progress shows the completion status of particular milestones for the user's account
func (as *AccountService) Progress() (*AccountMilestones, error) {
var milstones AccountMilestones
if err := as.client.Get("user/progress/", &milstones); err != nil {
return nil, err
}
return &milstones, nil
}