本文整理汇总了Python中ib.ext.Contract.Contract.m_strike方法的典型用法代码示例。如果您正苦于以下问题:Python Contract.m_strike方法的具体用法?Python Contract.m_strike怎么用?Python Contract.m_strike使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ib.ext.Contract.Contract
的用法示例。
在下文中一共展示了Contract.m_strike方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendOrder
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [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_strike [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: generate_spx
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [as 别名]
def generate_spx(self, symbol="SPX", exchange="SMART", currency="USD", \
secType="OPT", expiry="20151023",
strikep=None):
""" Function to resemble a main function """
# Establish a connection
sys.stdout.write("\nCalling connection\n")
connection = ibConnection()
connection.registerAll(self.ibhndl.my_callback_handler)
connection.connect()
# Get contract details
contract_values = Contract()
contract_values.m_symbol = symbol
contract_values.m_exchange = exchange
contract_values.m_currency = currency
contract_values.m_secType = secType
contract_values.m_expiry = expiry
if strikep:
contract_values.m_strike = strikep
self.ibhndl.get_contract_details(connection, 1, contract_values)
# Get Market values
self.ibhndl.get_market_data(connection)
if not os.path.isdir(os.path.join('.', 'spx_files')):
os.makedirs('spx_files')
mydir = os.path.join(os.getcwd(), 'spx_files', \
datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'))
os.makedirs(mydir)
OPTIONS.to_csv(os.path.join(mydir, 'Options.csv'))
sys.stdout.write("\n\n")
示例4: makeStkContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [as 别名]
def makeStkContract(sym):
newStkContract = Contract()
newStkContract.m_symbol = sym
newStkContract.m_secType = 'CASH'
newStkContract.m_strike = 0.00
newStkContract.m_exchange = 'IDEALPRO'
newStkContract.m_currency = 'USD'
return newStkContract
示例5: addoption
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [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 +")")
示例6: make_ib_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [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: __make_ib_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [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
示例8: mkContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [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
示例9: contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [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
示例10: create_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [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
示例11: makeStkContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [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
示例12: newContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [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
示例13: newContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [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
示例14: addoption
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [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)
示例15: makeOptContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_strike [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