Skip to content

Commit

Permalink
Merge pull request #163 from xiaojun207/dev
Browse files Browse the repository at this point in the history
修复BinanceWs.SubscribeDepth方法,深度数据解析错误bug,导致没有深度数据
  • Loading branch information
nntaoli authored May 24, 2020
2 parents be8fbd2 + fe0a206 commit 1238cca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 10 additions & 10 deletions binance/BinanceWs.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (bnWs *BinanceWs) SetCallbacks(
bnWs.klineCallback = klineCallback
}

func (bnWs *BinanceWs) subscribe(endpoint string, handle func(msg []byte) error) {
func (bnWs *BinanceWs) Subscribe(endpoint string, handle func(msg []byte) error) {
wsConn := NewWsBuilder().
WsUrl(endpoint).
AutoReconnect().
Expand Down Expand Up @@ -121,9 +121,9 @@ func (bnWs *BinanceWs) SubscribeDepth(pair CurrencyPair, size int) error {

handle := func(msg []byte) error {
rawDepth := struct {
LastUpdateID int64 `json:"lastUpdateId"`
Bids [][]interface{} `json:"bids"`
Asks [][]interface{} `json:"asks"`
LastUpdateID int64 `json:"T"`
Bids [][]interface{} `json:"b"`
Asks [][]interface{} `json:"a"`
}{}

err := json.Unmarshal(msg, &rawDepth)
Expand All @@ -137,7 +137,7 @@ func (bnWs *BinanceWs) SubscribeDepth(pair CurrencyPair, size int) error {
bnWs.depthCallback(depth)
return nil
}
bnWs.subscribe(endpoint, handle)
bnWs.Subscribe(endpoint, handle)
return nil
}

Expand Down Expand Up @@ -170,7 +170,7 @@ func (bnWs *BinanceWs) SubscribeTicker(pair CurrencyPair) error {
return errors.New("unknown message " + msgType)
}
}
bnWs.subscribe(endpoint, handle)
bnWs.Subscribe(endpoint, handle)
return nil
}

Expand Down Expand Up @@ -217,7 +217,7 @@ func (bnWs *BinanceWs) SubscribeTrade(pair CurrencyPair) error {
return errors.New("unknown message " + msgType)
}
}
bnWs.subscribe(endpoint, handle)
bnWs.Subscribe(endpoint, handle)
return nil
}

Expand Down Expand Up @@ -256,7 +256,7 @@ func (bnWs *BinanceWs) SubscribeKline(pair CurrencyPair, period int) error {
return errors.New("unknown message " + msgType)
}
}
bnWs.subscribe(endpoint, handle)
bnWs.Subscribe(endpoint, handle)
return nil
}

Expand Down Expand Up @@ -341,7 +341,7 @@ func (bnWs *BinanceWs) SubscribeAggTrade(pair CurrencyPair, tradeCallback func(*
return errors.New("unknown message " + msgType)
}
}
bnWs.subscribe(endpoint, handle)
bnWs.Subscribe(endpoint, handle)
return nil
}

Expand Down Expand Up @@ -380,7 +380,7 @@ func (bnWs *BinanceWs) SubscribeDiffDepth(pair CurrencyPair, depthCallback func(
depthCallback((*Depth)(unsafe.Pointer(diffDepth)))
return nil
}
bnWs.subscribe(endpoint, handle)
bnWs.Subscribe(endpoint, handle)
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions binance/BinanceWs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var bnWs = NewBinanceWs()

func init() {
bnWs.proxyUrl = "socks5://127.0.0.1:1080"
//bnWs.SetBaseUrl("wss://fstream.binancezh.com/ws")
//bnWs.SetCombinedBaseURL("wss://fstream.binancezh.com/stream?streams=")
bnWs.SetCallbacks(printfTicker, printfDepth, printfTrade, printfKline)
}

Expand Down

0 comments on commit 1238cca

Please sign in to comment.