-
Notifications
You must be signed in to change notification settings - Fork 38
/
place_order.go
245 lines (219 loc) · 5.15 KB
/
place_order.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package bybit_connector
import (
"context"
"net/http"
)
type Order struct {
c *Client
category string
symbol string
isLeverage *int
side string
orderType string
qty string
price *string
triggerDirection *int
orderFilter *string
triggerPrice *string
triggerBy *string
orderIv *string
timeInForce *string
positionIdx *int
orderLinkId *string
takeProfit *string
stopLoss *string
tpTriggerBy *string
slTriggerBy *string
reduceOnly *bool
closeOnTrigger *bool
smpType *string
mmp *bool
tpslMode *string
tpLimitPrice *string
slLimitPrice *string
tpOrderType *string
slOrderType *string
}
func (order *Order) TimeInForce(tif string) *Order {
order.timeInForce = &tif
return order
}
func (order *Order) IsLeverage(isLeverage int) *Order {
order.isLeverage = &isLeverage
return order
}
func (order *Order) TriggerPrice(triggerPrice string) *Order {
order.triggerPrice = &triggerPrice
return order
}
func (order *Order) OrderLinkId(orderLinkId string) *Order {
order.orderLinkId = &orderLinkId
return order
}
func (order *Order) Price(price string) *Order {
order.price = &price
return order
}
func (order *Order) TriggerDirection(direction int) *Order {
order.triggerDirection = &direction
return order
}
func (order *Order) OrderFilter(filter string) *Order {
order.orderFilter = &filter
return order
}
func (order *Order) TriggerBy(triggerBy string) *Order {
order.triggerBy = &triggerBy
return order
}
func (order *Order) OrderIv(iv string) *Order {
order.orderIv = &iv
return order
}
func (order *Order) PositionIdx(idx int) *Order {
order.positionIdx = &idx
return order
}
func (order *Order) TakeProfit(profit string) *Order {
order.takeProfit = &profit
return order
}
func (order *Order) StopLoss(loss string) *Order {
order.stopLoss = &loss
return order
}
func (order *Order) TpTriggerBy(triggerBy string) *Order {
order.tpTriggerBy = &triggerBy
return order
}
func (order *Order) SlTriggerBy(triggerBy string) *Order {
order.slTriggerBy = &triggerBy
return order
}
func (order *Order) ReduceOnly(reduce bool) *Order {
order.reduceOnly = &reduce
return order
}
func (order *Order) CloseOnTrigger(close bool) *Order {
order.closeOnTrigger = &close
return order
}
func (order *Order) SmpType(smp string) *Order {
order.smpType = &smp
return order
}
func (order *Order) Mmp(mmp bool) *Order {
order.mmp = &mmp
return order
}
func (order *Order) TpslMode(mode string) *Order {
order.tpslMode = &mode
return order
}
func (order *Order) TpLimitPrice(price string) *Order {
order.tpLimitPrice = &price
return order
}
func (order *Order) SlLimitPrice(price string) *Order {
order.slLimitPrice = &price
return order
}
func (order *Order) TpOrderType(orderType string) *Order {
order.tpOrderType = &orderType
return order
}
func (order *Order) SlOrderType(orderType string) *Order {
order.slOrderType = &orderType
return order
}
func (order *Order) Do(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) {
r := &request{
method: http.MethodPost,
endpoint: "/v5/order/create",
secType: secTypeSigned,
}
m := params{
"category": order.category,
"symbol": order.symbol,
"side": order.side,
"orderType": order.orderType,
"qty": order.qty,
}
if order.price != nil {
m["price"] = *order.price
}
if order.triggerDirection != nil {
m["triggerDirection"] = *order.triggerDirection
}
if order.orderFilter != nil {
m["orderFilter"] = *order.orderFilter
}
if order.triggerPrice != nil {
m["triggerPrice"] = *order.triggerPrice
}
if order.triggerBy != nil {
m["triggerBy"] = *order.triggerBy
}
if order.orderIv != nil {
m["orderIv"] = *order.orderIv
}
if order.timeInForce != nil {
m["timeInForce"] = *order.timeInForce
}
if order.positionIdx != nil {
m["positionIdx"] = *order.positionIdx
}
if order.orderLinkId != nil {
m["orderLinkId"] = *order.orderLinkId
}
if order.takeProfit != nil {
m["takeProfit"] = *order.takeProfit
}
if order.stopLoss != nil {
m["stopLoss"] = *order.stopLoss
}
if order.tpTriggerBy != nil {
m["tpTriggerBy"] = *order.tpTriggerBy
}
if order.slTriggerBy != nil {
m["slTriggerBy"] = *order.slTriggerBy
}
if order.reduceOnly != nil {
m["reduceOnly"] = *order.reduceOnly
}
if order.closeOnTrigger != nil {
m["closeOnTrigger"] = *order.closeOnTrigger
}
if order.smpType != nil {
m["smpType"] = *order.smpType
}
if order.mmp != nil {
m["mmp"] = *order.mmp
}
if order.tpslMode != nil {
m["tpslMode"] = *order.tpslMode
}
if order.tpLimitPrice != nil {
m["tpLimitPrice"] = *order.tpLimitPrice
}
if order.slLimitPrice != nil {
m["slLimitPrice"] = *order.slLimitPrice
}
if order.tpOrderType != nil {
m["tpOrderType"] = *order.tpOrderType
}
if order.slOrderType != nil {
m["slOrderType"] = *order.slOrderType
}
r.setParams(m)
data, err := order.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(ServerResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}