forked from hirokisan/bybit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv5_client_web_socket_service.go
89 lines (82 loc) · 2.77 KB
/
v5_client_web_socket_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
package bybit
import (
"github.com/gorilla/websocket"
)
// V5WebsocketServiceI :
type V5WebsocketServiceI interface {
Public(CategoryV5) (V5WebsocketPublicService, error)
Private() (V5WebsocketPrivateService, error)
Trade() (V5WebsocketTradeService, error)
}
// V5WebsocketService :
type V5WebsocketService struct {
client *WebSocketClient
}
// Public :
func (s *V5WebsocketService) Public(category CategoryV5) (V5WebsocketPublicServiceI, error) {
url := s.client.baseURL + V5WebsocketPublicPathFor(category)
var c *websocket.Conn
var err error
if s.client.dialer != nil {
c, _, err = s.client.dialer.Dial(url, nil)
} else {
c, _, err = websocket.DefaultDialer.Dial(url, nil)
}
if err != nil {
return nil, err
}
return &V5WebsocketPublicService{
client: s.client,
connection: c,
category: category,
paramOrderBookMap: make(map[V5WebsocketPublicOrderBookParamKey]func(V5WebsocketPublicOrderBookResponse) error),
paramKlineMap: make(map[V5WebsocketPublicKlineParamKey]func(V5WebsocketPublicKlineResponse) error),
paramTickerMap: make(map[V5WebsocketPublicTickerParamKey]func(V5WebsocketPublicTickerResponse) error),
paramTradeMap: make(map[V5WebsocketPublicTradeParamKey]func(V5WebsocketPublicTradeResponse) error),
paramLiquidationMap: make(map[V5WebsocketPublicLiquidationParamKey]func(V5WebsocketPublicLiquidationResponse) error),
}, nil
}
// Private :
func (s *V5WebsocketService) Private() (V5WebsocketPrivateServiceI, error) {
url := s.client.baseURL + V5WebsocketPrivatePath
var c *websocket.Conn
var err error
if s.client.dialer != nil {
c, _, err = s.client.dialer.Dial(url, nil)
} else {
c, _, err = websocket.DefaultDialer.Dial(url, nil)
}
if err != nil {
return nil, err
}
return &V5WebsocketPrivateService{
client: s.client,
connection: c,
paramOrderMap: make(map[V5WebsocketPrivateParamKey]func(V5WebsocketPrivateOrderResponse) error),
paramPositionMap: make(map[V5WebsocketPrivateParamKey]func(V5WebsocketPrivatePositionResponse) error),
paramExecutionMap: make(map[V5WebsocketPrivateParamKey]func(V5WebsocketPrivateExecutionResponse) error),
paramWalletMap: make(map[V5WebsocketPrivateParamKey]func(V5WebsocketPrivateWalletResponse) error),
}, nil
}
// Trade :
func (s *V5WebsocketService) Trade() (V5WebsocketTradeServiceI, error) {
url := s.client.baseURL + V5WebsocketTradePath
var c *websocket.Conn
var err error
if s.client.dialer != nil {
c, _, err = s.client.dialer.Dial(url, nil)
} else {
c, _, err = websocket.DefaultDialer.Dial(url, nil)
}
if err != nil {
return nil, err
}
return &V5WebsocketTradeService{
client: s.client,
connection: c,
}, nil
}
// V5 :
func (c *WebSocketClient) V5() *V5WebsocketService {
return &V5WebsocketService{c}
}