Not able to run the file

when i am running any code it is giving me error as follows, could you guide me how to resolve this.



runfile('C:/IBridgePy_Win_Anaconda37_64/RUN_ME.py', wdir='C:/IBridgePy_Win_Anaconda37_64')

Reloaded modules: configuration, BasicPyLib, BasicPyLib.BasicTools, Config, Config.config_defs, BasicPyLib.simpleLogger, Config.base_settings, IBridgePy, IBridgePy.constants, BasicPyLib.Printable, Config.configTools, IBridgePy.MarketManagerBase, broker_client_factory, broker_client_factory.broker_client_utils, broker_service_factory, broker_service_factory.BrokerService, IBridgePy.IbridgepyTools, IBridgePy.IBCpp, IBridgePy.quantopian, broker_client_factory.BrokerClientDefs, models, models.utils, models.Order, broker_service_factory.BrokerService_utils, data_provider_factory, data_provider_factory.data_provider, data_provider_factory.data_provider_utils, market_calendar_factory, market_calendar_factory.MarketCalendar, market_calendar_factory.market_calendar_lib, market_calendar_factory.market_calendar_lib.market_calendar, market_calendar_factory.market_calendar_lib.calendar_utils, market_calendar_factory.market_calendar_lib.exchange_calendar_cfe, market_calendar_factory.market_calendar_lib.us_holidays, market_calendar_factory.market_calendar_lib.exchange_calendar_ice, market_calendar_factory.market_calendar_lib.exchange_calendar_nyse, market_calendar_factory.market_calendar_lib.exchange_calendar_cme, market_calendar_factory.market_calendar_lib.exchange_calendar_bmf, market_calendar_factory.market_calendar_lib.exchange_calendar_lse, market_calendar_factory.market_calendar_lib.exchange_calendar_tsx, market_calendar_factory.market_calendar_lib.exchange_calendar_eurex, market_calendar_factory.MarketCalendar_utils, market_calendar_factory.FakeMarketCalendar, BasicPyLib.repeater, IBridgePy.TimeGenerator, models.Data, models.SingleTrader, models.AccountInfo, models.Position, settings, Config.backtest_settings, Config.hft_settings, Config.robinhood_settings, Config.td_settings, IBridgePy.Trader, IBridgePy.trader_defs, data_provider_factory.dataProvider_IB, data_provider_factory.data_provider_nonRandom, broker_client_factory.BrokerClient_IB, broker_client_factory.CallBacks, broker_client_factory.BrokerClient, broker_service_factory.BrokerService_IB, broker_service_factory.BrokerService_callback

IBridgePy version 9.1.3

fileName = example_get_historical_data.py

broker_client_factory.CallBacks:errorId=-1 errorCode=326 errorMessage=Unable connect as the client id is already in use. Retry with a unique client id.

broker_client_factory.CallBacks:EXIT IBridgePy version= 9.1.3

broker_client_factory.CallBacks: Connection between Gateway/TWS to IB server is broken. Please check internet connection or try it later. Or maybe IB server is under maintenance.

broker_client_factory.CallBacks: Connection between Gateway/TWS to IB Historical Data farm is broken. Please check internet connection or try it later. Or maybe IB server is under maintenance.

broker_client_factory.CallBacks: Connection between Gateway/TWS to IB Market Data Farm is broken. Please check internet connection or try it later. Or maybe IB server is under maintenance.

 

Hello Tarun,



Please restart IB TWS and try executing the code. It will work.

I have restarted multiple times, for the first time it gives result, but when i again run RUN_ME it gives me this error

Hello Tarun


Connection between Gateway/TWS to IB server is broken. Please check internet connection or try it later. Or maybe IB server is under maintenance.

The general architecture is that the Python code through IBridgepy communicates to the Trader Workstation (TWS) or Gateway and then TWS or Gateway connects with the Interactive Brokers servers. From the error message, it seems like the last leg is having a problem.

Can you check if the connection is intact from this link: https://www.interactivebrokers.com/cgi-bin/conn_test.pl
If you get fail then you can follow that link to troubleshoot the issue.


If the above connection is fine, then the issue is due to below

Unable connect as the client id is already in use. Retry with a unique client id.
 

This is a known issue in the recent release from IB API. Whenever you start the TWS the client id is assigned and on ending the code, the client id is still active. Thus, next time you run the code you will face the error message that the client id is already in use. When a fix is released by IB in IB API, this issue will be permanently solved.

Unfortunately, meanwhile, you can restart the kernel before running the code again. And when restarted a new clientid will be used and thus solve the issue.

A video guide on this can be accessed from here: https://www.youtube.com/watch?v=l4Cl9iSY4Bk

I hope this helps. If you face any issues then feel free to post here.

Thanks!