Skip to content

Closing all Positions

Closing all positions is a simple way to close all open positions at once. This is useful if you want to close all positions at once, for example when you want to stop trading for the day.

Method

tm.close_all_positions(comment="", tags={})

Inputs

ParameterArgument typeDescriptionDefault Value
commentOptional[str]Comment to add to the orders""
tagsOptional[Dict[str, str]]Tags to add to the orders{}

Outputs

List of orders that were created to close all positions.

Example usage

strategy.py
import tradomate as tm
@tm.strategy()
def my_strategy(config: tm.TradomateConfig, data: tm.TradomateData):
# ... Your strategy code here
# Close all positions
orders = tm.close_all_positions(comment="Closing all positions", tags={"reason": "End of day"})
# ... Your strategy code here