-
Notifications
You must be signed in to change notification settings - Fork 3
/
position_service.go
126 lines (112 loc) · 2.7 KB
/
position_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
package phemex
import (
"context"
"encoding/json"
"github.com/Krisa/go-phemex/common"
)
// PositionsLeverageService cancel an order
type PositionsLeverageService struct {
c *Client
symbol string
leverage *int64
leverageEr *int64
}
// Symbol set symbol
func (s *PositionsLeverageService) Symbol(symbol string) *PositionsLeverageService {
s.symbol = symbol
return s
}
// Leverage set leverage
func (s *PositionsLeverageService) Leverage(leverage int64) *PositionsLeverageService {
s.leverage = &leverage
return s
}
// LeverageEr set leverageEr
func (s *PositionsLeverageService) LeverageEr(leverageEr int64) *PositionsLeverageService {
s.leverageEr = &leverageEr
return s
}
// Do send request
func (s *PositionsLeverageService) Do(ctx context.Context, opts ...RequestOption) (res *BaseResponse, err error) {
r := &request{
method: "PUT",
endpoint: "/positions/leverage",
secType: secTypeSigned,
}
r.setParam("symbol", s.symbol)
if s.leverage != nil {
r.setParam("leverage", *s.leverage)
}
if s.leverageEr != nil {
r.setParam("leverageEr", *s.leverageEr)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
resp := new(BaseResponse)
err = json.Unmarshal(data, &resp)
if err != nil {
return nil, err
}
if resp.Code > 0 {
return nil, &common.APIError{
Code: resp.Code,
Message: resp.Msg,
}
}
return resp, nil
}
// PositionsAssignService cancel an order
type PositionsAssignService struct {
c *Client
symbol string
posBalance *float64
posBalanceEv *int64
}
// Symbol set symbol
func (s *PositionsAssignService) Symbol(symbol string) *PositionsAssignService {
s.symbol = symbol
return s
}
// PosBalance set posBalance
func (s *PositionsAssignService) PosBalance(posBalance float64) *PositionsAssignService {
s.posBalance = &posBalance
return s
}
// PosBalanceEr set posBalanceEv
func (s *PositionsAssignService) PosBalanceEr(posBalanceEv int64) *PositionsAssignService {
s.posBalanceEv = &posBalanceEv
return s
}
// Do send request
func (s *PositionsAssignService) Do(ctx context.Context, opts ...RequestOption) (res *BaseResponse, err error) {
r := &request{
method: "POST",
endpoint: "/positions/assign",
secType: secTypeSigned,
}
r.setParam("symbol", s.symbol)
if s.posBalance != nil {
r.setParam("posBalance", *s.posBalance)
}
if s.posBalanceEv != nil {
r.setParam("posBalanceEv", *s.posBalanceEv)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
resp := new(BaseResponse)
err = json.Unmarshal(data, &resp)
if err != nil {
return nil, err
}
if resp.Code > 0 {
return nil, &common.APIError{
Code: resp.Code,
Message: resp.Msg,
}
}
return resp, nil
}