Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Two Questions about IB Live Trading

Hi all,

I have two questions about live trading.

  1. The IB account can't be logged in while a live algo is trading on it. How am I able to view my IB account without forcing algo log out (e.g. view IB account only during midnight)? If I accidentally force a live algo out, can I just re-log in the live algo, and the algo will resume from its last status safely?
  2. The algo may be modified from time to time. Everytime a modification is made, I have to redeploy it as a new algo. The problem is: do I have to first close the positions manually, then deploy the modified algo? If the two algo's target portfolio has a significant overlap, some $ will be wasted in the spread and commissions. Is there a way to fix this?

Kindly show me some clue. Thanks in advance!

Best,
Han

4 responses

Hi Han,

To answer your questions,

  1. If you're trading a real money account, IB lets you create a second user so you can simultaneously view your IB account while your algorithm is running in Quantopian. IB doesn't extend this offer to paper accounts. If you accidentally force your live algo to logout, you will receive an automated email from us to relogin. And when you relogin, your algorithm will continue from the point it left off. If you'd like to setup a second user, check out the instructions in our live trading FAQ.

  2. When you stop the algorithm, this prevents any future trades from being placed. Essentially it stops any calls to your algorithm and handle_data - and your positions are maintained. If you want to close your positions, you can add this to the beginning of your algo code.

Hope that helps!

Cheers,
Alisa

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.

Hi Alisa, thanks for helping out. I am confused about If you want to close your positions, before running your algorithm you can add this piece of logic to the beginning of your code.

Besides, I may not describe my second question clearly. Is there a way to deploy a slightly modified algo without the need to liquidity the old algo's positions beforehand?
For example, suppose my old algo has a position of AAPL 100 shares. Now I modify the algo. During market close I close the old algo, but now I have an open position AAPL 100 shares. When I deploy my new algo in the next day, my new algo determines I need to buy 50 additional AAPL shares. Can I say this in my new algo's:

AAPL_add = target_amount() -context.portfolio.positions[symbol('AAPL')].amount
order(symbol('AAPL'), AAPL_add)

Thanks a lot!

Best,
Han

Sure - that works!

You can also use the order_target methods, which are more robust. Using your example, if you used order_target(symbol('AAPL'), 150) the algorithm would buy 50 additional shares when it started again to reach the target of 150 shares. Using these methods, you can set a target based on number of shares, value, or percentage of portfolio.

Thanks! I was wondering if Quantopian code retrieves position information from IB, or if Quantopian code keeps a separate copy of position information. So, the former one is right.