diff --git a/margins.go b/margins.go index f3d99be..859cade 100644 --- a/margins.go +++ b/margins.go @@ -39,9 +39,31 @@ type OrderMargins struct { Cash float64 `json:"cash"` VAR float64 `json:"var"` PNL PNL `json:"pnl"` + Leverage float64 `json:"leverage"` + Charges Charges `json:"charges"` Total float64 `json:"total"` } +// Charges represents breakdown of various charges that are applied to an order +type Charges struct { + TransactionTax float64 `json:"transaction_tax"` + TransactionTaxType string `json:"transaction_tax_type"` + ExchangeTurnoverCharge float64 `json:"exchange_turnover_charge"` + SEBITurnoverCharge float64 `json:"sebi_turnover_charge"` + Brokerage float64 `json:"brokerage"` + StampDuty float64 `json:"stamp_duty"` + GST GST `json:"gst"` + Total float64 `json:"total"` +} + +// GST represents the various GST charges +type GST struct { + IGST float64 `json:"igst"` + CGST float64 `json:"cgst"` + SGST float64 `json:"sgst"` + Total float64 `json:"total"` +} + // BasketMargins represents response from the Margin Calculator API for Basket orders type BasketMargins struct { Initial OrderMargins `json:"initial"` diff --git a/margins_test.go b/margins_test.go index 8964b41..43aea1c 100644 --- a/margins_test.go +++ b/margins_test.go @@ -17,20 +17,62 @@ func (ts *TestSuite) TestGetOrderMargins(t *testing.T) { TriggerPrice: 0, } - orderResponse, err := ts.KiteConnect.GetOrderMargins(GetMarginParams{ + compactOrderResp, err := ts.KiteConnect.GetOrderMargins(GetMarginParams{ OrderParams: []OrderMarginParam{params}, Compact: true, }) if err != nil { - t.Errorf("Error while getting order margins: %v", err) + t.Errorf("Error while getting compact order margins: %v", err) } - if len(orderResponse) != 1 { - t.Errorf("Incorrect response, expected len(orderResponse) to be 0, got: %v", len(orderResponse)) + if len(compactOrderResp) != 1 { + t.Errorf("Incorrect response length, expected len(compactOrderResp) to be 1, got: %v", len(compactOrderResp)) } - if orderResponse[0].Total != 961.45 { - t.Errorf("Incorrect total, expected 961.45, got: %v", orderResponse[0].Total) + 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) } } @@ -55,7 +97,7 @@ func (ts *TestSuite) TestGetBasketMargins(t *testing.T) { ConsiderPositions: true, }) if err != nil { - t.Errorf("Error while getting basket order margins: %v", err) + t.Errorf("Error while getting compact basket order margins: %v", err) } if len(orderResponseBasket.Orders) != 2 { diff --git a/mock_responses b/mock_responses index cce96db..02d0831 160000 --- a/mock_responses +++ b/mock_responses @@ -1 +1 @@ -Subproject commit cce96db49cc12197b6849c07a4a9430833a0670b +Subproject commit 02d0831c44d30a9f4ac647a3a2c89b3c0279f317