Rename login-mixin log method
This commit is contained in:
parent
2e5b9fd4b2
commit
8ebd6ad200
@ -16,7 +16,7 @@ class LoggingMixin():
|
|||||||
self.refresh_period = refresh_period
|
self.refresh_period = refresh_period
|
||||||
self._log_cache: TTLCache = TTLCache(maxsize=1024, ttl=self.refresh_period)
|
self._log_cache: TTLCache = TTLCache(maxsize=1024, ttl=self.refresh_period)
|
||||||
|
|
||||||
def log_on_refresh(self, logmethod, message: str) -> None:
|
def log_once(self, logmethod, message: str) -> None:
|
||||||
"""
|
"""
|
||||||
Logs message - not more often than "refresh_period" to avoid log spamming
|
Logs message - not more often than "refresh_period" to avoid log spamming
|
||||||
Logs the log-message as debug as well to simplify debugging.
|
Logs the log-message as debug as well to simplify debugging.
|
||||||
@ -25,10 +25,10 @@ class LoggingMixin():
|
|||||||
:return: None.
|
:return: None.
|
||||||
"""
|
"""
|
||||||
@cached(cache=self._log_cache)
|
@cached(cache=self._log_cache)
|
||||||
def _log_on_refresh(message: str):
|
def _log_once(message: str):
|
||||||
logmethod(message)
|
logmethod(message)
|
||||||
|
|
||||||
# Log as debug first
|
# Log as debug first
|
||||||
self.logger.debug(message)
|
self.logger.debug(message)
|
||||||
# Call hidden function.
|
# Call hidden function.
|
||||||
_log_on_refresh(message)
|
_log_once(message)
|
||||||
|
@ -76,9 +76,9 @@ class AgeFilter(IPairList):
|
|||||||
self._symbolsChecked[ticker['symbol']] = int(arrow.utcnow().float_timestamp) * 1000
|
self._symbolsChecked[ticker['symbol']] = int(arrow.utcnow().float_timestamp) * 1000
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
self.log_on_refresh(logger.info, f"Removed {ticker['symbol']} from whitelist, "
|
self.log_once(logger.info,
|
||||||
f"because age {len(daily_candles)} is less than "
|
f"Removed {ticker['symbol']} from whitelist, because age "
|
||||||
f"{self._min_days_listed} "
|
f"{len(daily_candles)} is less than {self._min_days_listed} "
|
||||||
f"{plural(self._min_days_listed, 'day')}")
|
f"{plural(self._min_days_listed, 'day')}")
|
||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
@ -59,9 +59,8 @@ class PrecisionFilter(IPairList):
|
|||||||
logger.debug(f"{ticker['symbol']} - {sp} : {stop_gap_price}")
|
logger.debug(f"{ticker['symbol']} - {sp} : {stop_gap_price}")
|
||||||
|
|
||||||
if sp <= stop_gap_price:
|
if sp <= stop_gap_price:
|
||||||
self.log_on_refresh(logger.info,
|
self.log_once(logger.info, f"Removed {ticker['symbol']} from whitelist, because "
|
||||||
f"Removed {ticker['symbol']} from whitelist, "
|
f"stop price {sp} would be <= stop limit {stop_gap_price}")
|
||||||
f"because stop price {sp} would be <= stop limit {stop_gap_price}")
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -64,9 +64,9 @@ class PriceFilter(IPairList):
|
|||||||
:return: True if the pair can stay, false if it should be removed
|
:return: True if the pair can stay, false if it should be removed
|
||||||
"""
|
"""
|
||||||
if ticker['last'] is None or ticker['last'] == 0:
|
if ticker['last'] is None or ticker['last'] == 0:
|
||||||
self.log_on_refresh(logger.info,
|
self.log_once(logger.info,
|
||||||
f"Removed {ticker['symbol']} from whitelist, because "
|
f"Removed {ticker['symbol']} from whitelist, because "
|
||||||
"ticker['last'] is empty (Usually no trade in the last 24h).")
|
"ticker['last'] is empty (Usually no trade in the last 24h).")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Perform low_price_ratio check.
|
# Perform low_price_ratio check.
|
||||||
@ -74,22 +74,22 @@ class PriceFilter(IPairList):
|
|||||||
compare = self._exchange.price_get_one_pip(ticker['symbol'], ticker['last'])
|
compare = self._exchange.price_get_one_pip(ticker['symbol'], ticker['last'])
|
||||||
changeperc = compare / ticker['last']
|
changeperc = compare / ticker['last']
|
||||||
if changeperc > self._low_price_ratio:
|
if changeperc > self._low_price_ratio:
|
||||||
self.log_on_refresh(logger.info, f"Removed {ticker['symbol']} from whitelist, "
|
self.log_once(logger.info, f"Removed {ticker['symbol']} from whitelist, "
|
||||||
f"because 1 unit is {changeperc * 100:.3f}%")
|
f"because 1 unit is {changeperc * 100:.3f}%")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Perform min_price check.
|
# Perform min_price check.
|
||||||
if self._min_price != 0:
|
if self._min_price != 0:
|
||||||
if ticker['last'] < self._min_price:
|
if ticker['last'] < self._min_price:
|
||||||
self.log_on_refresh(logger.info, f"Removed {ticker['symbol']} from whitelist, "
|
self.log_once(logger.info, f"Removed {ticker['symbol']} from whitelist, "
|
||||||
f"because last price < {self._min_price:.8f}")
|
f"because last price < {self._min_price:.8f}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Perform max_price check.
|
# Perform max_price check.
|
||||||
if self._max_price != 0:
|
if self._max_price != 0:
|
||||||
if ticker['last'] > self._max_price:
|
if ticker['last'] > self._max_price:
|
||||||
self.log_on_refresh(logger.info, f"Removed {ticker['symbol']} from whitelist, "
|
self.log_once(logger.info, f"Removed {ticker['symbol']} from whitelist, "
|
||||||
f"because last price > {self._max_price:.8f}")
|
f"because last price > {self._max_price:.8f}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -45,9 +45,9 @@ class SpreadFilter(IPairList):
|
|||||||
if 'bid' in ticker and 'ask' in ticker:
|
if 'bid' in ticker and 'ask' in ticker:
|
||||||
spread = 1 - ticker['bid'] / ticker['ask']
|
spread = 1 - ticker['bid'] / ticker['ask']
|
||||||
if spread > self._max_spread_ratio:
|
if spread > self._max_spread_ratio:
|
||||||
self.log_on_refresh(logger.info, f"Removed {ticker['symbol']} from whitelist, "
|
self.log_once(logger.info,
|
||||||
f"because spread {spread * 100:.3f}% >"
|
f"Removed {ticker['symbol']} from whitelist, because spread "
|
||||||
f"{self._max_spread_ratio * 100}%")
|
f"{spread * 100:.3f}% > {self._max_spread_ratio * 100}%")
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
@ -111,6 +111,6 @@ class VolumePairList(IPairList):
|
|||||||
# Limit pairlist to the requested number of pairs
|
# Limit pairlist to the requested number of pairs
|
||||||
pairs = pairs[:self._number_pairs]
|
pairs = pairs[:self._number_pairs]
|
||||||
|
|
||||||
self.log_on_refresh(logger.info, f"Searching {self._number_pairs} pairs: {pairs}")
|
self.log_once(logger.info, f"Searching {self._number_pairs} pairs: {pairs}")
|
||||||
|
|
||||||
return pairs
|
return pairs
|
||||||
|
@ -78,11 +78,10 @@ class RangeStabilityFilter(IPairList):
|
|||||||
if pct_change >= self._min_rate_of_change:
|
if pct_change >= self._min_rate_of_change:
|
||||||
result = True
|
result = True
|
||||||
else:
|
else:
|
||||||
self.log_on_refresh(logger.info,
|
self.log_once(logger.info,
|
||||||
f"Removed {pair} from whitelist, "
|
f"Removed {pair} from whitelist, because rate of change "
|
||||||
f"because rate of change over {plural(self._days, 'day')} is "
|
f"over {plural(self._days, 'day')} is {pct_change:.3f}, "
|
||||||
f"{pct_change:.3f}, which is below the "
|
f"which is below the threshold of {self._min_rate_of_change}.")
|
||||||
f"threshold of {self._min_rate_of_change}.")
|
|
||||||
result = False
|
result = False
|
||||||
self._pair_cache[pair] = result
|
self._pair_cache[pair] = result
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class CooldownPeriod(IProtection):
|
|||||||
]
|
]
|
||||||
trade = Trade.get_trades(filters).first()
|
trade = Trade.get_trades(filters).first()
|
||||||
if trade:
|
if trade:
|
||||||
self.log_on_refresh(logger.info, f"Cooldown for {pair} for {self._stop_duration}.")
|
self.log_once(logger.info, f"Cooldown for {pair} for {self._stop_duration}.")
|
||||||
until = self.calculate_lock_end([trade], self._stop_duration)
|
until = self.calculate_lock_end([trade], self._stop_duration)
|
||||||
|
|
||||||
return True, until, self._reason()
|
return True, until, self._reason()
|
||||||
|
@ -52,7 +52,7 @@ class LowProfitPairs(IProtection):
|
|||||||
|
|
||||||
profit = sum(trade.close_profit for trade in trades)
|
profit = sum(trade.close_profit for trade in trades)
|
||||||
if profit < self._required_profit:
|
if profit < self._required_profit:
|
||||||
self.log_on_refresh(
|
self.log_once(
|
||||||
logger.info,
|
logger.info,
|
||||||
f"Trading for {pair} stopped due to {profit:.2f} < {self._required_profit} "
|
f"Trading for {pair} stopped due to {profit:.2f} < {self._required_profit} "
|
||||||
f"within {self._lookback_period} minutes.")
|
f"within {self._lookback_period} minutes.")
|
||||||
|
@ -53,8 +53,8 @@ class StoplossGuard(IProtection):
|
|||||||
trades = Trade.get_trades(filters).all()
|
trades = Trade.get_trades(filters).all()
|
||||||
|
|
||||||
if len(trades) > self._trade_limit:
|
if len(trades) > self._trade_limit:
|
||||||
self.log_on_refresh(logger.info, f"Trading stopped due to {self._trade_limit} "
|
self.log_once(logger.info, f"Trading stopped due to {self._trade_limit} "
|
||||||
f"stoplosses within {self._lookback_period} minutes.")
|
f"stoplosses within {self._lookback_period} minutes.")
|
||||||
until = self.calculate_lock_end(trades, self._stop_duration)
|
until = self.calculate_lock_end(trades, self._stop_duration)
|
||||||
return True, until, self._reason()
|
return True, until, self._reason()
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ def static_pl_conf(whitelist_conf):
|
|||||||
return whitelist_conf
|
return whitelist_conf
|
||||||
|
|
||||||
|
|
||||||
def test_log_on_refresh(mocker, static_pl_conf, markets, tickers):
|
def test_log_cached(mocker, static_pl_conf, markets, tickers):
|
||||||
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
||||||
markets=PropertyMock(return_value=markets),
|
markets=PropertyMock(return_value=markets),
|
||||||
exchange_has=MagicMock(return_value=True),
|
exchange_has=MagicMock(return_value=True),
|
||||||
@ -102,14 +102,14 @@ def test_log_on_refresh(mocker, static_pl_conf, markets, tickers):
|
|||||||
logmock = MagicMock()
|
logmock = MagicMock()
|
||||||
# Assign starting whitelist
|
# Assign starting whitelist
|
||||||
pl = freqtrade.pairlists._pairlist_handlers[0]
|
pl = freqtrade.pairlists._pairlist_handlers[0]
|
||||||
pl.log_on_refresh(logmock, 'Hello world')
|
pl.log_once(logmock, 'Hello world')
|
||||||
assert logmock.call_count == 1
|
assert logmock.call_count == 1
|
||||||
pl.log_on_refresh(logmock, 'Hello world')
|
pl.log_once(logmock, 'Hello world')
|
||||||
assert logmock.call_count == 1
|
assert logmock.call_count == 1
|
||||||
assert pl._log_cache.currsize == 1
|
assert pl._log_cache.currsize == 1
|
||||||
assert ('Hello world',) in pl._log_cache._Cache__data
|
assert ('Hello world',) in pl._log_cache._Cache__data
|
||||||
|
|
||||||
pl.log_on_refresh(logmock, 'Hello world2')
|
pl.log_once(logmock, 'Hello world2')
|
||||||
assert logmock.call_count == 2
|
assert logmock.call_count == 2
|
||||||
assert pl._log_cache.currsize == 2
|
assert pl._log_cache.currsize == 2
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user