self.close_position

lumibot.strategies.strategy.Strategy.close_position(self, asset, fraction: float = 1.0, position_side=None, position_id=None)

Close a single position for the specified asset.

This method attempts to close an open position for the given asset. For most brokers, this is done by submitting a market sell order for the open position. For crypto futures brokers (such as Bitunix), this may use a broker-specific fast-close or “flash close” endpoint to close the position immediately at market price.

Parameters:

asset (str or Asset) – The symbol or Asset object identifying the position to close.

Returns:

The broker.close_position result, or None if no action was taken.

Return type:

Any

Notes

  • For crypto futures (e.g., Bitunix), this will use the broker’s flash close endpoint if available.

  • For spot/stock/futures brokers, this will submit a market sell order for the open position.

  • If no open position exists, this method does nothing.