当前位置: 首页>>代码示例>>Python>>正文


Python Contract.m_tradingClass方法代码示例

本文整理汇总了Python中ib.ext.Contract.Contract.m_tradingClass方法的典型用法代码示例。如果您正苦于以下问题:Python Contract.m_tradingClass方法的具体用法?Python Contract.m_tradingClass怎么用?Python Contract.m_tradingClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ib.ext.Contract.Contract的用法示例。


在下文中一共展示了Contract.m_tradingClass方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: place_order

# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_tradingClass [as 别名]
    def place_order(self, instrument, expiry, quantity, acc=None):
        """
        Send API request to place an order on the exchange.
        :param instrument: core.instrument.Instrument object
        :param expiry: contract label
        :param quantity: order size as a signed integer (quantity > 0 means 'BUY'
                         and quantity < 0 means 'SELL')
        :param acc: IB account to place order from, if None - the default account will be used
        """
        contract = Contract()
        contract.m_symbol = instrument.ib_code
        contract.m_secType = 'FUT'
        # place_order expects the contract label here, not the actual expiration date
        contract.m_expiry = expiry
        contract.m_exchange = instrument.exchange
        contract.m_currency = instrument.denomination
        if hasattr(instrument, 'ib_trading_class'):
            contract.m_tradingClass = instrument.ib_trading_class
        if hasattr(instrument, 'ib_multiplier'):
            contract.m_multiplier = instrument.ib_multiplier

        order = Order()
        order.m_orderType = 'MKT'
        order.m_algoStrategy = 'Adaptive'
        order.m_algoParams = [TagValue('adaptivePriority', 'Patient')]
        order.m_totalQuantity = int(abs(quantity))
        order.m_action = quantity > 0 and 'BUY' or 'SELL'
        if acc is not None:
            order.m_account = acc.name
            self.last_account = acc
        logger.warning(
            ' '.join(['Order:', str(self.order_id), contract.m_symbol, contract.m_expiry, \
                      order.m_action, str(order.m_totalQuantity)]))
        self.connection.placeOrder(self.order_id, contract, order)
        self.orders_cache[self.order_id] = {'contract': contract,
                                            'order': order}
        # order_id may not update just after the order is submitted so we save the previous one and
        # keep requesting until it's updated or we hit the time/iterations limit
        prev_id = self.order_id
        i = 0
        while prev_id >= self.order_id:
            sleep(self.api_delay)
            i += 1
            logger.debug('Requesting next order_id..')
            self.connection.reqIds(1)
            self.next_id_event.wait(timeout=(self.api_delay * 30))
            self.next_id_event.clear()
            if i > 60:
                logger.warning("Couldn't obtain next valid order id. Next orders may not be"
                               "submitted correctly!")
                return
开发者ID:renc,项目名称:PyTrendFollow,代码行数:53,代码来源:ibstate.py

示例2: create_contract

# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_tradingClass [as 别名]
def create_contract(sym,strike,expiry):
    symib = symdict[sym] 
    ibsecType = typedict[sym] #'CASH'
    ibexchange = exchdict[sym] #'IDEALPRO'
    cashcurr = currdict[sym] #'USD'
    right = optrightdict[sym] #'ignore'
    print symib,ibsecType,ibexchange,cashcurr,expiry,strike,right
    contract = Contract()  
    contract.m_symbol = symib
    contract.m_secType = ibsecType 
    contract.m_exchange = ibexchange
    contract.m_currency = cashcurr
    if ibsecType  == 'FUT':
        expiry = expiredict[sym]
        contract.m_expiry = expiry
        contract.m_tradingClass = sym
    if ibsecType  == 'OPT':
        contract.m_expiry = expiry
        contract.m_strike = strike
        contract.m_right = right
        contract.m_tradingClass = symib
        sleep(1)
    return contract
开发者ID:reprior123,项目名称:TraderSoftwareRP,代码行数:25,代码来源:ibutiles+-+Copy.py

示例3: create_contract

# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_tradingClass [as 别名]
 def create_contract(self, symbol, secType, exchange, currency,
                     right = None, strike = None, expiry = None,
                     multiplier = None, tradingClass = None):
     contract = Contract()
     contract.m_symbol = symbol
     contract.m_secType = secType
     contract.m_exchange = exchange
     contract.m_currency = currency
     contract.m_right = right
     contract.m_strike = strike
     contract.m_expiry = expiry
     contract.m_multiplier = multiplier
     contract.m_tradingClass = tradingClass
     return contract
开发者ID:anthonyng2,项目名称:ib,代码行数:16,代码来源:IBWrapper.py

示例4: makeContract

# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_tradingClass [as 别名]
def makeContract(symbol, derivative, exchange, expiration = None, 		strike = None, call_put = None, currency = "USD", tradingClass = None, multiplier = None):
	contract = Contract()
	contract.m_symbol = symbol
	contract.m_secType = derivative
	contract.m_exchange = exchange
	contract.m_currency = currency
	if derivative == "OPT":
		contract.m_expiry = expiration
		contract.m_strike = strike
		contract.m_right = call_put
		contract.m_multiplier = multiplier
		contract.m_tradingClass = tradingClass
	if derivative == "FUT":
		contract.m_expiry = expiration
	
	return contract
开发者ID:wcant,项目名称:ib-options,代码行数:18,代码来源:getHistOpt.py

示例5: create_contract

# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_tradingClass [as 别名]
def create_contract(contract_tuple):
    new_contract = Contract()
    new_contract.m_symbol = str(contract_tuple['ib_symbol'])
    new_contract.m_secType = str(contract_tuple['ib_type'])
    new_contract.m_exchange = str(contract_tuple['ib_exchange'])
    new_contract.m_currency = str(contract_tuple['ib_currency'])
    new_contract.m_strike = float(contract_tuple['ib_strike'])
    new_contract.m_tradingClass = str(contract_tuple['ib_trading_class'])
    if contract_tuple['ib_expiry']:
        new_contract.m_expiry = str(contract_tuple['ib_expiry'])     
    else:
        new_contract.m_expiy = ''
    if contract_tuple['ib_right']:
        new_contract.m_right = str(contract_tuple['ib_right'])
    else:
        new_contract.m_right = ''
    return new_contract
开发者ID:volchemist,项目名称:monitoring,代码行数:19,代码来源:monitor.py

示例6: create_contractOPTION

# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_tradingClass [as 别名]
def create_contractOPTION(sym,strike,expiry):
    symib = 'SPY'
    ibsecType = 'OPT' #typedict[sym] #'CASH'
    ibexchange = 'SMART' #exchdict[sym] #'IDEALPRO'
    cashcurr = 'USD' #currdict[sym] #'USD'
    right = 'P' #optrightdict[sym] #'ignore'
    print symib, sym,ibsecType,ibexchange,cashcurr,expiry,strike,right
    contract = Contract()  
    contract.m_symbol = sym
    contract.m_secType = ibsecType 
    contract.m_exchange = ibexchange
    contract.m_currency = cashcurr
    if ibsecType  == 'OPT':
        contract.m_expiry = expiry
        contract.m_strike = strike
        contract.m_right = right
        contract.m_tradingClass = symib
        sleep(1)
    return contract
开发者ID:reprior123,项目名称:TraderSoftwareRP,代码行数:21,代码来源:Mod_ibutiles.py

示例7: processMsg

# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_tradingClass [as 别名]

#.........这里部分代码省略.........
             orderState.m_initMargin = self.readStr()
             orderState.m_maintMargin = self.readStr()
             orderState.m_equityWithLoan = self.readStr()
             orderState.m_commission = self.readDoubleMax()
             orderState.m_minCommission = self.readDoubleMax()
             orderState.m_maxCommission = self.readDoubleMax()
             orderState.m_commissionCurrency = self.readStr()
             orderState.m_warningText = self.readStr()
         self.eWrapper().openOrder(order.m_orderId, contract, order, orderState)
     elif msgId == self.NEXT_VALID_ID:
         version = self.readInt()
         orderId = self.readInt()
         self.eWrapper().nextValidId(orderId)
     elif msgId == self.SCANNER_DATA:
         contract = ContractDetails()
         version = self.readInt()
         tickerId = self.readInt()
         numberOfElements = self.readInt()
         ## for-while
         ctr = 0
         while ctr < numberOfElements:
             rank = self.readInt()
             if version >= 3:
                 contract.m_summary.m_conId = self.readInt()
             contract.m_summary.m_symbol = self.readStr()
             contract.m_summary.m_secType = self.readStr()
             contract.m_summary.m_expiry = self.readStr()
             contract.m_summary.m_strike = self.readDouble()
             contract.m_summary.m_right = self.readStr()
             contract.m_summary.m_exchange = self.readStr()
             contract.m_summary.m_currency = self.readStr()
             contract.m_summary.m_localSymbol = self.readStr()
             contract.m_marketName = self.readStr()
             contract.m_tradingClass = self.readStr()
             distance = self.readStr()
             benchmark = self.readStr()
             projection = self.readStr()
             legsStr = None
             if version >= 2:
                 legsStr = self.readStr()
             self.eWrapper().scannerData(tickerId, rank, contract, distance, benchmark, projection, legsStr)
             ctr += 1
         self.eWrapper().scannerDataEnd(tickerId)
     elif msgId == self.CONTRACT_DATA:
         version = self.readInt()
         reqId = -1
         if version >= 3:
             reqId = self.readInt()
         contract = ContractDetails()
         contract.m_summary.m_symbol = self.readStr()
         contract.m_summary.m_secType = self.readStr()
         contract.m_summary.m_expiry = self.readStr()
         contract.m_summary.m_strike = self.readDouble()
         contract.m_summary.m_right = self.readStr()
         contract.m_summary.m_exchange = self.readStr()
         contract.m_summary.m_currency = self.readStr()
         contract.m_summary.m_localSymbol = self.readStr()
         contract.m_marketName = self.readStr()
         contract.m_tradingClass = self.readStr()
         contract.m_summary.m_conId = self.readInt()
         contract.m_minTick = self.readDouble()
         contract.m_summary.m_multiplier = self.readStr()
         contract.m_orderTypes = self.readStr()
         contract.m_validExchanges = self.readStr()
         if version >= 2:
             contract.m_priceMagnifier = self.readInt()
开发者ID:Jicheng-Yan,项目名称:ib-py,代码行数:70,代码来源:EReader.py

示例8: Contract

# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_tradingClass [as 别名]
        order.m_totalQuantity = qty
        order.m_action = action
        # more functionalities....
        return order


# In[23]:

ng = Contract()
ng.m_symbol = "CN"
ng.m_secType = "FUT"
ng.m_exchange = "SGX"
ng.m_expiry = "20161129"
ng.m_currency = "USD"
ng.m_multiplier = 1
ng.m_tradingClass = "CN"


# In[24]:

TWS = tws(ng) 


# In[25]:

TWS.connect()
#TWS.con.connect()


# In[26]:
开发者ID:InsomniaGoku,项目名称:-silentcrusader,代码行数:32,代码来源:Ib_Proj_1.py


注:本文中的ib.ext.Contract.Contract.m_tradingClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。