Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
In Live Trading with IB, does Quantopian sync up positions with IB?

Suppose I have a position of 100 MSFT in IB prior to using Quantopian, and then I turn on live trading of Quantopian with IB, will context.portfolio.positions[sec].amount, for MSFT will this equal 100?

For the following code, will positions automatically be synced up with IB? Or will IB and Quantopian have different notions of "position?"

def liquidate_orders(context):
for sec in context.secs:
amount = context.portfolio.positions[sec].amount
if amount:
order_target(sec,-amount)
message = 'Liquidate order for {amount} shares in {stock}'
message = message.format(amount, stock=sec)
log.info(message)

And, furthermore, can you have multiple portfolios in Quantopian? In IB? Can they be mapped 1:1 and how?

If a stock split occurs and IB adjusts the position, will that automatically flow through to Quantopian?

Thanks,
Abe

3 responses
def liquidate_orders(context):  
    for sec in context.secs:  
        amount = context.portfolio.positions[sec].amount  
        if amount:  
            order_target(sec,-amount)  
            message = 'Liquidate order for {amount} shares in {stock}'  
            message = message.format(amount, stock=sec)  
            log.info(message)  

Hi Abe,

In live trading there is a sync with IB on each run of the handle_data() method (1ce per minute). If there is a discrepancy between IB's info on position sizes and Quantopian's records the IB value is preferred as the value of record and the portfolio object is updated. This goes for the first time an algo is deployed as well - if your account had an existing position in MSFT for example that position is pulled in to Quantopian's portfolio object at the first sync point.

It is not currently supported to run more than one algorithm (or more than one portfolio object) per IB account. IB has a financial advisory account structure that makes it fairly straightforward to create sub-accounts funded with just the amount of capital you're looking to deploy/test against with a Quantopian algo - so that is the route we're advising people to take for now.

I believe splits should be handled automatically, but I'm going to double check if there are any known issues around that and get back on this thread.

Best regards,
Jess

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

It would be good if any discrepancies can be logged separately. Some IB makes mistakes too.