Skip to content

Commit 2a1f33c

Browse files
committed
DEPR: Remove old deprecation
1 parent 054d453 commit 2a1f33c

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

β€Žbacktesting/backtesting.pyβ€Ž

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def position(self) -> 'Position':
312312
@property
313313
def orders(self) -> 'Tuple[Order, ...]':
314314
"""List of orders (see `Order`) waiting for execution."""
315-
return _Orders(self._broker.orders)
315+
return tuple(self._broker.orders)
316316

317317
@property
318318
def trades(self) -> 'Tuple[Trade, ...]':
@@ -325,27 +325,6 @@ def closed_trades(self) -> 'Tuple[Trade, ...]':
325325
return tuple(self._broker.closed_trades)
326326

327327

328-
class _Orders(tuple):
329-
"""
330-
TODO: remove this class. Only for deprecation.
331-
"""
332-
def cancel(self):
333-
"""Cancel all non-contingent (i.e. SL/TP) orders."""
334-
for order in self:
335-
if not order.is_contingent:
336-
order.cancel()
337-
338-
def __getattr__(self, item):
339-
# TODO: Warn on deprecations from the previous version. Remove in the next.
340-
removed_attrs = ('entry', 'set_entry', 'is_long', 'is_short',
341-
'sl', 'tp', 'set_sl', 'set_tp')
342-
if item in removed_attrs:
343-
raise AttributeError(f'Strategy.orders.{"/.".join(removed_attrs)} were removed in'
344-
'Backtesting 0.2.0. '
345-
'Use `Order` API instead. See docs.')
346-
raise AttributeError(f"'tuple' object has no attribute {item!r}")
347-
348-
349328
class Position:
350329
"""
351330
Currently held asset position, available as

β€Žbacktesting/test/_test.pyβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ def next(self, _FEW_DAYS=pd.Timedelta('3 days')): # noqa: N803
173173
self.position.is_long
174174

175175
if crossover(self.sma, self.data.Close):
176-
self.orders.cancel() # cancels only non-contingent
176+
for order in self.orders:
177+
if not order.is_contingent:
178+
order.cancel()
177179
price = self.data.Close[-1]
178180
sl, tp = 1.05 * price, .9 * price
179181

0 commit comments

Comments
Β (0)