Skip to content

Commit 5f70273

Browse files
authored
Merge pull request #110 from zerodha/feat-mtf
feat: add mtf in holdings and orders
2 parents 8164b31 + 36d35f4 commit 5f70273

5 files changed

+45
-1
lines changed

connect.go

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const (
4949
ProductMIS = "MIS"
5050
ProductCNC = "CNC"
5151
ProductNRML = "NRML"
52+
ProductMTF = "MTF"
5253

5354
// Order types
5455
OrderTypeMarket = "MARKET"

orders_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func (ts *TestSuite) TestGetOrders(t *testing.T) {
3535
require.Equal(t, "22", orders[6].AuctionNumber)
3636
require.Equal(t, false, orders[6].Modified)
3737
})
38+
t.Run("test mtf order", func(t *testing.T) {
39+
require.Equal(t, "MTF", orders[7].Product)
40+
})
3841
}
3942

4043
func (ts *TestSuite) TestGetTrades(t *testing.T) {
@@ -176,6 +179,28 @@ func (ts *TestSuite) TestPlaceAuctionOrder(t *testing.T) {
176179
}
177180
}
178181

182+
func (ts *TestSuite) TestPlaceMTFOrder(t *testing.T) {
183+
t.Parallel()
184+
mtfParams := OrderParams{
185+
Exchange: "test_mtf",
186+
Tradingsymbol: "test_mtf",
187+
Validity: "test_mtf",
188+
Product: ProductMTF,
189+
OrderType: "test_mtf",
190+
TransactionType: "test_mtf",
191+
Quantity: 100,
192+
Price: 100,
193+
Tag: "test_mtf",
194+
}
195+
orderResponse, err := ts.KiteConnect.PlaceOrder("test", mtfParams)
196+
if err != nil {
197+
t.Errorf("Error while placing mtf order. %v", err)
198+
}
199+
if orderResponse.OrderID == "" {
200+
t.Errorf("No order id returned for placing mtf order. Error %v", err)
201+
}
202+
}
203+
179204
func (ts *TestSuite) TestModifyOrder(t *testing.T) {
180205
t.Parallel()
181206
params := OrderParams{

portfolio.go

+11
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ type Holding struct {
4545
PnL float64 `json:"pnl"`
4646
DayChange float64 `json:"day_change"`
4747
DayChangePercentage float64 `json:"day_change_percentage"`
48+
49+
MTF MTFHolding `json:"mtf"`
50+
}
51+
52+
// MTFHolding represents the mtf details for a holding
53+
type MTFHolding struct {
54+
Quantity int `json:"quantity"`
55+
UsedQuantity int `json:"used_quantity"`
56+
AveragePrice float64 `json:"average_price"`
57+
Value float64 `json:"value"`
58+
InitialMargin float64 `json:"initial_margin"`
4859
}
4960

5061
// Holdings is a list of holdings

portfolio_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ func (ts *TestSuite) TestGetHoldings(t *testing.T) {
4040
t.Errorf("Error while fetching tradingsymbol in holdings. %v", err)
4141
}
4242
}
43+
// MTF fields
44+
if holdings[0].MTF.Quantity != 1000 {
45+
t.Errorf("Error while fetching quantity in mtf holdings. %v", err)
46+
}
47+
if holdings[0].MTF.Value != 100000 {
48+
t.Errorf("Error while fetching value in mtf holdings. %v", err)
49+
}
4350
}
4451

4552
func (ts *TestSuite) TestGetAuctionInstruments(t *testing.T) {

0 commit comments

Comments
 (0)