Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mtf in holdings and orders #110

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading