File tree Expand file tree Collapse file tree 5 files changed +38
-8
lines changed
Expand file tree Collapse file tree 5 files changed +38
-8
lines changed Original file line number Diff line number Diff line change 44 LimitOrder as ibLimitOrder ,
55 Trade as ibTrade ,
66 Order as ibOrder ,
7+ StopOrder as ibStopOrder
78)
89
910from syscore .exceptions import missingContract
2627 snap_mkt_type ,
2728 snap_mid_type ,
2829 snap_prim_type ,
29- adaptive_mkt_type ,
30+ adaptive_mkt_type , stop_loss_order_type ,
3031)
3132
3233from sysobjects .contracts import futuresContract
@@ -148,6 +149,9 @@ def _build_ib_order(
148149 return missing_order
149150 else :
150151 ib_order = ibLimitOrder (ib_BS_str , ib_qty , limit_price )
152+ elif order_type == stop_loss_order_type :
153+ ib_order = ibStopOrder (ib_BS_str , ib_qty , limit_price )
154+
151155 elif order_type is snap_mkt_type :
152156 ## auxPrice is the offset so this will submit an order buy at the best offer, etc
153157 ## Works like a market order but works for instruments with no streaming data
Original file line number Diff line number Diff line change @@ -144,7 +144,7 @@ def get_list_of_broker_orders_with_account_id(
144144
145145 :return: list of brokerOrder objects
146146 """
147- list_of_control_objects = self ._get_list_of_broker_control_orders (
147+ list_of_control_objects = self .get_list_of_broker_control_orders (
148148 account_id = account_id
149149 )
150150 order_list = [
@@ -158,7 +158,7 @@ def get_list_of_broker_orders_with_account_id(
158158 def _get_dict_of_broker_control_orders (
159159 self , account_id : str = arg_not_supplied
160160 ) -> dict :
161- control_order_list = self ._get_list_of_broker_control_orders (
161+ control_order_list = self .get_list_of_broker_control_orders (
162162 account_id = account_id
163163 )
164164 dict_of_control_orders = dict (
@@ -169,7 +169,7 @@ def _get_dict_of_broker_control_orders(
169169 )
170170 return dict_of_control_orders
171171
172- def _get_list_of_broker_control_orders (
172+ def get_list_of_broker_control_orders (
173173 self , account_id : str = arg_not_supplied
174174 ) -> list :
175175 """
Original file line number Diff line number Diff line change 1212 brokerOrderType ,
1313 market_order_type ,
1414 limit_order_type ,
15- brokerOrder ,
15+ brokerOrder , stop_loss_order_type ,
1616)
1717from sysexecution .tick_data import tickerObject
1818from 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 ,
@@ -201,7 +201,6 @@ def set_limit_price(
201201 input_limit_price : float = None ,
202202 limit_price_from : str = limit_price_from_input ,
203203 ) -> float :
204- assert limit_price_from in sources_of_limit_price
205204
206205 if limit_price_from == limit_price_from_input :
207206 assert input_limit_price is not None
Original file line number Diff line number Diff line change 11from sysexecution .algos .algo import Algo , limit_price_from_input , limit_order_type
22from sysexecution .order_stacks .broker_order_stack import orderWithControls
3+ from sysexecution .orders .broker_orders import stop_loss_order_type
34
45
56class algoLimit (Algo ):
@@ -32,3 +33,28 @@ def manage_trade(
3233 self , broker_order_with_controls : orderWithControls
3334 ) -> orderWithControls :
3435 raise Exception ("Limit order shouldn't be managed" )
36+
37+
38+
39+
40+ class algoStopLoss (algoLimit ):
41+ """
42+ Submit a limit order which is a stop loss
43+ """
44+
45+ def submit_trade (self ) -> orderWithControls :
46+ contract_order = self .contract_order
47+ self .data .log .debug (
48+ "Submitting stop loss order for %s, limit price %f"
49+ % (str (contract_order ), contract_order .limit_price )
50+ )
51+ broker_order_with_controls = (
52+ self .get_and_submit_broker_order_for_contract_order (
53+ contract_order ,
54+ order_type = stop_loss_order_type ,
55+ input_limit_price = contract_order .limit_price ,
56+ limit_price_from = limit_price_from_input ,
57+ )
58+ )
59+
60+ return broker_order_with_controls
Original file line number Diff line number Diff line change @@ -40,9 +40,10 @@ def allowed_types(self):
4040 "snap_mid" ,
4141 "snap_prim" ,
4242 "adaptive_mkt" ,
43+ "stop_loss"
4344 ]
4445
45-
46+ stop_loss_order_type = brokerOrderType ( "stop loss" )
4647market_order_type = brokerOrderType ("market" )
4748limit_order_type = brokerOrderType ("limit" )
4849
You can’t perform that action at this time.
0 commit comments