market data in both - live and paper TWS containers
Raigedas opened this issue · 5 comments
TWS does not allow to show market data in a paper instance if live instance (for the same user) is running on ANOTHER machine (but shows if both are running on the same machine).
we run one container for live and another container for paper but they do not "see" each other and TWS does not show market data in paper container. any ideas how to make them both show market data? thank you.
What do you mean by the 'same machine' - how do you run both the live and paper accounts simultaneously on a machine?
i am not sure that i understand the question...
'same machine' - 'same computer'. just running live and paper instances side by side:
as it is designed to be run i believe, because there are even different default API ports set depending on mode (if you run live then default API port is 7496 and if paper then 7497) so that you will not get port conflicts if you run both live and paper on the same host.
and as can be understood from official documentation:
https://interactivebrokers.github.io/tws-api/market_data.html
Important: since your paper trading market data permissions are bound to your live one, you can only obtain live market data on your paper trading user if;
You have shared the market data subscriptions accordingly as described above.
You are NOT logged in with your live user name at the same time on a **different** computer.
if you run both live and paper on "different computer" then you will NOT get market data on both.
Okay, I think I get what you mean. I think TWS runs a server in the background, which both a live and paper instance on the same computer can connect to. I suspect this server is different from that provided by IB Gateway.
One way to do this would be to run 2 instances of TWS simultaneously in the container. However, IB Gateway is preferred over TWS because TWS needs manual intervention to open the ports.
Does opening 2 instances of IB Gateway instead work for you? That seems like the best solution.
first, thank you very much for taking time and effort to consider this case.
i am still seeing some misunderstanding here (at least me i do not understand what you mean by "this server is different from that provided by IB Gateway") so maybe i better explain my situation in a simplified way:
- we are developing a trading application.
- we run a TWS with real money and allow trading app to connect to this TWS via API. we want to see all the activity and charts visually so here it is TWS instead of Gateway.
- during the development process of the trading app we need to run some tests. we run those tests on the "paper" environment of course. here again we run TWS and need market data because:
-- some tests do need to get latest candle snapshots
-- we would like to visually see what actions (what buy/sell orders etc) the tests are performing. if we have the charts then we can easily see visually the location of those orders being created by tests.
Ah okay, I see what you mean there.
This will require running 2 instances of IBC Alpha, one of which will launch TWS Live, and the other TWS Paper.
What I meant by I suspect this server is different from that provided by IB Gateway is that when you run TWS, in the background, some sort of server is also running, which connects to IBKR. TWS then connects to that server. When you run 2 instances of TWS (one live and paper), they both connect to that same server. IBKR allows one such server per market data subscription.
However, when you run TWS in 2 different containers, each instance of TWS runs its own instance of that server mentioned above. Since IBKR does not allow these 2 different servers to share 1 market data subscription, you cannot use market data on both containers simultaneously.
However, modifying the scripts to run 2 instances of TWS/IBGateway will require a bit of effort, and is likely outside the scope of this repository (which is to run one instance of either TWS or IBGateway in a container), and is something I don't have the bandwidth to work on currently, unfortunately.
Hope this helps!