from abc import ABCMeta, abstractmethod


class AbstractExecutionHandler(object):
    """Abstract Execution Handler Class

    The execution handler abstract class handles the interaction between a  set
    of order objects generated by a portfolio and the ultimate set of fill
    objects that actually occur in the market.

    The handlers can be used to subclass simulated brokerages or live
    brokerages, with identical interfaces. This allows strategies to be
    backtested in a very similar manner to the live trading engine.
    """
    __metaclass__ = ABCMeta

    def __init__(self, events, is_live):
        """Initialize parameters of the abstract execution handler."""
        self.events = events
        self.is_live = is_live

    @abstractmethod
    def execute_order(self, order_event):
        """Objects that implement the abstract execution handler must implement
        a method for submitting order events to the brokerage. These submitted
        orders must then be processed to become fill events that indicate that a
        position was properly entered or exited.
        """
        raise NotImplementedError()
