Strategy finishing event
Called for each instance before the strategy is unloaded. Any final cleanup or logging can be done by the strategy at this point.
Interface: def on_finish(self,
md,
order,
service,
account):
pass
Same as for on_start()
Name | Type | Default | Information |
---|---|---|---|
self | object | required | The instance of Strategy (used by the system). |
md | object | required | Market data object. It should not be saved, as it may change in future calls. |
order | object | required | Order object. It should not be saved, as it may change in future calls. |
service | object | required | Service object. It should not be saved, as it may change in future calls. |
account | object | required | Account object. It should not be saved, as it may change in future calls. |
from cloudquant.interfaces import Strategy
class OnFinishExample(Strategy):
@classmethod
def is_symbol_qualified(cls, symbol, md, service, account):
return symbol == "AAL"
def on_start(self, md, order, service, account):
# print start time and symbol
print(self.symbol + "\n" + service.time_to_string(service.system_time) + "\tin on_start()\n\n")
# create a variable to count minute bars in a trading day
self.bar_count = 0
# on_minute_bar should not be called because of the terminate
def on_minute_bar(self, event, md, order, service, account, bar):
self.bar_count += 1
def on_finish(self, md, order, service, account):
print(service.time_to_string(service.system_time) + "\tin on_finish()\n\n")
# a print statement to let us know the self.bar_count
print("on_minute_bar was called " + str(self.bar_count) + " times today.")
Console
AAL 2016-11-01 09:30:00.000000 in on_start() 2016-11-01 16:00:00.000000 in on_finish() on_minute_bar was called 390 times today.