# Path: intuition/errors.py
# class AlgorithmEventFailed(dna.errors.FactoryError):
#     msg = """
# [{date}] \
# algorithm event failed: {reason}, \
# processing {data}
# """.strip()


import abc
import datetime as dt
from zipline.algorithm import TradingAlgorithm
from intuition.errors import AlgorithmEventFailed
        #NOTE A middleware Object ?
        # self.use() is usually called from initialize(), so no logger yet
        print('registering middleware {}'.format(func.__name__))
        self.middlewares.append({
            'call': func,
            'name': func.__name__,
            'args': func.func_code.co_varnames,
            'when': when
        })

    #NOTE I'm not superfan of initialize + warm
    def warm(self, data):
        ''' Called at the first handle_data frame '''
        pass

    @abc.abstractmethod
    def event(self, data):
        ''' User should overwrite this method '''
        pass

    def handle_data(self, data):
        ''' Method called for each event by zipline. In intuition this is the
        place to factorize algorithms and then call event() '''
        self.days += 1
        signals = {}
        self.orderbook = {}

        # Everytime but the first tick
        if self.initialized and self.manager:
            # Keep the portfolio aware of the situation

# Path: intuition/errors.py
# class AlgorithmEventFailed(dna.errors.FactoryError):
#     msg = """
# [{date}] \
# algorithm event failed: {reason}, \
# processing {data}
# """.strip()


# Path: intuition/api/algorithm.py
import abc
import datetime as dt
from zipline.algorithm import TradingAlgorithm
from intuition.errors import AlgorithmEventFailed

        #NOTE A middleware Object ?
        # self.use() is usually called from initialize(), so no logger yet
        print('registering middleware {}'.format(func.__name__))
        self.middlewares.append({
            'call': func,
            'name': func.__name__,
            'args': func.func_code.co_varnames,
            'when': when
        })

    #NOTE I'm not superfan of initialize + warm
    def warm(self, data):
        ''' Called at the first handle_data frame '''
        pass

    @abc.abstractmethod
    def event(self, data):
        ''' User should overwrite this method '''
        pass

    def handle_data(self, data):
        ''' Method called for each event by zipline. In intuition this is the
        place to factorize algorithms and then call event() '''
        self.days += 1
        signals = {}
        self.orderbook = {}

        # Everytime but the first tick
        if self.initialized and self.manager:
            # Keep the portfolio aware of the situation

            self.manager.update(