Skip to content

Commit

Permalink
Adds outside-RTH orders for IB.
Browse files Browse the repository at this point in the history
  • Loading branch information
petioptrv committed Aug 24, 2020
1 parent 855f614 commit 0ef6467
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion algotradepy/ib_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,16 @@ def _from_ib_order(ib_order: _IBOrder) -> Optional[AnOrder]:
def _to_ib_order(self, order: AnOrder) -> _IBOrder:
if isinstance(order, MarketOrder):
ib_order = _IBMarketOrder(
action=order.action.value, totalQuantity=order.quantity,
action=order.action.value,
totalQuantity=order.quantity,
outsideRth=order.outside_rth,
)
elif isinstance(order, LimitOrder):
ib_order = _IBLimitOrder(
action=order.action.value,
totalQuantity=order.quantity,
lmtPrice=round(order.limit_price, 2),
outsideRth=order.outside_rth,
)
elif isinstance(order, TrailingStopOrder):
ib_trail_percent = order.trail_percent or UNSET_DOUBLE
Expand All @@ -300,6 +303,7 @@ def _to_ib_order(self, order: AnOrder) -> _IBOrder:
trailingPercent=ib_trail_percent,
trailStopPrice=ib_stop_price,
auxPrice=ib_aux_price,
outsideRth=order.outside_rth,
)
else:
raise TypeError(f"Unknown type of order {type(order)}.")
Expand Down
6 changes: 6 additions & 0 deletions algotradepy/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(
time_in_force: Optional[TimeInForce] = None,
conditions: Optional[List[ACondition]] = None,
parent_id: Optional[int] = None,
outside_rth: bool = False,
):
super().__init__()
self._order_id = order_id
Expand All @@ -69,6 +70,7 @@ def __init__(
conditions = []
self._conditions = conditions
self._parent_id = parent_id
self._outside_rth = outside_rth

@property
def order_id(self) -> int:
Expand All @@ -94,6 +96,10 @@ def conditions(self) -> List[ACondition]:
def parent_id(self):
return self._parent_id

@property
def outside_rth(self):
return self._outside_rth


class MarketOrder(AnOrder):
"""A market order definition."""
Expand Down

0 comments on commit 0ef6467

Please sign in to comment.