Skip to content

Commit ec01516

Browse files
authored
Merge pull request #30 from ranjanrak/feat-vcn
feat: add virtual contract note API
2 parents 192cfe8 + 178ab86 commit ec01516

File tree

5 files changed

+196
-2
lines changed

5 files changed

+196
-2
lines changed

examples/kiteconnect_sample.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,41 @@
7777
]);
7878
echo "Trigger id is ".$place_GTT->trigger_id;
7979

80+
$orderParams = [[
81+
"order_id" => "111111111",
82+
"exchange" => "NSE",
83+
"tradingsymbol" => "SBIN",
84+
"transaction_type" => $kite::TRANSACTION_TYPE_BUY,
85+
"variety" => $kite::VARIETY_REGULAR,
86+
"product" => $kite::PRODUCT_CNC,
87+
"order_type" => $kite::ORDER_TYPE_MARKET,
88+
"quantity" => 1,
89+
"average_price" => 560
90+
],
91+
[
92+
"order_id" => "2222222222",
93+
"exchange" => "MCX",
94+
"tradingsymbol" => "GOLDPETAL23JULFUT",
95+
"transaction_type" => $kite::TRANSACTION_TYPE_SELL,
96+
"variety" => $kite::VARIETY_REGULAR,
97+
"product" => $kite::PRODUCT_NRML,
98+
"order_type" => $kite::ORDER_TYPE_LIMIT,
99+
"quantity" => 1,
100+
"average_price" => 5862
101+
],
102+
[
103+
"order_id" => "3333333333",
104+
"exchange" => "NFO",
105+
"tradingsymbol" => "NIFTY2371317900PE",
106+
"transaction_type" => $kite::TRANSACTION_TYPE_SELL,
107+
"variety" => $kite::VARIETY_REGULAR,
108+
"product" => $kite::PRODUCT_NRML,
109+
"order_type" => $kite::ORDER_TYPE_LIMIT,
110+
"quantity" => 100,
111+
"average_price" => 1.5
112+
]
113+
];
114+
115+
print_r($kite->getVirtualContractNote($orderParams));
116+
80117
?>

src/KiteConnect.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class KiteConnect
154154
"order.cancel" => "/orders/{variety}/{order_id}",
155155
"order.trades" => "/orders/{order_id}/trades",
156156
"order.margins" => "/margins/orders",
157+
"order.contract_note" => "/charges/orders",
157158

158159
"portfolio.positions" => "/portfolio/positions",
159160
"portfolio.holdings" => "/portfolio/holdings",
@@ -610,6 +611,33 @@ public function orderMargins(array $params): array
610611
return $this->post("order.margins", (array)json_encode($params), 'application/json');
611612
}
612613

