本文整理汇总了Python中ib.ext.Contract.Contract.m_right方法的典型用法代码示例。如果您正苦于以下问题:Python Contract.m_right方法的具体用法?Python Contract.m_right怎么用?Python Contract.m_right使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ib.ext.Contract.Contract
的用法示例。
在下文中一共展示了Contract.m_right方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendOrder
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def sendOrder(self, orderReq):
"""发单"""
# 增加报单号1,最后再次进行查询
# 这里双重设计的目的是为了防止某些情况下,连续发单时,nextOrderId的回调推送速度慢导致没有更新
self.orderId += 1
# 创建合约对象
contract = Contract()
contract.m_symbol = str(orderReq.symbol)
contract.m_exchange = exchangeMap.get(orderReq.exchange, '')
contract.m_secType = productClassMap.get(orderReq.productClass, '')
contract.m_currency = currencyMap.get(orderReq.currency, '')
contract.m_expiry = orderReq.expiry
contract.m_strike = orderReq.strikePrice
contract.m_right = optionTypeMap.get(orderReq.optionType, '')
# 创建委托对象
order = Order()
order.m_orderId = self.orderId
order.m_clientId = self.clientId
order.m_action = directionMap.get(orderReq.direction, '')
order.m_lmtPrice = orderReq.price
order.m_totalQuantity = orderReq.volume
order.m_orderType = priceTypeMap.get(orderReq.priceType, '')
# 发送委托
self.connection.placeOrder(self.orderId, contract, order)
# 查询下一个有效编号
self.connection.reqIds(1)
示例2: subscribe
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def subscribe(self, subscribeReq):
"""订阅行情"""
# 订阅行情
self.tickerId += 1
contract = Contract()
contract.m_symbol = str(subscribeReq.symbol)
contract.m_exchange = exchangeMap.get(subscribeReq.exchange, '')
contract.m_secType = productClassMap.get(subscribeReq.productClass, '')
contract.m_currency = currencyMap.get(subscribeReq.currency, '')
contract.m_expiry = subscribeReq.expiry
contract.m_strike = subscribeReq.strikePrice
contract.m_right = optionTypeMap.get(subscribeReq.optionType, '')
# 考虑设计为针对期货用代码_到期日的方式来代替单纯的代码
if contract.m_secType == 'FUT' and not subscribeReq.expiry:
# 期货 如果没有设置过期时间, 默认设置为下个月
dt_obj = datetime.now()
days = calendar.monthrange(dt_obj.year, dt_obj.month)[1]
nextMonth = dt_obj + timedelta(days=(days - dt_obj.day + 1))
contract.m_expiry = nextMonth.strftime('%Y%m')
self.connection.reqMktData(self.tickerId, contract, '', False)
# 获取合约详细信息
self.connection.reqContractDetails(self.tickerId, contract)
# 创建Tick对象并保存到字典中
tick = VtTickData()
tick.symbol = subscribeReq.symbol
tick.exchange = subscribeReq.exchange
tick.vtSymbol = '.'.join([tick.symbol, tick.exchange])
tick.gatewayName = self.gatewayName
tick.__setattr__('m_secType', productClassMap.get(subscribeReq.productClass, ''))
self.tickDict[self.tickerId] = tick
示例3: create_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [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
示例4: addoption
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def addoption(ticker, exchg, expiry, strike, right):
c = Contract()
c.m_symbol = ticker
c.m_secType = 'OPT'
c.m_exchange = exchg
c.m_expiry = expiry
c.m_strike = float(strike)
c.m_right = right
addcontract(c, "Opt(" + exchg + ", " + expiry + ", " + str(strike) + ", " + right +")")
示例5: __make_ib_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def __make_ib_contract(contract_tuple):
new_contract = Contract()
new_contract.m_symbol = contract_tuple[0]
new_contract.m_secType = contract_tuple[1]
new_contract.m_exchange = contract_tuple[2]
new_contract.m_currency = contract_tuple[3]
new_contract.m_expiry = contract_tuple[4]
new_contract.m_strike = contract_tuple[5]
new_contract.m_right = contract_tuple[6]
return new_contract
示例6: make_ib_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def make_ib_contract(contract_tuple):
contract = Contract()
contract.m_symbol = contract_tuple[0]
contract.m_secType = contract_tuple[1]
contract.m_exchange = contract_tuple[2]
contract.m_currency = contract_tuple[3]
contract.m_expiry = contract_tuple[4]
contract.m_strike = contract_tuple[5]
contract.m_right = contract_tuple[6]
return contract
示例7: create_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def create_contract(symbol, sec_type='STK', expiry='', strike=0.0, right=''):
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sec_type
contract.m_exchange = 'SMART'
contract.m_primaryExch = 'SMART'
contract.m_currency = 'USD'
contract.m_expiry = expiry
contract.m_strike = strike
contract.m_right = right
return contract
示例8: contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def contract(contractTuple):
newContract = Contract()
newContract.m_symbol = contractTuple[0]
newContract.m_secType = contractTuple[1]
newContract.m_exchange = contractTuple[2]
newContract.m_currency = contractTuple[3]
newContract.m_expiry = contractTuple[4]
newContract.m_strike = contractTuple[5]
newContract.m_right = contractTuple[6]
print 'Contract Parameters: [%s,%s,%s,%s,%s,%s,%s]' % contractTuple
return newContract
示例9: makeStkContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def makeStkContract(contractTuple):
newContract = Contract()
newContract.m_symbol = contractTuple[0]
newContract.m_secType = contractTuple[1]
newContract.m_exchange = contractTuple[2]
newContract.m_currency = contractTuple[3]
newContract.m_expiry = contractTuple[4]
newContract.m_strike = contractTuple[5]
newContract.m_right = contractTuple[6]
print 'Contract Values:%s,%s,%s,%s,%s,%s,%s:' % contractTuple
return newContract
示例10: mkContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def mkContract(symbol, secType='STK', exchange='SMART',currency='USD',exp='',strike=0.0,right=''):
''' create contract object '''
c = Contract()
c.m_symbol = symbol
c.m_secType= secType
c.m_exchange = exchange
c.m_currency = currency
c.m_expiry = exp
c.m_strike = strike
c.m_right = right
return c
示例11: newContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def newContract(symbol, sec_type, exch='SMART', prim_exch='SMART', curr='USD',
expiry=None, strike=None, opt_type=None):
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sec_type
contract.m_expiry = expiry
contract.m_strike = strike
contract.m_right = opt_type
contract.m_exchange = exch
contract.m_primaryExchange = prim_exch
contract.m_currency = curr
return contract
示例12: makeOptContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def makeOptContract(sym, exp, right, strike):
newOptContract = Contract()
newOptContract.m_symbol = sym
newOptContract.m_secType = 'OPT'
newOptContract.m_right = right
newOptContract.m_expiry = exp
newOptContract.m_strike = float(strike)
newOptContract.m_exchange = 'SMART'
newOptContract.m_currency = 'USD'
#newOptContract.m_localSymbol = ''
#newOptContract.m_primaryExch = ''
return newOptContract
示例13: addoption
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def addoption(self, ticker, exchg, expiry, strike, right):
c = Contract()
c.m_symbol = ticker
c.m_secType = 'OPT'
c.m_exchange = exchg
c.m_expiry = expiry
c.m_strike = float(strike)
c.m_right = right
cid = self.registercontract(c)
if not self.isActiveContract(cid):
self.activateContract(cid)
return(cid)
示例14: newContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def newContract(symbol, secType, optType="", strike=0, expiry=""):
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = secType
contract.m_exchange = "SMART"
contract.m_primaryExchange = "SMART"
contract.m_currency = "USD"
contract.m_expiry = expiry # dateString
contract.m_strike = float(strike)
contract.m_multiplier = 100
contract.m_right = optType
return contract
示例15: makeContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_right [as 别名]
def makeContract(contractTuple):
newContract = Contract()
newContract.m_symbol = contractTuple[0]
newContract.m_secType = contractTuple[1]
newContract.m_exchange = contractTuple[2]
newContract.m_currency = contractTuple[3]
newContract.m_expiry = contractTuple[4]
newContract.m_strike = contractTuple[5]
newContract.m_right = contractTuple[6]
if len(contractTuple) > 7:
if contractTuple[1] == "OPT":
newContract.m_multiplier = contractTuple[7]
return newContract