service.add_time_trigger()
service. (method) Overview:Method to schedule the system to call on_timer().
Interface: add_time_trigger(timestamp,
repeat_interval=None,
timer_id=None)
Sample - Calling Method
service.add_time_trigger( md.market_open_time - service.time_interval(0, 1) )
Name | Type | Default | Information |
---|---|---|---|
timestamp | muts | required | An integer timestamp, such as that derived from service.time(). |
repeat_interval | increment of time in muts | None | An integer timestamp indicating the frequency of repeats. |
timer_id | object | None | Something to identify this trigger after it fires. |
None
Remarks:- add_time_trigger() can be called from whenever from anywhere the service object is available
- Don't try to call too quickly (less than half a second), or your code will pay the price
- Triggers that haven't been processed after on_finish() are not processed
- clear_time_triggers() can be used to remove all unprocessed time triggers
Add time trigger at market close with a timer id.
from cloudquant.interfaces import Strategy
class AddTimeTriggerExample(Strategy):
@classmethod
def is_symbol_qualified(cls, symbol, md, service, account):
return symbol == "AAL"
def on_start(self, md, order, service, account):
print(self.symbol + "\n" + service.time_to_string(service.system_time) + "\n \n")
service.add_time_trigger(service.time(15, 55))
def on_timer(self, event, md, order, service, account):
print(service.time_to_string(event.timestamp) + " - Timer triggered")
Console
2016-08-08 09:23:14.962000 2016-08-08 15:55:00.000000 - Timer triggered