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
6 changes: 6 additions & 0 deletions integrate/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def place_order( # noqa: C901
product_type: str,
quantity: int,
tradingsymbol: str,
algo_id: str,
amo: Union[str, None] = None,
book_loss_price: Union[float, None] = None,
book_profit_price: Union[float, None] = None,
Expand All @@ -117,6 +118,7 @@ def place_order( # noqa: C901
:param `product_type`: Product type. Valid values are CNC, INTRADAY, NORMAL.
:param `quantity`: Quantity to transact.
:param `tradingsymbol`: Trading symbol of security to transact.
:param `algo_id`: Algo Id for the order.
:param `amo`: If set to True, AMO order will be placed. Defaults to False.
:param `book_loss_price`: Book loss price (Applicable only for Bracket orders).
:param `book_profit_price`: Book profit price (Applicable only for Bracket orders).
Expand All @@ -133,6 +135,7 @@ def place_order( # noqa: C901
:type `product_type`: `str`
:type `quantity`: `int`
:type `tradingsymbol`: `str`
:type `algo_id`:`str`
:type `amo`: `str`
:type `book_loss_price`: `float`
:type `book_profit_price`: `float`
Expand Down Expand Up @@ -177,6 +180,9 @@ def place_order( # noqa: C901
if quantity == 0:
raise ValueError("Quantity cannot be 0")

if algo_id == "":
raise ValueError("Algo id cannot be blank")

json_params: dict[str, Any] = locals()
for k in list(json_params.keys()):
if k == "self" or json_params[k] is None:
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/orders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def custom_order_placement(
product_type: str,
quantity: int,
tradingsymbol: str,
algo_id:str,
price: str = "ltp",
trigger_price: str = "ltp",
) -> dict[str, Any]:
Expand Down Expand Up @@ -96,6 +97,7 @@ def custom_order_placement(
product_type=product_type,
quantity=quantity,
tradingsymbol=tradingsymbol,
algo_id=algo_id,
)
elif price_type == c2i.PRICE_TYPE_LIMIT:
price_value: float = (
Expand All @@ -111,6 +113,7 @@ def custom_order_placement(
product_type=product_type,
quantity=quantity,
tradingsymbol=tradingsymbol,
algo_id=algo_id,
)
elif price_type == c2i.PRICE_TYPE_SL_MKT:
trigger_price_value: float = (
Expand All @@ -127,6 +130,7 @@ def custom_order_placement(
quantity=quantity,
tradingsymbol=tradingsymbol,
trigger_price=trigger_price_value,
algo_id=algo_id,
)
elif price_type == c2i.PRICE_TYPE_SL_LMT:
trigger_price_value = (
Expand All @@ -148,6 +152,7 @@ def custom_order_placement(
quantity=quantity,
tradingsymbol=tradingsymbol,
trigger_price=trigger_price_value,
algo_id=algo_id,
)

assert isinstance(order, dict)
Expand Down
1 change: 1 addition & 0 deletions tests/unit/orders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_placing_order(c2i: ConnectToIntegrate, io: IntegrateOrders) -> None:
product_type=c2i.PRODUCT_TYPE_NORMAL,
quantity=50,
tradingsymbol="NIFTY23FEB23F",
algo_id="99999",
)
# Assert that the response is a dict and contains the required keys
assert isinstance(order, dict)
Expand Down
Loading