'generated source for method reqHistoricalData'

@synchronized(mlock)
def reqHistoricalData(self, tickerId, contract, endDateTime, durationStr, barSizeSetting, whatToShow, useRTH, formatDate):

    if (not self.m_connected):
        self.notConnected()
        return
    VERSION = 5
    try:
        if (self.m_serverVersion < 16):
            self.error(EClientErrors.NO_VALID_ID, EClientErrors.UPDATE_TWS, '        It    does    not    support    historical    data    backfill.')
            return
        if (self.m_serverVersion < self.MIN_SERVER_VER_TRADING_CLASS):
            if ((not self.IsEmpty(contract.m_tradingClass)) or (contract.m_conId > 0)):
                self.error(tickerId, EClientErrors.UPDATE_TWS, '        It    does    not    support    conId    and    trade    parameters    in    reqHistroricalData.')
                return
        self.send(self.REQ_HISTORICAL_DATA)
        self.send(VERSION)
        self.send(tickerId)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_TRADING_CLASS):
            self.send(contract.m_conId)
        self.send(contract.m_symbol)
        self.send(contract.m_secType)
        self.send(contract.m_expiry)
        self.send(contract.m_strike)
        self.send(contract.m_right)
        self.send(contract.m_multiplier)
        self.send(contract.m_exchange)
        self.send(contract.m_primaryExch)
        self.send(contract.m_currency)
        self.send(contract.m_localSymbol)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_TRADING_CLASS):
            self.send(contract.m_tradingClass)
        if (self.m_serverVersion >= 31):
            self.send((1 if contract.m_includeExpired else 0))
        if (self.m_serverVersion >= 20):
            self.send(endDateTime)
            self.send(barSizeSetting)
        self.send(durationStr)
        self.send(useRTH)
        self.send(whatToShow)
        if (self.m_serverVersion > 16):
            self.send(formatDate)
        if (self.BAG_SEC_TYPE.lower() == contract.m_secType.lower()):
            if (contract.m_comboLegs is None):
                self.send(0)
            else:
                self.send(len(contract.m_comboLegs))
                i = 0
                while (i < len(contract.m_comboLegs)):
                    comboLeg = contract.m_comboLegs[i]
                    self.send(comboLeg.m_conId)
                    self.send(comboLeg.m_ratio)
                    self.send(comboLeg.m_action)
                    self.send(comboLeg.m_exchange)
                    i += 1
    except Exception as e:
        self.error(tickerId, EClientErrors.FAIL_SEND_REQHISTDATA, str(e))
        self.close()
