That seems like it could be problematic if people want to run multiple algos. Or if I'm running a single intra-day algo which sells everything at the end of day, but I still have stocks I want to keep long.
Our expectation is that you will set up a separate sub-account for your Quantopian algorithm to run in. If you have stocks you want to keep separate from your algorithm, you should not keep them in the sub-account that your algorithm is configured to use.
By design, you cannot have multiple Quantopian algorithms running against the same IB account / sub-account.
When does that occur? sounds like it would impact a currently running algo (which may be a good thing, but I would think we should have control over that).
We poll IB periodically to check if your cash balance has changed. IB sends pushes updates to us asynchronously whenever the equities in your account are changed, or because an order your algorithm placed was filled, or because you sold or bought stock through the IB web site while the algorithm was running, or because you exceeded your margin limit and IB put a margin call on your account and liquidated some of your holdings, etc.
When your algorithm needs to make buy/sell decisions based on what is in your account, it should always be consulting context.portfolio and treating whatever is recorded there as canonical; it should not keep its own, separate state about your holdings, or if it does, it should make sure to reconcile that state with what is in context.portfolio.
This is true of any algorithmic trading platform, not just Quantopian. Your holdings are what your brokerage says your holdings are, not what your algorithm thinks they should be.
And is this behavior reflected in paper trading as well?
In IB paper trading? Yes, to whatever extent as IB's paper trading implementation reflects it (which it seems to, by and large). As far as Quantopian is concerned, IB paper trading has no functional difference from IB real-money trading; the only difference is that the IB account number you give to Quantopian is a paper-trading account number rather than a real-money account number.