Mariner Backtesting - Strategy.on_nbbo_price()

National Best Bid/Best Offer Price Event

This method will be called whenever the NBBO price changes. NBBO price change would be when either the national bid price or ask price changes as published on the SIP feeds.

Interface:
 def on_nbbo_price(self,
                  event,
                  md,
                  order,
                  service,
                  account):
    pass
Data Attributes for event:
Name Type Information
agr_ask_size integer Sum of all ask participants in the SIP data.
agr_bid_size integer Sum of all bid participants in the SIP data.
ask float Current best ask price.
ask_exch string Best ask exchange ID. Exchange with largest size. ask_exch details
ask_size integer Number of lots (from md.stat.lot_size) at current best ask price.
bid float Current best bid price.
bid_exch float Best bid exchange ID. Exchange with largest size. bid_exch details
bid_size integer Number of lots (from md.stat.lot_size) at current best bid price.
is_halted boolean Boolean (True/False) for whether or not a symbol is halted.
kind integer Event enum (4) representing the kind of event. *LIVE AND FORWARD ONLY*, represents the type of event (trade, quote, news, imbalance etc)
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
Remarks:
  • 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.
Working Example:

Print the attributes of event when on_nbbo_price() is called.

from cloudquant.interfaces import Strategy


class OnNBBOImbalanceExample(Strategy):
    do_once = True

    @classmethod
    def is_symbol_qualified(cls, symbol, md, service, account):
        return symbol == 'SPY'

    def on_start(self, md, order, service, account):
        if self.__class__.do_once:
            print service.time_to_string(service.system_time, '%Y-%m-%d')
            self.__class__.do_once = False
        print self.symbol


    def on_nbbo_price( self, event, md, order, service, account ):
        print '\nin on_nbbo_price()\n\t%s\n' % service.time_to_string(service.system_time, '%H:%M:%S.%f')
        print 'event - NBBOEvent\n'

        print ' event.agr_ask_size  -   ', event.agr_ask_size
        print ' event.agr_bid_size  -   ', event.agr_bid_size
        print ' event.ask   -   ', event.ask
        print ' event.ask_exch  -   ', event.ask_exch
        print ' event.ask_size  -   ', event.ask_size
        print ' event.bid   -   ', event.bid
        print ' event.bid_exch  -   ', event.bid_exch
        print ' event.bid_size  -   ', event.bid_size
        print ' event.is_halted -   ', event.is_halted
        print ' event.kind  -   ', event.kind
        print ' event.symbol    -   ', event.symbol
        print ' event.timestamp -   ', event.timestamp

        service.terminate()

Console

2016-01-04
AAPL

in on_nbbo_price()
    09:28:00.119000

event - NBBOEvent

    event.agr_ask_size  -   1
    event.agr_bid_size  -   1
    event.ask   -   102.61000061
    event.ask_exch  -   Q
    event.ask_size  -   1
    event.bid   -   102.540000916
    event.bid_exch  -   P
    event.bid_size  -   1
    event.is_halted -   False
    event.kind  -   4
    event.symbol    -   AAPL
    event.timestamp -   1451917680119000