# Path: alephnull/protocol.py
# class BarData(object):
#     """
#     Holds the event data for all sids for a given dt.
# 
#     This is what is passed as `data` to the `handle_data` function.
# 
#     Note: Many methods are analogues of dictionary because of historical
#     usage of what this replaced as a dictionary subclass.
#     """
# 
#     def __init__(self):
#         self._data = {}
#         self._contains_override = None
# 
#     def __contains__(self, name):
#         if self._contains_override:
#             if self._contains_override(name):
#                 return name in self._data
#             else:
#                 return False
#         else:
#             return name in self._data
# 
#     def has_key(self, name):
#         """
#         DEPRECATED: __contains__ is preferred, but this method is for
#         compatibility with existing algorithms.
#         """
#         return name in self
# 
#     def __setitem__(self, name, value):
#         self._data[name] = value
# 
#     def __getitem__(self, name):
#         return self._data[name]
# 
#     def __delitem__(self, name):
#         del self._data[name]
# 
#     def __iter__(self):
#         for sid, data in self._data.iteritems():
#             # Allow contains override to filter out sids.
#             if sid in self:
#                 if len(data):
#                     yield sid
# 
#     def iterkeys(self):
#         # Allow contains override to filter out sids.
#         return (sid for sid in self._data.iterkeys() if sid in self)
# 
#     def keys(self):
#         # Allow contains override to filter out sids.
#         return list(self.iterkeys())
# 
#     def itervalues(self):
#         return (value for sid, value in self.iteritems())
# 
#     def values(self):
#         return list(self.itervalues())
# 
#     def iteritems(self):
#         return ((sid, value) for sid, value
#                 in self._data.iteritems()
#                 if sid in self)
# 
#     def items(self):
#         return list(self.iteritems())
# 
#     def __len__(self):
#         return len(self.keys())
# 
# class SIDData(object):
# 
#     def __init__(self, initial_values=None):
#         if initial_values:
#             self.__dict__ = initial_values
# 
#     def __getitem__(self, name):
#         return self.__dict__[name]
# 
#     def __setitem__(self, name, value):
#         self.__dict__[name] = value
# 
#     def __len__(self):
#         return len(self.__dict__)
# 
#     def __contains__(self, name):
#         return name in self.__dict__
# 
#     def __repr__(self):
#         return "SIDData({0})".format(self.__dict__)
# 
# DATASOURCE_TYPE = Enum(
#     'AS_TRADED_EQUITY',
#     'MERGER',
#     'SPLIT',
#     'DIVIDEND',
#     'TRADE',
#     'TRANSACTION',
#     'ORDER',
#     'EMPTY',
#     'DONE',
#     'CUSTOM',
#     'BENCHMARK',
#     'COMMISSION'
# )
# 
# Path: alephnull/gens/utils.py
# 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()


from logbook import Logger, Processor
from alephnull.protocol import (
    BarData,
    SIDData,
    DATASOURCE_TYPE
)
from alephnull.gens.utils import hash_args
import alephnull.finance.trading as trading

    def get_message(self, date):
        rvars = self.algo.recorded_vars
        if self.algo.perf_tracker.emission_rate == 'daily':
            perf_message = \
                self.algo.perf_tracker.handle_market_close()
            perf_message['daily_perf']['recorded_vars'] = rvars
            return perf_message

        elif self.algo.perf_tracker.emission_rate == 'minute':
            self.algo.perf_tracker.handle_minute_close(date)
            perf_message = self.algo.perf_tracker.to_dict()
            perf_message['minute_perf']['recorded_vars'] = rvars
            return perf_message

    def update_universe(self, event):
        """
        Update the universe with new event information.
        """
        # Update our knowledge of this event's sid

        if hasattr(event, 'contract'):
            if event.sid not in self.current_data.__dict__['_data']:
                self.current_data[event.sid] = {event.contract: SIDData()}
            sid_data = self.current_data[event.sid][event.contract] = SIDData()

        else:
            if event.sid in self.current_data:
                sid_data = self.current_data[event.sid]
            else:

