-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
ws_spot_v1_public_v2_test.go
51 lines (43 loc) · 1.31 KB
/
ws_spot_v1_public_v2_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
package bybit
import (
"encoding/json"
"testing"
"github.com/hirokisan/bybit/v2/testhelper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSpotWebsocketV1PublicV2Trade(t *testing.T) {
respBody := SpotWebsocketV1PublicV2TradeResponse{
Topic: SpotWebsocketV1PublicV2TopicTrade,
Params: SpotWebsocketV1PublicV2TradeResponseParams{
Symbol: SymbolSpotBTCUSDT,
Binary: "false",
},
Data: SpotWebsocketV1PublicV2TradeContent{
TradeID: "2100000000002571479",
Timestamp: 1664283342503,
Price: "20191.69",
Quantity: "0.000495",
IsBuySideTaker: true,
},
}
bytesBody, err := json.Marshal(respBody)
require.NoError(t, err)
server, teardown := testhelper.NewWebsocketServer(
testhelper.WithWebsocketHandlerOption(SpotWebsocketV1PublicV2Path, bytesBody),
)
defer teardown()
wsClient := NewTestWebsocketClient().
WithBaseURL(server.URL)
svc, err := wsClient.Spot().V1().PublicV2()
require.NoError(t, err)
unsubscribe, err := svc.SubscribeTrade(SymbolSpotBTCUSDT, func(response SpotWebsocketV1PublicV2TradeResponse) error {
assert.Equal(t, respBody, response)
return nil
})
require.NoError(t, err)
assert.NoError(t, svc.Run())
assert.NoError(t, unsubscribe())
assert.NoError(t, svc.Ping())
assert.NoError(t, svc.Close())
}