rename symbol_is_pair to market_is_tradable
Make it part of the exchange class, so subclasses can override this
This commit is contained in:
parent
f3824d970b
commit
b22e3a67d8
@ -14,7 +14,7 @@ from freqtrade.configuration import setup_utils_configuration
|
|||||||
from freqtrade.constants import USERPATH_HYPEROPTS, USERPATH_STRATEGIES
|
from freqtrade.constants import USERPATH_HYPEROPTS, USERPATH_STRATEGIES
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.exchange import (available_exchanges, ccxt_exchanges,
|
from freqtrade.exchange import (available_exchanges, ccxt_exchanges,
|
||||||
market_is_active, symbol_is_pair)
|
market_is_active)
|
||||||
from freqtrade.misc import plural
|
from freqtrade.misc import plural
|
||||||
from freqtrade.resolvers import ExchangeResolver, StrategyResolver
|
from freqtrade.resolvers import ExchangeResolver, StrategyResolver
|
||||||
from freqtrade.state import RunMode
|
from freqtrade.state import RunMode
|
||||||
@ -163,7 +163,7 @@ def start_list_markets(args: Dict[str, Any], pairs_only: bool = False) -> None:
|
|||||||
tabular_data.append({'Id': v['id'], 'Symbol': v['symbol'],
|
tabular_data.append({'Id': v['id'], 'Symbol': v['symbol'],
|
||||||
'Base': v['base'], 'Quote': v['quote'],
|
'Base': v['base'], 'Quote': v['quote'],
|
||||||
'Active': market_is_active(v),
|
'Active': market_is_active(v),
|
||||||
**({'Is pair': symbol_is_pair(v)}
|
**({'Is pair': exchange.market_is_tradable(v)}
|
||||||
if not pairs_only else {})})
|
if not pairs_only else {})})
|
||||||
|
|
||||||
if (args.get('print_one_column', False) or
|
if (args.get('print_one_column', False) or
|
||||||
|
@ -12,8 +12,7 @@ from freqtrade.exchange.exchange import (timeframe_to_seconds,
|
|||||||
timeframe_to_msecs,
|
timeframe_to_msecs,
|
||||||
timeframe_to_next_date,
|
timeframe_to_next_date,
|
||||||
timeframe_to_prev_date)
|
timeframe_to_prev_date)
|
||||||
from freqtrade.exchange.exchange import (market_is_active,
|
from freqtrade.exchange.exchange import (market_is_active)
|
||||||
symbol_is_pair)
|
|
||||||
from freqtrade.exchange.kraken import Kraken
|
from freqtrade.exchange.kraken import Kraken
|
||||||
from freqtrade.exchange.binance import Binance
|
from freqtrade.exchange.binance import Binance
|
||||||
from freqtrade.exchange.bibox import Bibox
|
from freqtrade.exchange.bibox import Bibox
|
||||||
|
@ -214,7 +214,7 @@ class Exchange:
|
|||||||
if quote_currencies:
|
if quote_currencies:
|
||||||
markets = {k: v for k, v in markets.items() if v['quote'] in quote_currencies}
|
markets = {k: v for k, v in markets.items() if v['quote'] in quote_currencies}
|
||||||
if pairs_only:
|
if pairs_only:
|
||||||
markets = {k: v for k, v in markets.items() if symbol_is_pair(v)}
|
markets = {k: v for k, v in markets.items() if self.symbol_is_pair(v)}
|
||||||
if active_only:
|
if active_only:
|
||||||
markets = {k: v for k, v in markets.items() if market_is_active(v)}
|
markets = {k: v for k, v in markets.items() if market_is_active(v)}
|
||||||
return markets
|
return markets
|
||||||
@ -238,6 +238,19 @@ class Exchange:
|
|||||||
"""
|
"""
|
||||||
return self.markets.get(pair, {}).get('base', '')
|
return self.markets.get(pair, {}).get('base', '')
|
||||||
|
|
||||||
|
def market_is_tradable(self, market: Dict[str, Any]) -> bool:
|
||||||
|
"""
|
||||||
|
Check if the market symbol is tradable by Freqtrade.
|
||||||
|
By default, checks if it's splittable by `/` and both sides correspond to base / quote
|
||||||
|
"""
|
||||||
|
symbol_parts = market['symbol'].split('/')
|
||||||
|
return (len(symbol_parts) == 2 and
|
||||||
|
len(symbol_parts[0]) > 0 and
|
||||||
|
len(symbol_parts[1]) > 0 and
|
||||||
|
symbol_parts[0] == market.get('base') and
|
||||||
|
symbol_parts[1] == market.get('quote')
|
||||||
|
)
|
||||||
|
|
||||||
def klines(self, pair_interval: Tuple[str, str], copy: bool = True) -> DataFrame:
|
def klines(self, pair_interval: Tuple[str, str], copy: bool = True) -> DataFrame:
|
||||||
if pair_interval in self._klines:
|
if pair_interval in self._klines:
|
||||||
return self._klines[pair_interval].copy() if copy else self._klines[pair_interval]
|
return self._klines[pair_interval].copy() if copy else self._klines[pair_interval]
|
||||||
@ -1210,22 +1223,6 @@ def timeframe_to_next_date(timeframe: str, date: datetime = None) -> datetime:
|
|||||||
return datetime.fromtimestamp(new_timestamp, tz=timezone.utc)
|
return datetime.fromtimestamp(new_timestamp, tz=timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
def symbol_is_pair(market_symbol: Dict[str, Any], base_currency: str = None,
|
|
||||||
quote_currency: str = None) -> bool:
|
|
||||||
"""
|
|
||||||
Check if the market symbol is a pair, i.e. that its symbol consists of the base currency and the
|
|
||||||
quote currency separated by '/' character. If base_currency and/or quote_currency is passed,
|
|
||||||
it also checks that the symbol contains appropriate base and/or quote currency part before
|
|
||||||
and after the separating character correspondingly.
|
|
||||||
"""
|
|
||||||
symbol_parts = market_symbol['symbol'].split('/')
|
|
||||||
return (len(symbol_parts) == 2 and
|
|
||||||
(market_symbol.get('base') == base_currency
|
|
||||||
if base_currency else len(symbol_parts[0]) > 0) and
|
|
||||||
(market_symbol.get('quote') == quote_currency
|
|
||||||
if quote_currency else len(symbol_parts[1]) > 0))
|
|
||||||
|
|
||||||
|
|
||||||
def market_is_active(market: Dict) -> bool:
|
def market_is_active(market: Dict) -> bool:
|
||||||
"""
|
"""
|
||||||
Return True if the market is active.
|
Return True if the market is active.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
""" FTX exchange subclass """
|
""" FTX exchange subclass """
|
||||||
import logging
|
import logging
|
||||||
from typing import Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
from freqtrade.exchange import Exchange
|
from freqtrade.exchange import Exchange
|
||||||
|
|
||||||
@ -12,3 +12,13 @@ class Ftx(Exchange):
|
|||||||
_ft_has: Dict = {
|
_ft_has: Dict = {
|
||||||
"ohlcv_candle_limit": 1500,
|
"ohlcv_candle_limit": 1500,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def market_is_tradable(self, market: Dict[str, Any]) -> bool:
|
||||||
|
"""
|
||||||
|
Check if the market symbol is tradable by Freqtrade.
|
||||||
|
Default checks + check if pair is darkpool pair.
|
||||||
|
"""
|
||||||
|
parent_check = super().market_is_tradable(market)
|
||||||
|
|
||||||
|
return (parent_check and
|
||||||
|
market.get('spot', False) is True)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
""" Kraken exchange subclass """
|
""" Kraken exchange subclass """
|
||||||
import logging
|
import logging
|
||||||
from typing import Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
import ccxt
|
import ccxt
|
||||||
|
|
||||||
@ -21,6 +21,16 @@ class Kraken(Exchange):
|
|||||||
"trades_pagination_arg": "since",
|
"trades_pagination_arg": "since",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def market_is_tradable(self, market: Dict[str, Any]) -> bool:
|
||||||
|
"""
|
||||||
|
Check if the market symbol is tradable by Freqtrade.
|
||||||
|
Default checks + check if pair is darkpool pair.
|
||||||
|
"""
|
||||||
|
parent_check = super().market_is_tradable(market)
|
||||||
|
|
||||||
|
return (parent_check and
|
||||||
|
market.get('darkpool', False) is False)
|
||||||
|
|
||||||
@retrier
|
@retrier
|
||||||
def get_balances(self) -> dict:
|
def get_balances(self) -> dict:
|
||||||
if self._config['dry_run']:
|
if self._config['dry_run']:
|
||||||
|
Loading…
Reference in New Issue
Block a user