forked from hirokisan/bybit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v5_client_web_socket_service.go
57 lines (51 loc) · 2.07 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
package bybit
import (
"github.com/gorilla/websocket"
)
// V5WebsocketServiceI :
type V5WebsocketServiceI interface {
Public(CategoryV5) (V5WebsocketPublicService, error)
Private() (V5WebsocketPrivateService, 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: 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
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
}
// V5 :
func (c *WebSocketClient) V5() *V5WebsocketService {
return &V5WebsocketService{c}
}