Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Al4ise committed Nov 22, 2024
1 parent fd242f4 commit b7e67ad
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lumibot/data_sources/interactive_brokers_rest_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,12 +837,8 @@ def get_last_price(self, asset, quote=None, exchange=None) -> float | None:
def get_conid_from_asset(self, asset: Asset):
self.ping_iserver()
# Get conid of underlying
if asset.asset_type == 'future':
url = f"{self.base_url}/iserver/secdef/search?symbol={asset.symbol}&secType=IND"
response = self.get_from_endpoint(url, "Getting Underlying conid")
else:
url = f"{self.base_url}/iserver/secdef/search?symbol={asset.symbol}"
response = self.get_from_endpoint(url, "Getting Underlying conid")
url = f"{self.base_url}/iserver/secdef/search?symbol={asset.symbol}"
response = self.get_from_endpoint(url, "Getting Underlying conid")

if (
isinstance(response, list)
Expand Down Expand Up @@ -899,7 +895,7 @@ def _get_conid_for_derivative(
asset: Asset,
sec_type: str,
additional_params: dict,
exchange: str,
exchange: str | None,
):
expiration_date = asset.expiration.strftime("%Y%m%d")
expiration_month = asset.expiration.strftime("%b%y").upper() # in MMMYY
Expand All @@ -911,7 +907,7 @@ def _get_conid_for_derivative(
"exchange": exchange
}
params.update(additional_params)
query_string = "&".join(f"{key}={value}" for key, value in params.items())
query_string = "&".join(f"{key}={value}" for key, value in params.items() if value is not None)

url_for_expiry = f"{self.base_url}/iserver/secdef/info?{query_string}"
contract_info = self.get_from_endpoint(
Expand Down Expand Up @@ -964,8 +960,6 @@ def get_market_snapshot(self, asset: Asset, fields: list):
conId = self.get_conid_from_asset(asset)
if conId is None:
return None

info = self.get_contract_details(conId)

fields_to_get = []
for identifier, name in all_fields.items():
Expand All @@ -977,7 +971,7 @@ def get_market_snapshot(self, asset: Asset, fields: list):
url = f"{self.base_url}/iserver/marketdata/snapshot?conids={conId}&fields={fields_str}"

# If fields are missing, fetch again
max_retries = 2
max_retries = 500
retries = 0
missing_fields = True

Expand Down

0 comments on commit b7e67ad

Please sign in to comment.