本文整理汇总了Python中ib.ext.Contract.Contract.m_symbol方法的典型用法代码示例。如果您正苦于以下问题:Python Contract.m_symbol方法的具体用法?Python Contract.m_symbol怎么用?Python Contract.m_symbol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ib.ext.Contract.Contract
的用法示例。
在下文中一共展示了Contract.m_symbol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: inner
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [as 别名]
def inner():
#con.reqAccountUpdates(1, '')
qqqq = Contract()
qqqq.m_symbol = 'QQQ'
qqqq.m_secType = 'STK'
qqqq.m_exchange = 'SMART'
contract = Contract() #
contract.m_symbol = 'AUD'
contract.m_currency = 'USD'
contract.m_secType = 'CASH'
contract.m_exchange = 'IDEALPRO'
fut = Contract() #
fut.m_localSymbol = 'CLM6'
#fut.m_symbol = 'CL'
fut.m_currency = 'USD'
fut.m_secType = 'FUT'
fut.m_exchange = 'NYMEX'
#fut.m_expiry = '201606'
#fut.m_multiplier = '1000'
#con.reqMktData(1, qqqq, '', False)
#con.reqMktData(1, contract, '', False)
con.reqMktData(1, fut, '', False)
示例2: inner
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [as 别名]
def inner():
con.reqAccountUpdates(1, '')
qqqq = Contract()
qqqq.m_symbol = 'QQQQ'
qqqq.m_secType = 'STK'
qqqq.m_exchange = 'SMART'
con.reqMktData(1, qqqq, '', False)
示例3: request_market_data
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [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)
示例4: sendOrder
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [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)
示例5: create_ib_futures_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [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: subscribe
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [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
示例7: makeStkContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [as 别名]
def makeStkContract(symbol, cur = 'USD'):
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = 'STK'
contract.m_exchange = 'SMART'
contract.m_currency = cur
return contract
示例8: main
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [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()
示例9: start
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [as 别名]
def start(self):
"""Start the connection and read the realtime bars for the specified
tickers.
"""
# connection and handler
self.connection = ibConnection(
host=self.host,
port=self.port,
clientId=self.client_id)
# registration
self.connection.register( self.ticker_updated, message.RealtimeBar )
# connect
self.connection.connect()
for inx,stock in enumerate(self.stocks):
print "Requesting:\t%d = %s" % (inx,stock)
# create the contract
contract = Contract()
contract.m_symbol = stock
contract.m_secType = 'STK'
contract.m_exchange = self.exchange
contract.m_currency = 'USD'
self.connection.reqRealTimeBars(inx, contract, 5, 'TRADES', False)
示例10: makeStkContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [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]
return newContract
示例11: main
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [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()
示例12: reqMktData
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [as 别名]
def reqMktData(self):
contract = Contract() #
contract.m_symbol = 'AUD'
contract.m_currency = 'USD'
contract.m_secType = 'CASH'
contract.m_exchange = 'IDEALPRO'
self.connection.reqMktData(1, contract, '', False)
示例13: makeContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [as 别名]
def makeContract(self, symbol):
c = Contract()
c.m_symbol = symbol
c.m_secType = "STK"
c.m_currency = "USD"
c.m_exchange = "SMART"
return c
示例14: subscribe_to_market_data
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [as 别名]
def subscribe_to_market_data(self,
symbol,
sec_type='STK',
exchange='SMART',
currency='USD'):
if symbol in self.symbol_to_ticker_id:
# Already subscribed to market data
return
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = symbol_to_sec_type[symbol]
contract.m_exchange = symbol_to_exchange[symbol]
contract.m_currency = currency
ticker_id = self.next_ticker_id
self.symbol_to_ticker_id[symbol] = ticker_id
self.ticker_id_to_symbol[ticker_id] = symbol
# INDEX tickers cannot be requested with market data. The data can,
# however, be requested with realtimeBars. This change will make
# sure we can request data from INDEX tickers like SPX, VIX, etc.
if contract.m_secType == 'IND':
self.reqRealTimeBars(ticker_id, contract, 60, 'TRADES', True)
else:
tick_list = "233" # RTVolume, return tick_type == 48
self.reqMktData(ticker_id, contract, tick_list, False)
sleep(11)
示例15: addfutur
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_symbol [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 + ")")