-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
v5_ws_trade_order.go
67 lines (59 loc) · 1.57 KB
/
v5_ws_trade_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
package bybit
import (
"encoding/json"
"strconv"
"time"
"github.com/google/uuid"
"github.com/gorilla/websocket"
)
// CreateOrder :
func (s *V5WebsocketTradeService) CreateOrder(orders []*V5CreateOrderParam) error {
timestamp := strconv.FormatInt(time.Now().UnixMilli(), 10)
headers := make(map[string]string)
headers["X-BAPI-TIMESTAMP"] = timestamp
headers["X-BAPI-RECV-WINDOW"] = "8000"
param := struct {
ReqId string `json:"reqId"`
Headers map[string]string `json:"header"`
Op string `json:"op"`
Args []*V5CreateOrderParam `json:"args"`
}{
ReqId: uuid.New().String(),
Headers: headers,
Op: "order.create",
Args: orders,
}
buf, err := json.Marshal(param)
if err != nil {
return err
}
if err := s.writeMessage(websocket.TextMessage, buf); err != nil {
return err
}
return nil
}
func (s *V5WebsocketTradeService) CancelOrder(orders []*V5CancelOrderParam) error {
timestamp := strconv.FormatInt(time.Now().UnixMilli(), 10)
headers := make(map[string]string)
headers["X-BAPI-TIMESTAMP"] = timestamp
headers["X-BAPI-RECV-WINDOW"] = "8000"
param := struct {
ReqId string `json:"reqId"`
Headers map[string]string `json:"header"`
Op string `json:"op"`
Args []*V5CancelOrderParam `json:"args"`
}{
ReqId: uuid.New().String(),
Headers: headers,
Op: "order.cancel",
Args: orders,
}
buf, err := json.Marshal(param)
if err != nil {
return err
}
if err := s.writeMessage(websocket.TextMessage, buf); err != nil {
return err
}
return nil
}