forked from adshao/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_service.go
106 lines (97 loc) · 3.47 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
package futures
import (
"context"
"encoding/json"
)
// GetBalanceService get account balance
type GetBalanceService struct {
c *Client
}
// Do send request
func (s *GetBalanceService) Do(ctx context.Context, opts ...RequestOption) (res []*Balance, err error) {
r := &request{
method: "GET",
endpoint: "/fapi/v1/balance",
secType: secTypeSigned,
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return []*Balance{}, err
}
res = make([]*Balance, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return []*Balance{}, err
}
return res, nil
}
// Balance define user balance of your account
type Balance struct {
AccountAlias string `json:"accountAlias"`
Asset string `json:"asset"`
Balance string `json:"balance"`
WithdrawAvailable string `json:"withdrawAvailable"`
}
// GetAccountService get account info
type GetAccountService struct {
c *Client
}
// Do send request
func (s *GetAccountService) Do(ctx context.Context, opts ...RequestOption) (res *Account, err error) {
r := &request{
method: "GET",
endpoint: "/fapi/v1/account",
secType: secTypeSigned,
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(Account)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// Account define account info
type Account struct {
Assets []*AccountAsset `json:"assets"`
CanDeposit bool `json:"canDeposit"`
CanTrade bool `json:"canTrade"`
CanWithdraw bool `json:"canWithdraw"`
FeeTier int `json:"feeTier"`
MaxWithdrawAmount string `json:"maxWithdrawAmount"`
Positions []*AccountPosition `json:"positions"`
TotalInitialMargin string `json:"totalInitialMargin"`
TotalMaintMargin string `json:"totalMaintMargin"`
TotalMarginBalance string `json:"totalMarginBalance"`
TotalOpenOrderInitialMargin string `json:"totalOpenOrderInitialMargin"`
TotalPositionInitialMargin string `json:"totalPositionInitialMargin"`
TotalUnrealizedProfit string `json:"totalUnrealizedProfit"`
TotalWalletBalance string `json:"totalWalletBalance"`
UpdateTime int64 `json:"updateTime"`
}
// AccountAsset define account asset
type AccountAsset struct {
Asset string `json:"asset"`
InitialMargin string `json:"initialMargin"`
MaintMargin string `json:"maintMargin"`
MarginBalance string `json:"marginBalance"`
MaxWithdrawAmount string `json:"maxWithdrawAmount"`
OpenOrderInitialMargin string `json:"openOrderInitialMargin"`
PositionInitialMargin string `json:"positionInitialMargin"`
UnrealizedProfit string `json:"unrealizedProfit"`
WalletBalance string `json:"walletBalance"`
}
// AccountPosition define account position
type AccountPosition struct {
Isolated bool `json:"isolated"`
Leverage string `json:"leverage"`
InitialMargin string `json:"initialMargin"`
MaintMargin string `json:"maintMargin"`
OpenOrderInitialMargin string `json:"openOrderInitialMargin"`
PositionInitialMargin string `json:"positionInitialMargin"`
Symbol string `json:"symbol"`
UnrealizedProfit string `json:"unrealizedProfit"`
}