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

Number of open positions



  • Hello,

    Is there a way to get the number of all the open positions without looping through all the data to find if self.getposition(d) has a size > 0?

    Thanks



  • found it:

    len(self.broker.positions)
    

    I needed it in Sizer



  • After debugging I found the positions in self.broker.positions are not only the ones with positive size so I'm back to looping. To get the nuber of open positions inside a Sizer I am using a list comprehension:

    open_positions = len([position for position in self.broker.positions if self.broker.getposition(position).size > 0])
    

    anyone can suggest a better solution?


Log in to reply
 

});