Skip to content

Commit 48b656b

Browse files
committed
BUG: Fix bug with buy/sell size=0
Fixes #900
1 parent 8f2c1d2 commit 48b656b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

backtesting/backtesting.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def buy(self, *,
208208
209209
See also `Strategy.sell()`.
210210
"""
211-
assert 0 < size < 1 or round(size) == size, \
211+
assert 0 < size < 1 or round(size) == size >= 1, \
212212
"size must be a positive fraction of equity, or a positive whole number of units"
213213
return self._broker.new_order(size, limit, stop, sl, tp, tag)
214214

@@ -228,7 +228,7 @@ def sell(self, *,
228228
If you merely want to close an existing long position,
229229
use `Position.close()` or `Trade.close()`.
230230
"""
231-
assert 0 < size < 1 or round(size) == size, \
231+
assert 0 < size < 1 or round(size) == size >= 1, \
232232
"size must be a positive fraction of equity, or a positive whole number of units"
233233
return self._broker.new_order(-size, limit, stop, sl, tp, tag)
234234

@@ -741,6 +741,7 @@ def new_order(self,
741741
tp = tp and float(tp)
742742

743743
is_long = size > 0
744+
assert size != 0, size
744745
adjusted_price = self._adjusted_price(size)
745746

746747
if is_long:

0 commit comments

Comments
 (0)