code cleanup and comments

This commit is contained in:
nightshift2k 2021-07-03 11:47:17 +02:00
parent 055229a44a
commit 62da4b452c

View File

@ -4,16 +4,14 @@ Volume PairList provider
Provides dynamic pair list based on trade volumes
"""
import logging
import arrow
from typing import Any, Dict, List
from cachetools.ttl import TTLCache
from freqtrade.exceptions import OperationalException
from freqtrade.plugins.pairlist.IPairList import IPairList
import arrow
from copy import deepcopy
from freqtrade.exchange import timeframe_to_minutes
from freqtrade.plugins.pairlist.IPairList import IPairList
logger = logging.getLogger(__name__)
@ -48,15 +46,16 @@ class VolumePairList(IPairList):
self._lookback_timeframe = '1d'
self._lookback_period = self._lookback_days
# get timeframe in minutes and seconds
self._tf_in_min = timeframe_to_minutes(self._lookback_timeframe)
self._tf_in_secs = self._tf_in_min * 60
self._tf_in_sec = self._tf_in_min * 60
self._use_range = (self._tf_in_min > 0) & (self._lookback_period > 0)
if self._use_range & (self._refresh_period < self._tf_in_secs):
raise OperationalException(
f'Refresh period of {self._refresh_period} seconds is smaller than one timeframe of {self._lookback_timeframe}. '
f'Please adjust refresh_period to at least {self._tf_in_secs} and restart the bot.'
f'Please adjust refresh_period to at least {self._tf_in_sec} and restart the bot.'
)
if not self._exchange.exchange_has('fetchTickers'):
@ -129,10 +128,10 @@ class VolumePairList(IPairList):
:param tickers: Tickers (from exchange.get_tickers()). May be cached.
:return: new whitelist
"""
# Use the incoming pairlist.
filtered_tickers = [v for k, v in tickers.items() if k in pairlist]
# get lookback period in ms, for exchange ohlcv fetch
if self._use_range == True:
since_ms = int(arrow.utcnow()
.floor('minute')
@ -141,31 +140,25 @@ class VolumePairList(IPairList):
self.log_once(f"Using volume range of {self._lookback_period} {self._lookback_timeframe} candles from {since_ms}", logger.info)
needed_pairs = [(p, self._lookback_timeframe) for p in [s['symbol'] for s in filtered_tickers] if p not in self._pair_cache]
# Get all candles
candles = {}
if needed_pairs:
candles = self._exchange.refresh_latest_ohlcv(needed_pairs, since_ms=since_ms,
cache=False)
candles = self._exchange.refresh_latest_ohlcv(needed_pairs, since_ms=since_ms, cache=False)
for i,p in enumerate(filtered_tickers):
# for p in deepcopy([s['symbol'] for s in filtered_tickers]):
pair_candles = candles[(p['symbol'], self._lookback_timeframe)] if (p['symbol'], self._lookback_timeframe) in candles else None
#print(p['symbol'], " 24h quote volume = ",filtered_tickers[i]['quoteVolume'])
#if p['symbol'] == 'BCC/USDT':
#print(pair_candles)
#quit()
print(p['symbol'], " 24h quote volume = ",filtered_tickers[i]['quoteVolume'])
# print(p['symbol'], " 24h quote volume = ",filtered_tickers[i]['quoteVolume'])
# in case of candle data calculate typical price and quoteVolume for candle
if not pair_candles.empty:
pair_candles['typical_price'] = (pair_candles['high'] + pair_candles['low'] + pair_candles['close']) / 3
pair_candles['quoteVolume'] = pair_candles['volume'] * pair_candles['typical_price']
# print(p['symbol'], " range quote volume = ", pair_candles['quoteVolume'].sum())
# replace quoteVolume with range sum
filtered_tickers[i]['quoteVolume'] = pair_candles['quoteVolume'].sum()
else:
filtered_tickers[i]['quoteVolume'] = 0
print(p['symbol'], " range quote volume = ",filtered_tickers[i]['quoteVolume'])
# print(p['symbol'], " range quote volume = ",filtered_tickers[i]['quoteVolume'])
if self._min_value > 0:
filtered_tickers = [
@ -175,13 +168,10 @@ class VolumePairList(IPairList):
# Validate whitelist to only have active market pairs
pairs = self._whitelist_for_active_markets([s['symbol'] for s in sorted_tickers])
pairs = self.verify_blacklist(pairs, logger.info)
pairs = self.verify_blacklist(pairs, logger.info)
# Limit pairlist to the requested number of pairs
pairs = pairs[:self._number_pairs]
self.log_once(f"Searching {self._number_pairs} pairs: {pairs}", logger.info)
quit()
return pairs