-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
v5_ws_private_order_test.go
85 lines (76 loc) · 2.28 KB
/
v5_ws_private_order_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
package bybit
import (
"encoding/json"
"testing"
"github.com/hirokisan/bybit/v2/testhelper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestV5WebsocketPrivate_Order(t *testing.T) {
respBody := V5WebsocketPrivateOrderResponse{
Topic: "order",
ID: "75d86e42f18b23b9ad2c1f10eaffa8bb:18483ff242aca593:0:01",
CreationTime: 1677226839837,
Data: []V5WebsocketPrivateOrderData{
{
AvgPrice: "23090.80",
BlockTradeID: "",
CancelType: "UNKNOWN",
Category: "linear",
CloseOnTrigger: false,
CreatedTime: "1677375772152",
CumExecFee: "0.01385448",
CumExecQty: "0.001",
CumExecValue: "23.0908",
LeavesQty: "0",
LeavesValue: "0",
OrderID: "cd770a60-549f-433b-8000-aacefec3c7c3",
OrderIv: "",
IsLeverage: "",
LastPriceOnCreated: "23089.30",
OrderStatus: "Filled",
OrderLinkID: "",
OrderType: "Market",
PositionIdx: 1,
Price: "24243.70",
Qty: "0.001",
ReduceOnly: false,
RejectReason: "EC_NoError",
Side: "Buy",
SlTriggerBy: "UNKNOWN",
StopLoss: "0.00",
StopOrderType: "UNKNOWN",
Symbol: "BTCUSDT",
TakeProfit: "0.00",
TimeInForce: "IOC",
TpTriggerBy: "UNKNOWN",
TriggerBy: "UNKNOWN",
TriggerDirection: 0,
TriggerPrice: "0.00",
UpdatedTime: "1677375772154",
},
},
}
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")
svc, err := wsClient.V5().Private()
require.NoError(t, err)
require.NoError(t, svc.Subscribe())
{
_, err := svc.SubscribeOrder(func(response V5WebsocketPrivateOrderResponse) 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())
}