Mariner Backtesting - Strategy.on_ack()

Order Acknowledgment Event

Called whenever a previously placed order is acknowledged by the exchange.

Interface:
 def on_ack(self,
           event,
           md,
           order,
           service,
           account):
    pass
Data Attributes for event:
Name Type Information
account_id integer The account id of the order event. Will be the same as account id of the script.
clordid string Client Order Id in FIX. Is generated when the order is sent. Will be the same on executions.
expected_direction enum Either increase, reduce, or reverse. This will be set when the order is first placed, and is a prediction of whether your order will increase, reduce, or reverse your current posistion. Note a short on a symbol that you do not currently hold would be considered an increase of that position. This can obviously change as it's possible you have orders in flight, that haven't filled yet. Can be usefull in debugging order behavior
instruction_id string Unique GUID for the instance of the script that generated the initial order. Will be None if the initial order wasn't started from same machine (e.g. from trading client)
intent string The intent attribute you set in the order that generated this event.
kind integer Event enum (9) representing the kind of event. *LIVE AND FORWARD ONLY*, represents the type of event (trade, quote, news, imbalance etc)
line_number string line_number is the line in your strategy script where the order was placed that generated this event. Can be used to help debug order behavior
order_algorithm string The order_algorithm GUID you set in the order that generated this event. This can be useful in debugging order behavior.
order_id string Unique GUID of order being achknowledged (very similar clordid). Will be None if the initial order wasn't started from same machine (e.g. from trading client)
price float Price of the order.
script_class_name string script_class_name represents the name of your Strategy class that placed the order that generated this event. Can be used to help debug order behavior
script_id string GUID of the script. Will be None if the initial order wasn't started from same machine (e.g. from trading client)
shares integer Shares acknowledged.
state string Order Message's States
symbol string Event Symbol. In most cases symbol is obvious (self.symbol, md.symbol). If the script has subscribed to multiple symbols events, then event.symbol should be used to identify the symbol.
timestamp muts Timestamp of the event.
user_key string user_key set on the order. Can be used to identify trades that go together (pairs/batch/strategy). account object can be filtered on user_key
Working Example:
from cloudquant.interfaces import Strategy


class OnAckExample(Strategy):

    @classmethod
    def is_symbol_qualified(cls, symbol, md, service, account):
        return symbol == "AAL"

    def on_start(self, md, order, service, account):
        # print the symbol and timestamp
        print(self.symbol + "\n" + service.time_to_string(service.system_time) + "\tin on_start()\n\n")

        # instance variable
        self.do_once = True

    def on_trade(self, event, md, order, service, account):
        print( service.time_to_string(service.system_time) + "\tin on_trade()\n\n")

        if self.do_once:
            #send order
            order.algo_buy(self.symbol, "market", intent="init", order_quantity=100)

            #set instance variable False
            self.do_once = False

    def on_ack(self, event, md, order, service, account):
        #print  timestamp
        print( service.time_to_string(service.system_time) + "\tin on_ack()\n\n")

        print("an order has been acknowledged\n")

        #print ack event
        print (event)

Console

AAL
2016-08-15 09:25:00.000000  in on_start()

2016-08-15 09:30:00.149000  in on_trade()


2016-08-15 09:30:00.149000  in on_ack()


an order has been acknowledged

AckEvent(instruction_id='bae421c9-7ba7-49d2-b11e-bbb6b2de6e93', script_id=u'053e729d-d0cd-4306-aa2b-064bae664d72', user_key='bae421c9-7ba7-49d2-b11e-bbb6b2de6e93', order_id='0000000000000001', state='N', price=0.0, shares=100, timestamp=1471267800149000, symbol='AAL', account_number=0, clordid=None, kind=9)