本文整理汇总了Python中ib.ext.Contract.Contract类的典型用法代码示例。如果您正苦于以下问题:Python Contract类的具体用法?Python Contract怎么用?Python Contract使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Contract类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
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)
示例2: makeContract
def makeContract(self, symbol):
c = Contract()
c.m_symbol = symbol
c.m_secType = "STK"
c.m_currency = "USD"
c.m_exchange = "SMART"
return c
示例3: makeStkContract
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
示例4: makeStkContract
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
示例5: addfutur
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 + ")")
示例6: inner
def inner():
con.reqAccountUpdates(1, '')
qqqq = Contract()
qqqq.m_symbol = 'QQQQ'
qqqq.m_secType = 'STK'
qqqq.m_exchange = 'SMART'
con.reqMktData(1, qqqq, '', False)
示例7: reqMktData
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)
示例8: create_option_ticker
def create_option_ticker(self, ticker, currency='USD', exchange='SMART'):
c = Contract()
c.m_secType = 'OPT'
c.m_localSymbol = ticker
c.m_currency = currency
c.m_exchange = exchange
return c
示例9: subscribe_to_market_data
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)
示例10: addstock
def addstock(ticker, exchg, cur = None):
c = Contract()
c.m_symbol = ticker
c.m_secType = 'STK'
c.m_exchange = exchg
if cur != None:
c.m_currency = cur
addcontract(c, "Stock(" + exchg + ")")
示例11: build_qqq_msg
def build_qqq_msg(symbol_id):
print i
qqq = Contract()
qqq.m_symbol = i
qqq.m_secType = ibsecType
qqq.m_exchange = ibexchange
qqq.m_currency = cashcurr
return qqq
示例12: createContract
def createContract(symbol, secType='STK', exchange='SMART', currency='USD'):
""" contract factory function """
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = secType
contract.m_exchange = exchange
contract.m_currency = currency
return contract
示例13: createContract
def createContract(symbol, secType="STK", exchange="SMART", currency="USD"):
""" contract factory function """
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = secType
contract.m_exchange = exchange
contract.m_currency = currency
return contract
示例14: createContract
def createContract(symbol,secType='STK',exchange='SMART',currency='USD'):
''' create contract object '''
c = Contract()
c.m_symbol = symbol
c.m_secType= secType
c.m_exchange = exchange
c.m_currency = currency
return c
示例15: request_data
def request_data(self):
for ticker_id, instrument in self.instruments.items():
contract = Contract()
contract.m_symbol = instrument['symbol']
contract.m_currency = instrument['currency']
contract.m_secType = instrument['secType']
contract.m_exchange = instrument['exchange']
self.contracts[instrument['symbol']] = contract
self.connection.reqMktData(ticker_id, contract, '', False)