# Path: intuition/errors.py
# class LoadDataFailed(dna.errors.FactoryError):
#     msg = "Failed to load data for {sids}: {reason}"
# 
# class InvalidDatafeed(dna.errors.FactoryError):
#     msg = "Invalid datafeed setup: {reason}"


import pandas as pd
import dna.logging
import intuition.utils as utils
from datetime import timedelta
from zipline.sources.data_source import DataSource
from zipline.gens.utils import hash_args
from intuition.errors import LoadDataFailed, InvalidDatafeed
        'sid': sid,
        'volume': event.get('volume', 1000)
    })
    return event


def _check_data_modules(backtest, live, start, end):
    # TODO Fails if the class as no get_data method
    # TODO Fails if no backtest for past dates and same for live
    if not backtest and not live:
        raise InvalidDatafeed(
            reason='provide at least a backtest or a live data module')
    return True


class HybridDataFactory(DataSource):
    '''
    Surcharge of zipline.DataSource, switching automatically between live
    stream and backtest sources
    '''

    backtest = None
    live = None
    _is_live = False

    def __init__(self, **kwargs):
        # TODO Use alternatives to `index` and `universe` objects
        self.log = dna.logging.logger(__name__)

        if 'index' not in kwargs or 'universe' not in kwargs:

# Path: intuition/errors.py
# class LoadDataFailed(dna.errors.FactoryError):
#     msg = "Failed to load data for {sids}: {reason}"
# 
# class InvalidDatafeed(dna.errors.FactoryError):
#     msg = "Invalid datafeed setup: {reason}"


# Path: intuition/api/datafeed.py
import pandas as pd
import dna.logging
import intuition.utils as utils
from datetime import timedelta
from zipline.sources.data_source import DataSource
from zipline.gens.utils import hash_args
from intuition.errors import LoadDataFailed, InvalidDatafeed

        'sid': sid,
        'volume': event.get('volume', 1000)
    })
    return event


def _check_data_modules(backtest, live, start, end):
    # TODO Fails if the class as no get_data method
    # TODO Fails if no backtest for past dates and same for live
    if not backtest and not live:
        raise InvalidDatafeed(
            reason='provide at least a backtest or a live data module')
    return True


class HybridDataFactory(DataSource):
    '''
    Surcharge of zipline.DataSource, switching automatically between live
    stream and backtest sources
    '''

    backtest = None
    live = None
    _is_live = False

    def __init__(self, **kwargs):
        # TODO Use alternatives to `index` and `universe` objects
        self.log = dna.logging.logger(__name__)

        if 'index' not in kwargs or 'universe' not in kwargs:

            raise InvalidDatafeed(