本文整理汇总了Python中ib.ext.Contract.Contract.m_primaryExch方法的典型用法代码示例。如果您正苦于以下问题:Python Contract.m_primaryExch方法的具体用法?Python Contract.m_primaryExch怎么用?Python Contract.m_primaryExch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ib.ext.Contract.Contract
的用法示例。
在下文中一共展示了Contract.m_primaryExch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: request_market_data
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [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)
示例2: create_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [as 别名]
def create_contract(symbol, sec_type, exch, prim_exch, curr):
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sec_type
contract.m_exchange = exch
contract.m_primaryExch = prim_exch
contract.m_currency = curr
return contract
示例3: makeContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [as 别名]
def makeContract(self, symbol):
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = 'STK'
contract.m_exchange = 'SMART'
contract.m_primaryExch = 'SMART'
contract.m_currency = 'USD'
contract.m_localSymbol = symbol
return contract
示例4: _create_security_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [as 别名]
def _create_security_contract(self):
"""To pass into IB messages"""
contract = Contract()
contract.m_symbol = self.symbol
contract.m_secType = self.secType
contract.m_exchange = self.exchange
if self.primaryExch != None: #don't set m_primaryExch at all if None
contract.m_primaryExch = self.primaryExch
contract.m_currency = self.currency
return contract
示例5: create_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [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
示例6: create_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [as 别名]
def create_contract(self, symbol, sec_type, exch, prim_exch, curr):
""" Create a contract object defining purchase specifications. To
transact a trade it is necessary to create an IbPy Contract instance
and pair it with an IbPy Order instance to send to the IB API.
"""
contract = Contract()
contract.m_symbol = symbol # ticker
contract.m_secType = sec_type # security type ('STK' = stock)
contract.m_exchange = exch # exchange
contract.m_primaryExch = prim_exch # primary exchange
contract.m_currency = curr # currency in which to purchase asset
return contract
示例7: create_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [as 别名]
def create_contract(self, symbol, sec_type, exch, prim_exch, curr):
"""Create a Contract object defining what will
be purchased, at which exchange and in which currency.
symbol - The ticker symbol for the contract
sec_type - The security type for the contract ('STK' is 'stock')
exch - The exchange to carry out the contract on
prim_exch - The primary exchange to carry out the contract on
curr - The currency in which to purchase the contract
In cases where SMART exchange results in ambiguity SYMBOL:PRIMARY_EXCHANGE can be passed."""
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sec_type
contract.m_exchange = exch
if symbol in self.primary_exchange_map.keys():
contract.m_primaryExch = self.primary_exchange_map[symbol]
else:
contract.m_primaryExch = prim_exch
contract.m_currency = curr
return contract
示例8: makeStkContract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [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]
if contractTuple[0]=='ASHR':
newContract.m_primaryExch = 'ARCA'
print 'Contract Values:%s,%s,%s,%s,%s,%s,%s:' % contractTuple
return newContract
示例9: craft_contract_stock
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [as 别名]
def craft_contract_stock(details):
if isinstance(details, dict):
try:
newContract = Contract()
newContract.m_symbol = details['symbol']
newContract.m_secType = details['security_type']
newContract.m_primaryExch = details['primary_exchange']
newContract.m_exchange = details['exchange']
newContract.m_currency = details['currency']
return newContract
except:
raise TypeError
else:
raise TypeError
示例10: create_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [as 别名]
def create_contract(symbol, sec_type, exch, prim_exch, curr):
"""Create a Contract object defining what will
be purchased, at which exchange and in which currency.
symbol - The ticker symbol for the contract
sec_type - The security type for the contract ('STK' is 'stock')
exch - The exchange to carry out the contract on
prim_exch - The primary exchange to carry out the contract on
curr - The currency in which to purchase the contract"""
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sec_type
contract.m_exchange = exch
contract.m_primaryExch = prim_exch
contract.m_currency = curr
return contract
示例11: create_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [as 别名]
def create_contract(security):
if security.split('.')[0]=='FUT':
contract = Contract()
contract.m_symbol = security.split('.')[1]
contract.m_secType = 'FUT'
contract.m_exchange = 'GLOBEX'
contract.m_currency = security.split('.')[2]
contract.m_expiry= security.split('.')[3]
contract.m_primaryExch='GLOBEX'
elif security.split('.')[0]=='CASH':
contract = Contract()
contract.m_symbol = security.split('.')[1]
contract.m_secType = 'CASH'
contract.m_exchange = 'IDEALPRO'
contract.m_currency = security.split('.')[2]
contract.m_primaryExch='IDEALPRO'
elif security.split('.')[0]=='STK':
contract = Contract()
contract.m_symbol = security.split('.')[1]
contract.m_secType = 'STK'
contract.m_exchange = 'SMART'
contract.m_currency = 'USD'
contract.m_primaryExch='SMART'
return contract
示例12: newContract_GUI
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [as 别名]
def newContract_GUI(contractTuple):
newContract = Contract()
symbol=contractTuple[0]
newContract.m_symbol = symbol
newContract.m_secType = contractTuple[1]
newContract.m_exchange='SMART'
#download exchange information from yahoo finance
url='http://download.finance.yahoo.com/d/quotes.csv?s='+symbol+'&f=x'
primexchange=pd.read_csv(url,header=None)
primexchange=primexchange.iloc[0,0]
if primexchange=='NasdaqNM' or primexchange=='NGM':
primexchange='NASDAQ'
#print primexchange
newContract.m_primaryExch=primexchange
return newContract
示例13: create_ib_stock_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [as 别名]
def create_ib_stock_contract(symbol, exch='NASDAQ', prim_exch='NASDAQ', curr='USD'):
"""
Create a stock contract used for IB orders.
:param symbol:
:param exch:
:param prim_exch:
:param curr:
:return:
"""
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = 'STK'
contract.m_exchange = exch
contract.m_primaryExch = prim_exch
contract.m_currency = curr
print contract.__dict__
return contract
示例14: create_contract
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [as 别名]
def create_contract(self, symbol, sec_type, exch, prim_exch, curr):
"""
Create a Contract object defining what will
be purchased, at which exchange and in which currency.
:param symbol: (str) The ticker symbol for the contract.
:param sec_type: (str) The security type for the contract.
:param exch: (str) The exchange to carry out the contract on.
:param prim_exch: The primary exchange to carry out the contract on.
:param curr: The currency in which to purchase the contract.
"""
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sec_type
contract.m_exchange = exch
contract.m_primaryExch = prim_exch
contract.m_currency = curr
return contract
示例15: craft_contract_option
# 需要导入模块: from ib.ext.Contract import Contract [as 别名]
# 或者: from ib.ext.Contract.Contract import m_primaryExch [as 别名]
def craft_contract_option(details, strike, expiry):
print(strike)
print(expiry)
if isinstance(details, dict):
try:
newContract = Contract()
newContract.m_symbol = details['symbol']
newContract.m_secType = details['security_type']
newContract.m_primaryExch = details['primary_exchange']
newContract.m_exchange = details['exchange']
newContract.m_currency = details['currency']
newContract.m_multiplier = details['multiplier']
newContract.m_right = details['right']
newContract.m_expiry = expiry
newContract.m_strike = strike # not sure how comfortable I am with float representation...anyway...
return newContract
except:
raise TypeError
else:
raise TypeError