PEP8 compliance
This commit is contained in:
parent
348dbeff3f
commit
9919061c78
@ -4,15 +4,16 @@ Volume PairList provider
|
||||
Provides dynamic pair list based on trade volumes
|
||||
"""
|
||||
import logging
|
||||
import arrow
|
||||
from typing import Any, Dict, List
|
||||
|
||||
import arrow
|
||||
from cachetools.ttl import TTLCache
|
||||
|
||||
from freqtrade.exceptions import OperationalException
|
||||
from freqtrade.exchange import timeframe_to_minutes
|
||||
from freqtrade.plugins.pairlist.IPairList import IPairList
|
||||
from freqtrade.misc import format_ms_time
|
||||
from freqtrade.plugins.pairlist.IPairList import IPairList
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -44,8 +45,9 @@ class VolumePairList(IPairList):
|
||||
|
||||
if (self._lookback_days > 0) & (self._lookback_period > 0):
|
||||
raise OperationalException(
|
||||
f'Ambigous configuration: lookback_days and lookback_period both set in pairlist config. '
|
||||
f'Please set lookback_days only or lookback_period and lookback_timeframe and restart the bot.'
|
||||
'Ambigous configuration: lookback_days and lookback_period both set in pairlist '
|
||||
'config. Please set lookback_days only or lookback_period and lookback_timeframe '
|
||||
'and restart the bot.'
|
||||
)
|
||||
|
||||
# overwrite lookback timeframe and days when lookback_days is set
|
||||
@ -62,8 +64,9 @@ class VolumePairList(IPairList):
|
||||
|
||||
if self._use_range & (self._refresh_period < self._tf_in_sec):
|
||||
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_sec} and restart the bot.'
|
||||
f'Refresh period of {self._refresh_period} seconds is smaller than one '
|
||||
f'timeframe of {self._lookback_timeframe}. Please adjust refresh_period '
|
||||
f'to at least {self._tf_in_sec} and restart the bot.'
|
||||
)
|
||||
|
||||
if not self._exchange.exchange_has('fetchTickers'):
|
||||
@ -76,7 +79,6 @@ class VolumePairList(IPairList):
|
||||
raise OperationalException(
|
||||
f'key {self._sort_key} not in {SORT_VALUES}')
|
||||
|
||||
|
||||
if self._lookback_period < 0:
|
||||
raise OperationalException("VolumeFilter requires lookback_period to be >= 0")
|
||||
if self._lookback_period > exchange.ohlcv_candle_limit(self._lookback_timeframe):
|
||||
@ -140,10 +142,11 @@ class VolumePairList(IPairList):
|
||||
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:
|
||||
if self._use_range:
|
||||
since_ms = int(arrow.utcnow()
|
||||
.floor('minute')
|
||||
.shift(minutes=-(self._lookback_period * self._tf_in_min) - self._tf_in_min)
|
||||
.shift(minutes=-(self._lookback_period * self._tf_in_min)
|
||||
- self._tf_in_min)
|
||||
.float_timestamp) * 1000
|
||||
|
||||
to_ms = int(arrow.utcnow()
|
||||
@ -152,20 +155,35 @@ class VolumePairList(IPairList):
|
||||
.float_timestamp) * 1000
|
||||
|
||||
# todo: utc date output for starting date
|
||||
self.log_once(f"Using volume range of {self._lookback_period} candles, timeframe: {self._lookback_timeframe}, starting from {format_ms_time(since_ms)} till {format_ms_time(to_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]
|
||||
self.log_once(f"Using volume range of {self._lookback_period} candles, timeframe: "
|
||||
f"{self._lookback_timeframe}, starting from {format_ms_time(since_ms)} "
|
||||
f"till {format_ms_time(to_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):
|
||||
pair_candles = candles[(p['symbol'], self._lookback_timeframe)] if (p['symbol'], self._lookback_timeframe) in candles else None
|
||||
for i, p in enumerate(filtered_tickers):
|
||||
pair_candles = candles[
|
||||
(p['symbol'], self._lookback_timeframe)
|
||||
] if (p['symbol'], self._lookback_timeframe) in candles else None
|
||||
# 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']
|
||||
pair_candles['typical_price'] = (pair_candles['high'] + pair_candles['low']
|
||||
+ pair_candles['close']) / 3
|
||||
pair_candles['quoteVolume'] = (
|
||||
pair_candles['volume'] * pair_candles['typical_price']
|
||||
)
|
||||
|
||||
# replace quoteVolume with range quoteVolume sum calculated above
|
||||
filtered_tickers[i]['quoteVolume'] = pair_candles['quoteVolume'].sum()
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user