Skip to content

Commit 3e7c7c1

Browse files
committed
added stop loss order type
1 parent a8f78d0 commit 3e7c7c1

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

sysexecution/algos/algo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
brokerOrderType,
1313
market_order_type,
1414
limit_order_type,
15-
brokerOrder,
15+
stop_loss_order_type
1616
)
1717
from sysexecution.tick_data import tickerObject
1818
from sysexecution.orders.contract_orders import contractOrder
@@ -105,7 +105,7 @@ def get_and_submit_broker_order_for_contract_order(
105105
## We want to preserve these otherwise there is a danger they will dynamically change
106106
collected_prices = copy(collected_prices)
107107

108-
if order_type == limit_order_type:
108+
if order_type == limit_order_type or order_type==stop_loss_order_type:
109109
limit_price = self.set_limit_price(
110110
contract_order=contract_order,
111111
collected_prices=collected_prices,

sysexecution/algos/algo_limit_orders.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from sysexecution.algos.algo import Algo, limit_price_from_input, limit_order_type
22
from sysexecution.order_stacks.broker_order_stack import orderWithControls
3+
from sysexecution.orders.broker_orders import stop_loss_order_type
34

45

56
class algoLimit(Algo):
@@ -32,3 +33,26 @@ def manage_trade(
3233
self, broker_order_with_controls: orderWithControls
3334
) -> orderWithControls:
3435
raise Exception("Limit order shouldn't be managed")
36+
37+
38+
class algoStopLoss(algoLimit):
39+
"""
40+
Submit a limit order which is a stop loss
41+
"""
42+
43+
def submit_trade(self) -> orderWithControls:
44+
contract_order = self.contract_order
45+
self.data.log.debug(
46+
"Submitting stop loss order for %s, limit price %f"
47+
% (str(contract_order), contract_order.limit_price)
48+
)
49+
broker_order_with_controls = (
50+
self.get_and_submit_broker_order_for_contract_order(
51+
contract_order,
52+
order_type=stop_loss_order_type,
53+
input_limit_price=contract_order.limit_price,
54+
limit_price_from=limit_price_from_input,
55+
)
56+
)
57+
58+
return broker_order_with_controls

0 commit comments

Comments
 (0)