Trade by position and execution price

I am having trouble figureing out how to do two things.


  1. Sell my position where I don't know the quantity or value. For example, if I buy $10K of equity A and want to sell the entire position later, I needd to know either the quantity that I bought or the the current value. I am having trouble pulling these up in real time. 


  2. Sell my position based on a predetermined gain. So if my position increases in value by 30%, I want to sell the entire position. I would assume the easiest way to due this would be to pull up the execution price, but I can't see how to do that. Of course, if I can pull up performance data showing the unrealized gains/losses that would work to.



    I appreciate any help. 



    Thank you!

Hi Rory, 



You can query context.portfolio.positions to access the positions data within the strategy code. 

You can refer to this documentation for the list of attributes. 



Hope this helps!



Thanks,

Bhavika