-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
v5_ws_public_kline_test.go
66 lines (57 loc) · 1.46 KB
/
v5_ws_public_kline_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
package bybit
import (
"encoding/json"
"testing"
"github.com/hirokisan/bybit/v2/testhelper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestWebsocketV5Public_Kline(t *testing.T) {
respBody := map[string]interface{}{
"topic": "kline.5.BTCUSDT",
"type": "snapshot",
"ts": 1672324988882,
"data": []map[string]interface{}{
{
"start": 1672324800000,
"end": 1672325099999,
"interval": "5",
"open": "16649.5",
"close": "16677",
"high": "16677",
"low": "16608",
"volume": "2.081",
"turnover": "34666.4005",
"confirm": false,
"timestamp": 1672324988882,
},
},
}
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.SubscribeKline(
V5WebsocketPublicKlineParamKey{
Interval: Interval5,
Symbol: SymbolV5BTCUSDT,
},
func(response V5WebsocketPublicKlineResponse) 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())
}