def get_actual_expiry_date_for_contract(self, contract_object): """ Get the actual expiry date of a contract from IB :param contract_object: type futuresContract :return: YYYYMMDD or None """ new_log = self.log.setup( instrument_code=contract_object.instrument_code, contract_date=contract_object.date_str, ) contract_object_with_ib_data = self.get_contract_object_with_IB_metadata( contract_object) if contract_object_with_ib_data is missing_contract: new_log.msg("Can't resolve contract so can't find expiry date") return missing_contract expiry_date = self.ibconnection.broker_get_contract_expiry_date( contract_object_with_ib_data) if expiry_date is missing_contract: new_log.msg("No IB expiry date found") return missing_contract else: expiry_date = expiryDate.from_str(expiry_date) return expiry_date
def _get_actual_expiry_date_given_contract_with_ib_metadata( self, contract_object_with_ib_data: futuresContract) -> expiryDate: expiry_date = self.ibconnection.broker_get_contract_expiry_date( contract_object_with_ib_data) if expiry_date is missing_contract: log = contract_object_with_ib_data.log(self.log) log.msg("No IB expiry date found") return missing_contract else: expiry_date = expiryDate.from_str(expiry_date) return expiry_date
def _get_actual_expiry_date_given_single_contract_with_ib_metadata( self, futures_contract_with_ib_data: futuresContract) -> expiryDate: log = futures_contract_with_ib_data.specific_log(self.log) if futures_contract_with_ib_data.is_spread_contract(): log.warn("Can't find expiry for multiple leg contract here") return missing_contract expiry_date = self.ib_client.broker_get_single_contract_expiry_date( futures_contract_with_ib_data) if expiry_date is missing_contract: return missing_contract else: expiry_date = expiryDate.from_str(expiry_date) return expiry_date