Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand Down
7 changes: 6 additions & 1 deletion src/KiteConnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions tests/KiteConnectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/MockJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Loading