How to check if my capital is fully utilized before placing a new order?

I want to check how much of my capital is already utilized either through buy or sell order before placing any new order. Which method can help me do that ?

Hi Abhishek,



This can be done by using "context.portfolio" attribute. There is an attribute "cash" which gives the total undeployed cash. Also, you can go through the "context.account" attribute to explore additional functionalities. You can refer to the following links for the same - 



context.portfolio

context.account



Hope it helps!



Thanks,

Akshay 

Thanks for the response @Akshay.



I tried using some of the attributes in the account object. But its not giving the desired results.





I am getting this error - 

InsufficientFund: Insufficient fund: Account equity balanace negative

To avoid it, i am adding this check before executing the trade

#target weight
weight = 0.1 #same as the argument in order_target_position
# buy transaction
if context.target_position[security] >0:
    # check if funds available is more than the target weight for the new stock to be considered
    if context.account.available_funds >= weight*context.account.total_positions_exposure:
        order_id = order_target_percent(security, context.target_position[security],limit_price = context.limit_price[security])

with this code i wanted to check if the funds are available before executing the trade. This does not seem to work, any suggestions ? 

I think its resolved now, using the below code to check.



if context.portfolio.cash >= weight*context.portfolio.starting_cash:

Hi Abhishek,



Good to know that you were able to solve it yourself. Great work!