Is there a way of getting positions and account information but grouped by model? So if I have set up a model in TWS called ETFs-US, that has several accounts invested in the model. I want to know what positions are in ETFs-US regardless of account, and the cash balances and other info.
This isn’t currently supported. The concept of models somewhat overlaps with how QuantRocket uses IB’s OrderRef field: by assigning an OrderRef to each order (usually corresponding to the strategy code), the blotter can track positions/executions/pnl by order ref/strategy. You can assign order refs to orders placed manually in TWS and the blotter should pick up those executions as well and you can then query by order ref. Overall the concept of models seems fairly TWS-centric while order ref is more flexible and generic for API use.
Do you see a QR use case that is better handled by models?
The way I use it is I have a couple of accounts invested in a certain model (I have an FA account). When I need to rebalance that model, I download the positions and cash balance invested in the model to calculate the trades that need to take place. I then place the trades on TWS and specify the model to allocate the trades to. TWS then allocates shares proportionally to the accounts invested in the model. I use models because I can aggregate trades and get the same price for all accounts trading the same position and IB then distributes the shares to the corresponding accounts. It also makes it easier to keep track of the performance of the different strategies.
The way I do it now is I use QuantRocket to download and manage all the data I need. But then I need to connect to TWS through the API outside of the QR environment to download the positions and account balances by model.
I don’t think the OrderRef would work for my situation. Models may have cash balances associated with them and the OrderRef doesn’t deal with any cash. I also don’t know how the allocation between different accounts would take place if the model wasn’t specified.
I know this is a pretty specific use case, thanks for any help!
Since it sounds like you already have code to pull the data from IB API, this sounds like a good candidate to bring that code inside QR as a custom script using the
satellite service. That would save you from having to leave the QR environment and would allow a more automated process. The custom scripts documentation includes some guidance for connecting directly to the IB API:
Yeah that will definitely work. Thanks for pointing me in the right direction.