本文整理汇总了Python中ib.ext.Contract.Contract.m_expiry方法的典型用法代码示例。如果您正苦于以下问题:Python Contract.m_expiry方法的具体用法?Python Contract.m_expiry怎么用?Python Contract.m_expiry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ib.ext.Contract.Contract
的用法示例。
在下文中一共展示了Contract.m_expiry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: subscribe
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [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
示例2: makeContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [as 别名]
def makeContract(symbol, derivative, exchange, expiration = None,
strike = None, call_put = None, currency = "USD"):
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
if derivative == "FUT":
contract.m_expiry = expiration
return contract
示例3: generate_spx
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [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: makeContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [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
示例5: create_ib_futures_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [as 别名]
def create_ib_futures_contract(symbol, exp_month=1, exp_year=2016, exchange='NYMEX', currency='USD'):
"""
Creates a futures contract used for IB orders.
:param symbol: (string) base symbol e.g. 'CL'
:param type: (string) 'FUT' --> futures
:param exp_month: (int) e.g. 6 --> June
:param exp_year: (int) e.g. 2016
:param exchange:
:param currency:
:return:
"""
# TODO: create IBContract class
exp_month = str(exp_month)
if len(exp_month) == 1:
exp_month = '0' + exp_month
exp_year = str(exp_year)
expiry = exp_year + exp_month
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = 'FUT'
contract.m_expiry = expiry
contract.m_exchange = exchange
contract.m_currency = currency
return contract
示例6: create_ticksym
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [as 别名]
def create_ticksym(symbol_id,sym):
libsyms = EXE + 'library.syms.csv'
symdict = rpu_rp.create_dict(libsyms,0,1)
exchdict = rpu_rp.create_dict(libsyms,0,2)
typedict = rpu_rp.create_dict(libsyms,0,5)
currdict = rpu_rp.create_dict(libsyms,0,3)
expiredict = rpu_rp.create_dict(libsyms,0,4)
dboostdict = rpu_rp.create_dict(libsyms,0,6)
tickdict = rpu_rp.create_dict(libsyms,0,8)
tsizedict = rpu_rp.create_dict(libsyms,0,7)
roundfactordict = rpu_rp.create_dict(libsyms,0,9)
entrywiderdict = rpu_rp.create_dict(libsyms,0,10)
symib = symdict[sym]
ibsecType = typedict[sym] #'CASH'
ibexchange = exchdict[sym] #'IDEALPRO'
cashcurr = currdict[sym] #'USD'
expiry = expiredict[sym] #'ignore'
contract = Contract()
contract.m_symbol = symib
contract.m_secType = ibsecType
contract.m_exchange = ibexchange
contract.m_currency = cashcurr
if ibsecType == 'FUT':
contract.m_expiry = expiry
sleep(2)
return contract
示例7: main
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [as 别名]
def main():
symbol = sys.argv[1]
exch = sys.argv[2]
expiry = sys.argv[3]
date = sys.argv[4]
d = pd.to_datetime(date) - pd.DateOffset(1)
prev_date = '%04d%02d%02d' % (d.year, d.month, d.day)
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = 'FUT'
contract.m_exchange = exch
contract.m_currency = 'USD'
contract.m_expiry = expiry
print 'Collecting', date, 'data for', contract.m_symbol, 'expiration', contract.m_expiry
outfile = open(date+'.bars', 'w')
for h in xrange(20,24,2):
broker = datacol.Datacol(contract, prev_date, ('%02d:00:00' % h), 7200, outfile)
broker.close()
for h in xrange(0,18,2):
broker = datacol.Datacol(contract, date, ('%02d:00:00' % h), 7200, outfile)
broker.close()
broker = datacol.Datacol(contract, date, '17:15:00', 4500, outfile)
broker.close()
outfile.close()
示例8: addfutur
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [as 别名]
def addfutur(ticker, exchg, expiry):
c = Contract()
c.m_symbol = ticker
c.m_secType = 'FUT'
c.m_exchange = exchg
c.m_expiry = expiry
addcontract(c, "Fut(" + exchg + ", " + expiry + ")")
示例9: sendOrder
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [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)
示例10: main
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [as 别名]
def main():
symbol = sys.argv[1]
exch = sys.argv[2]
expiry = convert_date(sys.argv[3])
date = pd.to_datetime(convert_date(sys.argv[4])) - pd.DateOffset(days=1)
to_date = pd.to_datetime(convert_date(sys.argv[5]))
timeframe = sys.argv[6] + ' '
units = sys.argv[7]
duration = to_date - date
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = 'FUT'
contract.m_exchange = exch
contract.m_currency = 'USD'
contract.m_expiry = expiry
print 'Collecting', date, 'data for', contract.m_symbol, 'expiration', contract.m_expiry
outfile = open('from %s to %s' % (sys.argv[4], sys.argv[5])+'.bars', 'w')
# for h in xrange(20,24,2):
# broker = Datacol(contract, prev_date, ('%02d:00:00' % h), 7200, outfile)
# broker.close()
# for h in xrange(0,18,2):
# broker = Datacol(contract, date, ('%02d:00:00' % h), 7200, outfile)
# broker.close()
for h in range(duration.days):
date = date + pd.DateOffset(days=1)
broker = Datacol(contract, '%04d%02d%02d 21:59:00' % (date.year, date.month, date.day), timeframe+units, outfile)
broker.close()
outfile.close()
示例11: request_market_data
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [as 别名]
def request_market_data(self, timeframe, interval, symbol, sectype, \
exchange, currency=None, expiry=None, \
primexch=None, latestdate=None):
# Establish a connection
sys.stdout.write("\nCalling connection\n")
connection = ibConnection()
connection.register(self.ibhndl.my_callback_handler, \
message.historicalData)
connection.connect()
#Contract
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sectype
contract.m_exchange = exchange
contract.m_currency = currency
if primexch:
contract.m_primaryExch = primexch
if expiry:
contract.m_expiry = expiry
# Get historical data
rtnData = self.ibhndl.reqHistoricalData(contract, interval, connection,\
timeframe, latestdate)
connection.disconnect()
if not rtnData[0]:
sys.stderr.write("ERROR: No data return for %s : %s\n" % (symbol,\
interval))
return rtnData, ""
dateList = list()
stockFile = list()
for data, volume in zip(rtnData[0], rtnData[1]):
dateList = dateList + [data[0]]
dataStr = '%s, %s, %s, %s, %s, %s' % \
(strftime("%Y-%m-%d %H:%M:%S", \
localtime(int(str(data[0]))/1000)), data[1], \
data[2], data[3], data[4], str(volume[1]))
stockFile = stockFile + [dataStr]
convertStr = '%Y-%m-%d %H:%M:%S'
date, _, _, _, closep, volume = \
np.loadtxt(stockFile, delimiter=',', unpack=True, \
converters={0:mdates.strpdate2num(convertStr)})
#PATTERNS
retpat = []
try:
patterndb = PatternDB()
patterndb.add(HS())
patterndb.add(IHS())
retpat = patterndb.check(closep[-60:], date[-60:])
except Exception, excp:
sys.stderr.write("ERROR: PATTERNS failed with exception " \
"%s\n" % excp)
示例12: makeContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [as 别名]
def makeContract(self, 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]
return newContract
示例13: addoption
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [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 +")")
示例14: set_contract_ib
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [as 别名]
def set_contract_ib(self, symbol, sec_type, exchange, currency, multiplier, expiry):
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sec_type
contract.m_exchange = exchange
contract.m_currency = currency
contract.m_multiplier = multiplier
contract.m_expiry = expiry
self.contract = contract
示例15: create_ticksym
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_expiry [as 别名]
def create_ticksym(symbol_id,sym,ibsecType,ibexchange,cashcurr,expiry):
contract = Contract()
contract.m_symbol = sym
contract.m_secType = ibsecType
contract.m_exchange = ibexchange
contract.m_currency = cashcurr
if ibsecType == 'FUT':
contract.m_expiry = expiry
return contract