whittlem / pycryptobot

Python Crypto Bot (PyCryptoBot)
Apache License 2.0
1.97k stars 738 forks source link

MarginHelper.py float division by zero #340

Closed antonp01 closed 3 years ago

antonp01 commented 3 years ago

Describe the bug just did a git pull to update source, and tried running --sim fast and got division by zero.

To Reproduce

python3.9 pycryptobot.py --sim fast
--------------------------------------------------------------------------------
|                             Python Crypto Bot                                |
--------------------------------------------------------------------------------
|                Release : v2.32.0                                             |
-----------------------------------------------------------------------------
|               Bot Mode : TEST - test trades using dummy funds :)             |
|            Bot Started : 2021-06-16 14:16:33.836437                          |
================================================================================
|           Sell At Loss : True  --sellatloss True                             |
|     Sell At Resistance : False  --sellatresistance                           |
|        Trade Bull Only : False  --disablebullonly                            |
|          Buy Near High : True  --disablebuynearhigh                          |
|           Use Buy MACD : True  --disablebuymacd                              |
|            Use Buy OBV : True  --disablebuyobv                               |
|      Use Buy Elder-Ray : True  --disablebuyelderray                          |
|     Sell Fibonacci Low : True  --disablefailsafefibonaccilow                 |
|   Candlestick Reversal : True  --disableprofitbankreversal                   |
|               Telegram : True  --disabletelegram                             |
|                    Log : True  --disablelog                                  |
|                Tracker : True  --disabletracker                              |
|       Auto restart Bot : False  --autorestart                                |
================================================================================
2021-06-13 18:15:00 | BTC-USD | 900 | Close: 37514.9500 | EMA12/26: 37514.9500 = 37514.9500 | MACD: 0.0000 = 0.0000OBV: 406.4252 (0.0000%)ERI: |  | WAIT | Last Action: WAIT
2021-06-13 18:30:00 | BTC-USD | 900 | Close: 37375.6400 | *v EMA12/26: 37493.5176 < 37504.6307 v* | *v MACD: -11.1130 < -2.2226 v*v OBV: 237.5648 (-41.5500%) v | ERI: sell |  | SELL | Last Action: WAIT
ZeroDivisionError('float division by zero')
Traceback (most recent call last):
  File "/home/anton/pycryptobot/BTC/models/helper/MarginHelper.py", line 28, in calculate_margin
    margin = round((profit / buy_size) * 100, precision)
ZeroDivisionError: float division by zero
Vashiru commented 3 years ago

Running into the same issue on Binance KAVA/USDT (live) just now. v2.32.0 as well.

In my case I do own some KAVA, but it's pending in a sell order. Maybe that's tripping up the bot? The simulation ran just fine for me.

Config for simulation:

        "config": {
            "base_currency": "KAVA",
            "quote_currency": "USDT",
            "live": 0,
            "autorestart": 1,
            "granularity": "15m",
            "sim": "fast-sample",
            "simenddate": "now"
        }

Config to actually run it:

        "config": {
            "base_currency": "KAVA",
            "quote_currency": "USDT",
            "live": 1,
            "autorestart": 1,
            "granularity": "15m"
        }

Logs:

Restarting application after exception: ZeroDivisionError('float division by zero')

ZeroDivisionError('float division by zero')

Traceback (most recent call last):

  File "/app/models/helper/MarginHelper.py", line 28, in calculate_margin

    margin = round((profit / buy_size) * 100, precision)

ZeroDivisionError: float division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/app/models/helper/MarginHelper.py", line 28, in calculate_margin

    margin = round((profit / buy_size) * 100, precision)

ZeroDivisionError: float division by zero
stefanoregis commented 3 years ago

same problem on my side

arma6655 commented 3 years ago

Caused by #338 https://github.com/whittlem/pycryptobot/pull/338/files#diff-f1e8f1fd905f7dd48b2bb077d93ddad51edcec730e5ca6f6c8c37ef99b452ab7L111 needs self.last_action = 'SELL' added back

Vashiru commented 3 years ago

@arma6655 Thanks for the clear description, I've opened a pull request to get it fixed.

germainlefebvre4 commented 3 years ago

Opened #367 to solve another case of division by zero from MarginHelper.py.

The retrieved orders (from getOrders) contain orders with status filled and new. The new orders do not contain any buy_size correct value. So it is converted as a 0 (zero) and the calling method raise this error. This fix solve the "float division by zero" error message when running the bot in parallele of trading on limits.