forked from adshao/go-binance
/
position_risk.go
66 lines (60 loc) · 1.68 KB
/
position_risk.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
package delivery
import (
"context"
"encoding/json"
)
// GetPositionRiskService get account balance
type GetPositionRiskService struct {
c *Client
pair *string
marginAsset *string
}
// MarginAsset set margin asset
func (s *GetPositionRiskService) MarginAsset(marginAsset string) *GetPositionRiskService {
s.marginAsset = &marginAsset
return s
}
// Pair set pair
func (s *GetPositionRiskService) Pair(pair string) *GetPositionRiskService {
s.pair = &pair
return s
}
// Do send request
func (s *GetPositionRiskService) Do(ctx context.Context, opts ...RequestOption) (res []*PositionRisk, err error) {
r := &request{
method: "GET",
endpoint: "/dapi/v1/positionRisk",
secType: secTypeSigned,
}
if s.marginAsset != nil {
r.setParam("marginAsset", *s.marginAsset)
}
if s.pair != nil {
r.setParam("pair", *s.pair)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return []*PositionRisk{}, err
}
res = make([]*PositionRisk, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return []*PositionRisk{}, err
}
return res, nil
}
// PositionRisk define position risk info
type PositionRisk struct {
Symbol string `json:"symbol"`
PositionAmt string `json:"positionAmt"`
EntryPrice string `json:"entryPrice"`
MarkPrice string `json:"markPrice"`
UnRealizedProfit string `json:"unRealizedProfit"`
LiquidationPrice string `json:"liquidationPrice"`
Leverage string `json:"leverage"`
MaxQuantity string `json:"maxQty"`
MarginType string `json:"marginType"`
IsolatedMargin string `json:"isolatedMargin"`
IsAutoAddMargin string `json:"isAutoAddMargin"`
PositionSide string `json:"positionSide"`
}