diff --git a/ws/ws.go b/ws/ws.go index d490157..4aac4bf 100644 --- a/ws/ws.go +++ b/ws/ws.go @@ -12,6 +12,8 @@ import ( "github.com/gorilla/websocket" "github.com/tidwall/gjson" "log" + "net/http" + "net/url" "strings" "sync" "time" @@ -54,6 +56,7 @@ var ( type Configuration struct { Addr string `json:"addr"` + Proxy string `json:"proxy"` // http://127.0.0.1:1081 ApiKey string `json:"api_key"` SecretKey string `json:"secret_key"` AutoReconnect bool `json:"auto_reconnect"` @@ -81,10 +84,18 @@ func New(config *Configuration) *ByBitWS { orderBookLocals: make(map[string]*OrderBookLocal), } b.ctx, b.cancel = context.WithCancel(context.Background()) + b.conn = &recws.RecConn{ KeepAliveTimeout: 60 * time.Second, NonVerbose: true, } + if config.Proxy != "" { + proxy, err := url.Parse(config.Proxy) + if err != nil { + return nil + } + b.conn.Proxy = http.ProxyURL(proxy) + } b.conn.SubscribeHandler = b.subscribeHandler return b } diff --git a/ws/ws_test.go b/ws/ws_test.go index 5192363..f552ad2 100644 --- a/ws/ws_test.go +++ b/ws/ws_test.go @@ -59,8 +59,9 @@ func handleOrder(data []*Order) { func TestOrderBookL2(t *testing.T) { cfg := &Configuration{ Addr: HostTestnet, - ApiKey: "6IASD6KDBdunn5qLpT", - SecretKey: "nXjZMUiB3aMiPaQ9EUKYFloYNd0zM39RjRWF", + Proxy: "http://127.0.0.1:1081", + ApiKey: "rwEwhfC6mDFYIGfcyb", + SecretKey: "yfNJSzGapfFwbJyvguAyVXLJSIOCIegBg42Z", AutoReconnect: true, DebugMode: true, }