Someone help me please.
Try brokerClient IB port=7496
port=7496 is correct and set port to userConfig.brokerClientConfig.IB_CLIENT
Connected to IB is successful using port=7496
IBridgePy version 16.3.2
fileName = example_get_historical_data.py
broker_client_factory.BrokerClient::request_data: EXIT, the following requestRecord failed
{reqId=0;status=Submitted;reqType=reqIds;followUp=True;param={}}
Traceback (most recent call last):
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\RUN_ME.py", line 53, in <module>
run_me(fileName, globals())
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\configuration.py", line 85, in run_me
finally_run(userConfig, LiveBacktest.LIVE)
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\configuration.py", line 222, in finally_run
c.run()
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\IBridgePy\MarketManagerBase.py", line 55, in run
self._run_once()
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\IBridgePy\MarketManagerBase.py", line 51, in _run_once
self.trader.initialize_Function()
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\IBridgePy\Trader.py", line 339, in initialize_Function
self._brokerService.submit_requests(ReqIds())
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\broker_service_factory\BrokerService.py", line 293, in submit_requests
return self._brokerClient.request_data(*args)
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\broker_client_factory\BrokerClient.py", line 351, in request_data
raise RuntimeError('%s server did not response to the request at all. Maybe the market is closed? Consider trying it later.' % (self.name, ))
RuntimeError: IB server did not response to the request at all. Maybe the market is closed? Consider trying it later.
Help please.
Hello,
One thing you can do is to change the symbol for which you want to get the data. If you are using a demo account while fetching the data, you will not have access to all the tickers. Your access will be limited to Forex pairs mostly. Can try the below code:
context.security=symbol('CASH,EUR,USD')
Also, try running other available .py files and see if you are getting the same error.
If you are still facing the issue, please let us know.
Thanks!
FIrst time run is working and it showed historical data.
Second run is not working and it didn't show historical data it showed as follow,
"IB server did not response to the request at all. Maybe the market is closed? Consider trying it later."
And this code didn't not working at the first time run,
print ('Historical Data of %s' % (str(context.security, ),))
hist = request_historical_data(context.security, '1 min', '365 D')
print(hist)
print(hist.iloc[-1]['close'])
Could you please send the error for the mentioned code. And what symbol you are passing in the context.security.
Can try this line of code
context.security=symbol('CASH,EUR,USD')
hist = request_data(context.security, '1 min', '1 D'),
this is the code:
hist = request_data(context.security, '1 min', '10 D')
print(hist)
This is an errors:
runfile('D:/IB_Historical_Data/IBridgePy_Win_Anaconda38_64/RUN_ME.py', wdir='D:/IB_Historical_Data/IBridgePy_Win_Anaconda38_64')
Try brokerClient IB port=7496
port=7496 is correct and set port to userConfig.brokerClientConfig.IB_CLIENT
Connected to IB is successful using port=7496
IBridgePy version 16.3.2
fileName = example_get_historical_data.py
broker_client_factory.BrokerClient::request_data: EXIT, the following requestRecord failed
{reqId=0;status=Submitted;reqType=reqIds;followUp=True;param={}}
Traceback (most recent call last):
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\RUN_ME.py", line 54, in <module>
run_me(fileName, globals())
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\configuration.py", line 85, in run_me
finally_run(userConfig, LiveBacktest.LIVE)
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\configuration.py", line 222, in finally_run
c.run()
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\IBridgePy\MarketManagerBase.py", line 55, in run
self._run_once()
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\IBridgePy\MarketManagerBase.py", line 51, in _run_once
self.trader.initialize_Function()
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\IBridgePy\Trader.py", line 339, in initialize_Function
self._brokerService.submit_requests(ReqIds())
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\broker_service_factory\BrokerService.py", line 293, in submit_requests
return self._brokerClient.request_data(*args)
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\broker_client_factory\BrokerClient.py", line 351, in request_data
raise RuntimeError('%s server did not response to the request at all. Maybe the market is closed? Consider trying it later.' % (self.name, ))
RuntimeError: IB server did not response to the request at all. Maybe the market is closed? Consider trying it later.
Hi,
Please comment the following lines in the file "example_get_historical_data.py":
hist = data.history(context.secList, ['open', 'high', 'low', 'close'], 5, '1d')
for i in range(len(context.secList)):
print ('Historical Data CLOSE of %s' % (str(context.secList[i], ),))
print (hist['close'][context.secList[i]])
It would be lines 43 to 46 (both inclusive). Once you do it the code should run fine. There are chances that you will face the same error even after commenting out the above-mentioned code. In that case, you simply restart your console. I am assuming that you are running the codes on Spyder IDE. Right-click on the console and click quit on the pop-up menu and then run the code (keep the above-mentioned lines commented). It should run without any issue.
def initialize(context):
# IB offers free historical data for FOREX. Please refer to this YouTube tutorial https://youtu.be/JkyxLYD2RBk
#context.security = symbol('SPY')
# context.secList = symbols('AAPL', 'GOOG')
context.security=symbol('CASH,EUR,USD') #EUR.JPY-IDEALPRO-CASH
def handle_data(context, data):
# Method 1: IBridgePy function request_historical_data(str_security, barSize, goBack)
# Users have more controls on this function.
# http://www.ibridgepy.com/ibridgepy-documentation/#request_historical_data
#print ('Historical Data of %s' % (str(context.security, ),))
hist = request_data(context.security, '1 min', '1 D'),
print(hist)
#hist.to_csv('D:\IB_Historical_Data\hist.csv')
#print(hist.iloc[-1]['close'])
# Method 2 Same as Quantopian's function
# http://www.ibridgepy.com/ibridgepy-documentation/#datahistory_8212_similar_as_datahistory_at_Quantopian
# data.history(str_security, fields, bar_count, frequency)
"""
hist = data.history(context.secList, ['open', 'high', 'low', 'close'], 5, '1d')
for i in range(len(context.secList)):
print ('Historical Data CLOSE of %s' % (str(context.secList[i], ),))
print (hist['close'][context.secList[i]])
end()
"""
---------------------------------------------
Got the same result as follows,
File "D:\IB_Historical_Data\IBridgePy_Win_Anaconda38_64\broker_client_factory\BrokerClient.py", line 351, in request_data
raise RuntimeError('%s server did not response to the request at all. Maybe the market is closed? Consider trying it later.' % (self.name, ))
RuntimeError: IB server did not response to the request at all. Maybe the market is closed? Consider trying it later.
There are many possible reasons for the error you are getting.
- Market is not open
- Weekends
- IB server is down
- IB server maintenance
- Some issue with the internet connection
- Forex Market is not closed on Wednesday.
2.I am trading on Wednesday. Other trading software was still working but the RUN_ME.py was not.
3.IB server was working well as I see on the IB web site.
4.IB server was not maintenance while I was running RUN_ME.py. - Internet connection was ok.
Have you ever got connected to IB and seen your account information using IBridgePy? If yes, it means that the connection between your computer and IB server was not stable. It is hard to know what caused the issue but you need to check connectivitiy and firewalls to see what blocks the communication at the moment.
If no, it means that the connectivity is permenentaly blocked in your computer for unknown reason. You can open IB TWS and see if any errors. As the last resort, you can call IB technical representative for help. They will ask you provide the IB log for debug. IBridgePy itself is pretty stable because it communicates with your local TWS/Gateway but the connection between your computer and IB server is not as stable as you think.
I have connected IB to Amibroker and it was working well. What is the Spyder version do you use that compatible with IBridgePY?
What is requirement of Python packages for IBridgePY?
There are no such specific requirements for the Spyder version or Python packages. The only thing required is the latest versions of IB and IBridgePy compatible with your Python version.