For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Exception in line series length at paper trading



  • Hi, Backtraders!

    I'm trying to run backtrader with Interactive Broker where I fed data for 10 equities. But I get an error related to the length of some of the data lines at the beginning of the simulation. When I reduce the number of equities to three all run ok. I searched on this community and found a related problem but any
    solution is yet proposed.

    Here the full exception trace:

    Traceback (most recent call last):
      File "/home/galvez/repos/research_factory/20180822_PortafolioBacktrader/XBranch_NN/backTesting/run_backtest.py", line 335, in <module>
        run_live(equity)
      File "/home/galvez/repos/research_factory/20180822_PortafolioBacktrader/XBranch_NN/backTesting/run_backtest.py", line 325, in run_live
        cerebro.run()
      File "/home/galvez/anaconda3/envs/backtrader/lib/python3.5/site-packages/backtrader/cerebro.py", line 1127, in run
        runstrat = self.runstrategies(iterstrat)
      File "/home/galvez/anaconda3/envs/backtrader/lib/python3.5/site-packages/backtrader/cerebro.py", line 1298, in runstrategies
        self._runnext(runstrats)
      File "/home/galvez/anaconda3/envs/backtrader/lib/python3.5/site-packages/backtrader/cerebro.py", line 1630, in _runnext
        strat._next()
      File "/home/galvez/anaconda3/envs/backtrader/lib/python3.5/site-packages/backtrader/strategy.py", line 325, in _next
        super(Strategy, self)._next()
      File "/home/galvez/anaconda3/envs/backtrader/lib/python3.5/site-packages/backtrader/lineiterator.py", line 255, in _next
        clock_len = self._clk_update()
      File "/home/galvez/anaconda3/envs/backtrader/lib/python3.5/site-packages/backtrader/strategy.py", line 305, in _clk_update
        newdlens = [len(d) for d in self.datas]
      File "/home/galvez/anaconda3/envs/backtrader/lib/python3.5/site-packages/backtrader/strategy.py", line 305, in <listcomp>
        newdlens = [len(d) for d in self.datas]
      File "/home/galvez/anaconda3/envs/backtrader/lib/python3.5/site-packages/backtrader/lineseries.py", line 464, in __len__
        return len(self.lines)
      File "/home/galvez/anaconda3/envs/backtrader/lib/python3.5/site-packages/backtrader/lineseries.py", line 220, in __len__
        return len(self.lines[0])
    ValueError: __len__() should return >= 0
    
    Process finished with exit code 1
    

    Thanks in advance and happy trading.


  • administrators

    You are provoking pacing violations, due to the number of requests. That's why reducing the number of assets gets you up and running.



  • Thank you for your prompt response. Any clue how to overcome the issue? Or is there a limited number of assets we can work with Interactive Brokers and Backtrader?


  • administrators

    @j-javier-gálvez said in Exception in line series length at paper trading:

    Or is there a limited number of assets we can work with Interactive Brokers

    The limit is there. Even if some of the limits have been softened over the years, IB praises to be a broker and not a data provider. That's why they also provide 250 ms snapshot-ticks of the market instead of real time ticks.

    Using IB is of course fit for many purposes and trading situations, but working simultaneously with a large number of assets isn't one of them.

    Your options:

    • Disable backfilling
    • Use data files (or any other source) as backfill_from

    Because the pacing violations are hit when requesting historical data (which is the backfilling source)

    There is an additional limit which is the number of simultanteous assets you can request real-time information from (NBBO), but this also has to do with your account commissions level, if you have acquired a boost package and other things.

    Let me add: if you didn't know these things before ... you should know all the rules that apply to your trading (data provision and brokerage) before you trade. It is the 1st rule when gambling (sorry trading): "Know the house rules".



  • @backtrader Thank you very much for your response and suggestions. I appreciate it.