From c9060e11b2c570215b72d266bab01ee795fb9cac Mon Sep 17 00:00:00 2001 From: Maik Hinrichs Date: Tue, 29 Aug 2017 16:47:01 +0200 Subject: [PATCH 1/2] Option to compact log output --- default.cfg.example | 4 ++++ docs/configuration.rst | 6 ++++++ modules/Lending.py | 3 +-- modules/Logger.py | 15 +++++++++++++++ www/lendingbot.js | 11 ++++++++++- 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/default.cfg.example b/default.cfg.example index 32580116..38507699 100644 --- a/default.cfg.example +++ b/default.cfg.example @@ -105,6 +105,10 @@ hideCoins = True #Limits the amount of log lines to save. #jsonlogsize = 200 +#If True some frequent log messages (e.g. "Not lending ... due to rate below ..." will not append to log list. +#Last equal log message will be shown in currency web page section. Default is false +#jsonlogcompact = true + #Enables a webserver for the www folder, in order to easily use the lendingbot.html with the .json log. #startWebServer = true diff --git a/docs/configuration.rst b/docs/configuration.rst index c001edb9..70910c1f 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -292,6 +292,12 @@ Advanced logging and Web Display - Format: ``200`` - Reasons to lower this include: you are conscious of bandwidth when hosting your webserver, you prefer (slightly) faster loading times and less RAM usage of bot. +- ``jsonlogcompact`` enables to log frequent repeated log messages (like "Not lending due to rate below ...") to +currency web page section instead of appending to log list. If enabled only last message is displayed. + + - Default value: Commented out, compacting of log is disabled (false) + - Allowed values: true, false + - ``startWebServer`` if true, this enables a webserver on the www/ folder. - Default value: Commented out, uncomment to enable. diff --git a/modules/Lending.py b/modules/Lending.py index f6deef15..e48df82a 100644 --- a/modules/Lending.py +++ b/modules/Lending.py @@ -412,8 +412,7 @@ def lend_cur(active_cur, total_lent, lending_balances, ticker): below_min = Decimal(orders['rates'][i]) < Decimal(cur_min_daily_rate) if hide_coins and below_min: - log.log("Not lending {:s} due to rate below {:.4f}% (actual: {:.4f}%)" - .format(active_cur, (cur_min_daily_rate * 100), (orders['rates'][i] * 100))) + log.notLending(active_cur, cur_min_daily_rate, orders['rates'][i]) return 0 elif below_min: rate = str(cur_min_daily_rate) diff --git a/modules/Logger.py b/modules/Logger.py index 0298a1f9..ea53922d 100644 --- a/modules/Logger.py +++ b/modules/Logger.py @@ -90,8 +90,10 @@ class Logger(object): def __init__(self, json_file='', json_log_size=-1, exchange=''): self._lent = '' self._daysRemaining = '' + self.compactLog = False if json_file != '' and json_log_size != -1: self.output = JsonOutput(json_file, json_log_size, exchange) + self.compactLog = bool(Config.get('BOT', 'jsonlogcompact', False)) else: self.output = ConsoleOutput() self.refreshStatus() @@ -117,6 +119,8 @@ def offer(self, amt, cur, rate, days, msg): line = self.timestamp() + ' Placing ' + str(amt) + ' ' + str(cur) + ' at ' + str( float(rate) * 100) + '% for ' + days + ' days... ' + self.digestApiMsg(msg) self.output.printline(line) + if self.compactLog: + self.output.statusValue(cur, 'log', '') self.refreshStatus() def cancelOrder(self, cur, msg): @@ -124,6 +128,17 @@ def cancelOrder(self, cur, msg): self.output.printline(line) self.refreshStatus() + def notLending(self, cur, minRate, actRate): + if self.compactLog: + self.output.statusValue(cur, 'log', + '{:s} Not lending due to rate below {:.4f}% (actual: {:.4f}%)' + .format(self.timestamp(), (minRate * 100), (actRate * 100))) + else: + self.log('Not lending {:s} due to rate below {:.4f}% (actual: {:.4f}%)' + .format(cur, (minRate * 100), (actRate * 100))) + + self.refreshStatus() + def refreshStatus(self, lent='', days_remaining=''): if lent != '': self._lent = lent diff --git a/www/lendingbot.js b/www/lendingbot.js index 6b8919c2..0c493f91 100644 --- a/www/lendingbot.js +++ b/www/lendingbot.js @@ -120,6 +120,7 @@ function updateRawValues(rawData){ var totalCoins = parseFloat(rawData[currency]['totalCoins']); var maxToLend = parseFloat(rawData[currency]['maxToLend']); var highestBidBTC = parseFloat(rawData[currency]['highestBid']); + var compactLog = 'log' in rawData[currency] ? rawData[currency]['log'] : '' if (currency == 'BTC') { // no bids for BTC provided by poloniex @@ -208,12 +209,20 @@ function updateRawValues(rawData){ } $(row).find('[data-toggle="tooltip"]').tooltip(); + if (compactLog.length > 0) { + table.insertRow() + row = table.insertRow() + var cell = row.appendChild(document.createElement("td")) + cell.setAttribute("colspan", rowValues.length) + cell.innerHTML = "
" + compactLog + "
" + } + var earningsColspan = rowValues.length - 1; // print coin earnings var row = table.insertRow(); if (lentSum > 0) { var cell1 = row.appendChild(document.createElement("td")); - cell1.innerHTML = "Est. "+ compoundRateText +"
Earnings"; + cell1.innerHTML = "Est. "+ compoundRateText +"
Earnings" var cell2 = row.appendChild(document.createElement("td")); cell2.setAttribute("colspan", earningsColspan); if (earningsSummaryCoin != '') { From 6dc286fe022c15bcdf65a5f9384afdb5ae09fdae Mon Sep 17 00:00:00 2001 From: Maik Hinrichs Date: Sat, 23 Sep 2017 18:33:07 +0200 Subject: [PATCH 2/2] Documentation --- docs/configuration.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 70910c1f..5c1a459e 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -292,12 +292,16 @@ Advanced logging and Web Display - Format: ``200`` - Reasons to lower this include: you are conscious of bandwidth when hosting your webserver, you prefer (slightly) faster loading times and less RAM usage of bot. -- ``jsonlogcompact`` enables to log frequent repeated log messages (like "Not lending due to rate below ...") to -currency web page section instead of appending to log list. If enabled only last message is displayed. +- ``jsonlogcompact`` enables to log frequent repeated log messages to currency web page section instead of appending to + log list. If enabled only last message is displayed. - Default value: Commented out, compacting of log is disabled (false) - Allowed values: true, false + When enabled, following log messages will be printed to currency section: + + - Cause of not lending: "Not lending due to rate below ..." + - ``startWebServer`` if true, this enables a webserver on the www/ folder. - Default value: Commented out, uncomment to enable.