-
Notifications
You must be signed in to change notification settings - Fork 2
/
account_service.go
189 lines (165 loc) · 5.56 KB
/
account_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
package binance
import (
"context"
"github.com/crypto-zero/go-binance/v2/common"
)
// GetAccountService get account info
type GetAccountService struct {
c *Client
}
// Do send Request
func (s *GetAccountService) Do(ctx context.Context, opts ...common.RequestOption) (res *Account, err error) {
r := common.NewGetRequestSigned("/api/v3/account")
res = new(Account)
if err = s.c.CallAPI(ctx, r, res, opts...); err != nil {
return nil, err
}
return res, nil
}
// Account define account info
type Account struct {
MakerCommission int64 `json:"makerCommission"`
TakerCommission int64 `json:"takerCommission"`
BuyerCommission int64 `json:"buyerCommission"`
SellerCommission int64 `json:"sellerCommission"`
CanTrade bool `json:"canTrade"`
CanWithdraw bool `json:"canWithdraw"`
CanDeposit bool `json:"canDeposit"`
UpdateTime uint64 `json:"updateTime"`
AccountType string `json:"accountType"`
Balances []Balance `json:"balances"`
Permissions []string `json:"permissions"`
}
// Balance define user balance of your account
type Balance struct {
Asset string `json:"asset"`
Free float64 `json:"free,string"`
Locked float64 `json:"locked,string"`
}
// GetAccountSnapshotService all account orders; active, canceled, or filled
type GetAccountSnapshotService struct {
c *Client
accountType string
startTime *int64
endTime *int64
limit *int
}
// Type set account type ("SPOT", "MARGIN", "FUTURES")
func (s *GetAccountSnapshotService) Type(accountType string) *GetAccountSnapshotService {
s.accountType = accountType
return s
}
// StartTime set starttime
func (s *GetAccountSnapshotService) StartTime(startTime int64) *GetAccountSnapshotService {
s.startTime = &startTime
return s
}
// EndTime set endtime
func (s *GetAccountSnapshotService) EndTime(endTime int64) *GetAccountSnapshotService {
s.endTime = &endTime
return s
}
// Limit set limit
func (s *GetAccountSnapshotService) Limit(limit int) *GetAccountSnapshotService {
s.limit = &limit
return s
}
// Do send Request
func (s *GetAccountSnapshotService) Do(ctx context.Context, opts ...common.RequestOption) (res *Snapshot, err error) {
r := common.NewGetRequestSigned("/sapi/v1/accountSnapshot")
r.SetQuery("type", s.accountType)
if s.startTime != nil {
r.SetQuery("startTime", *s.startTime)
}
if s.endTime != nil {
r.SetQuery("endTime", *s.endTime)
}
if s.limit != nil {
r.SetQuery("limit", *s.limit)
}
res = new(Snapshot)
if err = s.c.CallAPI(ctx, r, res, opts...); err != nil {
return &Snapshot{}, err
}
return res, nil
}
// Snapshot define snapshot
type Snapshot struct {
Code int `json:"code"`
Msg string `json:"msg"`
Snapshot []*SnapshotVos `json:"snapshotVos"`
}
// SnapshotVos define content of a snapshot
type SnapshotVos struct {
Data *SnapshotData `json:"data"`
Type string `json:"type"`
UpdateTime int64 `json:"updateTime"`
}
// SnapshotData define content of a snapshot
type SnapshotData struct {
MarginLevel string `json:"marginLevel"`
TotalAssetOfBtc string `json:"totalAssetOfBtc"`
TotalLiabilityOfBtc string `json:"totalLiabilityOfBtc"`
TotalNetAssetOfBtc string `json:"totalNetAssetOfBtc"`
Balances []*SnapshotBalances `json:"balances"`
UserAssets []*SnapshotUserAssets `json:"userAssets"`
Assets []*SnapshotAssets `json:"assets"`
Positions []*SnapshotPositions `json:"position"`
}
// SnapshotBalances define snapshot balances
type SnapshotBalances struct {
Asset string `json:"asset"`
Free string `json:"free"`
Locked string `json:"locked"`
}
// SnapshotUserAssets define snapshot user assets
type SnapshotUserAssets struct {
Asset string `json:"asset"`
Borrowed string `json:"borrowed"`
Free string `json:"free"`
Interest string `json:"interest"`
Locked string `json:"locked"`
NetAsset string `json:"netAsset"`
}
// SnapshotAssets define snapshot assets
type SnapshotAssets struct {
Asset string `json:"asset"`
MarginBalance string `json:"marginBalance"`
WalletBalance string `json:"walletBalance"`
}
// SnapshotPositions define snapshot positions
type SnapshotPositions struct {
EntryPrice string `json:"entryPrice"`
MarkPrice string `json:"markPrice"`
PositionAmt string `json:"positionAmt"`
Symbol string `json:"symbol"`
UnRealizedProfit string `json:"unRealizedProfit"`
}
// APIRestrictionService query permission from binance.
type APIRestrictionService struct {
c *Client
}
// Do send Request
func (s *APIRestrictionService) Do(ctx context.Context, opts ...common.RequestOption) (
res *APIRestriction, err error,
) {
r := common.NewGetRequestSigned("/sapi/v1/account/apiRestrictions")
res = new(APIRestriction)
if err = s.c.CallAPI(ctx, r, res, opts...); err != nil {
return nil, err
}
return res, nil
}
type APIRestriction struct {
IPRestrict bool `json:"ipRestrict"`
CreateTime uint64 `json:"createTime"`
EnableWithdrawals bool `json:"enableWithdrawals"`
EnableInternalTransfer bool `json:"enableInternalTransfer"`
PermitsUniversalTransfer bool `json:"permitsUniversalTransfer"`
EnableVanillaOptions bool `json:"enableVanillaOptions"`
EnableReading bool `json:"enableReading"`
EnableFutures bool `json:"enableFutures"`
EnableMargin bool `json:"enableMargin"`
EnableSpotAndMarginTrading bool `json:"enableSpotAndMarginTrading"`
TradingAuthorityExpirationTime uint64 `json:"tradingAuthorityExpirationTime"`
}