Esempio n. 1
0
    def get_adj_dates(self, start, end, assets, data_frequency):
        """
        Contains a date range to the trading availability of the specified
        markets.

        Parameters
        ----------
        start: pd.Timestamp
        end: pd.Timestamp
        assets: list[TradingPair]
        data_frequency: str

        Returns
        -------
        pd.Timestamp, pd.Timestamp
        """
        earliest_trade = None
        last_entry = None
        for asset in assets:
            if earliest_trade is None or earliest_trade > asset.start_date:
                if asset.start_date >= self.calendar.first_session:
                    earliest_trade = asset.start_date

                else:
                    earliest_trade = self.calendar.first_session

            end_asset = asset.end_minute if data_frequency == 'minute' else \
                asset.end_daily
            if end_asset is not None:
                if last_entry is None or end_asset > last_entry:
                    last_entry = end_asset

            else:
                end = None
                last_entry = None

        if start is None or \
                (earliest_trade is not None and earliest_trade > start):
            start = earliest_trade

        if end is None or (last_entry is not None and end > last_entry):
            end = last_entry.replace(minute=59, hour=23) \
                if data_frequency == 'minute' else last_entry

        if end is None or start is None or start > end:
            raise NoDataAvailableOnExchange(
                exchange=[asset.exchange for asset in assets],
                symbol=[asset.symbol for asset in assets],
                data_frequency=data_frequency,
            )

        return start, end
Esempio n. 2
0
def get_adj_dates(start, end, assets, data_frequency):
    """
    Contains a date range to the trading availability of the specified pairs.

    :param start:
    :param end:
    :param assets:
    :param data_frequency:
    :return:
    """
    earliest_trade = None
    last_entry = None
    for asset in assets:
        if earliest_trade is None or earliest_trade > asset.start_date:
            earliest_trade = asset.start_date

        end_asset = asset.end_minute if data_frequency == 'minute' else \
            asset.end_daily
        if end_asset is not None and \
                (last_entry is None or end_asset > last_entry):
            last_entry = end_asset

    if start is None or earliest_trade > start:
        start = earliest_trade

    if end is None or (last_entry is not None and end > last_entry):
        end = last_entry

    if end is None or start >= end:
        raise NoDataAvailableOnExchange(
            exchange=asset.exchange.title(),
            symbol=[asset.symbol.encode('utf-8')],
            data_frequency=data_frequency,
        )

    return start, end
Esempio n. 3
0
    def get_asset(self,
                  symbol,
                  data_frequency=None,
                  is_exchange_symbol=False,
                  is_local=None):
        """
        The market for the specified symbol.

        Parameters
        ----------
        symbol: str
            The Catalyst or exchange symbol.

        data_frequency: str
            Check for asset corresponding to the specified data_frequency.
            The same asset might exist in the Catalyst repository or
            locally (following a CSV ingestion). Filtering by
            data_frequency picks the right asset.

        is_exchange_symbol: bool
            Whether the symbol uses the Catalyst or exchange convention.

        is_local: bool
            For the local or Catalyst asset.

        Returns
        -------
        TradingPair
            The asset object.

        """
        asset = None

        # TODO: temp mapping, fix to use a single symbol convention
        og_symbol = symbol
        symbol = self.get_symbol(symbol) if not is_exchange_symbol else symbol
        log.debug('searching assets for: {} {}'.format(self.name, symbol))
        # TODO: simplify and loose the loop
        for a in self.assets:
            if asset is not None:
                break

            if is_local is not None:
                data_source = 'local' if is_local else 'catalyst'
                applies = (a.data_source == data_source)

            elif data_frequency is not None:
                applies = (
                    (data_frequency == 'minute' and a.end_minute is not None)
                    or (data_frequency == 'daily' and a.end_daily is not None))
            else:
                applies = True

            # The symbol provided may use the Catalyst or the exchange
            # convention
            key = a.exchange_symbol if \
                is_exchange_symbol else self.get_symbol(a)
            if not asset and key.lower() == symbol.lower():
                if applies:
                    asset = a

                else:
                    raise NoDataAvailableOnExchange(
                        symbol=key,
                        exchange=self.name,
                        data_frequency=data_frequency,
                    )

        if asset is None:
            supported_symbols = sorted([a.symbol for a in self.assets])

            raise SymbolNotFoundOnExchange(symbol=og_symbol,
                                           exchange=self.name.title(),
                                           supported_symbols=supported_symbols)

        log.debug('found asset: {}'.format(asset))
        return asset