diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ae5e79..360d004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to `phpkiteconnect` will be documented in this file. +## 5.1.0 - 2026-03-27 +- Added `MARKET_PROTECTION_AUTO` constant (`-1`) for system-default market protection +- Added `market_protection` parameter support for `placeOrder` and `modifyOrder` +- Added tests for `placeOrder` and `modifyOrder` with `market_protection` + ## 4.0.0 - 2021-04-06 - Major refactor to project structure and code - PHP support 7.3+ diff --git a/src/KiteConnect.php b/src/KiteConnect.php index 3263055..c2adf15 100644 --- a/src/KiteConnect.php +++ b/src/KiteConnect.php @@ -121,7 +121,10 @@ class KiteConnect public const POSITION_TYPE_DAY = "day"; public const POSITION_TYPE_OVERNIGHT = "overnight"; - public const VERSION = "3.2.0"; + // Market protection + public const MARKET_PROTECTION_AUTO = -1; + + public const VERSION = "5.1.0"; // Kite connect header version private $kiteVersion = "3"; @@ -465,6 +468,7 @@ public function getMargins(?string $segment = null): mixed * $params int|null "auction_number" A unique identifier for a particular auction * $params float|null "tag" (Optional) Order tag * $params string|null "validity" (Optional) Order validity (DAY, IOC). + * $params float "market_protection" (Mandatory only for MARKET orders) Set to -1 for system-default market protection, or a percentage value greater than 0 up to 100 * @return mixed|null * @throws DataException * @throws GeneralException @@ -494,6 +498,7 @@ public function placeOrder(string $variety, array $params) * $params float|null "price" (Optional) Order Price * $params float|null "trigger_price" (Optional) Trigger price * $params string|null "validity" (Optional) Order validity (DAY, IOC). + * $params float|null "market_protection" (Optional) Set to -1 for system-default market protection, or a percentage value greater than 0 up to 100 * * @return mixed * @throws DataException diff --git a/tests/KiteConnectTest.php b/tests/KiteConnectTest.php index ecaafe0..949e246 100644 --- a/tests/KiteConnectTest.php +++ b/tests/KiteConnectTest.php @@ -204,6 +204,39 @@ public function placeOrderTest($kiteConnect): void } + /** + * @depends initializeMock + * @test placeOrder with market_protection + */ + public function placeOrderWithMarketProtectionTest($kiteConnect): void + { + $response = $kiteConnect->placeOrder("regular", [ + "tradingsymbol" => "INFY", + "exchange" => "NSE", + "quantity" => 1, + "transaction_type" => "BUY", + "order_type" => "MARKET", + "product" => "NRML", + "market_protection" => KiteConnect::MARKET_PROTECTION_AUTO + ]); + + $this->assertObjectHasProperty('order_id', $response); + } + + /** + * @depends initializeMock + * @test modifyOrder with market_protection + */ + public function modifyOrderWithMarketProtectionTest($kiteConnect): void + { + $response = $kiteConnect->modifyOrder("regular", "123456789", [ + "price" => 10, + "market_protection" => KiteConnect::MARKET_PROTECTION_AUTO + ]); + + $this->assertObjectHasProperty('order_id', $response); + } + /** * @depends initializeMock * @test getOrders diff --git a/tests/MockJson.php b/tests/MockJson.php index 4763cb3..1e277be 100644 --- a/tests/MockJson.php +++ b/tests/MockJson.php @@ -26,6 +26,8 @@ public function generateMock() $response_array[] = new Response($status_code, $header_content, $this->fetchMock("holdings.json")); $response_array[] = new Response($status_code, $header_content, $this->fetchMock("positions.json")); $response_array[] = new Response($status_code, $header_content, $this->fetchMock("order_response.json")); + $response_array[] = new Response($status_code, $header_content, $this->fetchMock("order_response.json")); + $response_array[] = new Response($status_code, $header_content, $this->fetchMock("order_modify.json")); $response_array[] = new Response($status_code, $header_content, $this->fetchMock("orders.json")); $response_array[] = new Response($status_code, $header_content, $this->fetchMock("order_info.json")); $response_array[] = new Response($status_code, $header_content, $this->fetchMock("order_trades.json"));