forked from hirokisan/bybit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v5_client_web_socket_service.go
71 lines (64 loc) · 2.45 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
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)
c, _, err := websocket.DefaultDialer.Dial(url, nil)
if err != nil {
return nil, err
}
return &V5WebsocketPublicService{
client: s.client,
connection: c,
category: category,
paramOrderBookMap: NewPublicWsHandlersMap[V5WebsocketPublicOrderBookParamKey, V5WebsocketPublicOrderBookResponse](),
paramKlineMap: NewPublicWsHandlersMap[V5WebsocketPublicKlineParamKey, V5WebsocketPublicKlineResponse](),
paramTickerMap: NewPublicWsHandlersMap[V5WebsocketPublicTickerParamKey, V5WebsocketPublicTickerResponse](),
paramTradeMap: NewPublicWsHandlersMap[V5WebsocketPublicTradeParamKey, V5WebsocketPublicTradeResponse](),
paramLiquidationMap: NewPublicWsHandlersMap[V5WebsocketPublicLiquidationParamKey, V5WebsocketPublicLiquidationResponse](),
}, nil
}
// Private :
func (s *V5WebsocketService) Private() (V5WebsocketPrivateServiceI, error) {
url := s.client.baseURL + V5WebsocketPrivatePath
c, _, err := websocket.DefaultDialer.Dial(url, nil)
if err != nil {
return nil, err
}
return &V5WebsocketPrivateService{
client: s.client,
connection: c,
paramOrderMap: NewPublicWsHandlersMap[V5WebsocketPrivateParamKey, V5WebsocketPrivateOrderResponse](),
paramPositionMap: NewPublicWsHandlersMap[V5WebsocketPrivateParamKey, V5WebsocketPrivatePositionResponse](),
paramExecutionMap: NewPublicWsHandlersMap[V5WebsocketPrivateParamKey, V5WebsocketPrivateExecutionResponse](),
paramWalletMap: NewPublicWsHandlersMap[V5WebsocketPrivateParamKey, V5WebsocketPrivateWalletResponse](),
}, nil
}
// Trade :
func (s *V5WebsocketService) Trade() (V5WebsocketTradeServiceI, error) {
url := s.client.baseURL + V5WebsocketTradePath
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}
}