Mariner Backtesting - service.alert()

 service.alert()

service. (method) Overview:

Record a message if the trading strategy is being run in info mode.

Otherwise, any message is silently ignored.

Interface:
 alert(symbol,
      guid,
      message)

Sample - Calling Method

 _alertList = [('float', 0.0), ('integer', 0), ('boolean', True), ('string', 'Buy Low & Sell High')]
service.alert( md.symbol, '67999edc-37ee-42da-b416-562456198d21', _alertList )
Parameters:
Name Type Default Information
symbol string required Symbol
guid string required Alert GUID (forward/live); Backtesting can be any unique string identifier. If you have multiple types of alerts in the same script, they need to have different guids
message list of tuples required Payload of data - list of tuples (name value pairs)
Returns:

None

Working Example:
from cloudquant.interfaces import Strategy


class BuyAlert(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")

        #send order; use a variable to accept the order_id that order.algo_buy returns
        order_id = order.algo_buy(self.symbol, "market", intent="init", order_quantity=100)
        my_alert = [('intent', 'init'), ('order_id', order_id), ('order_algo', 'market'), ('symbol', self.symbol)]
        service.alert(self.symbol, '67999edc-37ee-42da-b416-562456198d21', my_alert)

        #print the symbol, the shares, and the order_id
        print("100 shares of " + self.symbol + " have been purchased\norder number: " + order_id + "\n\n")

    def on_minute_bar(self, event, md, order, service, account, bar):
        if event.timestamp > service.time(9, 31):
            print(service.time_to_string(event.timestamp) + "\tin on_minute_bar()")

            # print position information
            print self.symbol + ' Information:\n'
            print account[self.symbol].position
            service.terminate()

Alert Displayed Under Log

Alerts under Log