614+
/**
615+
* Fetch detailed charges order-wise for the order book
616+
*
617+
* @param array $params Order params to fetch charges detail
618+
* $params string "order_id" Unique order ID
619+
* $params string "exchange" Name of the exchange(eg. NSE, BSE, NFO, CDS, MCX)
620+
* $params string "tradingsymbol" Trading symbol of the instrument
621+
* $params string "transaction_type" eg. BUY, SELL
622+
* $params string "variety" Order variety (regular, amo, bo, co etc.)
623+
* $params string "product" Margin product to use for the order
624+
* $params string "order_type" Order type (MARKET, LIMIT etc.)
625+
* $params int "quantity" Quantity of the order
626+
* $params float "average_price" Average price at which the order was executed (Note: Should be non-zero).
627+
* @return array
628+
* @throws DataException
629+
* @throws GeneralException
630+
* @throws InputException
631+
* @throws NetworkException
632+
* @throws OrderException
633+
* @throws PermissionException
634+
* @throws TokenException
635+
*/
636+
public function getVirtualContractNote(array $params): array
637+
{
638+
return $this->post("order.contract_note", (array)json_encode($params), 'application/json');
639+
}
640+
613641
/**
614642
* Retrieve the list of trades executed.
615643
* @return array

tests/KiteConnectTest.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,55 @@ public function getMFHoldingsTest($kiteConnect): void
473473
}
474474
}
475475

476+
/**
477+
* @depends initializeMock
478+
* @test getVirtualContractNote
479+
*/
480+
public function getVirtualContractNoteTest($kiteConnect): void
481+
{
482+
$orderParams = [[
483+
"order_id" => "111111111",
484+
"exchange" => "NSE",
485+
"tradingsymbol" => "SBIN",
486+
"transaction_type" => $kiteConnect::TRANSACTION_TYPE_BUY,
487+
"variety" => $kiteConnect::VARIETY_REGULAR,
488+
"product" => $kiteConnect::PRODUCT_CNC,
489+
"order_type" => $kiteConnect::ORDER_TYPE_MARKET,
490+
"quantity" => 1,
491+
"average_price" => 560
492+
],
493+
[
494+
"order_id" => "2222222222",
495+
"exchange" => "MCX",
496+
"tradingsymbol" => "GOLDPETAL23JULFUT",
497+
"transaction_type" => $kiteConnect::TRANSACTION_TYPE_SELL,
498+
"variety" => $kiteConnect::VARIETY_REGULAR,
499+
"product" => $kiteConnect::PRODUCT_NRML,
500+
"order_type" => $kiteConnect::ORDER_TYPE_LIMIT,
501+
"quantity" => 1,
502+
"average_price" => 5862
503+
],
504+
[
505+
"order_id" => "3333333333",
506+
"exchange" => "NFO",
507+
"tradingsymbol" => "NIFTY2371317900PE",
508+
"transaction_type" => $kiteConnect::TRANSACTION_TYPE_SELL,
509+
"variety" => $kiteConnect::VARIETY_REGULAR,
510+
"product" => $kiteConnect::PRODUCT_NRML,
511+
"order_type" => $kiteConnect::ORDER_TYPE_LIMIT,
512+
"quantity" => 100,
513+
"average_price" => 1.5
514+
]
515+
];
516+
$response = $kiteConnect->getVirtualContractNote($orderParams);
517+
518+
foreach ($response as $values) {
519+
$this->assertObjectHasAttribute('charges',$values);
520+
$this->assertObjectHasAttribute('transaction_type',$values);
521+
$this->assertObjectHasAttribute('tradingsymbol',$values);
522+
}
523+
}
524+
476525
/**
477526
* @depends initializeMock
478527
* @test getInstruments
@@ -520,5 +569,4 @@ public function getMFInstrumentsTest($kiteConnect): void
520569
$this->assertObjectHasAttribute('redemption_allowed',$values);
521570
}
522571
}
523-
524572
}

tests/MockJson.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public function generateMock()
3535
"mf_orders_info.json",
3636
"mf_sips.json",
3737
"mf_sip_info.json",
38-
"mf_holdings.json"
38+
"mf_holdings.json",
39+
"virtual_contract_note.json",
3940
];
4041
$response_array = array();
4142
foreach ($mock_files as $values) {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"status": "success",
3+
"data": [
4+
{
5+
"transaction_type": "BUY",
6+
"tradingsymbol": "SBIN",
7+
"exchange": "NSE",
8+
"variety": "regular",
9+
"product": "CNC",
10+
"order_type": "MARKET",
11+
"quantity": 1,
12+
"price": 560,
13+
"charges": {
14+
"transaction_tax": 0.56,
15+
"transaction_tax_type": "stt",
16+
"exchange_turnover_charge": 0.01876,
17+
"sebi_turnover_charge": 0.00056,
18+
"brokerage": 0,
19+
"stamp_duty": 0,
20+
"gst": {
21+
"igst": 0.0033767999999999997,
22+
"cgst": 0,
23+
"sgst": 0,
24+
"total": 0.0033767999999999997
25+
},
26+
"total": 0.5826968
27+
}
28+
},
29+
{
30+
"transaction_type": "SELL",
31+
"tradingsymbol": "GOLDPETAL23JULFUT",
32+
"exchange": "MCX",
33+
"variety": "regular",
34+
"product": "NRML",
35+
"order_type": "LIMIT",
36+
"quantity": 1,
37+
"price": 5862,
38+
"charges": {
39+
"transaction_tax": 0.5862,
40+
"transaction_tax_type": "ctt",
41+
"exchange_turnover_charge": 0.152412,
42+
"sebi_turnover_charge": 0.005862,
43+
"brokerage": 1.7586,
44+
"stamp_duty": 0,
45+
"gst": {
46+
"igst": 0.34503732,
47+
"cgst": 0,
48+
"sgst": 0,
49+
"total": 0.34503732
50+
},
51+
"total": 2.84811132
52+
}
53+
},
54+
{
55+
"transaction_type": "BUY",
56+
"tradingsymbol": "NIFTY2371317900PE",
57+
"exchange": "NFO",
58+
"variety": "regular",
59+
"product": "NRML",
60+
"order_type": "LIMIT",
61+
"quantity": 100,
62+
"price": 1.5,
63+
"charges": {
64+
"transaction_tax": 0,
65+
"transaction_tax_type": "stt",
66+
"exchange_turnover_charge": 0.07575,
67+
"sebi_turnover_charge": 0.00015,
68+
"brokerage": 20,
69+
"stamp_duty": 0,
70+
"gst": {
71+
"igst": 3.613527,
72+
"cgst": 0,
73+
"sgst": 0,
74+
"total": 3.613527
75+
},
76+
"total": 23.689427000000002
77+
}
78+
}
79+
]
80+
}

0 commit comments

Comments
 (0)