-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
v5_ws_public_orderbook_test.go
68 lines (59 loc) · 1.35 KB
/
v5_ws_public_orderbook_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package bybit
import (
"encoding/json"
"testing"
"github.com/hirokisan/bybit/v2/testhelper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestWebsocketV5Public_OrderBook(t *testing.T) {
respBody := map[string]interface{}{
"topic": "orderbook.1.BTCUSDT",
"type": "snapshot",
"ts": 1677322353682,
"data": map[string]interface{}{
"s": "BTCUSDT",
"b": [][]string{
{
"22975.10",
"261.537",
},
},
"a": [][]string{
{
"22975.40",
"131.388",
},
},
"u": 642570,
"seq": 7995099758,
},
}
bytesBody, err := json.Marshal(respBody)
require.NoError(t, err)
category := CategoryV5Linear
server, teardown := testhelper.NewWebsocketServer(
testhelper.WithWebsocketHandlerOption(V5WebsocketPublicPathFor(category), bytesBody),
)
defer teardown()
wsClient := NewTestWebsocketClient().
WithBaseURL(server.URL)
svc, err := wsClient.V5().Public(category)
require.NoError(t, err)
{
_, err := svc.SubscribeOrderBook(
V5WebsocketPublicOrderBookParamKey{
Depth: 1,
Symbol: SymbolV5BTCUSDT,
},
func(response V5WebsocketPublicOrderBookResponse) error {
assert.Equal(t, respBody["topic"], response.Topic)
return nil
},
)
require.NoError(t, err)
}
assert.NoError(t, svc.Run())
assert.NoError(t, svc.Ping())
assert.NoError(t, svc.Close())
}