示例#1
0
    def get_asset(self, symbol, data_frequency=None):
        """
        The market for the specified symbol.

        Parameters
        ----------
        symbol: str

        Returns
        -------
        TradingPair

        """
        asset = None

        log.debug('searching asset {} on the server'.format(symbol))
        asset = self._find_asset(asset, symbol, data_frequency, False)

        log.debug('asset {} not found on the server, searching local '
                  'assets'.format(symbol))
        asset = self._find_asset(asset, symbol, data_frequency, True)

        if not asset:
            all_values = list(self.assets.values()) + \
                         list(self.local_assets.values())
            supported_symbols = sorted([asset.symbol for asset in all_values])

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

        return asset
示例#2
0
    def get_asset(self, symbol):
        """
        The market for the specified symbol.

        Parameters
        ----------
        symbol: str

        Returns
        -------
        TradingPair

        """
        asset = None

        for key in self.assets:
            if not asset and self.assets[key].symbol.lower() == symbol.lower():
                asset = self.assets[key]

        if not asset:
            supported_symbols = [
                pair.symbol for pair in list(self.assets.values())
            ]

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

        return asset
示例#3
0
    def get_asset(self, symbol):
        """
        Find an Asset on the current exchange based on its Catalyst symbol
        :param symbol: the [target]_[base] currency pair symbol
        :return: Asset
        """
        asset = None

        for key in self.assets:
            if not asset and self.assets[key].symbol.lower() == symbol.lower():
                asset = self.assets[key]

        if not asset:
            supported_symbols = [
                pair.symbol.encode('utf-8') for pair in self.assets.values()
            ]
            raise SymbolNotFoundOnExchange(symbol=symbol,
                                           exchange=self.name.title(),
                                           supported_symbols=supported_symbols)

        return asset
示例#4
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