backtrader
backtrader copied to clipboard
Broker position Error
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 ?
My Strategie code is working correctly on pandas feed.
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 ?
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 :)
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