Strategy Control Option
- The following are keys that can be used in the exit_options dictionary when placing an order with an exit strategy, or in the options dictionary when starting a strategy with service.start_strategy(). None of these options are required.
Name | Type |
---|---|
DeployBeginTime or StartTime | milliseconds from midnight |
Hibernate | boolean |
PauseTime or StopTime | milliseconds from midnight |
PauseRelativeTime or StopRelativeTime | milliseconds from market close |
SingleInstanceOnly | boolean |
UseAbsoluteTime | boolean |
Example usage with an exit script
# Start the exit script at 3pm, and make sure only one is started
# even if more than one order with this exit script was placed.
# 54000000 milliseconds == 3pm (which is 15 hours after midnight)
order.algo_buy(self.symbol, 'limit', 'init', price=15.37, order_quantity=500, exit_script="MyExitScript", exit_options={"StartTime": 54000000, "SingleInstanceOnly": True})
Example usage with service.start_strategy
# Start the strategy at 3pm, and make sure only one is started
service.start_strategy("MyScript", self.symbol, options={"StartTime": 54000000, "SingleInstanceOnly": True})
DeployBeginTime or StartTime
- Specifies the time the system will start a Strategy in units of milliseconds since midnight using local time.
- If service.system_time is greater than or equal to StartTime when the system receives the Strategy start instruction, then the system will start the Strategy immediately.
- If StartTime is greater than service.system_time, then the system will queue up the Strategy to be started once StartTime is reached.
- The default value for StartTime is 8 a.m. Eastern Time.
Hibernate
- If True, the system will hibernate the Strategy when StopTime is reached. A Strategy that is hibernated will be restarted on the following trading day using the StartTime specified when the Strategy was originally started.
- If False, the system will not hibernate the Strategy unless the Strategy was forced into hibernation in the Strategy's code with a call to service.hibernate().
- The default value is False.
PauseTime or StopTime
- Specifies the time the system will stop a Strategy in units of milliseconds since midnight using local time.
- Used by the system to stop a Strategy if UseAbsoluteTime is True. If UseAbsoluteTime is False, this option will be ignored.
- If service.system_time is greater than or equal to StopTime when the system receives the Strategy start instruction, then the system will report an error "StopTime (timestamp) must be set to a future time" and the Strategy will not be started.
PauseRelativeTime or StopRelativeTime
- Specifies the time the system will stop a Strategy as an offset from market close, measured in milliseconds.
- Used by the system to stop a Strategy if UseAbsoluteTime is False.
- Calculates a StopTime from market close + StopRelativeTime.
- If service.system_time is greater than or equal to the calculated StopTime when the system receives the Strategy start instruction, then the system will report an error "StopTime (timestamp) must be set to a future time" and the Strategy will not be started.
- This value can be negative, which implies that the strategy will be stopped before the market close.
SingleInstanceOnly
- Used by the system only when a Strategy is started explicitly for one symbol.
- If True, the system will start only one Strategy for a given account symbol pair. Subsequent start instructions for the same account symbol pair will be blocked by the system and the warning is reported to the user.
- The default value is False.
UseAbsoluteTime
- If True then the system will stop the Strategy at the time specified in StopTime.
- If False then the Strategy will be stopped using StopRelativeTime (offset from market close).
- The default value is False.