-
Notifications
You must be signed in to change notification settings - Fork 73
/
margins_test.go
158 lines (134 loc) · 4.34 KB
/
margins_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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package kiteconnect
import "testing"
func (ts *TestSuite) TestGetOrderMargins(t *testing.T) {
t.Parallel()
params := OrderMarginParam{
Exchange: "NSE",
Tradingsymbol: "INFY",
TransactionType: "BUY",
Variety: "regular",
Product: "CNC",
OrderType: "MARKET",
Quantity: 1,
Price: 0,
TriggerPrice: 0,
}
compactOrderResp, err := ts.KiteConnect.GetOrderMargins(GetMarginParams{
OrderParams: []OrderMarginParam{params},
Compact: true,
})
if err != nil {
t.Errorf("Error while getting compact order margins: %v", err)
}
if len(compactOrderResp) != 1 {
t.Errorf("Incorrect response length, expected len(compactOrderResp) to be 1, got: %v", len(compactOrderResp))
}
if compactOrderResp[0].TradingSymbol != "INFY" {
t.Errorf("Incorrect tradingsymbol, expected INFY, got: %v", compactOrderResp[0].TradingSymbol)
}
if compactOrderResp[0].Total == 0 {
t.Errorf("Incorrect compact total margins, got: %v", compactOrderResp[0].Total)
}
// Detailed order margin tests include charges, leverage
detailOrderResp, err := ts.KiteConnect.GetOrderMargins(GetMarginParams{
OrderParams: []OrderMarginParam{params},
Compact: false,
})
if err != nil {
t.Errorf("Error while getting detailed order margins: %v", err)
}
if detailOrderResp[0].Leverage != 1 {
t.Errorf("Incorrect leverage multiplier, expected 1x, got: %v", detailOrderResp[0].TradingSymbol)
}
if len(detailOrderResp) != 1 {
t.Errorf("Incorrect response, expected len(detailOrderResp) to be 1, got: %v", len(detailOrderResp))
}
if detailOrderResp[0].Charges.TransactionTax == 0 {
t.Errorf("Incorrect TransactionTax in detailed order margins, got: %v", detailOrderResp[0].Charges.TransactionTax)
}
if detailOrderResp[0].Charges.StampDuty == 0 {
t.Errorf("Incorrect StampDuty in detailed order margins, got: %v", detailOrderResp[0].Charges.StampDuty)
}
if detailOrderResp[0].Charges.GST.Total == 0 {
t.Errorf("Incorrect GST in detailed order margins, got: %v", detailOrderResp[0].Charges.GST.Total)
}
if detailOrderResp[0].Charges.Total == 0 {
t.Errorf("Incorrect charges total in detailed order margins, got: %v", detailOrderResp[0].Charges.Total)
}
if detailOrderResp[0].Total == 0 {
t.Errorf("Incorrect total margin in detailed order margins, got: %v", detailOrderResp[0].Total)
}
}
func (ts *TestSuite) TestGetBasketMargins(t *testing.T) {
t.Parallel()
params := OrderMarginParam{
Exchange: "NSE",
Tradingsymbol: "INFY",
TransactionType: "BUY",
Variety: "regular",
Product: "CNC",
OrderType: "MARKET",
Quantity: 1,
Price: 0,
TriggerPrice: 0,
}
orderResponseBasket, err := ts.KiteConnect.GetBasketMargins(GetBasketParams{
OrderParams: []OrderMarginParam{params},
Compact: true,
ConsiderPositions: true,
})
if err != nil {
t.Errorf("Error while getting compact basket order margins: %v", err)
}
if len(orderResponseBasket.Orders) != 2 {
t.Errorf("Incorrect response, expected len(orderResponseBasket.Orders) to be 2, got: %v", len(orderResponseBasket.Orders))
}
}
func (ts *TestSuite) TestGetOrderCharges(t *testing.T) {
t.Parallel()
params :=
[]OrderChargesParam{
{
Exchange: "SBIN",
Tradingsymbol: "INFY",
TransactionType: "BUY",
Variety: "regular",
Product: "CNC",
OrderType: "MARKET",
Quantity: 1,
AveragePrice: 560,
OrderID: "11111",
},
{
Exchange: "MCX",
Tradingsymbol: "GOLDPETAL23JULFUT",
TransactionType: "SELL",
Variety: "regular",
Product: "NRML",
OrderType: "LIMIT",
Quantity: 1,
AveragePrice: 5862,
OrderID: "22222",
},
{
Exchange: "NFO",
Tradingsymbol: "NIFTY2371317900PE",
TransactionType: "BUY",
Variety: "regular",
Product: "NRML",
OrderType: "LIMIT",
Quantity: 100,
AveragePrice: 1.5,
OrderID: "33333",
},
}
orderResponseCharges, err := ts.KiteConnect.GetOrderCharges(GetChargesParams{
OrderParams: params,
})
if err != nil {
t.Errorf("Error while getting order charges: %v", err)
}
if len(orderResponseCharges) != 3 {
t.Errorf("Incorrect response, expected len(orderResponseCharges) to be 3, got: %v", len(orderResponseCharges))
}
}