BitBotFactory / MikaLendingBot

Automated lending on Cryptocurrency exchanges Poloniex and Bitfinex
http://poloniexlendingbot.readthedocs.io/en/latest/index.html
MIT License
1.11k stars 344 forks source link

Maxtolendrate KeyError Crash #150

Closed praeluceo closed 7 years ago

praeluceo commented 7 years ago

I believe a bug may have been intruduced in #143 or that a variable wasn't updated in the default.cfg.example.

I think this update may have introduced a bug:

$ python lendingbot.py 
Welcome to Poloniex Lending Bot
Started WebServer, lendingbot status available at http://localhost:8000/lendingbot.html
2016-11-28 22:14:55 ERROR: 'maxtolendrate'
2016-11-28 22:14:55
Traceback (most recent call last):
  File "lendingbot.py", line 91, in <module>
    Lending.lend_all()
  File "/home/ronald/bots/poloniexlendingbot/modules/Lending.py", line 133, in lend_all
    MaxToLend.amount_to_lend(total_lended[key], key, 0, 0)
  File "/home/ronald/bots/poloniexlendingbot/modules/MaxToLend.py", line 30, in amount_to_lend
    cur_max_to_lend_rate =  coin_cfg[active_cur]['maxtolendrate']
KeyError: 'maxtolendrate'

with the following config:

#maxtolend = 0
maxpercenttolend = 90
maxtolendrate = 0.05
coinconfig = ["BTC:0.0127:1:0:90:0.1","FCT:0.015:1:0:0:0","ETH:0.005:1:0:0:0","XMR:0.015:1:0:0:0"]

Rolling back to commit "8e73a38eb309a90000713b972f5dde6703acf5da" with the same config above works fine. I've tried several variations on the config file, but can't seem to get any to match what is expected. Even by diffing my older config with the new one, and pulling over every change, I can't get #143 to work.

Evanito commented 7 years ago

Are you on master? This bug would only exist if you are on the branch between #143 and this commit: https://github.com/Mikadily/poloniexlendingbot/pull/142/commits/5dd62589fb6b80f234b826434f22f467ef45ee0c

praeluceo commented 7 years ago

It was on master, yes, now I'm on a checkout: `$ git branch -a

praeluceo commented 7 years ago

So commit #143 was to Evanito-Modularise from MaxToLend-code-complexity, 5dd6258 was a merge from Evanito-Modularise the next day to master. When I try to bisect the issue on the Evanito-Modularise branch, I don't see the error between ef7f5fd32b135c2446676492bb018ba61c038f7a and 907e280d6c0135697ef42d01af9ab06ea1393249.

On the master branch, I stepped backward and can definitely isolate the fault to being introduced in 951f9b6276c2e31d7179199b3247f74ea9f2cc7a of master, and the KeyError does not occur in 8e73a38eb309a90000713b972f5dde6703acf5da

I believe I see an error however, the lines here refer to the older misspelled variable:

$ git diff modules/Configuration.py
diff --git a/modules/Configuration.py b/modules/Configuration.py
index 9caf226..db9226d 100644
--- a/modules/Configuration.py
+++ b/modules/Configuration.py
@@ -62,8 +62,8 @@ def get_coin_cfg():
             for cur in coin_config:
                 cur = cur.split(':')
                 coin_cfg[cur[0]] = dict(minrate=(Decimal(cur[1])) / 100, maxactive=Decimal(cur[2]),
-                                        maxtolent=Decimal(cur[3]), maxpercenttolent=(Decimal(cur[4])) / 100,
-                                        maxtolentrate=(Decimal(cur[5])) / 100)
+                                        maxtolend=Decimal(cur[3]), maxpercenttolent=(Decimal(cur[4])) / 100,
+                                        maxtolendrate=(Decimal(cur[5])) / 100)
         except Exception as ex:
             print "Coinconfig parsed incorrectly, please refer to the documentation. Error: " + str(ex)
     return coin_cfg

making the above modification doesn't make the bot work, but it does return a different error:

$ python lendingbot.py
Welcome to Poloniex Lending Bot
Started WebServer, lendingbot status available at http://localhost:8000/lendingbot.html
2016-11-29 19:37:11
Traceback (most recent call last):
  File "lendingbot.py", line 91, in <module>
    Lending.lend_all()
  File "/home/ronald/bots/poloniexlendingbot/modules/Lending.py", line 133, in lend_all
    MaxToLend.amount_to_lend(total_lended[key], key, 0, 0)
  File "/home/ronald/bots/poloniexlendingbot/modules/MaxToLend.py", line 32, in amount_to_lend
    cur_max_percent_to_lend = coin_cfg[active_cur]['maxpercenttolend']
KeyError: 'maxpercenttolend'

I am not terribly great with python really, so I'm not sure why checkout from 8e73a38eb309a90000713b972f5dde6703acf5da works for me but nothing more recent does, even though the Evanito-Modularise branch does.