Time Triggers Question

Dustin_LangDustin_Lang Posts: 25
edited August 2016 in Under The Hood

Does service.clear_time_triggers( ) clear all time triggers for all symbols? I would like to clear time triggers for a particular symbol and/or a given TimerID but this doesn't seem to be an option?

Tagged:

Comments

  • shayneshayne Posts: 70
    edited August 2016

    At this time, it just clears time trigger for the current instance. We will add the request for clearing by timer_id to the backlog. Other users please add a comment if you like the idea.

  • idaganiidagani Posts: 11

    I like it a lot, needless to say that cancelling specific timers adds a lot of flexibility

  • Yeah I definitely would like to see this!

  • I also like to have a end_time parameter when set up a time trigger. So, a trigger only lives during a time interval.

  • current workaround to cancel a time trigger with specific id:

    `

    from cloudquant.interfaces import Strategy

    class test_trigger(Strategy):

    @classmethod
    def is_symbol_qualified(cls, symbol, md, service, account):
        return symbol == 'SPY'
    
    def on_start(self, md, order, service, account):
        service.add_time_trigger(service.time(9, 40),service.time_interval(0, 0, 1), timer_id='id-1')
        service.add_time_trigger(service.time(9, 40,10), timer_id='id-stop')
    
    def on_timer(self, event, md, order, service, account):
        if event.timer_id == 'id-1':
            print 'id-1', service.time_to_string(service.system_time)
    
        if event.timer_id=='id-stop':
            print 'id-stop', service.time_to_string(service.system_time)
            service.clear_time_triggers()
            service.add_time_trigger(service.time(9, 41), timer_id='id-2')
    
        if event.timer_id=='id-2':
            print 'this is id-2 trigger*****',self.symbol,service.time_to_string(service.system_time)
    
    
    def on_finish(self, md, order, service, account):
        pass
    

    `
    output :
    id-1 2016-12-13 09:40:00.000000
    id-1 2016-12-13 09:40:01.000000
    id-1 2016-12-13 09:40:02.000000
    id-1 2016-12-13 09:40:03.000000
    id-1 2016-12-13 09:40:04.000000
    id-1 2016-12-13 09:40:05.000000
    id-1 2016-12-13 09:40:06.000000
    id-1 2016-12-13 09:40:07.000000
    id-1 2016-12-13 09:40:08.000000
    id-1 2016-12-13 09:40:09.000000
    id-stop 2016-12-13 09:40:10.000000
    this is id-2 trigger***** SPY 2016-12-13 09:41:00.000000

Sign In or Register to comment.