forked from bitfinexcom/bfxfixgw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet_balance_test.go
82 lines (69 loc) · 4.43 KB
/
wallet_balance_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
package main
//TestWalletSnapshotUpdate assures the gateway service will publish wallet snapshots and updates to FIX
func (s *gatewaySuite) TestWalletSnapshotUpdate() {
// assert FIX MD logon
fix, err := s.fixMd.WaitForMessage(s.MarketDataSessionID, 1)
s.Require().Nil(err)
err = s.checkFixTags(fix, "35=A", "49=BFXFIX", "56=EXORG_MD")
s.Require().Nil(err)
// assert FIX order logon
fix, err = s.fixOrd.WaitForMessage(s.OrderSessionID, 1)
s.Require().Nil(err)
err = s.checkFixTags(fix, "35=A", "49=BFXFIX", "56=EXORG_ORD")
s.Require().Nil(err)
// assume both ws clients connected in setup()
s.srvWs.Broadcast(`{"event":"info","version":2}`)
// assert MD ws auth request
msg, err := s.srvWs.WaitForMessage(MarketDataClient, 0)
s.Require().Nil(err)
s.Require().EqualValues(`{"subId":"nonce1","event":"auth","apiKey":"apiKey1","authSig":"2744ec1afc974eadbda7e09efa03da80578628ba90e2aa5fcba8c2c61014b811f3a8be5a041c3ee35c464a59856b3869","authPayload":"AUTHnonce1","authNonce":"nonce1"}`, msg)
// assert order ws auth request
msg, err = s.srvWs.WaitForMessage(OrdersClient, 0)
s.Require().Nil(err)
s.Require().EqualValues(`{"subId":"nonce1","event":"auth","apiKey":"apiKey1","authSig":"2744ec1afc974eadbda7e09efa03da80578628ba90e2aa5fcba8c2c61014b811f3a8be5a041c3ee35c464a59856b3869","authPayload":"AUTHnonce1","authNonce":"nonce1"}`, msg)
// broadcast auth ack to both clients
s.srvWs.Broadcast(`{"event":"auth","status":"OK","chanId":0,"userId":1,"subId":"nonce1","auth_id":"valid-auth-guid","caps":{"orders":{"read":1,"write":0},"account":{"read":1,"write":0},"funding":{"read":1,"write":0},"history":{"read":1,"write":0},"wallets":{"read":1,"write":0},"withdraw":{"read":0,"write":0},"positions":{"read":1,"write":0}}}`)
// service publish wallet snapshot
s.srvWs.Send(OrdersClient, `[0,"ws",[["exchange", "fUSD", 1234.56, 10.0, 1123.45]]]`)
fix, err = s.fixOrd.WaitForMessage(s.OrderSessionID, 2)
s.Require().Nil(err)
err = s.checkFixTags(fix, "35=AP", "49=BFXFIX", "56=EXORG_ORD", "1=user123", "581=exchange", "15=fUSD", "730=1123.4500", "746=10.0000", "734=1234.5600")
s.Require().Nil(err)
// service publish wallet update
s.srvWs.Send(OrdersClient, `[0,"wu",["exchange", "fUSD", 2234.56, 20.0, 2123.45]]`)
fix, err = s.fixOrd.WaitForMessage(s.OrderSessionID, 3)
s.Require().Nil(err)
err = s.checkFixTags(fix, "35=AP", "49=BFXFIX", "56=EXORG_ORD", "1=user123", "581=exchange", "15=fUSD", "730=2123.4500", "746=20.0000", "734=2234.5600")
s.Require().Nil(err)
}
//TestBalanceUpdate assures the gateway service will publish balance updates to FIX
func (s *gatewaySuite) TestBalanceUpdate() {
// assert FIX MD logon
fix, err := s.fixMd.WaitForMessage(s.MarketDataSessionID, 1)
s.Require().Nil(err)
err = s.checkFixTags(fix, "35=A", "49=BFXFIX", "56=EXORG_MD")
s.Require().Nil(err)
// assert FIX order logon
fix, err = s.fixOrd.WaitForMessage(s.OrderSessionID, 1)
s.Require().Nil(err)
err = s.checkFixTags(fix, "35=A", "49=BFXFIX", "56=EXORG_ORD")
s.Require().Nil(err)
// assume both ws clients connected in setup()
s.srvWs.Broadcast(`{"event":"info","version":2}`)
// assert MD ws auth request
msg, err := s.srvWs.WaitForMessage(MarketDataClient, 0)
s.Require().Nil(err)
s.Require().EqualValues(`{"subId":"nonce1","event":"auth","apiKey":"apiKey1","authSig":"2744ec1afc974eadbda7e09efa03da80578628ba90e2aa5fcba8c2c61014b811f3a8be5a041c3ee35c464a59856b3869","authPayload":"AUTHnonce1","authNonce":"nonce1"}`, msg)
// assert order ws auth request
msg, err = s.srvWs.WaitForMessage(OrdersClient, 0)
s.Require().Nil(err)
s.Require().EqualValues(`{"subId":"nonce1","event":"auth","apiKey":"apiKey1","authSig":"2744ec1afc974eadbda7e09efa03da80578628ba90e2aa5fcba8c2c61014b811f3a8be5a041c3ee35c464a59856b3869","authPayload":"AUTHnonce1","authNonce":"nonce1"}`, msg)
// broadcast auth ack to both clients
s.srvWs.Broadcast(`{"event":"auth","status":"OK","chanId":0,"userId":1,"subId":"nonce1","auth_id":"valid-auth-guid","caps":{"orders":{"read":1,"write":0},"account":{"read":1,"write":0},"funding":{"read":1,"write":0},"history":{"read":1,"write":0},"wallets":{"read":1,"write":0},"withdraw":{"read":0,"write":0},"positions":{"read":1,"write":0}}}`)
// service publish balance update
s.srvWs.Send(OrdersClient, `[0,"bu",[123.45, 12.34]]`)
fix, err = s.fixOrd.WaitForMessage(s.OrderSessionID, 2)
s.Require().Nil(err)
err = s.checkFixTags(fix, "35=AP", "49=BFXFIX", "56=EXORG_ORD", "1=user123", "581=balance", "15=all", "730=12.3400", "734=123.4500")
s.Require().Nil(err)
}