Skip to content

Commit f8f4969

Browse files
committed
BUG: Ensure order.size is an int
Fixes #954
1 parent f94b20f commit f8f4969

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

backtesting/backtesting.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,8 @@ def _copy(self, **kwargs):
590590
def close(self, portion: float = 1.):
591591
"""Place new `Order` to close `portion` of the trade at next market price."""
592592
assert 0 < portion <= 1, "portion must be a fraction between 0 and 1"
593-
size = copysign(max(1, round(abs(self.__size) * portion)), -self.__size)
593+
# Ensure size is an int to avoid rounding errors on 32-bit OS
594+
size = copysign(max(1, int(round(abs(self.__size) * portion))), -self.__size)
594595
order = Order(self.__broker, size, parent_trade=self, tag=self.__tag)
595596
self.__broker.orders.insert(0, order)
596597

0 commit comments

Comments
 (0)