Skip to content

Commit

Permalink
Merge pull request #110 from zerodha/feat-mtf
Browse files Browse the repository at this point in the history
feat: add mtf in holdings and orders
  • Loading branch information
ranjanrak authored Jan 17, 2025
2 parents 8164b31 + 36d35f4 commit 5f70273
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
ProductMIS = "MIS"
ProductCNC = "CNC"
ProductNRML = "NRML"
ProductMTF = "MTF"

// Order types
OrderTypeMarket = "MARKET"
Expand Down
2 changes: 1 addition & 1 deletion mock_responses
Submodule mock_responses updated 2 files
+46 −28 holdings.json
+35 −0 orders.json
25 changes: 25 additions & 0 deletions orders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func (ts *TestSuite) TestGetOrders(t *testing.T) {
require.Equal(t, "22", orders[6].AuctionNumber)
require.Equal(t, false, orders[6].Modified)
})
t.Run("test mtf order", func(t *testing.T) {
require.Equal(t, "MTF", orders[7].Product)
})
}

func (ts *TestSuite) TestGetTrades(t *testing.T) {
Expand Down Expand Up @@ -176,6 +179,28 @@ func (ts *TestSuite) TestPlaceAuctionOrder(t *testing.T) {
}
}

func (ts *TestSuite) TestPlaceMTFOrder(t *testing.T) {
t.Parallel()
mtfParams := OrderParams{
Exchange: "test_mtf",
Tradingsymbol: "test_mtf",
Validity: "test_mtf",
Product: ProductMTF,
OrderType: "test_mtf",
TransactionType: "test_mtf",
Quantity: 100,
Price: 100,
Tag: "test_mtf",
}
orderResponse, err := ts.KiteConnect.PlaceOrder("test", mtfParams)
if err != nil {
t.Errorf("Error while placing mtf order. %v", err)
}
if orderResponse.OrderID == "" {
t.Errorf("No order id returned for placing mtf order. Error %v", err)
}
}

func (ts *TestSuite) TestModifyOrder(t *testing.T) {
t.Parallel()
params := OrderParams{
Expand Down
11 changes: 11 additions & 0 deletions portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ type Holding struct {
PnL float64 `json:"pnl"`
DayChange float64 `json:"day_change"`
DayChangePercentage float64 `json:"day_change_percentage"`

MTF MTFHolding `json:"mtf"`
}

// MTFHolding represents the mtf details for a holding
type MTFHolding struct {
Quantity int `json:"quantity"`
UsedQuantity int `json:"used_quantity"`
AveragePrice float64 `json:"average_price"`
Value float64 `json:"value"`
InitialMargin float64 `json:"initial_margin"`
}

// Holdings is a list of holdings
Expand Down
7 changes: 7 additions & 0 deletions portfolio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ func (ts *TestSuite) TestGetHoldings(t *testing.T) {
t.Errorf("Error while fetching tradingsymbol in holdings. %v", err)
}
}
// MTF fields
if holdings[0].MTF.Quantity != 1000 {
t.Errorf("Error while fetching quantity in mtf holdings. %v", err)
}
if holdings[0].MTF.Value != 100000 {
t.Errorf("Error while fetching value in mtf holdings. %v", err)
}
}

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

0 comments on commit 5f70273

Please sign in to comment.