I tried to run TEST_ME.py to get_historical data bit it fails. I would be grateful for help! 1. Started IB with TWS 2. Edited TEST_ME.py : fileName = 'example_get_historical_data.py' logLevel = 'DEBUG' runMode = 'SUDO_RUN_LIKE_QUANTOPIAN' 3. Ran python TEST_ME.py (using python 3.7) 4. IBridgePy breaks ingesting data - IBridgePy.MarketManagerBase::setup_services:userConfig id=140557613986576 trader id=140557613943568 broker_client_factory.BrokerClient::__init__ broker_client_factory.BrokerClient_Local::setup_client_local_broker broker_service_factory.BrokerService_utils::get_broker_client {projectConfig=@PROJECT_Config@{accountCode=DU1474428;fileName=example_get_historical_data.py;logLevel=DEBUG;repBarFreq=60;dataProviderName=IB;brokerName=LOCAL_BROKER;sysTimeZone=@US/Eastern@US/Eastern;liveOrBacktest=2;rootFolderPath=/home/scubamut/IBridgePy37;histIngestionPlan=@HistIngestionPlan@{barSize=1 min;goBack=1 D;endTime=@datetime@2020-07-28 15:22:43.699825-07:00;dataSourceName=None;folderName=None;finalPlan=@set@{<data_provider_factory.data_loading_plan.Plan object at 0x7fd61f416d90>, <data_provider_factory.data_loading_plan.Plan object at 0x7fd61f416650>}};runScheduledFunctionBeforeHandleData=False;showTimeZone=@US/Eastern@US/Eastern}; marketManagerConfig=@MARKET_MANAGER_Config@{baseFreqOfProcessMessage=1;marketName=NONSTOP;beforeTradeStartHour=9;beforeTradeStartMinute=25}; repeaterConfig=@REPEATER_Config@{slowdownInSecond=0.0}; timeGeneratorConfig=@TIME_GENERATOR_Config@{timeGeneratorType=AUTO;startingTime=@datetime@2020-07-14 15:22:00.713762;endingTime=@datetime@2020-07-24 15:22:00.713762;freq=1T;custom=[]}; traderConfig=@TRADER_Config@{runMode=SUDO_RUN_LIKE_QUANTOPIAN}; brokerClientConfig=@BROKER_CLIENT_Config@{IB_CLIENT={'host': '', 'port': 7496, 'clientId': 9};TD_CLIENT={'apiKey': '', 'refreshToken': '', 'refreshTokenCreatedOn': datetime.date(2020, 5, 7)};ROBINHOOD_CLIENT={'username': '', 'password': ''}}; initialize_quantopian=@function@<function initialize at 0x7fd61ea04560>; handle_data_quantopian=@function@<function handle_data at 0x7fd61ea045f0>; before_trading_start_quantopian=@function@<function _set_default_values_for_user_input.<locals>.<lambda> at 0x7fd61ea044d0>; timeGenerator=@TimeGenerator@<IBridgePy.TimeGenerator.TimeGenerator object at 0x7fd61f41b750>; dataFromServer=@DataFromServer@Print models::Data::DataFromServer Empty keyedTickInfoRecords id=140557613518352 Empty keyedTickInfoRecords id=140557613518416; singleTrader=@SingleTrader@Print models::SingleTrader id=140557613517648 Print models::Broker=LOCAL_BROKER id=140557613517584 Print models::Account=DU1474428 id=140557624107600 Empty keyedPositionRecords Empty KeyedIbridgePyOrders Print models::AccountInfo::AccountInfo EMPTY models::AccountInfo::AccountValue::_updateAccountValueRecords EMPTY models::AccountInfo::AccountSummaries::_accountSummaryRecords ; trader=@Trader@<IBridgePy.Trader.Trader object at 0x7fd61ea64b10>; dataProvider=@IB@<data_provider_factory.dataProvider_IB.IB object at 0x7fd61e9fcf10>; dataProviderClient=@ClientLocalBroker@<broker_client_factory.BrokerClient_Local.ClientLocalBroker object at 0x7fd61e9fcf30>; log=@SimpleLoggerClass@<BasicPyLib.simpleLogger.SimpleLoggerClass object at 0x7fd61f41bd10>; userLog=@SimpleLoggerClass@<BasicPyLib.simpleLogger.SimpleLoggerClass object at 0x7fd62135f290>; brokerService=@LocalBroker@<broker_service_factory.BrokerService_Local.LocalBroker object at 0x7fd61ea1b7d0>; brokerClient=@ClientLocalBroker@<broker_client_factory.BrokerClient_Local.ClientLocalBroker object at 0x7fd61e9fcf30>; marketCalendar=@FakeMarketCalendar@<market_calendar_factory.FakeMarketCalendar.FakeMarketCalendar object at 0x7fd620a160d0>} broker_client_factory.BrokerClient::__init__ broker_client_factory.BrokerClient_IB::setup_client_IB IBridgePy.MarketManagerBase::__init__ #### Data ingestion starts #### broker_client_factory.BrokerClient_IB::connectWrapper data_provider_factory.data_provider_nonRandom::ingest_hists: loadingPlan={barSize=1 min;goBack=1 D;endTime=@datetime@2020-07-28 15:22:43.699825-07:00;dataSourceName=None;folderName=None;finalPlan=@set@{<data_provider_factory.data_loading_plan.Plan object at 0x7fd61f416d90>, <data_provider_factory.data_loading_plan.Plan object at 0x7fd61f416650>}} client=<broker_client_factory.BrokerClient_IB.ClientIB object at 0x7fd61e80be30> data_provider_factory.dataProvider_IB::_get_hist_from_IB broker_client_factory.BrokerClient_IB::add_exchange_to_security: security=STK,,,SPY,USD broker_client_factory.BrokerClient_IB::add_primaryExchange_to_security: security=STK,,SMART,SPY,USD broker_client_factory.BrokerClient_IB::add_primaryExchange_to_security: Found from security_info.csv ans=ARCA broker_client_factory.BrokerClient::_send_req_to_server {reqId=0;status=Submitted;reqType=reqHistoricalData;followUp=True;param={security:STK,ARCA,SMART,SPY,USD,barSize:1 min,goBack:10 D,endTime:20200728 22:22:43 UTC,whatToShow:TRADES,useRTH:1,formatDate:2,timezoneOfReturn:US/Eastern,}} broker_client_factory.CallBacks::nextValidId: Id = 1 broker_client_factory.CallBacks::currentTime: tm=1595942563 broker_client_factory.CallBacks:errorId=0 errorCode=162 errorMessage=Historical Market Data Service error message:No market data permissions for AMEX STK broker_client_factory.CallBacks:EXIT IBridgePy version= 9.4.1 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. Process finished with exit code 0
Hello Dave,
Try restarting the IB TWS. Another thing you can try it restarting the kernel running your code on spyder. This will allow the client running on the sypder IDE to connect to the server running on TWS. You can do this by going to the console menu —> restart kernel.
Hi Akshay,
thanks for responding speedily
I tried restarting TWS but I got the same error -
/home/scubamut/miniconda3/envs/ibridgepy/bin/python3.7 /home/scubamut/IBridgePy37/TEST_ME_IB.py
Data ingestion starts ####
broker_client_factory.CallBacks:errorId=0 errorCode=162 errorMessage=Historical Market Data Service error message:No market data permissions for AMEX STK
broker_client_factory.CallBacks:EXIT IBridgePy version= 9.4.1
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.
Process finished with exit code 0
But I run RUN_ME.py ok -
/home/scubamut/miniconda3/envs/ibridgepy/bin/python3.7 /home/scubamut/IBridgePy37/RUN_ME.py
IBridgePy version 9.4.1
fileName = example_show_positions.py
Starting to initialize trader ####
ACCOUNT Balance DU1474428 ##
CASH=878962.83
portfolio_value=1012350.03
positions_value=133387.2
POSITIONS DU1474428 ##
Symbol Amount Cost_basis
STK,AMZN,USD 20 3057.080715
STK,BND,USD 100 89.196403
STK,SPY,USD 200 322.4499525
NO any order ##
Initialize trader COMPLETED ####
I use Linux, a conda env and Pycharm. I know there was something about not using Anaconda (I use miniconda3/envs). Does that have anything to do with my problem?
Hello Dave,
The error is different this time.
I think you're using the demo account so as the message says " Service error message:No market data permissions for AMEX STK" - the account does not have permission to access this particular instrument.