Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
f0cii committed Feb 6, 2022
1 parent e1e79d9 commit 813e4bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions ws/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/gorilla/websocket"
"github.com/tidwall/gjson"
"log"
"net/http"
"net/url"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions ws/ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 813e4bc

Please sign in to comment.