예제 #1
0
    def _validate_whitelist(self, whitelist: List[str]) -> List[str]:
        """
        Check available markets and remove pair from whitelist if necessary
        :param whitelist: the sorted list of pairs the user might want to trade
        :return: the list of pairs the user wants to trade without those unavailable or
        black_listed
        """
        markets = self._freqtrade.exchange.markets

        sanitized_whitelist = set()
        for pair in whitelist:
            # pair is not in the generated dynamic market, or in the blacklist ... ignore it
            if (pair in self.blacklist or pair not in markets
                    or not pair.endswith(self._config['stake_currency'])):
                logger.warning(
                    f"Pair {pair} is not compatible with exchange "
                    f"{self._freqtrade.exchange.name} or contained in "
                    f"your blacklist. Removing it from whitelist..")
                continue
            # Check if market is active
            market = markets[pair]
            if not market_is_active(market):
                logger.info(
                    f"Ignoring {pair} from whitelist. Market is not active.")
                continue
            sanitized_whitelist.add(pair)

        # We need to remove pairs that are unknown
        return list(sanitized_whitelist)
예제 #2
0
    def _whitelist_for_active_markets(self, pairlist: List[str]) -> List[str]:
        """
        Check available markets and remove pair from whitelist if necessary
        :param whitelist: the sorted list of pairs the user might want to trade
        :return: the list of pairs the user wants to trade without those unavailable or
        black_listed
        """
        markets = self._exchange.markets

        sanitized_whitelist: List[str] = []
        for pair in pairlist:
            # pair is not in the generated dynamic market or has the wrong stake currency
            if pair not in markets:
                logger.warning(f"Pair {pair} is not compatible with exchange "
                               f"{self._exchange.name}. Removing it from whitelist..")
                continue

            if self._exchange.get_pair_quote_currency(pair) != self._config['stake_currency']:
                logger.warning(f"Pair {pair} is not compatible with your stake currency "
                               f"{self._config['stake_currency']}. Removing it from whitelist..")
                continue

            # Check if market is active
            market = markets[pair]
            if not market_is_active(market):
                logger.info(f"Ignoring {pair} from whitelist. Market is not active.")
                continue
            if pair not in sanitized_whitelist:
                sanitized_whitelist.append(pair)

        # We need to remove pairs that are unknown
        return sanitized_whitelist
예제 #3
0
def start_list_markets(args: Dict[str, Any], pairs_only: bool = False) -> None:
    """
    Print pairs/markets on the exchange
    :param args: Cli args from Arguments()
    :param pairs_only: if True print only pairs, otherwise print all instruments (markets)
    :return: None
    """
    config = setup_utils_configuration(args, RunMode.UTIL_EXCHANGE)

    # Init exchange
    exchange = ExchangeResolver(config['exchange']['name'],
                                config,
                                validate=False).exchange

    # By default only active pairs/markets are to be shown
    active_only = not args.get('list_pairs_all', False)

    base_currencies = args.get('base_currencies', [])
    quote_currencies = args.get('quote_currencies', [])

    try:
        pairs = exchange.get_markets(base_currencies=base_currencies,
                                     quote_currencies=quote_currencies,
                                     pairs_only=pairs_only,
                                     active_only=active_only)
        # Sort the pairs/markets by symbol
        pairs = OrderedDict(sorted(pairs.items()))
    except Exception as e:
        raise OperationalException(f"Cannot get markets. Reason: {e}") from e

    else:
        summary_str = (
            (f"Exchange {exchange.name} has {len(pairs)} ") +
            ("active " if active_only else "") +
            (plural(len(pairs), "pair" if pairs_only else "market")) +
            (f" with {', '.join(base_currencies)} as base "
             f"{plural(len(base_currencies), 'currency', 'currencies')}"
             if base_currencies else "") +
            (" and" if base_currencies and quote_currencies else "") +
            (f" with {', '.join(quote_currencies)} as quote "
             f"{plural(len(quote_currencies), 'currency', 'currencies')}"
             if quote_currencies else ""))

        headers = [
            "Id", "Symbol", "Base", "Quote", "Active",
            *(['Is pair'] if not pairs_only else [])
        ]

        tabular_data = []
        for _, v in pairs.items():
            tabular_data.append({
                'Id':
                v['id'],
                'Symbol':
                v['symbol'],
                'Base':
                v['base'],
                'Quote':
                v['quote'],
                'Active':
                market_is_active(v),
                **({
                    'Is pair': symbol_is_pair(v['symbol'])
                } if not pairs_only else {})
            })

        if (args.get('print_one_column', False)
                or args.get('list_pairs_print_json', False)
                or args.get('print_csv', False)):
            # Print summary string in the log in case of machine-readable
            # regular formats.
            logger.info(f"{summary_str}.")
        else:
            # Print empty string separating leading logs and output in case of
            # human-readable formats.
            print()

        if len(pairs):
            if args.get('print_list', False):
                # print data as a list, with human-readable summary
                print(f"{summary_str}: {', '.join(pairs.keys())}.")
            elif args.get('print_one_column', False):
                print('\n'.join(pairs.keys()))
            elif args.get('list_pairs_print_json', False):
                print(rapidjson.dumps(list(pairs.keys()), default=str))
            elif args.get('print_csv', False):
                writer = csv.DictWriter(sys.stdout, fieldnames=headers)
                writer.writeheader()
                writer.writerows(tabular_data)
            else:
                # print data as a table, with the human-readable summary
                print(f"{summary_str}:")
                print(tabulate(tabular_data, headers='keys', tablefmt='pipe'))
        elif not (args.get('print_one_column', False)
                  or args.get('list_pairs_print_json', False)
                  or args.get('print_csv', False)):
            print(f"{summary_str}.")