Skip to content

Commit a8f78d0

Browse files
committed
added stop loss order type
1 parent 2e7e5df commit a8f78d0

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

sysbrokers/IB/client/ib_orders_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
LimitOrder as ibLimitOrder,
55
Trade as ibTrade,
66
Order as ibOrder,
7+
StopOrder as ibStopOrder
78
)
89

910
from syscore.exceptions import missingContract
@@ -27,6 +28,7 @@
2728
snap_mid_type,
2829
snap_prim_type,
2930
adaptive_mkt_type,
31+
stop_loss_order_type
3032
)
3133

3234
from sysobjects.contracts import futuresContract
@@ -148,6 +150,13 @@ def _build_ib_order(
148150
return missing_order
149151
else:
150152
ib_order = ibLimitOrder(ib_BS_str, ib_qty, limit_price)
153+
elif order_type is stop_loss_order_type:
154+
if limit_price is None:
155+
self.log.critical("Need to have limit price with limit order!")
156+
return missing_order
157+
else:
158+
ib_order = ibStopOrder(ib_BS_str, ib_qty, limit_price)
159+
151160
elif order_type is snap_mkt_type:
152161
## auxPrice is the offset so this will submit an order buy at the best offer, etc
153162
## Works like a market order but works for instruments with no streaming data

sysbrokers/IB/ib_orders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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
"""

sysexecution/orders/broker_orders.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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")
4647
market_order_type = brokerOrderType("market")
4748
limit_order_type = brokerOrderType("limit")
4849

systems/portfolio.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,13 +642,13 @@ def get_raw_estimated_instrument_weights(self) -> pd.DataFrame:
642642

643643
# these will probably be annual
644644
optimiser = self.calculation_of_raw_instrument_weights()
645-
weights_of_instruments_with_weights = optimiser.weights()
645+
instrument_weights = optimiser.weights()
646646

647-
instrument_weights = self._add_zero_weights_to_instrument_weights_df(
648-
weights_of_instruments_with_weights
647+
instrument_weights_with_zeros = self._add_zero_weights_to_instrument_weights_df(
648+
instrument_weights
649649
)
650650

651-
return instrument_weights
651+
return instrument_weights_with_zeros
652652

653653
def fit_periods(self):
654654
# FIXME, NO GUARANTEE THIS OBJECT HAS AN ESTIMATOR UNLESS IT INHERITS FROM

0 commit comments

Comments
 (0)