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

Interactive Brokers "Broker" function issue



  • Hi there!

    I am trying to connect to IB TWS and retrieve positions and balances.

    However, the IB script just returns "0.0" for both Value and Cash, which is incorrect. My script:

    import backtrader as bt
    
    cerebro = bt.Cerebro()
    ibstore = bt.stores.IBStore(port=7496, clientId=123,timeout=180,reconnect=3)
    cerebro.broker = ibstore.getbroker()  # or cerebro.setbroker(...)
    
    print(cerebro.broker.getvalue())
    print(cerebro.broker.getcash())
    
    

    What am I missing? How can I fix this to display the correct values and cash positions, instead of "0.0"?

    Thank you!
    CWSE


  • administrators

    cerebro is not running, which means there is no communication with the broker. Anything other than 0.0 would be a surprise.