When collecting historical data from IBKR, you might see this error message in the logs:
quantrocket.history: WARNING [demo-stk-1d] ibg1 got IBKR error code 162 for historical data request for 1 M of 15 mins TRADES for EDC STK (conid 225312853) ending 20181122 21:00:00 GMT: Historical Market Data Service error message:Trading TWS session is connected from a different IP address
quantrocket.history: WARNING [demo-stk-1d] Waiting 60 seconds before collecting demo-stk-1d history to see if other TWS session terminatesThis error occurs when you are logged in to an IBKR platform in two places simultaneously with the same user login. IBKR permits each set of user credentials to be logged into only one session at a time. This restriction applies to IB Gateway, Trader Workstation (TWS), Client Portal, and any other IBKR platform where market data can be accessed.
If you're using a paper account, this error can occur when you are logged in to one IBKR platform with your live login and using the corresponding paper account with QuantRocket, or vice versa. Because paper accounts share the live account's market data subscription, IBKR does not permit you to be logged into both the live and paper accounts at the same time.
When QuantRocket detects this error, it waits 60 seconds and then retries the data request. The error continues until you disconnect your other session, at which point QuantRocket can resume data collection:
quantrocket.history: INFO [demo-stk-1d] Resuming collecting demo-stk-1d history after delayIf you need to access TWS or another platform while collecting data with QuantRocket, create a second user login, reserving one login for QuantRocket and the other for your own use.
If you only need to access TWS at certain times of day and want to use that login to speed up IBKR historical data collection, you can schedule the IB Gateway associated with that login to start and stop at certain times. For example, if you need to use TWS while the US stock market is open, you might schedule IB Gateway to start after the market closes and stop before the open:
# Start ibg2 weekdays at 4:30 PM
30 16 * * mon-fri quantrocket ibg start 'ibg2'
# Stop ibg2 weekdays at 9 AM
0 9 * * mon-fri quantrocket ibg stop 'ibg2'You don't need to cancel and restart a long-running historical data collection to start or stop IB Gateway. QuantRocket's historical data collection automatically detects the appearance and disappearance of IB Gateways and seamlessly uses whichever gateways are available to maximize IBKR historical data collection speed.