Skip to content

Commit 3e2a55d

Browse files
committed
feat: add market_protection param for placeOrder and modifyOrder
1 parent c11a554 commit 3e2a55d

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes to `phpkiteconnect` will be documented in this file.
44

5+
## 5.1.0 - 2026-03-27
6+
- Added `MARKET_PROTECTION_AUTO` constant (`-1`) for system-default market protection
7+
- Added `market_protection` parameter support for `placeOrder` and `modifyOrder`
8+
- Added tests for `placeOrder` and `modifyOrder` with `market_protection`
9+
510
## 4.0.0 - 2021-04-06
611
- Major refactor to project structure and code
712
- PHP support 7.3+

src/KiteConnect.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ class KiteConnect
121121
public const POSITION_TYPE_DAY = "day";
122122
public const POSITION_TYPE_OVERNIGHT = "overnight";
123123

124-
public const VERSION = "3.2.0";
124+
// Market protection
125+
public const MARKET_PROTECTION_AUTO = -1;
126+
127+
public const VERSION = "5.1.0";
125128

126129
// Kite connect header version
127130
private $kiteVersion = "3";
@@ -465,6 +468,7 @@ public function getMargins(?string $segment = null): mixed
465468
* $params int|null "auction_number" A unique identifier for a particular auction
466469
* $params float|null "tag" (Optional) Order tag
467470
* $params string|null "validity" (Optional) Order validity (DAY, IOC).
471+
* $params float "market_protection" Set to -1 for system-default market protection, or a percentage value greater than 0 up to 100
468472
* @return mixed|null
469473
* @throws DataException
470474
* @throws GeneralException
@@ -494,6 +498,7 @@ public function placeOrder(string $variety, array $params)
494498
* $params float|null "price" (Optional) Order Price
495499
* $params float|null "trigger_price" (Optional) Trigger price
496500
* $params string|null "validity" (Optional) Order validity (DAY, IOC).
501+
* $params float|null "market_protection" (Optional) Set to -1 for system-default market protection, or a percentage value greater than 0 up to 100
497502
*
498503
* @return mixed
499504
* @throws DataException

tests/KiteConnectTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,39 @@ public function placeOrderTest($kiteConnect): void
204204

205205
}
206206

207+
/**
208+
* @depends initializeMock
209+
* @test placeOrder with market_protection
210+
*/
211+
public function placeOrderWithMarketProtectionTest($kiteConnect): void
212+
{
213+
$response = $kiteConnect->placeOrder("regular", [
214+
"tradingsymbol" => "INFY",
215+
"exchange" => "NSE",
216+
"quantity" => 1,
217+
"transaction_type" => "BUY",
218+
"order_type" => "MARKET",
219+
"product" => "NRML",
220+
"market_protection" => KiteConnect::MARKET_PROTECTION_AUTO
221+
]);
222+
223+
$this->assertObjectHasProperty('order_id', $response);
224+
}
225+
226+
/**
227+
* @depends initializeMock
228+
* @test modifyOrder with market_protection
229+
*/
230+
public function modifyOrderWithMarketProtectionTest($kiteConnect): void
231+
{
232+
$response = $kiteConnect->modifyOrder("regular", "123456789", [
233+
"price" => 10,
234+
"market_protection" => KiteConnect::MARKET_PROTECTION_AUTO
235+
]);
236+
237+
$this->assertObjectHasProperty('order_id', $response);
238+
}
239+
207240
/**
208241
* @depends initializeMock
209242
* @test getOrders

tests/MockJson.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public function generateMock()
2626
$response_array[] = new Response($status_code, $header_content, $this->fetchMock("holdings.json"));
2727
$response_array[] = new Response($status_code, $header_content, $this->fetchMock("positions.json"));
2828
$response_array[] = new Response($status_code, $header_content, $this->fetchMock("order_response.json"));
29+
$response_array[] = new Response($status_code, $header_content, $this->fetchMock("order_response.json"));
30+
$response_array[] = new Response($status_code, $header_content, $this->fetchMock("order_modify.json"));
2931
$response_array[] = new Response($status_code, $header_content, $this->fetchMock("orders.json"));
3032
$response_array[] = new Response($status_code, $header_content, $this->fetchMock("order_info.json"));
3133
$response_array[] = new Response($status_code, $header_content, $this->fetchMock("order_trades.json"));

0 commit comments

Comments
 (0)