Dave-Vallance / bt-ccxt-store

Fork of Ed Bartosh's CCXT Store Work
MIT License
422 stars 185 forks source link

TypeError: unsupported operand type(s) for *: 'NoneType' and 'float' #6

Closed garofas closed 5 years ago

garofas commented 5 years ago

Hi,

I'm having this error with Bitfinex:

Traceback (most recent call last):
  File "/home/user/.vscode/extensions/ms-python.python-2019.1.0/pythonFiles/ptvsd_launcher.py", line 45, in <module>
    main(ptvsdArgs)
  File "/home/user/.vscode/extensions/ms-python.python-2019.1.0/pythonFiles/lib/python/ptvsd/__main__.py", line 348, in main
    run()
  File "/home/user/.vscode/extensions/ms-python.python-2019.1.0/pythonFiles/lib/python/ptvsd/__main__.py", line 253, in run_file
    runpy.run_path(target, run_name='__main__')
  File "/usr/lib/python3.6/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/user/TEST/my_test_ccxt/bot_bitfinex.py", line 107, in <module>
    cerebro.run(exactbars=0) #https://www.backtrader.com/docu/memory-savings/memory-savings.html
  File "/home/user/.local/lib/python3.6/site-packages/backtrader/cerebro.py", line 1127, in run
    runstrat = self.runstrategies(iterstrat)
  File "/home/user/.local/lib/python3.6/site-packages/backtrader/cerebro.py", line 1298, in runstrategies
    self._runnext(runstrats)
  File "/home/user/.local/lib/python3.6/site-packages/backtrader/cerebro.py", line 1623, in _runnext
    self._brokernotify()
  File "/home/user/.local/lib/python3.6/site-packages/backtrader/cerebro.py", line 1360, in _brokernotify
    self._broker.next()
  File "/usr/local/lib/python3.6/dist-packages/bt_ccxt_store-1.0-py3.6.egg/ccxtbt/ccxtbroker.py", line 199, in next
  File "/home/user/.local/lib/python3.6/site-packages/backtrader/position.py", line 193, in update
    self.price = (self.price * oldsize + size * price) / self.size
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

it happens after this:

2019-02-18 15:32:57.065339 - fetch_open_orders - Attempt 0 2019-02-18 15:33:17.162320 - create_order - Attempt 0 2019-02-18 15:33:27.426503 - fetch_order - Attempt 0 2019-02-18 15:33:37.524229 - fetch_ohlcv - Attempt 0 2019-02-18 15:33:47.613561 - fetch_ohlcv - Attempt 0 2019-02-18 15:33:57.695672 - fetch_order - Attempt 0

is happening in with: self.price = (self.price oldsize + size price) / self.size

the error is "TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'" Any clue? Thanks

Dave-Vallance commented 5 years ago

Hi @garofas

Would you be able to recreate it using a simple script that you can share here? That would help for taking a look!

Cheers

garofas commented 5 years ago

Hi @Dave-Vallance,

I'm trying to reproduce. For the moment I've inserted a small piece of code to log what is happening into method "update" of file "backtrader/position.py":

     if size > 0:  # increased position
                opened, closed = size, 0
                import sys
                print("position.py tracing increased position: " + str(self.price), file=sys.stderr) # None
                print("position.py tracing increased position: " + str(oldsize   ), file=sys.stderr) # value at runtime ->0.004
                print("position.py tracing increased position: " + str(size      ), file=sys.stderr) # value at runtime ->0.004
                print("position.py tracing increased position: " + str(price     ), file=sys.stderr) # None
                print("position.py tracing increased position: " + str(self.size ), file=sys.stderr) # value at runtime ->0.008

                self.price = (self.price * oldsize + size * price) / self.size

in the comment the values I'm getting at runtime. Thanks

garofas commented 5 years ago

Most likely the bug was caused by a problem in the custom sizer. I will update if it happens again.

Dave-Vallance commented 5 years ago

Ok - Closing for now. Re-open it if you manage to reproduce.

garofas commented 5 years ago

Hi, I still have the issue. My CCXT version: 1.18.486