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

Self.broker.get_cash() not getting updated after selling



  • Hello,

    As a part of weekly rebalancing, I want to sell some securities in my portfolio and use the proceeds to buy others meeting my custom criteria.
    I have written a function that gets executed when notify_time is invoked on weekly basis.
    The problem is when I sell the security,

    pos = self.getposition(d).size
    if pos:
        self.o[d]=self.close(data=d)
    cash = self.broker.get_cash()
    

    Here, cash does not get updated, so that I can use it to place a buy order in the incoming lines of code.



  • AFAIU, the cash position is updated upon order execution and not upon order creation.

    self.close will just issue the order - it doesn't mean it will be immediately executed. IMHO it is probably better to check for the broker cash in notify_order method.


Log in to reply
 

});