backtrader icon indicating copy to clipboard operation
backtrader copied to clipboard

Broker position Error

Open sirhc78 opened this issue 6 years ago • 4 comments

Hi, Using Bitmex feed and Bitmex broker on BTC/USD production. (same before and after https://github.com/bartosh/backtrader/commit/0ce07e524722f83b6eea7e7379fff5cf622a8f74)

I have a strange position object. First self.getposition().size does not exist :

  File "D:\Dev2\Anaconda3\lib\site-packages\backtrader\strategy.py", line 325, in _next
    super(Strategy, self)._next()

  File "D:\Dev2\Anaconda3\lib\site-packages\backtrader\lineiterator.py", line 266, in _next
    self.next()

  File "D:\Dev2\Dev\JimTrading\BTStrategies.py", line 150, in next
    if self.getposition().size>0:

AttributeError: 'float' object has no attribute 'size'

And if I run :

    def __init__(self):
        print(self.getposition())

I get a float : 0.01
which seems to be the account value and not my position on future perpetual contract XBTUSD.

Could it be CCXT error ?

sirhc78 avatar Sep 27 '18 14:09 sirhc78

My Strategie code is working correctly on pandas feed.

sirhc78 avatar Sep 27 '18 14:09 sirhc78

May be I don't understand how it should work.

if self.position : is true. I should get a structure with size and price members and not a float. Is that correct ?

sirhc78 avatar Oct 02 '18 07:10 sirhc78

It's a bug that has to be fixed. The getposition method should return position object. I'll fix it when I have time. You can fix it too :)

bartosh avatar Oct 02 '18 15:10 bartosh

Hi, I was just wondering if this bug has been fixed. When i use the self.getposition() i receive empty object where I should get a list of my open positions.

Positions --- Position Begin

  • Size: 0
  • Price: 0.0
  • Price orig: 0.0
  • Closed: 0
  • Opened: 0
  • Adjbase: None --- Position End

pfederra avatar Mar 26 '19 13:03 pfederra