Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion v2/delivery/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ type ErrHandler func(err error)
type WsConfig struct {
Endpoint string
Proxy *string
Header http.Header
}

func newWsConfig(endpoint string) *WsConfig {
return &WsConfig{
Endpoint: endpoint,
Proxy: getWsProxyUrl(),
Header: Header,
}
}

Expand All @@ -42,7 +44,7 @@ var wsServe = func(cfg *WsConfig, handler WsHandler, errHandler ErrHandler) (don
EnableCompression: true,
}

c, _, err := Dialer.Dial(cfg.Endpoint, nil)
c, _, err := Dialer.Dial(cfg.Endpoint, cfg.Header)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions v2/delivery/websocket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"time"
Expand All @@ -25,6 +26,7 @@ var (
// UseTestnet switch all the WS streams from production to the testnet
UseTestnet = false
ProxyUrl = ""
Header = make(http.Header)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does using global variables make maintenance difficult? For example, if a service modifies this variable, then all new websocket dialup connections will use this variable, which may cause an error.

)

// getWsEndpoint return the base endpoint of the WS according the UseTestnet flag
Expand Down
6 changes: 4 additions & 2 deletions v2/futures/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ type ErrHandler func(err error)
type WsConfig struct {
Endpoint string
Proxy *string
Header http.Header
}

func newWsConfig(endpoint string) *WsConfig {
return &WsConfig{
Endpoint: endpoint,
Proxy: getWsProxyUrl(),
Header: Header,
}
}

Expand All @@ -42,7 +44,7 @@ var wsServe = func(cfg *WsConfig, handler WsHandler, errHandler ErrHandler) (don
EnableCompression: true,
}

c, _, err := Dialer.Dial(cfg.Endpoint, nil)
c, _, err := Dialer.Dial(cfg.Endpoint, cfg.Header)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -132,7 +134,7 @@ var WsGetReadWriteConnection = func(cfg *WsConfig) (*websocket.Conn, error) {
EnableCompression: false,
}

c, _, err := Dialer.Dial(cfg.Endpoint, nil)
c, _, err := Dialer.Dial(cfg.Endpoint, cfg.Header)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions v2/futures/websocket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strings"
"time"

Expand Down Expand Up @@ -34,6 +35,7 @@ var (
// using for websocket API (read/write)
WebsocketTimeoutReadWriteConnection = time.Second * 10
ProxyUrl = ""
Header = make(http.Header)
)

func getWsProxyUrl() *string {
Expand Down
2 changes: 2 additions & 0 deletions v2/options/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ type ErrHandler func(err error)
type WsConfig struct {
Endpoint string
Proxy *string
Header http.Header
}

func newWsConfig(endpoint string) *WsConfig {
return &WsConfig{
Endpoint: endpoint,
Proxy: getWsProxyUrl(),
Header: Header,
}
}

Expand Down
2 changes: 2 additions & 0 deletions v2/options/websocket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strings"
"time"
)
Expand All @@ -27,6 +28,7 @@ var (
UseTestnet = false

ProxyUrl = ""
Header = make(http.Header)
)

// getWsEndpoint return the base endpoint of the WS according the UseTestnet flag
Expand Down
2 changes: 2 additions & 0 deletions v2/portfolio/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ type ErrHandler func(err error)
type WsConfig struct {
Endpoint string
Proxy *string
Header http.Header
}

func newWsConfig(endpoint string) *WsConfig {
return &WsConfig{
Endpoint: endpoint,
Proxy: getWsProxyUrl(),
Header: Header,
}
}

Expand Down
2 changes: 2 additions & 0 deletions v2/portfolio/websocket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package portfolio
import (
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/bitly/go-simplejson"
Expand All @@ -24,6 +25,7 @@ var (
// using for websocket API (read/write)
WebsocketTimeoutReadWriteConnection = time.Second * 10
ProxyUrl = ""
Header = make(http.Header)
)

func getWsProxyUrl() *string {
Expand Down
6 changes: 4 additions & 2 deletions v2/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ type ErrHandler func(err error)
type WsConfig struct {
Endpoint string
Proxy *string
Header http.Header
}

func newWsConfig(endpoint string) *WsConfig {
return &WsConfig{
Endpoint: endpoint,
Proxy: getWsProxyUrl(),
Header: Header,
}
}

Expand All @@ -42,7 +44,7 @@ var wsServe = func(cfg *WsConfig, handler WsHandler, errHandler ErrHandler) (don
EnableCompression: true,
}

c, _, err := Dialer.Dial(cfg.Endpoint, nil)
c, _, err := Dialer.Dial(cfg.Endpoint, cfg.Header)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -136,7 +138,7 @@ var WsGetReadWriteConnection = func(cfg *WsConfig) (*websocket.Conn, error) {
EnableCompression: false,
}

c, _, err := Dialer.Dial(cfg.Endpoint, nil)
c, _, err := Dialer.Dial(cfg.Endpoint, cfg.Header)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions v2/websocket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package binance
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"time"

Expand All @@ -28,6 +29,7 @@ var (
// using for websocket API (read/write)
WebsocketTimeoutReadWriteConnection = time.Second * 10
ProxyUrl = ""
Header = make(http.Header)
)

func getWsProxyUrl() *string {
Expand Down