Skip to content

Commit

Permalink
add WsCombinedDepthServe100Ms
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-milan committed Jan 20, 2022
1 parent afa0336 commit 03a81e7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
13 changes: 13 additions & 0 deletions v2/websocket_service.go
Expand Up @@ -211,6 +211,19 @@ func WsCombinedDepthServe(symbols []string, handler WsDepthHandler, errHandler E
endpoint += fmt.Sprintf("%s@depth", strings.ToLower(s)) + "/"
}
endpoint = endpoint[:len(endpoint)-1]
return wsCombinedDepthServe(endpoint, handler, errHandler)
}

func WsCombinedDepthServe100Ms(symbols []string, handler WsDepthHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error) {
endpoint := getCombinedEndpoint()
for _, s := range symbols {
endpoint += fmt.Sprintf("%s@depth@100ms", strings.ToLower(s)) + "/"
}
endpoint = endpoint[:len(endpoint)-1]
return wsCombinedDepthServe(endpoint, handler, errHandler)
}

func wsCombinedDepthServe(endpoint string, handler WsDepthHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error) {
cfg := newWsConfig(endpoint)
wsHandler := func(message []byte) {
j, err := newJSON(message)
Expand Down
52 changes: 52 additions & 0 deletions v2/websocket_service_test.go
Expand Up @@ -436,6 +436,58 @@ func (s *websocketServiceTestSuite) TestCombinedDepthServe() {
<-doneC
}

func (s *websocketServiceTestSuite) TestCombinedDepthServe100Ms() {
data := []byte(`{
"stream":"btcusdt@depth",
"data":{
"e":"depthUpdate",
"E":1629769560797,
"s":"BTCUSDT",
"U":13544035,
"u":13544037,
"b":[["49095.23000000","0.01018500"],["49081.00000000","0.00000000"]],
"a":[["49095.65000000","0.01018500"]]}}
`)
symbols := []string{
"BTCUSDT",
"ETHUSDT",
}
fakeErrMsg := "fake error"
s.mockWsServe(data, errors.New(fakeErrMsg))
defer s.assertWsServe()
doneC, stopC, err := WsCombinedDepthServe100Ms(symbols, func(event *WsDepthEvent) {
e := &WsDepthEvent{
Symbol: "BTCUSDT",
Time: 1629769560797,
LastUpdateID: 13544037,
FirstUpdateID: 13544035,
Bids: []Bid{
{
Price: "49095.23000000",
Quantity: "0.01018500",
},
{
Price: "49081.00000000",
Quantity: "0.00000000",
},
},
Asks: []Ask{
{
Price: "49095.65000000",
Quantity: "0.01018500",
},
},
}
s.assertWsDepthEventEqual(e, event)
},
func(err error) {
s.r().EqualError(err, fakeErrMsg)
})
s.r().NoError(err)
stopC <- struct{}{}
<-doneC
}

func (s *websocketServiceTestSuite) TestKlineServe() {
data := []byte(`{
"e": "kline",
Expand Down

0 comments on commit 03a81e7

Please sign in to comment.