'generated source for method placeOrder'

@synchronized(mlock)
def placeOrder(self, id, contract, order):

    if (not self.m_connected):
        self.notConnected()
        return
    if (self.m_serverVersion < self.MIN_SERVER_VER_SCALE_ORDERS):
        if ((order.m_scaleInitLevelSize != Integer.MAX_VALUE) or (order.m_scalePriceIncrement != Double.MAX_VALUE)):
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    Scale    orders.')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_SSHORT_COMBO_LEGS):
        if contract.m_comboLegs:
            i = 0
            while (i < len(contract.m_comboLegs)):
                comboLeg = contract.m_comboLegs[i]
                if ((comboLeg.m_shortSaleSlot != 0) or (not self.IsEmpty(comboLeg.m_designatedLocation))):
                    self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    SSHORT    flag    for    combo    legs.')
                    return
                i += 1
    if (self.m_serverVersion < self.MIN_SERVER_VER_WHAT_IF_ORDERS):
        if order.m_whatIf:
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    what-if    orders.')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_UNDER_COMP):
        if (contract.m_underComp is not None):
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    delta-neutral    orders.')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_SCALE_ORDERS2):
        if (order.m_scaleSubsLevelSize != Integer.MAX_VALUE):
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    Subsequent    Level    Size    for    Scale    orders.')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_ALGO_ORDERS):
        if (not self.IsEmpty(order.m_algoStrategy)):
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    algo    orders.')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_NOT_HELD):
        if order.m_notHeld:
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    notHeld    parameter.')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_SEC_ID_TYPE):
        if ((not self.IsEmpty(contract.m_secIdType)) or (not self.IsEmpty(contract.m_secId))):
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    secIdType    and    secId    parameters.')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_PLACE_ORDER_CONID):
        if (contract.m_conId > 0):
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    conId    parameter.')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_SSHORTX):
        if (order.m_exemptCode != (-1)):
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    exemptCode    parameter.')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_SSHORTX):
        if contract.m_comboLegs:
            i = 0
            while (i < len(contract.m_comboLegs)):
                comboLeg = contract.m_comboLegs[i]
                if (comboLeg.m_exemptCode != (-1)):
                    self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    exemptCode    parameter.')
                    return
                i += 1
    if (self.m_serverVersion < self.MIN_SERVER_VER_HEDGE_ORDERS):
        if (not self.IsEmpty(order.m_hedgeType)):
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    hedge    orders.')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_OPT_OUT_SMART_ROUTING):
        if order.m_optOutSmartRouting:
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    optOutSmartRouting    parameter.')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_DELTA_NEUTRAL_CONID):
        if ((order.m_deltaNeutralConId > 0) or (not self.IsEmpty(order.m_deltaNeutralSettlingFirm)) or (not self.IsEmpty(order.m_deltaNeutralClearingAccount)) or (not self.IsEmpty(order.m_deltaNeutralClearingIntent))):
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    deltaNeutral    parameters:    ConId,    SettlingFirm,    ClearingAccount,    ClearingIntent')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_DELTA_NEUTRAL_OPEN_CLOSE):
        if ((not self.IsEmpty(order.m_deltaNeutralOpenClose)) or order.m_deltaNeutralShortSale or (order.m_deltaNeutralShortSaleSlot > 0) or (not self.IsEmpty(order.m_deltaNeutralDesignatedLocation))):
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    deltaNeutral    parameters:    OpenClose,    ShortSale,    ShortSaleSlot,    DesignatedLocation')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_SCALE_ORDERS3):
        if ((order.m_scalePriceIncrement > 0) and (order.m_scalePriceIncrement != Double.MAX_VALUE)):
            if ((order.m_scalePriceAdjustValue != Double.MAX_VALUE) or (order.m_scalePriceAdjustInterval != Integer.MAX_VALUE) or (order.m_scaleProfitOffset != Double.MAX_VALUE) or order.m_scaleAutoReset or (order.m_scaleInitPosition != Integer.MAX_VALUE) or (order.m_scaleInitFillQty != Integer.MAX_VALUE) or order.m_scaleRandomPercent):
                self.error(id, EClientErrors.UPDATE_TWS, ('        It    does    not    support    Scale    order    parameters:    PriceAdjustValue,    PriceAdjustInterval,    ' + 'ProfitOffset,    AutoReset,    InitPosition,    InitFillQty    and    RandomPercent'))
                return
    if ((self.m_serverVersion < self.MIN_SERVER_VER_ORDER_COMBO_LEGS_PRICE) and (self.BAG_SEC_TYPE.lower() == contract.m_secType.lower())):
        if order.m_orderComboLegs:
            i = 0
            while (i < len(order.m_orderComboLegs)):
                orderComboLeg = order.m_orderComboLegs[i]
                if (orderComboLeg.m_price != Double.MAX_VALUE):
                    self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    per-leg    prices    for    order    combo    legs.')
                    return
                i += 1
    if (self.m_serverVersion < self.MIN_SERVER_VER_TRAILING_PERCENT):
        if (order.m_trailingPercent != Double.MAX_VALUE):
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    trailing    percent    parameter')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_TRADING_CLASS):
        if (not self.IsEmpty(contract.m_tradingClass)):
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    tradingClass    parameters    in    placeOrder.')
            return
    if (self.m_serverVersion < self.MIN_SERVER_VER_SCALE_TABLE):
        if ((not self.IsEmpty(order.m_scaleTable)) or (not self.IsEmpty(order.m_activeStartTime)) or (not self.IsEmpty(order.m_activeStopTime))):
            self.error(id, EClientErrors.UPDATE_TWS, '        It    does    not    support    scaleTable,    activeStartTime    and    activeStopTime    parameters.')
            return
    VERSION = (27 if (self.m_serverVersion < self.MIN_SERVER_VER_NOT_HELD) else 41)
    try:
        self.send(self.PLACE_ORDER)
        self.send(VERSION)
        self.send(id)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_PLACE_ORDER_CONID):
            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)
        if (self.m_serverVersion >= 15):
            self.send(contract.m_multiplier)
        self.send(contract.m_exchange)
        if (self.m_serverVersion >= 14):
            self.send(contract.m_primaryExch)
        self.send(contract.m_currency)
        if (self.m_serverVersion >= 2):
            self.send(contract.m_localSymbol)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_TRADING_CLASS):
            self.send(contract.m_tradingClass)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_SEC_ID_TYPE):
            self.send(contract.m_secIdType)
            self.send(contract.m_secId)
        self.send(order.m_action)
        self.send(order.m_totalQuantity)
        self.send(order.m_orderType)
        if (self.m_serverVersion < self.MIN_SERVER_VER_ORDER_COMBO_LEGS_PRICE):
            self.send((0 if (order.m_lmtPrice == Double.MAX_VALUE) else order.m_lmtPrice))
        else:
            self.sendMax(order.m_lmtPrice)
        if (self.m_serverVersion < self.MIN_SERVER_VER_TRAILING_PERCENT):
            self.send((0 if (order.m_auxPrice == Double.MAX_VALUE) else order.m_auxPrice))
        else:
            self.sendMax(order.m_auxPrice)
        self.send(order.m_tif)
        self.send(order.m_ocaGroup)
        self.send(order.m_account)
        self.send(order.m_openClose)
        self.send(order.m_origin)
        self.send(order.m_orderRef)
        self.send(order.m_transmit)
        if (self.m_serverVersion >= 4):
            self.send(order.m_parentId)
        if (self.m_serverVersion >= 5):
            self.send(order.m_blockOrder)
            self.send(order.m_sweepToFill)
            self.send(order.m_displaySize)
            self.send(order.m_triggerMethod)
            if (self.m_serverVersion < 38):
                self.send(False)
            else:
                self.send(order.m_outsideRth)
        if (self.m_serverVersion >= 7):
            self.send(order.m_hidden)
        if ((self.m_serverVersion >= 8) and (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)
                    self.send(comboLeg.m_openClose)
                    if (self.m_serverVersion >= self.MIN_SERVER_VER_SSHORT_COMBO_LEGS):
                        self.send(comboLeg.m_shortSaleSlot)
                        self.send(comboLeg.m_designatedLocation)
                    if (self.m_serverVersion >= self.MIN_SERVER_VER_SSHORTX_OLD):
                        self.send(comboLeg.m_exemptCode)
                    i += 1
        if ((self.m_serverVersion >= self.MIN_SERVER_VER_ORDER_COMBO_LEGS_PRICE) and (self.BAG_SEC_TYPE.lower() == contract.m_secType.lower())):
            if (order.m_orderComboLegs is None):
                self.send(0)
            else:
                self.send(len(order.m_orderComboLegs))
                i = 0
                while (i < len(order.m_orderComboLegs)):
                    orderComboLeg = order.m_orderComboLegs[i]
                    self.sendMax(orderComboLeg.m_price)
                    i += 1
        if ((self.m_serverVersion >= self.MIN_SERVER_VER_SMART_COMBO_ROUTING_PARAMS) and (self.BAG_SEC_TYPE.lower() == contract.m_secType.lower())):
            smartComboRoutingParams = order.m_smartComboRoutingParams
            smartComboRoutingParamsCount = (0 if (smartComboRoutingParams is None) else len(smartComboRoutingParams))
            self.send(smartComboRoutingParamsCount)
            if (smartComboRoutingParamsCount > 0):
                i = 0
                while (i < smartComboRoutingParamsCount):
                    tagValue = smartComboRoutingParams[i]
                    self.send(tagValue.m_tag)
                    self.send(tagValue.m_value)
                    i += 1
        if (self.m_serverVersion >= 9):
            self.send('')
        if (self.m_serverVersion >= 10):
            self.send(order.m_discretionaryAmt)
        if (self.m_serverVersion >= 11):
            self.send(order.m_goodAfterTime)
        if (self.m_serverVersion >= 12):
            self.send(order.m_goodTillDate)
        if (self.m_serverVersion >= 13):
            self.send(order.m_faGroup)
            self.send(order.m_faMethod)
            self.send(order.m_faPercentage)
            self.send(order.m_faProfile)
        if (self.m_serverVersion >= 18):
            self.send(order.m_shortSaleSlot)
            self.send(order.m_designatedLocation)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_SSHORTX_OLD):
            self.send(order.m_exemptCode)
        if (self.m_serverVersion >= 19):
            self.send(order.m_ocaType)
            if (self.m_serverVersion < 38):
                self.send(False)
            self.send(order.m_rule80A)
            self.send(order.m_settlingFirm)
            self.send(order.m_allOrNone)
            self.sendMax(order.m_minQty)
            self.sendMax(order.m_percentOffset)
            self.send(order.m_eTradeOnly)
            self.send(order.m_firmQuoteOnly)
            self.sendMax(order.m_nbboPriceCap)
            self.sendMax(order.m_auctionStrategy)
            self.sendMax(order.m_startingPrice)
            self.sendMax(order.m_stockRefPrice)
            self.sendMax(order.m_delta)
            lower = (Double.MAX_VALUE if ((self.m_serverVersion == 26) and (order.m_orderType == 'VOL')) else order.m_stockRangeLower)
            upper = (Double.MAX_VALUE if ((self.m_serverVersion == 26) and (order.m_orderType == 'VOL')) else order.m_stockRangeUpper)
            self.sendMax(lower)
            self.sendMax(upper)
        if (self.m_serverVersion >= 22):
            self.send(order.m_overridePercentageConstraints)
        if (self.m_serverVersion >= 26):
            self.sendMax(order.m_volatility)
            self.sendMax(order.m_volatilityType)
            if (self.m_serverVersion < 28):
                self.send((order.m_deltaNeutralOrderType.lower() == 'MKT'.lower()))
            else:
                self.send(order.m_deltaNeutralOrderType)
                self.sendMax(order.m_deltaNeutralAuxPrice)
                if ((self.m_serverVersion >= self.MIN_SERVER_VER_DELTA_NEUTRAL_CONID) and (not self.IsEmpty(order.m_deltaNeutralOrderType))):
                    self.send(order.m_deltaNeutralConId)
                    self.send(order.m_deltaNeutralSettlingFirm)
                    self.send(order.m_deltaNeutralClearingAccount)
                    self.send(order.m_deltaNeutralClearingIntent)
                if ((self.m_serverVersion >= self.MIN_SERVER_VER_DELTA_NEUTRAL_OPEN_CLOSE) and (not self.IsEmpty(order.m_deltaNeutralOrderType))):
                    self.send(order.m_deltaNeutralOpenClose)
                    self.send(order.m_deltaNeutralShortSale)
                    self.send(order.m_deltaNeutralShortSaleSlot)
                    self.send(order.m_deltaNeutralDesignatedLocation)
            self.send(order.m_continuousUpdate)
            if (self.m_serverVersion == 26):
                lower = (order.m_stockRangeLower if (order.m_orderType == 'VOL') else Double.MAX_VALUE)
                upper = (order.m_stockRangeUpper if (order.m_orderType == 'VOL') else Double.MAX_VALUE)
                self.sendMax(lower)
                self.sendMax(upper)
            self.sendMax(order.m_referencePriceType)
        if (self.m_serverVersion >= 30):
            self.sendMax(order.m_trailStopPrice)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_TRAILING_PERCENT):
            self.sendMax(order.m_trailingPercent)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_SCALE_ORDERS):
            if (self.m_serverVersion >= self.MIN_SERVER_VER_SCALE_ORDERS2):
                self.sendMax(order.m_scaleInitLevelSize)
                self.sendMax(order.m_scaleSubsLevelSize)
            else:
                self.send('')
                self.sendMax(order.m_scaleInitLevelSize)
            self.sendMax(order.m_scalePriceIncrement)
        if ((self.m_serverVersion >= self.MIN_SERVER_VER_SCALE_ORDERS3) and (order.m_scalePriceIncrement > 0.0) and (order.m_scalePriceIncrement != Double.MAX_VALUE)):
            self.sendMax(order.m_scalePriceAdjustValue)
            self.sendMax(order.m_scalePriceAdjustInterval)
            self.sendMax(order.m_scaleProfitOffset)
            self.send(order.m_scaleAutoReset)
            self.sendMax(order.m_scaleInitPosition)
            self.sendMax(order.m_scaleInitFillQty)
            self.send(order.m_scaleRandomPercent)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_SCALE_TABLE):
            self.send(order.m_scaleTable)
            self.send(order.m_activeStartTime)
            self.send(order.m_activeStopTime)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_HEDGE_ORDERS):
            self.send(order.m_hedgeType)
            if (not self.IsEmpty(order.m_hedgeType)):
                self.send(order.m_hedgeParam)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_OPT_OUT_SMART_ROUTING):
            self.send(order.m_optOutSmartRouting)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_PTA_ORDERS):
            self.send(order.m_clearingAccount)
            self.send(order.m_clearingIntent)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_NOT_HELD):
            self.send(order.m_notHeld)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_UNDER_COMP):
            if (contract.m_underComp is not None):
                underComp = contract.m_underComp
                self.send(True)
                self.send(underComp.m_conId)
                self.send(underComp.m_delta)
                self.send(underComp.m_price)
            else:
                self.send(False)
        if (self.m_serverVersion >= self.MIN_SERVER_VER_ALGO_ORDERS):
            self.send(order.m_algoStrategy)
            if (not self.IsEmpty(order.m_algoStrategy)):
                algoParams = order.m_algoParams
                algoParamsCount = (0 if (algoParams is None) else len(algoParams))
                self.send(algoParamsCount)
                if (algoParamsCount > 0):
                    i = 0
                    while (i < algoParamsCount):
                        tagValue = algoParams[i]
                        self.send(tagValue.m_tag)
                        self.send(tagValue.m_value)
                        i += 1
        if (self.m_serverVersion >= self.MIN_SERVER_VER_WHAT_IF_ORDERS):
            self.send(order.m_whatIf)
    except Exception as e:
        self.error_0(id, EClientErrors.FAIL_SEND_ORDER, str(e))
        self.close()
