-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
v5_ws_public_trade_test.go
62 lines (53 loc) · 1.33 KB
/
v5_ws_public_trade_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
package bybit
import (
"encoding/json"
"testing"
"github.com/hirokisan/bybit/v2/testhelper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestWebsocketV5Public_Trade(t *testing.T) {
respBody := map[string]interface{}{
"topic": "publicTrade.BTCUSDT",
"type": "snapshot",
"ts": 1672304486868,
"data": []map[string]interface{}{
{
"T": 1672304486865,
"s": "BTCUSDT",
"S": "Buy",
"v": "0.001",
"p": "16578.50",
"L": "PlusTick",
"i": "20f43950-d8dd-5b31-9112-a178eb6023af",
"BT": false,
},
},
}
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.SubscribeTrade(
V5WebsocketPublicTradeParamKey{
Symbol: SymbolV5BTCUSDT,
},
func(response V5WebsocketPublicTradeResponse) 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())
}