-
Notifications
You must be signed in to change notification settings - Fork 0
/
positions_service.go
65 lines (54 loc) · 1.65 KB
/
positions_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
package bingx
import (
"context"
"encoding/json"
"net/http"
)
type GetOpenPositionsService struct {
c *Client
symbol string
}
func (s *GetOpenPositionsService) Symbol(symbol string) *GetOpenPositionsService {
s.symbol = symbol
return s
}
type Position struct {
Symbol string `json:"symbol"`
PositionId string `json:"positionId"`
PositionSide string `json:"positionSide"`
Isolated bool `json:"isolated"`
PositionAmt string `json:"positionAmt"`
AvailableAmt string `json:"availableAmt"`
UnrealizedProfit string `json:"unrealizedProfit"`
RealisedProfit string `json:"realisedProfit"`
InitialMargin string `json:"initialMargin"`
AvgPrice string `json:"avgPrice"`
LiquidationPrice float64 `json:"liquidationPrice"`
Leverage int `json:"leverage"`
PositionValue string `json:"positionValue"`
MarkPrice string `json:"markPrice"`
RiskRate string `json:"riskRate"`
MaxMarginReduction string `json:"maxMarginReduction"`
PnlRatio string `json:"pnlRatio"`
}
func (s *GetOpenPositionsService) Do(ctx context.Context, opts ...RequestOption) (res *[]Position, err error) {
r := &request{method: http.MethodGet, endpoint: "/openApi/swap/v2/user/positions"}
if s.symbol != "" {
r.addParam("symbol", s.symbol)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
resp := new(struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data *[]Position `json:"data"`
})
err = json.Unmarshal(data, &resp)
res = resp.Data
if err != nil {
return nil, err
}
return res, nil
}