-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
v5_ws_private_position_test.go
87 lines (78 loc) · 2.16 KB
/
v5_ws_private_position_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package bybit
import (
"encoding/json"
"net/http"
"net/url"
"testing"
"time"
"github.com/gorilla/websocket"
"github.com/hirokisan/bybit/v2/testhelper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestV5WebsocketPrivate_Position(t *testing.T) {
respBody := V5WebsocketPrivatePositionResponse{
Topic: "position",
ID: "75d86e42f18b23b9ad2c1f10eaffa8bb:18483ff242aca593:0:01",
CreationTime: 1677226839837,
Data: []V5WebsocketPrivatePositionData{
{
BustPrice: "0.10",
Category: "linear",
CreatedTime: "1666729101704",
CumRealisedPnl: "-4.77363636",
EntryPrice: "23780.1",
Leverage: "10",
LiqPrice: "0.10",
MarkPrice: "23782.27",
PositionBalance: "2.39085126",
PositionIdx: 1,
PositionMM: "0.0000005",
PositionIM: "0.237801",
PositionStatus: "Normal",
PositionValue: "23.7801",
RiskID: 1,
RiskLimitValue: "2000000",
Side: "Buy",
Size: "0.001",
StopLoss: "0.00",
Symbol: "BTCUSDT",
TakeProfit: "0.00",
TpslMode: "Full",
TradeMode: 0,
AutoAddMargin: 0,
TrailingStop: "0.00",
UnrealisedPnl: "0.00217",
UpdatedTime: "1677226839835",
},
},
}
bytesBody, err := json.Marshal(respBody)
require.NoError(t, err)
server, teardown := testhelper.NewWebsocketServer(
testhelper.WithWebsocketHandlerOption(V5WebsocketPrivatePath, bytesBody),
)
defer teardown()
wsClient := NewTestWebsocketClient().
WithBaseURL(server.URL).
WithAuth("test", "test").
WithDialer(&websocket.Dialer{
Proxy: func(req *http.Request) (*url.URL, error) {
return nil, nil
},
HandshakeTimeout: 5 * time.Second,
})
svc, err := wsClient.V5().Private()
require.NoError(t, err)
require.NoError(t, svc.Subscribe())
{
_, err := svc.SubscribePosition(func(response V5WebsocketPrivatePositionResponse) error {
assert.Equal(t, respBody, response)
return nil
})
require.NoError(t, err)
}
assert.NoError(t, svc.Run())
assert.NoError(t, svc.Ping())
assert.NoError(t, svc.Close())
}