本文整理汇总了Python中itrade_connection.ITradeConnection.getDataFromUrl方法的典型用法代码示例。如果您正苦于以下问题:Python ITradeConnection.getDataFromUrl方法的具体用法?Python ITradeConnection.getDataFromUrl怎么用?Python ITradeConnection.getDataFromUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类itrade_connection.ITradeConnection
的用法示例。
在下文中一共展示了ITradeConnection.getDataFromUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Import_ListOfQuotes_NZE
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
def Import_ListOfQuotes_NZE(quotes,market='NEW ZEALAND EXCHANGE',dlg=None,x=0):
if itrade_config.verbose:
print 'Update %s list of symbols' % market
connection=ITradeConnection(cookies=None,
proxy=itrade_config.proxyHostname,
proxyAuth=itrade_config.proxyAuthentication)
if market=='NEW ZEALAND EXCHANGE':
url = 'http://www.findata.co.nz/Markets/NZX/%s.htm'
else:
return False
def splitLines(buf):
lines = string.split(buf, '\n')
lines = filter(lambda x:x, lines)
def removeCarriage(s):
if s[-1]=='\r':
return s[:-1]
else:
return s
lines = [removeCarriage(l) for l in lines]
return lines
select_alpha = map(chr,range(65,91)) # A to Z
count = 0
isin = ''
for letter in select_alpha:
if dlg:
dlg.Update(x," NZX : %s to Z"%letter)
try:
data=connection.getDataFromUrl(url%letter)
except:
debug('Import_ListOfQuotes_NZE unable to connect :-(')
return False
# returns the data
lines = splitLines(data)
for line in lines:
if '"hideInfo();">' in line:
tickername = line[line.find('"hideInfo();">')+14:line.find('</td><td align=right>')]
if not 'Index' in tickername:
ticker = tickername[:tickername.index('<')]
if not '0' in ticker[-1:]:
name = tickername[tickername.index('<td>')+4:]
count = count + 1
# ok to proceed
quotes.addQuote(isin=isin,name=name,
ticker=ticker,market='NEW ZEALAND EXCHANGE',currency='NZD',place='NZE',country='NZ')
if itrade_config.verbose:
print 'Imported %d lines from NEW ZEALAND EXCHANGE' % (count)
return True
示例2: Import_ListOfQuotes_SWX
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
def Import_ListOfQuotes_SWX(quotes,market='SWISS EXCHANGE',dlg=None,x=0):
if itrade_config.verbose:
print 'Update %s list of symbols' % market
connection = ITradeConnection(cookies = None,
proxy = itrade_config.proxyHostname,
proxyAuth = itrade_config.proxyAuthentication,
connectionTimeout = itrade_config.connectionTimeout
)
if market=='SWISS EXCHANGE':
url = 'http://www.six-swiss-exchange.com/shares/companies/download/issuers_all_fr.csv'
try:
data = connection.getDataFromUrl(url)
except:
info('Import_ListOfQuotes_SWX_%s:unable to get file name :-(' % market)
return False
else:
return False
def splitLines(buf):
lines = string.split(buf, '\n')
lines = filter(lambda x:x, lines)
def removeCarriage(s):
if s[-1]=='\r':
return s[:-1]
else:
return s
lines = [removeCarriage(l) for l in lines]
return lines
# returns the data
lines = splitLines(data)
n = 0
isin = ''
for line in lines[1:]:
line = line.replace('!',' ')
line = line.replace(',',' ')
line = line.replace('à','a')
line = line.replace('ä','a')
line = line.replace('â','a')
line = line.replace('ö','o')
line = line.replace('ü','u')
line = line.replace('é','e')
line = line.replace('è','e')
line = line.replace('+',' ')
data = string.split(line,';') # csv line
name = data[0].strip()
ticker = data[1].strip()
country = data[3].strip()
currency = data[4].strip()
exchange = data[5].strip()
quotes.addQuote(isin=isin,name=name, ticker=ticker,market='SWISS EXCHANGE',
currency=currency,place=exchange,country=country)
n = n + 1
if itrade_config.verbose:
print 'Imported %d lines from %s' % (n,market)
return True
示例3: Import_ListOfQuotes_Xetra
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
def Import_ListOfQuotes_Xetra(quotes,market='FRANKFURT EXCHANGE',dlg=None,x=0):
if itrade_config.verbose:
print 'Update %s list of symbols' % market
connection = ITradeConnection(cookies = None,
proxy = itrade_config.proxyHostname,
proxyAuth = itrade_config.proxyAuthentication,
connectionTimeout = itrade_config.connectionTimeout
)
if market=='FRANKFURT EXCHANGE':
url = 'http://deutsche-boerse.com/dbag/dispatch/en/xetraCSV/gdb_navigation/trading/20_tradable_instruments/900_tradable_instruments/100_xetra'
else:
return False
def splitLines(buf):
lines = string.split(buf, '\n')
lines = filter(lambda x:x, lines)
def removeCarriage(s):
if s[-1]=='\r':
return s[:-1]
else:
return s
lines = [removeCarriage(l) for l in lines]
return lines
try:
data=connection.getDataFromUrl(url)
except:
debug('Import_ListOfQuotes_Deutsche Borse AG :unable to connect :-(')
return False
# returns the data
lines = splitLines(data)
n = 0
for line in lines[6:]:
data = string.split (line, ';') # ; delimited
if len(data) >5:
if data[8] == 'EQUITIES FFM2':
if data[2][:2] == 'DE':
name = data[1].replace(',','').replace(' ','').replace (' -','-').replace ('. ','.').replace(' + ','&').replace('+','&')
quotes.addQuote(isin=data[2],name=name,ticker=data[5],market='FRANKFURT EXCHANGE',currency=data[73],place='FRA',country='DE')
n = n + 1
if itrade_config.verbose:
print 'Imported %d/%d lines from %s' % (n,len(lines),market)
return True
示例4: Import_ListOfQuotes_ASX
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
def Import_ListOfQuotes_ASX(quotes,market='ASX',dlg=None,x=0):
print 'Update %s list of symbols' % market
connection = ITradeConnection(cookies = None,
proxy = itrade_config.proxyHostname,
proxyAuth = itrade_config.proxyAuthentication,
connectionTimeout = itrade_config.connectionTimeout
)
if market=='ASX':
url = "http://www.asx.com.au/asx/research/ASXListedCompanies.csv"
n = 0
else:
return False
def splitLines(buf):
lines = string.split(buf, '\n')
lines = filter(lambda x:x, lines)
def removeCarriage(s):
if s[-1]=='\r':
return s[:-1]
else:
return s
lines = [removeCarriage(l) for l in lines]
return lines
try:
data=connection.getDataFromUrl(url)
except:
debug('Import_ListOfQuotes_ASX:unable to connect :-(')
return False
# returns the data
lines = splitLines(data)
isin = ''
for line in lines[3:]:
line = line.replace('"','')
data = string.split (line, ',')
name=data[0]
ticker=data[1]
quotes.addQuote(isin = isin,name = name, \
ticker = ticker,market='ASX',currency='AUD',place='SYD',country='AU')
n = n + 1
if itrade_config.verbose:
print 'Imported %d lines from %s data.' % (n,market)
return True
示例5: Import_ListOfQuotes_OTCBB
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
def Import_ListOfQuotes_OTCBB(quotes,market='OTCBB',dlg=None,x=0):
if itrade_config.verbose:
print 'Update %s list of symbols' % market
connection = ITradeConnection(cookies = None,
proxy = itrade_config.proxyHostname,
proxyAuth = itrade_config.proxyAuthentication,
connectionTimeout = itrade_config.connectionTimeout
)
if market=='OTCBB':
url = 'http://www.otcbb.com/dynamic/tradingdata/download/allotcbb.txt'
else:
return False
def splitLines(buf):
lines = string.split(buf, '\n')
lines = filter(lambda x:x, lines)
def removeCarriage(s):
if s[-1]=='\r':
return s[:-1]
else:
return s
lines = [removeCarriage(l) for l in lines]
return lines
try:
data=connection.getDataFromUrl(url)
except:
debug('Import_ListOfQuotes_OTCBB:unable to connect :-(')
return False
# returns the data
lines = splitLines(data)
count = 0
isin = ''
for line in lines[1:]:
if '|' in line:
data = string.split (line, '|')
if data[3]== 'ACTIVE':
count = count + 1
name = data[2]
name = name.strip()
name =name.replace(',','')
ticker = data[0]
quotes.addQuote(isin=isin,name=name,ticker=ticker,market='OTCBB',currency='USD',place='NYC',country='US')
if itrade_config.verbose:
print 'Imported %d lines from OTCBB data.' % count
return True
示例6: Import_ListOfQuotes_NYSE
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
def Import_ListOfQuotes_NYSE(quotes,market='NYSE',dlg=None,x=0):
print 'Update %s list of symbols' % market
connection = ITradeConnection(cookies = None,
proxy = itrade_config.proxyHostname,
proxyAuth = itrade_config.proxyAuthentication,
connectionTimeout = itrade_config.connectionTimeout
)
if market=='NYSE':
url = "http://www.nysedata.com/nysedata/asp/download.asp?s=txt&prod=symbols"
else:
return False
def splitLines(buf):
lines = string.split(buf, '\n')
lines = filter(lambda x:x, lines)
def removeCarriage(s):
if s[-1]=='\r':
return s[:-1]
else:
return s
lines = [removeCarriage(l) for l in lines]
return lines
try:
data=connection.getDataFromUrl(url)
except:
debug('Import_ListOfQuotes_NYSE:unable to connect :-(')
return False
# returns the data
lines = splitLines(data)
for line in lines:
data = string.split (line, '|')
if len(data)==5:
country,issuer,issue = extractCUSIP(data[1])
if issue=='10':
#print data[1],country,issuer,issue,data[2]
if country=='US':
isin = buildISIN(country,data[1])
name = filterName(data[2])
quotes.addQuote(isin=isin,name=name,ticker=data[0],market='NYSE',currency='USD',place='NYC',country='US')
print 'Imported %d lines from NYSE data.' % len(lines)
return True
示例7: checkNewRelease
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
def checkNewRelease(ping=False):
# just to test : remove '#' from the line just below
#__svnversion__ = 'r565'
# development release : do not test
if not ping and __svnversion__[0] == 'x':
if verbose:
print 'checkNewRelease(): development release'
return 'dev'
from itrade_connection import ITradeConnection
connection = ITradeConnection(cookies = None,
proxy = proxyHostname,
proxyAuth = proxyAuthentication,
connectionTimeout = 3
)
# get OFFICIAL file from svn
try:
latest=connection.getDataFromUrl(softwareLatest)
except IOError:
print 'checkNewRelease(): exeption getting OFFICIAL file'
return 'err'
if latest[0]!='r':
if verbose:
print 'checkNewRelease(): OFFICIAL file malformed'
return 'err'
# development release : do not test
if __svnversion__[0] == 'x':
if verbose:
print 'checkNewRelease(): development release (ping)'
return 'dev'
current = int(__svnversion__[1:])
latest = int(latest[1:])
#print current,latest
if current<latest:
print 'checkNewRelease(): please update (%d vs %d) : %s' % (current,latest,downloadURL)
return downloadURL
else:
print 'checkNewRelease(): up to date'
return 'ok'
示例8: Import_ListOfQuotes_ASX
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
def Import_ListOfQuotes_ASX(quotes,market='ASX',dlg=None,x=0):
print 'Update %s list of symbols' % market
connection = ITradeConnection(cookies = None,
proxy = itrade_config.proxyHostname,
proxyAuth = itrade_config.proxyAuthentication,
connectionTimeout = itrade_config.connectionTimeout
)
if market=='ASX':
url = "http://www.asx.com.au/programs/ISIN.xls" # is actually tab delimited
else:
return False
def splitLines(buf):
lines = string.split(buf, '\n')
lines = filter(lambda x:x, lines)
def removeCarriage(s):
if s[-1]=='\r':
return s[:-1]
else:
return s
lines = [removeCarriage(l) for l in lines]
return lines
try:
data=connection.getDataFromUrl(url)
except:
debug('Import_ListOfQuotes_ASX:unable to connect :-(')
return False
# returns the data
lines = splitLines(data)
n = 0
for line in lines[5:]: # skip header lines (PeterMills> 2007-06-22)
data = string.split (line, '\t') # tab delimited
if data[2]=='ORDINARY FULLY PAID': # only want ordinary shares
quotes.addQuote(isin=data[3],name=data[1].replace(',',' '), \
ticker=data[0],market='ASX',currency='AUD',place='SYD',country='AU')
n = n + 1
print 'Imported %d/%d lines from ASX data.' % (n,len(lines))
return True
示例9: Import_ListOfQuotes_SWX
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
def Import_ListOfQuotes_SWX(quotes,market='SWISS EXCHANGE',dlg=None,x=0):
print 'Update %s list of symbols' % market
connection = ITradeConnection(cookies = None,
proxy = itrade_config.proxyHostname,
proxyAuth = itrade_config.proxyAuthentication,
connectionTimeout = itrade_config.connectionTimeout
)
if market=='SWISS EXCHANGE':
url = "http://www.swx.com/data/market/statistics/swx_swiss_shares_reference_data.csv" # is actually tab delimited
else:
return False
def splitLines(buf):
lines = string.split(buf, '\n')
lines = filter(lambda x:x, lines)
def removeCarriage(s):
if s[-1]=='\r':
return s[:-1]
else:
return s
lines = [removeCarriage(l) for l in lines]
return lines
info('Import_ListOfQuotes_SWX:connect to %s' % url)
try:
data=connection.getDataFromUrl(url)
except:
info('Import_ListOfQuotes_SWX:unable to connect :-(')
return False
# returns the data
lines = splitLines(data)
n = 0
indice = {}
for line in lines:
item = itrade_csv.parse(line,7)
if len(item)>2:
if n==0:
i = 0
for ind in item:
indice[ind] = i
i = i + 1
iISIN = indice['ISIN']
iName = indice['ShortName']
iCurrency = indice['TradingBaseCurrency']
iExchange = indice['Exchange']
iCountry = indice['GeographicalAreaCode']
iTicker = indice['ValorSymbol']
else:
quotes.addQuote(isin=item[iISIN],name=item[iName].replace(',',' '), ticker=item[iTicker],market='SWISS EXCHANGE',\
currency=item[iCurrency],place=item[iExchange],country=item[iCountry])
n = n + 1
print 'Imported %d/%d lines from %s data.' % (n,len(lines),market)
return True
示例10: News_Balo
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
class News_Balo(object):
def __init__(self):
debug('News_Balo:__init__')
self.m_feed = None
self.m_url = None
self.m_quote = None
self.m_baseurl = "balo.journal-officiel.gouv.fr"
self.m_connection = ITradeConnection(cookies = None,
proxy = itrade_config.proxyHostname,
proxyAuth = itrade_config.proxyAuthentication,
connectionTimeout = itrade_config.connectionTimeout
)
# ---[ protected interface ] ---
def getURL(self):
return self.m_url
def getQuote(self):
return self.m_quote
def getFeed(self):
return self.m_feed
def splitLines(self,buf):
p = re.compile(r"\d\d/\d\d/\d\d\d\d</td>[ \t\n\r]*<td></td>[ \t\n\r]*.*</td>", re.IGNORECASE|re.MULTILINE)
return p.findall(buf)
def feed(self,url):
self.m_url = url
self.m_feed = _Feed()
self.m_feed.entries = []
self.m_feed.feed = _Feed()
self.m_feed.feed.title = 'Balo'
info('Balo News refresh %s',self.m_url)
try:
buf=self.m_connection.getDataFromUrl(self.m_url)
except:
debug('News_Balo:unable to connect :-(')
return None
iter = self.splitLines(buf)
for eachLine in iter:
sdate = eachLine[0:10]
sdate = datetime.datetime(int(sdate[6:10]),int(sdate[3:5]),int(sdate[0:2])).strftime('%a, %d %b %Y')
snum = re.search(r'news=\d*', eachLine, re.IGNORECASE|re.MULTILINE)
if snum:
snum = snum.group()[5:]
stitle = re.search(r'<a.*>.*</a>', eachLine, re.IGNORECASE|re.MULTILINE)
if stitle:
stitle = stitle.group()
stitle = re.search(r'>.*<', stitle, re.IGNORECASE|re.MULTILINE)
if stitle:
stitle = stitle.group()[1:-1]
entry = _Feed()
entry.link = itrade_config.boursoNewsLinkxxxxxxxxxxxxxxxxUrl%snum
entry.title = stitle
entry.date = sdate
entry.summary = ""
print('%s: %s' % (sdate,stitle))
self.m_feed.entries.append(entry)
return self.m_feed
def goto(self,html,url):
if html:
html.paint0()
info('goto %s',url)
try:
buf=self.m_connection.getDataFromUrl(url)
except:
debug('News_Balo:unable to connect :-(')
if html:
html.paint_NC()
else:
print 'unable to connect'
return
#print buf
title = re.search(r'<tr>[ \t\n\r]+<td.*</td>[ \t\n\r]+</tr>', buf, re.IGNORECASE|re.MULTILINE|re.DOTALL)
if title:
title = title.group()
else:
title = ''
buf = re.search(r'<tr>[ \t\n\r]*<td>.*</table>', buf, re.IGNORECASE|re.MULTILINE|re.DOTALL)
if buf:
buf = buf.group()[:-8]
page = '<html><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><body>' + "<br><a href=':back'>%s</a><H3>" % message('backtolist') + title + "</H3>" + buf + "<br><br><a href=':back'>%s</a>" % message('backtolist') + "</body></html>"
if html:
html.SetPageWithoutCache(page)
else:
print page
else:
#.........这里部分代码省略.........
示例11: Import_ListOfQuotes_LSE
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
def Import_ListOfQuotes_LSE(quotes,market='LSE SETS',dlg=None,x=0):
print 'Update %s list of symbols' % market
connection = ITradeConnection(cookies = None,
proxy = itrade_config.proxyHostname,
proxyAuth = itrade_config.proxyAuthentication,
connectionTimeout = itrade_config.connectionTimeout
)
import xlrd
if market=='LSE SETS':
url = "http://www.londonstockexchange.com/NR/rdonlyres/1BCC9E48-6846-411B-8F2A-06F1DD17EB22/0/ListofSETSsecurities.xls"
elif market=='LSE SETSmm':
url = "http://www.londonstockexchange.com/NR/rdonlyres/6B92591A-68A2-4715-8333-F28FD517AB27/0/ListofSETSmmsecurities.xls"
elif market=='LSE SEAQ':
url = "http://www.londonstockexchange.com/NR/rdonlyres/9731A6AB-B60B-469F-BE6B-A721247CE76C/0/ListofSEAQsecurities.xls"
else:
return False
def splitLines(buf):
lines = string.split(buf, '\n')
lines = filter(lambda x:x, lines)
def removeCarriage(s):
if s[-1]=='\r':
return s[:-1]
else:
return s
lines = [removeCarriage(l) for l in lines]
return lines
info('Import_ListOfQuotes_LSE_%s:connect to %s' % (market,url))
try:
data = connection.getDataFromUrl(url)
except:
info('Import_ListOfQuotes_LSE_%s:unable to connect :-(' % market)
return False
#print data[:250]
# returns the data
book = itrade_excel.open_excel(file=None,content=data)
sh = book.sheet_by_index(0)
n = 0
indice = {}
print 'Import_ListOfQuotes_LSE_%s:' % market,'book',book,'sheet',sh,'nrows=',sh.nrows
for line in range(sh.nrows):
if sh.cell_type(line,1) != xlrd.XL_CELL_EMPTY:
if n==0:
for i in range(sh.ncols):
val = sh.cell_value(line,i)
indice[val] = i
# be sure we have detected the title
if val=='ISIN': n = n + 1
if n==1:
if itrade_config.verbose: print 'Indice:',indice
iISIN = indice['ISIN']
iName = indice['Short Name']
iCurrency = indice['Currency']
iCountry = indice['Country of Register']
iTicker = indice['Mnemonic']
else:
ticker = sh.cell_value(line,iTicker)
if type(ticker)==float: ticker='%s' % ticker
#print line,iTicker,ticker,type(ticker)
if ticker[-1:]=='.':
ticker = ticker[:-1]
name = sh.cell_value(line,iName).replace(',',' ')
#print line,'>',sh.cell_value(line,iISIN),' : ',name,ticker
quotes.addQuote(isin=sh.cell_value(line,iISIN),name=name, \
ticker=ticker,market=market,\
currency=sh.cell_value(line,iCurrency),place='LON',\
country=sh.cell_value(line,iCountry))
n = n + 1
print 'Imported %d/%d lines from %s data.' % (n,sh.nrows,market)
return True
示例12: Import_ListOfQuotes_Euronext
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
def Import_ListOfQuotes_Euronext(quotes,market='EURONEXT',dlg=None,x=0):
print 'Update %s list of symbols' % market
connection = ITradeConnection(cookies = None,
proxy = itrade_config.proxyHostname,
proxyAuth = itrade_config.proxyAuthentication,
connectionTimeout = max(45,itrade_config.connectionTimeout)
)
cha = "7213"
if market=='EURONEXT':
url = "http://www.euronext.com/search/download/trapridownloadpopup.jcsv?pricesearchresults=actif&filter=1&lan=EN&belongsToList=market_EURLS&cha=%s&format=txt&formatDecimal=.&formatDate=dd/MM/yy" % cha
elif market=='ALTERNEXT':
url = "http://www.euronext.com/search/download/trapridownloadpopup.jcsv?pricesearchresults=actif&filter=1&lan=EN&belongsToList=market_ALTX&cha=%s&format=txt&formatDecimal=.&formatDate=dd/MM/yy" % cha
elif market=='PARIS MARCHE LIBRE':
url = "http://www.euronext.com/search/download/trapridownloadpopup.jcsv?pricesearchresults=actif&filter=1&lan=EN&belongsToList=market_MC&cha=%s&format=txt&formatDecimal=.&formatDate=dd/MM/yy" % cha
elif market=='BRUXELLES MARCHE LIBRE':
url = "http://www.euronext.com/search/download/trapridownloadpopup.jcsv?pricesearchresults=actif&filter=1&lan=EN&belongsToList=market_BRUMC&cha=%s&format=txt&formatDecimal=.&formatDate=dd/MM/yy" % cha
else:
return False
def splitLines(buf):
lines = string.split(buf, '\n')
lines = filter(lambda x:x, lines)
def removeCarriage(s):
if s[-1]=='\r':
return s[:-1]
else:
return s
lines = [removeCarriage(l) for l in lines]
return lines
try:
data=connection.getDataFromUrl(url)
except:
debug('Import_ListOfQuotes_Euronext:unable to connect :-(')
return False
indice = {}
"""
"Instrument's name";
"ISIN";
"Euronext code";
"MEP";
"Symbol";
"ICB Sector (Level 4)";
"Trading currency";
"Last";
"Volume";
"D/D-1 (%)";
"Date - time (CET)";
"Turnover";
"Total number of shares";
"Capitalisation";
"Trading mode";
"Day First";
"Day High";
"Day High / Date - time (CET)";
"Day Low";
"Day Low / Date - time (CET)";
"31-12/Change (%)";
"31-12/High";
"31-12/High/Date";
"31-12/Low";
"31-12/Low/Date";
"52 weeks/Change (%)";
"52 weeks/High";
"52 weeks/High/Date";
"52 weeks/Low";
"52 weeks/Low/Date";
"Suspended";
"Suspended / Date - time (CET)";
"Reserved";
"Reserved / Date - time (CET)"
"""
# returns the data
lines = splitLines(data)
count = 0
for line in lines:
data = string.split (line, ';')
if len(data)>2:
if not indice.has_key("ISIN"):
i = 0
for ind in data:
indice[ind] = i
i = i + 1
iName = indice["Instrument's name"]
iISIN = indice["ISIN"]
iMEP = indice["MEP"]
iTicker = indice["Symbol"]
iCurr = indice["Trading currency"]
else:
if data[iISIN]!="ISIN":
if checkISIN(data[iISIN]):
if data[iMEP]=='PAR' or data[iMEP]=='BRU' or data[iMEP]=='AMS' or data[iMEP]=='LIS':
#.........这里部分代码省略.........
示例13: euronext_InstrumentId
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
def euronext_InstrumentId(quote):
deprecated
#
if quote.list() == QLIST_INDICES:
urlid = "http://www.euronext.com/quicksearch/resultquicksearchindices-7000-EN.html?matchpattern=%s&fromsearchbox=true&path=/quicksearch&searchTarget=quote"
else:
urlid = "http://www.euronext.com/quicksearch/resultquicksearch-2986-EN.html?matchpattern=%s&fromsearchbox=true&path=/quicksearch&searchTarget=quote"
connection = ITradeConnection(
cookies=None,
proxy=itrade_config.proxyHostname,
proxyAuth=itrade_config.proxyAuthentication,
connectionTimeout=itrade_config.connectionTimeout,
)
# get instrument ID
IdInstrument = quote.get_pluginID()
if IdInstrument == None:
try:
f = open(os.path.join(itrade_config.dirCacheData, "%s.id" % quote.key()), "r")
IdInstrument = f.read().strip()
f.close()
# print "euronext_InstrumentId: get id from file for %s " % quote.isin()
except IOError:
# print "euronext_InstrumentId: can't get id file for %s " % quote.isin()
pass
if IdInstrument == None:
url = urlid % quote.isin()
if itrade_config.verbose:
print "euronext_InstrumentId: urlID=%s " % url
try:
buf = connection.getDataFromUrl(url)
except:
print "euronext_InstrumentId: %s exception error" % url
return None
sid = re.search(
"selectedMep=%d&idInstrument=\d*&isinCode=%s"
% (euronext_place2mep(quote.place()), quote.isin()),
buf,
re.IGNORECASE | re.MULTILINE,
)
if sid:
sid = buf[sid.start() : sid.end()]
# print'seq-1 found:',sid
sexch = re.search("&isinCode", sid, re.IGNORECASE | re.MULTILINE)
if sexch:
IdInstrument = sid[31 : sexch.start()]
# print 'seq-2 found:',IdInstrument
else:
print "euronext_InstrumentId: seq-2 not found : &isinCode"
else:
print "euronext_InstrumentId: seq-1 not found : selectedMep=%d&idInstrument=\d*&isinCode=%s" % (
euronext_place2mep(quote.place()),
quote.isin(),
)
# print buf
# exit(0)
if IdInstrument == None:
print "euronext_InstrumentId:can't get IdInstrument for %s " % quote.isin()
return None
else:
if itrade_config.verbose:
print "euronext_InstrumentId: IdInstrument for %s is %s" % (quote.isin(), IdInstrument)
quote.set_pluginID(IdInstrument)
try:
f = open(os.path.join(itrade_config.dirCacheData, "%s.id" % quote.key()), "w")
f.write("%s" % IdInstrument)
f.close()
except IOError:
# print "euronext_InstrumentId: can't write id file for %s " % quote.isin()
pass
return IdInstrument
示例14: Import_ListOfQuotes_SGX
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
def Import_ListOfQuotes_SGX(quotes,market='SINGAPORE EXCHANGE',dlg=None,x=0):
if itrade_config.verbose:
print 'Update %s list of symbols' % market
connection=ITradeConnection(cookies=None,
proxy=itrade_config.proxyHostname,
proxyAuth=itrade_config.proxyAuthentication)
def splitLines(buf):
lines = string.split(buf, '\n')
lines = filter(lambda x:x, lines)
def removeCarriage(s):
if s[-1]=='\r':
return s[:-1]
else:
return s
lines = [removeCarriage(l) for l in lines]
return lines
# find date to update list
try:
data = connection.getDataFromUrl('http://info.sgx.com/webstocks.nsf/isincodedownload/')
except:
info('Import_ListOfQuotes_SGX_%s:unable to get file name :-(' % market)
return False
date = data[data.find('/ISINCODEDOWNLOAD/')+18:data.find('/$File/ISINCODE.txt')]
url = 'http://info.sgx.com/webstocks.nsf/ISINCODEDOWNLOAD/'+date+'/%24File/ISINCODE.txt'
#info('Import_ListOfQuotes_SGX_%s:connect to %s' % (market,url))
if market == 'SINGAPORE EXCHANGE':
currency = 'SGD'
place = 'SGX'
country = 'SG'
else:
return False
try:
data = connection.getDataFromUrl(url)
except:
info('Import_ListOfQuotes_SGX_%s:unable to connect :-(' % market)
return False
# returns the data
lines = splitLines(data)
n = 0
for line in lines[1:]:
n = n + 1
name = line[:50]
isin = line[60:72]
ticker = line[80:89]
name = name.strip()
isin = isin.strip()
ticker = ticker.strip()
quotes.addQuote(isin = isin,name = name,ticker = ticker,market = market,currency = currency,place = place,country = country)
if itrade_config.verbose:
print 'Imported %d lines from %s' % (n,market)
return True
示例15: LiveUpdate_yahoojp
# 需要导入模块: from itrade_connection import ITradeConnection [as 别名]
# 或者: from itrade_connection.ITradeConnection import getDataFromUrl [as 别名]
#.........这里部分代码省略.........
def yahooDate (self,date):
# Date part is easy.
sdate = string.split (date[1:-1], '/')
month = string.atoi (sdate[0])
day = string.atoi (sdate[1])
year = string.atoi (sdate[2])
return "%4d%02d%02d" % (year,month,day)
def convertClock(self,place,clock,date):
min = clock[-2:]
hour = clock[:-3]
val = (int(hour)*60) + int(min)
if val>self.m_lastclock and date>=self.m_lastdate:
self.m_lastdate = date
self.m_lastclock = val
# convert from connector timezone to market place timezone
mdatetime = datetime(int(date[0:4]),int(date[4:6]),int(date[6:8]),val/60,val%60)
mdatetime = convertConnectorTimeToPlaceTime(mdatetime,self.timezone(),place)
return "%d:%02d" % (mdatetime.hour,mdatetime.minute)
def getdata(self,quote):
sname = yahooTicker(quote.ticker(),quote.market(),quote.place())
ss = sname
url = yahooUrlJapan(quote.market(),live=True) + '?' +'s=%s&d=v2' % (ss)
debug("LiveUpdate_yahoojp:getdata: url=%s",url)
try:
data=self.m_connection.getDataFromUrl(url)
data = data.replace('</td>','\n')
lines = self.splitLines(data)
# returns the data
for line in lines:
if 'uncompressed' in line:
year = line[line.find('JST ')+4:line.find(' -->')]
else : year = '0000'
#sdata =[]
ch = '<td nowrap align=center>'
i = 0
n = 0
#typical lines
#1 datetime <td nowrap align=center>1/21
#2 last <td nowrap><b>226</b>
#3 changetoday <td nowrap><font color=ff0020>-4</font>
#<td nowrap>---
#4 change_percent <td nowrap><font color=ff0020>-1.74%</font>
#<td nowrap>
#5 volume <td nowrap>1,705,200
#6 open <td nowrap>221
#7 high <td nowrap>230
#8 low <td nowrap>221
for line in lines: