Place new `Order` to close `portion` of the trade at next market price.
(self, portion: float = 1.)
| 588 | return copy(self)._replace(**kwargs) |
| 589 | |
| 590 | def close(self, portion: float = 1.): |
| 591 | """Place new `Order` to close `portion` of the trade at next market price.""" |
| 592 | assert 0 < portion <= 1, "portion must be a fraction between 0 and 1" |
| 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) |
| 595 | order = Order(self.__broker, size, parent_trade=self, tag=self.__tag) |
| 596 | self.__broker.orders.insert(0, order) |
| 597 | |
| 598 | # Fields getters |
| 599 |
no test coverage detected