Hi,
I'm having an issue with get_securities(exchanges=["NYSE"]) when trying to execute this code:
from quantrocket.license import set_license
set_license("xxxxxxxxxxxx")
from quantrocket.ibg import set_credentials
set_credentials("ibg1", username="xxxxxxxxxxx", trading_mode="paper")
from quantrocket.master import collect_ibkr_listings
collect_ibkr_listings(exchanges = ["NYSE"])
from quantrocket.master import get_securities
securities = get_securities(exchanges=["NYSE"], sec_types=["STK"])
import pandas as pd
pd.options.display.max_columns = None
pd.options.display.max_rows = None
securities.to_csv("nyse_listings.csv")
securities.head()
I'm getting this error message
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
Input In [4], in <cell line: 6>()
4 set_credentials("ibg1", username="xxxxxxxx", trading_mode="paper")
5 from quantrocket.master import collect_ibkr_listings
----> 6 collect_ibkr_listings(exchanges = ["NYSE"])
7 from quantrocket.master import get_securities
8 securities = get_securities(exchanges=["NYSE"], sec_types=["STK"])
File /opt/conda/lib/python3.9/site-packages/quantrocket/master.py:378, in collect_ibkr_listings(exchanges, sec_types, currencies, symbols, universes, sids)
375 params["sids"] = sids
377 response = houston.post("/master/securities/ibkr", params=params)
--> 378 houston.raise_for_status_with_json(response)
379 return response.json()
File /opt/conda/lib/python3.9/site-packages/quantrocket/houston.py:225, in Houston.raise_for_status_with_json(response)
223 e.json_response = {}
224 e.args = e.args + ("please check the logs for more details",)
--> 225 raise e
File /opt/conda/lib/python3.9/site-packages/quantrocket/houston.py:217, in Houston.raise_for_status_with_json(response)
212 """
213 Raises 400/500 error codes, attaching a json response to the
214 exception, if possible.
215 """
216 try:
--> 217 response.raise_for_status()
218 except requests.exceptions.HTTPError as e:
219 try:
File /opt/conda/lib/python3.9/site-packages/requests/models.py:1021, in Response.raise_for_status(self)
1016 http_error_msg = (
1017 f"{self.status_code} Server Error: {reason} for url: {self.url}"
1018 )
1020 if http_error_msg:
-> 1021 raise HTTPError(http_error_msg, response=self)
HTTPError: ('403 Client Error: FORBIDDEN for url: http://houston/master/securities/ibkr?exchanges=NYSE', {'status': 'error', 'error': 'An active subscription is required (view license details if this is unexpected, see http://qrok.it/h/lkey for help)'})
I've also tried doing the same with IBKR live account:
from quantrocket.license import set_license
set_license("xxxxxxxxxxxx")
from quantrocket.ibg import set_credentials
set_credentials("ibg1", username="xxxxxx", trading_mode="live")
from quantrocket.master import collect_ibkr_listings
collect_ibkr_listings(exchanges = ["NYSE"])
from quantrocket.master import get_securities
securities = get_securities(exchanges=["NYSE"], sec_types=["STK"])
import pandas as pd
pd.options.display.max_columns = None
pd.options.display.max_rows = None
securities.to_csv("nyse_listings.csv")
securities.head()
I've done the 2 factor authentication and the got this error:
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
Input In [6], in <cell line: 4>()
2 set_license("xxxxxxxxxxxxxxxxxxx")
3 from quantrocket.ibg import set_credentials
----> 4 set_credentials("ibg1", username="xxxxxxxxx", trading_mode="live")
5 from quantrocket.master import collect_ibkr_listings
6 collect_ibkr_listings(exchanges = ["NYSE"])
File /opt/conda/lib/python3.9/site-packages/quantrocket/ibg.py:142, in set_credentials(gateway, username, password, trading_mode)
139 data["trading_mode"] = trading_mode
141 response = houston.put("/{0}/credentials".format(gateway), data=data, timeout=180)
--> 142 houston.raise_for_status_with_json(response)
143 return response.json()
File /opt/conda/lib/python3.9/site-packages/quantrocket/houston.py:225, in Houston.raise_for_status_with_json(response)
223 e.json_response = {}
224 e.args = e.args + ("please check the logs for more details",)
--> 225 raise e
File /opt/conda/lib/python3.9/site-packages/quantrocket/houston.py:217, in Houston.raise_for_status_with_json(response)
212 """
213 Raises 400/500 error codes, attaching a json response to the
214 exception, if possible.
215 """
216 try:
--> 217 response.raise_for_status()
218 except requests.exceptions.HTTPError as e:
219 try:
File /opt/conda/lib/python3.9/site-packages/requests/models.py:1021, in Response.raise_for_status(self)
1016 http_error_msg = (
1017 f"{self.status_code} Server Error: {reason} for url: {self.url}"
1018 )
1020 if http_error_msg:
-> 1021 raise HTTPError(http_error_msg, response=self)
HTTPError: ('400 Client Error: BAD REQUEST for url: http://houston/ibg1/credentials', {'status': 'error', 'msg': 'please stop IB Gateway before setting credentials (current status is: running)'})
I've "NYSE (Network A/CTA) - Trader Workstation" subscription provided by Interactive Brokers. I also have subscription sharing with a paper account enabled. I've changed the username and license key with "xxxxxxxxx" before posting.
Why am I getting this error? What would be the steps to workaround/fix?