# Path: alephnull/protocol.py
# class BarData(object):
#     """
#     Holds the event data for all sids for a given dt.
# 
#     This is what is passed as `data` to the `handle_data` function.
# 
#     Note: Many methods are analogues of dictionary because of historical
#     usage of what this replaced as a dictionary subclass.
#     """
# 
#     def __init__(self):
#         self._data = {}
#         self._contains_override = None
# 
#     def __contains__(self, name):
#         if self._contains_override:
#             if self._contains_override(name):
#                 return name in self._data
#             else:
#                 return False
#         else:
#             return name in self._data
# 
#     def has_key(self, name):
#         """
#         DEPRECATED: __contains__ is preferred, but this method is for
#         compatibility with existing algorithms.
#         """
#         return name in self
# 
#     def __setitem__(self, name, value):
#         self._data[name] = value
# 
#     def __getitem__(self, name):
#         return self._data[name]
# 
#     def __delitem__(self, name):
#         del self._data[name]
# 
#     def __iter__(self):
#         for sid, data in self._data.iteritems():
#             # Allow contains override to filter out sids.
#             if sid in self:
#                 if len(data):
#                     yield sid
# 
#     def iterkeys(self):
#         # Allow contains override to filter out sids.
#         return (sid for sid in self._data.iterkeys() if sid in self)
# 
#     def keys(self):
#         # Allow contains override to filter out sids.
#         return list(self.iterkeys())
# 
#     def itervalues(self):
#         return (value for sid, value in self.iteritems())
# 
#     def values(self):
#         return list(self.itervalues())
# 
#     def iteritems(self):
#         return ((sid, value) for sid, value
#                 in self._data.iteritems()
#                 if sid in self)
# 
#     def items(self):
#         return list(self.iteritems())
# 
#     def __len__(self):
#         return len(self.keys())
# 
# class SIDData(object):
# 
#     def __init__(self, initial_values=None):
#         if initial_values:
#             self.__dict__ = initial_values
# 
#     def __getitem__(self, name):
#         return self.__dict__[name]
# 
#     def __setitem__(self, name, value):
#         self.__dict__[name] = value
# 
#     def __len__(self):
#         return len(self.__dict__)
# 
#     def __contains__(self, name):
#         return name in self.__dict__
# 
#     def __repr__(self):
#         return "SIDData({0})".format(self.__dict__)
# 
# DATASOURCE_TYPE = Enum(
#     'AS_TRADED_EQUITY',
#     'MERGER',
#     'SPLIT',
#     'DIVIDEND',
#     'TRADE',
#     'TRANSACTION',
#     'ORDER',
#     'EMPTY',
#     'DONE',
#     'CUSTOM',
#     'BENCHMARK',
#     'COMMISSION'
# )
# 
# Path: alephnull/gens/utils.py
# 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/gens/tradesimulation.py
from logbook import Logger, Processor
from alephnull.protocol import (
    BarData,
    SIDData,
    DATASOURCE_TYPE
)
from alephnull.gens.utils import hash_args
import alephnull.finance.trading as trading


    def get_message(self, date):
        rvars = self.algo.recorded_vars
        if self.algo.perf_tracker.emission_rate == 'daily':
            perf_message = \
                self.algo.perf_tracker.handle_market_close()
            perf_message['daily_perf']['recorded_vars'] = rvars
            return perf_message

        elif self.algo.perf_tracker.emission_rate == 'minute':
            self.algo.perf_tracker.handle_minute_close(date)
            perf_message = self.algo.perf_tracker.to_dict()
            perf_message['minute_perf']['recorded_vars'] = rvars
            return perf_message

    def update_universe(self, event):
        """
        Update the universe with new event information.
        """
        # Update our knowledge of this event's sid

        if hasattr(event, 'contract'):
            if event.sid not in self.current_data.__dict__['_data']:
                self.current_data[event.sid] = {event.contract: SIDData()}
            sid_data = self.current_data[event.sid][event.contract] = SIDData()

        else:
            if event.sid in self.current_data:
                sid_data = self.current_data[event.sid]
            else:

                sid_data = self.current_data[event.sid] = SIDData()