forked from zerodha/gokiteconnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
portfolio_test.go
104 lines (96 loc) · 2.63 KB
/
portfolio_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package kiteconnect
import (
"strings"
"testing"
)
func (ts *TestSuite) TestGetPositions(t *testing.T) {
t.Parallel()
positions, err := ts.KiteConnect.GetPositions()
if err != nil {
t.Errorf("Error while fetching positions. %v", err)
}
if positions.Day == nil {
t.Errorf("Error while fetching day positions. %v", err)
}
if positions.Net == nil {
t.Errorf("Error while fetching net positions. %v", err)
}
for _, position := range positions.Day {
if position.Tradingsymbol == "" {
t.Errorf("Error while fetching trading symbol in day position. %v", err)
}
}
for _, position := range positions.Net {
if position.Tradingsymbol == "" {
t.Errorf("Error while fetching tradingsymbol in net position. %v", err)
}
}
}
func (ts *TestSuite) TestGetHoldings(t *testing.T) {
t.Parallel()
holdings, err := ts.KiteConnect.GetHoldings()
if err != nil {
t.Errorf("Error while fetching holdings. %v", err)
}
for _, holding := range holdings {
if holding.Tradingsymbol == "" {
t.Errorf("Error while fetching tradingsymbol in holdings. %v", err)
}
}
}
func (ts *TestSuite) TestGetAuctionInstruments(t *testing.T) {
t.Parallel()
auctionIns, err := ts.KiteConnect.GetAuctionInstruments()
if err != nil {
t.Errorf("Error while fetching auction instrument : %v", err)
}
for _, ins := range auctionIns {
if ins.AuctionNumber == "" {
t.Errorf("Error while retrieving auction number from the auction instruments list : %v", err)
}
if ins.Quantity == 0 {
t.Errorf("Error while retrieving auction qty from the auction instruments list : %v", err)
}
}
}
func (ts *TestSuite) TestConvertPosition(t *testing.T) {
t.Parallel()
params := ConvertPositionParams{
Exchange: "test",
TradingSymbol: "test",
OldProduct: "test",
NewProduct: "test",
PositionType: "test",
TransactionType: "test",
Quantity: 1,
}
response, err := ts.KiteConnect.ConvertPosition(params)
if err != nil || response != true {
t.Errorf("Error while converting position. %v", err)
}
}
func (ts *TestSuite) TestInitiateHoldingsAuth(t *testing.T) {
t.Parallel()
params := HoldingAuthParams{
Instruments: []HoldingsAuthInstruments{
{
ISIN: "INE002A01018",
Quantity: 50,
},
{
ISIN: "INE009A01021",
Quantity: 50,
},
},
}
response, err := ts.KiteConnect.InitiateHoldingsAuth(params)
if err != nil {
t.Errorf("Error while initiating holdings auth. %v", err)
}
if response.RequestID != "na8QgCeQm05UHG6NL9sAGRzdfSF64UdB" {
t.Errorf("Error while parsing holdings auth response")
}
if !strings.Contains(response.RedirectURL, kiteBaseURI) {
t.Errorf("Incorrect response URL")
}
}