@@ -9,16 +9,16 @@ import (
99 "time"
1010
1111 "github.com/google/uuid"
12- "github.com/gorilla/websocket"
1312 "github.com/nbitslabs/nOracle/pkg/connector"
13+ "github.com/recws-org/recws"
1414)
1515
1616const Name = "bybit"
1717
1818type Connector struct {
1919 ctx context.Context
2020 pairs []string
21- ws * websocket. Conn
21+ ws * recws. RecConn
2222}
2323
2424func NewConnector (ctx context.Context , wsUrl string , pairs []string ) (connector.ExchangeConnector , error ) {
@@ -31,10 +31,10 @@ func NewConnector(ctx context.Context, wsUrl string, pairs []string) (connector.
3131
3232 wsUrlWithChannels := fmt .Sprintf ("%s/v5/public/spot" , wsUrl )
3333
34- ws , _ , err := websocket .DefaultDialer .Dial (wsUrlWithChannels , nil )
35- if err != nil {
36- return nil , err
34+ ws := & recws.RecConn {
35+ KeepAliveTimeout : 10 * time .Second ,
3736 }
37+ ws .Dial (wsUrlWithChannels , nil )
3838
3939 args := make ([]string , 0 , len (pairs ))
4040 for _ , pair := range pairs {
@@ -51,23 +51,19 @@ func NewConnector(ctx context.Context, wsUrl string, pairs []string) (connector.
5151 return nil , err
5252 }
5353
54- connector := & Connector {
54+ return & Connector {
5555 ctx : ctx ,
5656 pairs : pairs ,
5757 ws : ws ,
58- }
59-
60- // We send heart beat every 10 seconds
61- connector .sendHeartbeat ()
62- return connector , nil
58+ }, nil
6359}
6460
6561func (c * Connector ) Close () error {
6662 if c .ctx != nil {
6763 c .ctx .Done ()
6864 }
6965 if c .ws != nil {
70- return c .ws .Close ()
66+ c .ws .Close ()
7167 }
7268
7369 return nil
@@ -112,20 +108,3 @@ func (c *Connector) Name() string {
112108func (c * Connector ) Tickers () []string {
113109 return c .pairs
114110}
115-
116- func (c * Connector ) sendHeartbeat () {
117- req := SubscriptionMessage {
118- Op : "ping" ,
119- ReqId : "100001" ,
120- }
121-
122- // We send heart beat every 10 seconds
123- go func () {
124- for {
125- time .Sleep (10 * time .Second )
126- if err := c .ws .WriteJSON (req ); err != nil {
127- slog .Warn ("error sending heartbeat" , "error" , err , "exchange" , Name )
128- }
129- }
130- }()
131- }
0 commit comments