# Path: alephnull/protocol.py
# DATASOURCE_TYPE = Enum(
#     'AS_TRADED_EQUITY',
#     'MERGER',
#     'SPLIT',
#     'DIVIDEND',
#     'TRADE',
#     'TRANSACTION',
#     'ORDER',
#     'EMPTY',
#     'DONE',
#     'CUSTOM',
#     'BENCHMARK',
#     'COMMISSION'
# )
# 
# Path: alephnull/gens/utils.py
# def assert_sort_unframe_protocol(event):
#     """Same as above."""
#     assert isinstance(event.source_id, basestring)
#     assert event.type in DATASOURCE_TYPE
# 
# def hash_args(*args, **kwargs):
#     """Define a unique string for any set of representable args."""
#     arg_string = '_'.join([str(arg) for arg in args])
#     kwarg_string = '_'.join([str(key) + '=' + str(value)
#                              for key, value in kwargs.iteritems()])
#     combined = ':'.join([arg_string, kwarg_string])
# 
#     hasher = md5()
#     hasher.update(combined)
#     return hasher.hexdigest()
# 
# Path: alephnull/finance/trading.py
# class TradingEnvironment(object):
# class SimulationParameters(object):
#     def __init__(
#         self,
#         load=None,
#         bm_symbol='^GSPC',
#         exchange_tz="US/Eastern",
#         max_date=None,
#         extra_dates=None
#     ):
#     def __enter__(self, *args, **kwargs):
#     def __exit__(self, exc_type, exc_val, exc_tb):
#     def normalize_date(self, test_date):
#     def utc_dt_in_exchange(self, dt):
#     def exchange_dt_in_utc(self, dt):
#     def is_market_hours(self, test_date):
#     def is_trading_day(self, test_date):
#     def next_trading_day(self, test_date):
#     def days_in_range(self, start, end):
#     def next_open_and_close(self, start_date):
#     def get_open_and_close(self, day):
#     def market_minutes_for_day(self, midnight):
#     def trading_day_distance(self, first_date, second_date):
#     def get_index(self, dt):
#     def __init__(self, period_start, period_end,
#                  capital_base=10e3,
#                  emission_rate='daily',
#                  data_frequency='daily'):
#     def calculate_first_open(self):
#     def calculate_last_close(self):
#     def days_in_period(self):
#     def __repr__(self):


import types
import logbook
from numbers import Integral
from datetime import datetime
from collections import deque
from abc import ABCMeta, abstractmethod
from alephnull.protocol import DATASOURCE_TYPE
from alephnull.gens.utils import assert_sort_unframe_protocol, hash_args
from alephnull.finance import trading
            # TransformMeta's parent class, which is 'type'. This is
            # what is implicitly done behind the scenes by the python
            # interpreter for most classes anyway, but here we have to
            # be explicit because we've overridden the method that
            # usually resolves to our super call.
            self.state = super(TransformMeta, tnfm_class).__call__(
                *args, **kwargs)
        # Normal object instantiation.
        else:
            self.state = tnfm_class(*args, **kwargs)
        # save the window_length of the state for external access.
        self.window_length = self.state.window_length
        # Create the string associated with this generator's output.
        self.namestring = tnfm_class.__name__ + hash_args(*args, **kwargs)

    def get_hash(self):
        return self.namestring

    def transform(self, stream_in):
        return self._gen(stream_in)

    def _gen(self, stream_in):
        # IMPORTANT: Messages may contain pointers that are shared with
        # other streams.  Transforms that modify their input
        # messages should only manipulate copies.
        for message in stream_in:
            # we only handle TRADE events.
            if (hasattr(message, 'type')
                    and message.type not in (
                        DATASOURCE_TYPE.TRADE,

# Path: alephnull/protocol.py
# DATASOURCE_TYPE = Enum(
#     'AS_TRADED_EQUITY',
#     'MERGER',
#     'SPLIT',
#     'DIVIDEND',
#     'TRADE',
#     'TRANSACTION',
#     'ORDER',
#     'EMPTY',
#     'DONE',
#     'CUSTOM',
#     'BENCHMARK',
#     'COMMISSION'
# )
# 
# Path: alephnull/gens/utils.py
# def assert_sort_unframe_protocol(event):
#     """Same as above."""
#     assert isinstance(event.source_id, basestring)
#     assert event.type in DATASOURCE_TYPE
# 
# def hash_args(*args, **kwargs):
#     """Define a unique string for any set of representable args."""
#     arg_string = '_'.join([str(arg) for arg in args])
#     kwarg_string = '_'.join([str(key) + '=' + str(value)
#                              for key, value in kwargs.iteritems()])
#     combined = ':'.join([arg_string, kwarg_string])
# 
#     hasher = md5()
#     hasher.update(combined)
#     return hasher.hexdigest()
# 
# Path: alephnull/finance/trading.py
# class TradingEnvironment(object):
# class SimulationParameters(object):
#     def __init__(
#         self,
#         load=None,
#         bm_symbol='^GSPC',
#         exchange_tz="US/Eastern",
#         max_date=None,
#         extra_dates=None
#     ):
#     def __enter__(self, *args, **kwargs):
#     def __exit__(self, exc_type, exc_val, exc_tb):
#     def normalize_date(self, test_date):
#     def utc_dt_in_exchange(self, dt):
#     def exchange_dt_in_utc(self, dt):
#     def is_market_hours(self, test_date):
#     def is_trading_day(self, test_date):
#     def next_trading_day(self, test_date):
#     def days_in_range(self, start, end):
#     def next_open_and_close(self, start_date):
#     def get_open_and_close(self, day):
#     def market_minutes_for_day(self, midnight):
#     def trading_day_distance(self, first_date, second_date):
#     def get_index(self, dt):
#     def __init__(self, period_start, period_end,
#                  capital_base=10e3,
#                  emission_rate='daily',
#                  data_frequency='daily'):
#     def calculate_first_open(self):
#     def calculate_last_close(self):
#     def days_in_period(self):
#     def __repr__(self):


# Path: alephnull/transforms/utils.py
import types
import logbook
from numbers import Integral
from datetime import datetime
from collections import deque
from abc import ABCMeta, abstractmethod
from alephnull.protocol import DATASOURCE_TYPE
from alephnull.gens.utils import assert_sort_unframe_protocol, hash_args
from alephnull.finance import trading

            # TransformMeta's parent class, which is 'type'. This is
            # what is implicitly done behind the scenes by the python
            # interpreter for most classes anyway, but here we have to
            # be explicit because we've overridden the method that
            # usually resolves to our super call.
            self.state = super(TransformMeta, tnfm_class).__call__(
                *args, **kwargs)
        # Normal object instantiation.
        else:
            self.state = tnfm_class(*args, **kwargs)
        # save the window_length of the state for external access.
        self.window_length = self.state.window_length
        # Create the string associated with this generator's output.
        self.namestring = tnfm_class.__name__ + hash_args(*args, **kwargs)

    def get_hash(self):
        return self.namestring

    def transform(self, stream_in):
        return self._gen(stream_in)

    def _gen(self, stream_in):
        # IMPORTANT: Messages may contain pointers that are shared with
        # other streams.  Transforms that modify their input
        # messages should only manipulate copies.
        for message in stream_in:
            # we only handle TRADE events.
            if (hasattr(message, 'type')
                    and message.type not in (
                        DATASOURCE_TYPE.TRADE,

                        DATASOURCE_TYPE.CUSTOM)):