add VolumePrecisionPairList
This commit is contained in:
parent
e0c420b93f
commit
b7afcf3416
@ -1,5 +1,5 @@
|
|||||||
""" FreqTrade bot """
|
""" FreqTrade bot """
|
||||||
__version__ = '0.18.1-dev'
|
__version__ = '0.18.2-dev'
|
||||||
|
|
||||||
|
|
||||||
class DependencyException(BaseException):
|
class DependencyException(BaseException):
|
||||||
|
@ -17,7 +17,7 @@ REQUIRED_ORDERTIF = ['buy', 'sell']
|
|||||||
REQUIRED_ORDERTYPES = ['buy', 'sell', 'stoploss', 'stoploss_on_exchange']
|
REQUIRED_ORDERTYPES = ['buy', 'sell', 'stoploss', 'stoploss_on_exchange']
|
||||||
ORDERTYPE_POSSIBILITIES = ['limit', 'market']
|
ORDERTYPE_POSSIBILITIES = ['limit', 'market']
|
||||||
ORDERTIF_POSSIBILITIES = ['gtc', 'fok', 'ioc']
|
ORDERTIF_POSSIBILITIES = ['gtc', 'fok', 'ioc']
|
||||||
AVAILABLE_PAIRLISTS = ['StaticPairList', 'VolumePairList']
|
AVAILABLE_PAIRLISTS = ['StaticPairList', 'VolumePairList', 'VolumePrecisionPairList']
|
||||||
|
|
||||||
TICKER_INTERVAL_MINUTES = {
|
TICKER_INTERVAL_MINUTES = {
|
||||||
'1m': 1,
|
'1m': 1,
|
||||||
|
@ -229,7 +229,7 @@ def download_pair_history(datadir: Optional[Path],
|
|||||||
|
|
||||||
misc.file_dump_json(filename, data)
|
misc.file_dump_json(filename, data)
|
||||||
return True
|
return True
|
||||||
except BaseException:
|
except BaseException as e:
|
||||||
logger.info('Failed to download the pair: "%s", Interval: %s',
|
logger.info('Failed to download the pair: "%s", Interval: %s\n'
|
||||||
pair, tick_interval)
|
'Error message: %s', pair, tick_interval, e)
|
||||||
return False
|
return False
|
||||||
|
86
freqtrade/pairlist/VolumePrecisionPairList.py
Normal file
86
freqtrade/pairlist/VolumePrecisionPairList.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
"""
|
||||||
|
Static List provider
|
||||||
|
|
||||||
|
Provides lists as configured in config.json
|
||||||
|
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
from typing import List
|
||||||
|
from cachetools import TTLCache, cached
|
||||||
|
|
||||||
|
from freqtrade.pairlist.IPairList import IPairList
|
||||||
|
from freqtrade import OperationalException
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
SORT_VALUES = ['askVolume', 'bidVolume', 'quoteVolume']
|
||||||
|
|
||||||
|
|
||||||
|
class VolumePrecisionPairList(IPairList):
|
||||||
|
|
||||||
|
def __init__(self, freqtrade, config: dict) -> None:
|
||||||
|
super().__init__(freqtrade, config)
|
||||||
|
self._whitelistconf = self._config.get('pairlist', {}).get('config')
|
||||||
|
if 'number_assets' not in self._whitelistconf:
|
||||||
|
raise OperationalException(
|
||||||
|
f'`number_assets` not specified. Please check your configuration '
|
||||||
|
'for "pairlist.config.number_assets"')
|
||||||
|
self._number_pairs = self._whitelistconf['number_assets']
|
||||||
|
self._sort_key = self._whitelistconf.get('sort_key', 'quoteVolume')
|
||||||
|
|
||||||
|
if not self._freqtrade.exchange.exchange_has('fetchTickers'):
|
||||||
|
raise OperationalException(
|
||||||
|
'Exchange does not support dynamic whitelist.'
|
||||||
|
'Please edit your config and restart the bot'
|
||||||
|
)
|
||||||
|
if not self._validate_keys(self._sort_key):
|
||||||
|
raise OperationalException(
|
||||||
|
f'key {self._sort_key} not in {SORT_VALUES}')
|
||||||
|
|
||||||
|
def _validate_keys(self, key):
|
||||||
|
return key in SORT_VALUES
|
||||||
|
|
||||||
|
def short_desc(self) -> str:
|
||||||
|
"""
|
||||||
|
Short whitelist method description - used for startup-messages
|
||||||
|
-> Please overwrite in subclasses
|
||||||
|
"""
|
||||||
|
return f"{self.name} - top {self._whitelistconf['number_assets']} volume pairs."
|
||||||
|
|
||||||
|
def refresh_pairlist(self) -> None:
|
||||||
|
"""
|
||||||
|
Refreshes pairlists and assigns them to self._whitelist and self._blacklist respectively
|
||||||
|
-> Please overwrite in subclasses
|
||||||
|
"""
|
||||||
|
# Generate dynamic whitelist
|
||||||
|
pairs = self._gen_pair_whitelist(self._config['stake_currency'], self._sort_key)
|
||||||
|
# Validate whitelist to only have active market pairs
|
||||||
|
self._whitelist = self._validate_whitelist(pairs)[:self._number_pairs]
|
||||||
|
|
||||||
|
@cached(TTLCache(maxsize=1, ttl=1800))
|
||||||
|
def _gen_pair_whitelist(self, base_currency: str, key: str) -> List[str]:
|
||||||
|
"""
|
||||||
|
Updates the whitelist with with a dynamically generated list
|
||||||
|
:param base_currency: base currency as str
|
||||||
|
:param key: sort key (defaults to 'quoteVolume')
|
||||||
|
:return: List of pairs
|
||||||
|
"""
|
||||||
|
|
||||||
|
tickers = self._freqtrade.exchange.get_tickers()
|
||||||
|
# check length so that we make sure that '/' is actually in the string
|
||||||
|
tickers = [v for k, v in tickers.items()
|
||||||
|
if len(k.split('/')) == 2 and k.split('/')[1] == base_currency]
|
||||||
|
|
||||||
|
if self._freqtrade.strategy.stoploss is not None:
|
||||||
|
precisions = [self._freqtrade.exchange.markets[
|
||||||
|
t["symbol"]]["precision"].get("price") for t in tickers]
|
||||||
|
tickers = [t for t, p in zip(tickers, precisions) if (
|
||||||
|
self._freqtrade.exchange.symbol_price_prec(
|
||||||
|
t["symbol"],
|
||||||
|
self._freqtrade.get_target_bid(
|
||||||
|
t["symbol"], t) * (1 + self._freqtrade.strategy.stoploss)
|
||||||
|
) < self._freqtrade.get_target_bid(t["symbol"], t)
|
||||||
|
)]
|
||||||
|
|
||||||
|
sorted_tickers = sorted(tickers, reverse=True, key=lambda t: t[key])
|
||||||
|
pairs = [s['symbol'] for s in sorted_tickers]
|
||||||
|
return pairs
|
Loading…
Reference in New Issue
Block a user