def load(self, fn=None): # open and read the file to load these closure information infile = itrade_csv.read( fn, os.path.join(itrade_config.dirSysData, 'closed.txt')) if infile: # scan each line to read each quote for eachLine in infile: item = itrade_csv.parse(eachLine, 3) if item: if len(item) > 2: self.addClosed(item[0], item[1], item[2]) else: info("can't import item=%s" % item) # open and read the file to load these SRD information infile = itrade_csv.read( fn, os.path.join(itrade_config.dirSysData, 'srd.txt')) if infile: # scan each line to read each quote for eachLine in infile: item = itrade_csv.parse(eachLine, 3) if item: if len(item) > 2: self.addSRD(item[0], item[1], item[2]) else: info("can't import item=%s" % item)
def load(self, fn=None): if self.m_llang.has_key(self.m_lang): warning('lang %s already loaded !' % self.m_lang) return infile = itrade_csv.read( fn, os.path.join(itrade_config.dirSysData, '%s.messages.txt' % self.m_lang)) if infile: # store filename used for messaging if fn: self.m_llang[self.m_lang] = fn else: self.m_llang[self.m_lang] = os.path.join( itrade_config.dirSysData, '%s.messages.txt' % self.m_lang) # scan each line to read each trade for eachLine in infile: item = itrade_csv.parse(eachLine, 2) if item: self.addMsg(item) # info print 'Language Pack %s : %s' % (self.m_lang, self.m_llang[self.m_lang]) else: print 'No Language Pack for %s !' % self.m_lang
def load(self,fn): infile = itrade_csv.read(None,os.path.join(itrade_config.dirUserData,'%s.matrix.txt' % fn)) if infile: # scan each line to read each quote for eachLine in infile: item = itrade_csv.parse(eachLine,1) if item: if len(item)>4: #print 'addKey:new fmt: %s : %s : %s : %s '% (item[0],item[2],item[3],item[5]) ref = None # be sure the market is loaded quotes.loadMarket(item[3]) if item[0]=='': quote = quotes.lookupTicker(ticker=item[2],market=item[3],place=item[5]) if quote: ref = quote.key() if not ref: ref = quote_reference(isin=item[0],ticker=item[2],market=item[3],place=item[5]) if not self.addKey(ref): print 'load (new format): %s/%s : quote not found in quotes list ! (ref=%s)' % (item[0],item[2],ref) elif len(item)<=4: print 'old matrix format : not supported anymore'
def load(self, fn): infile = itrade_csv.read( None, os.path.join(itrade_config.dirUserData, '%s.matrix.txt' % fn)) if infile: # scan each line to read each quote for eachLine in infile: item = itrade_csv.parse(eachLine, 1) if item: if len(item) > 4: #print 'addKey:new fmt: %s : %s : %s : %s '% (item[0],item[2],item[3],item[5]) ref = None # be sure the market is loaded quotes.loadMarket(item[3]) if item[0] == '': quote = quotes.lookupTicker(ticker=item[2], market=item[3], place=item[5]) if quote: ref = quote.key() if not ref: ref = quote_reference(isin=item[0], ticker=item[2], market=item[3], place=item[5]) if not self.addKey(ref): print 'load (new format): %s/%s : quote not found in quotes list ! (ref=%s)' % ( item[0], item[2], ref) elif len(item) <= 4: print 'old matrix format : not supported anymore'
def load(self,fn=None): # open and read the file to load these alerts information infile = itrade_csv.read(fn,os.path.join(itrade_config.dirUserData,'alerts.txt')) if infile: # scan each line to read each alert for eachLine in infile: item = itrade_csv.parse(eachLine,2) if item: self.addAlert(item[1],int(item[0]))
def load(self,fn=None): # open and read the file to load these alerts information infile = itrade_csv.read(fn, itrade_config.default_alerts_file()) if infile: # scan each line to read each alert for eachLine in infile: item = itrade_csv.parse(eachLine,2) if item: self.addAlert(item[1],int(item[0]))
def load(self, fn=None): # open and read the file to load these alerts information infile = itrade_csv.read(fn, itrade_config.default_alerts_file()) if infile: # scan each line to read each alert for eachLine in infile: item = itrade_csv.parse(eachLine, 2) if item: self.addAlert(item[1], int(item[0]))
def load(self,fn=None): # open and read the file to load these currencies information infile = itrade_csv.read(fn,os.path.join(itrade_config.dirCacheData,'currencies.txt')) if infile: # scan each line to read each rate for eachLine in infile: item = itrade_csv.parse(eachLine,3) if item: # logging.debug('%s ::: %s' % (eachLine,item)) self.update(item[0],item[1],float(item[2]))
def load(self,fn=None): # open and read the file to load these currencies information infile = itrade_csv.read(fn,os.path.join(itrade_config.dirCacheData,'currencies.txt')) if infile: # scan each line to read each rate for eachLine in infile: item = itrade_csv.parse(eachLine,3) if item: # debug('%s ::: %s' % (eachLine,item)) self.update(item[0],item[1],float(item[2]))
def imp(self,data,bLive): #debug('Trades::imp %s : %s : bLive=%s' % (self.m_quote.ticker(),data,bLive)) #print data if data: # scan each line to read each trade for eachLine in data: item = itrade_csv.parse(eachLine,7) if item: if (item[0]==self.m_quote.key()) or (item[0]==self.m_quote.isin() and item[0]!=''): #print item self.add(item,bImporting=not bLive)
def load(self,infile=None): infile = itrade_csv.read(infile,os.path.join(itrade_config.dirCacheData,'%s.txt' % self.m_quote.key())) #print 'Trades:load::',infile if infile: # scan each line to read each trade #debug('Trades::load %s %s' % (self.m_quote.ticker(),self.m_quote.key())) for eachLine in infile: item = itrade_csv.parse(eachLine,7) if item: if (item[0]==self.m_quote.key()) or (item[0]==self.m_quote.isin() and item[0]!=''): #print item self.add(item,bImporting=True);
def load(self,infile=None): infile = itrade_csv.read(infile,os.path.join(itrade_config.dirCacheData,'%s.txt' % self.m_quote.key())) #print 'Trades:load::',infile if infile: # scan each line to read each trade debug('Trades::load %s %s' % (self.m_quote.ticker(),self.m_quote.key())) for eachLine in infile: item = itrade_csv.parse(eachLine,7) if item: if (item[0]==self.m_quote.key()) or (item[0]==self.m_quote.isin() and item[0]!=''): #print item debug('Trades::load %s on %s' % (item[5],item[1])) self.add(item,bImporting=True)
def load(self,fn=None): # open and read the file to load these closure information infile = itrade_csv.read(fn,os.path.join(itrade_config.dirSysData,'closed.txt')) if infile: # scan each line to read each quote for eachLine in infile: item = itrade_csv.parse(eachLine,3) if item: if len(item)>2: self.addClosed(item[0],item[1],item[2]) else: info("can't import item=%s" % item) # open and read the file to load these SRD information infile = itrade_csv.read(fn,os.path.join(itrade_config.dirSysData,'srd.txt')) if infile: # scan each line to read each quote for eachLine in infile: item = itrade_csv.parse(eachLine,3) if item: if len(item)>2: self.addSRD(item[0],item[1],item[2]) else: info("can't import item=%s" % item)
def load(self, fn=None): if self.m_lang in self.m_llang: logging.warning('lang %s already loaded !' % self.m_lang) return if fn is None: fn = os.path.join(itrade_config.dir_sys_data(), '%s.messages.txt'%self.m_lang) infile = itrade_csv.read(fn) if infile: # store filename used for messaging self.m_llang[self.m_lang] = fn # scan each line to read each trade for eachLine in infile: item = itrade_csv.parse(eachLine.decode("utf-8"),2) if item: self.addMsg(item) # info print 'Language Pack %s : %s' % (self.m_lang,self.m_llang[self.m_lang]) else: print 'No Language Pack for %s !' % self.m_lang
def load(self, fn=None): if self.m_lang in self.m_llang: logging.warning('lang %s already loaded !' % self.m_lang) return if fn is None: fn = os.path.join(itrade_config.dir_sys_data(), '%s.messages.txt' % self.m_lang) infile = itrade_csv.read(fn) if infile: # store filename used for messaging self.m_llang[self.m_lang] = fn # scan each line to read each trade for eachLine in infile: item = itrade_csv.parse(eachLine.decode("utf-8"), 2) if item: self.addMsg(item) # info print 'Language Pack %s : %s' % (self.m_lang, self.m_llang[self.m_lang]) else: print 'No Language Pack for %s !' % self.m_lang
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
sticker = ticker + yahoo_suffix[key] else: sticker = ticker # check if we need to translate to something different ! if yahoo_map_tickers.has_key(sticker): return yahoo_map_tickers[sticker] return sticker infile = itrade_csv.read(None, os.path.join(itrade_config.dirSysData, "yahoo_tickers.txt")) if infile: # scan each line to read each quote for eachLine in infile: item = itrade_csv.parse(eachLine, 2) if item: yahoo_map_tickers[item[0]] = item[1].strip().upper() # ============================================================================ # euronext_place2mep # ============================================================================ euronext_place = {"PAR": 1, "AMS": 2, "BRU": 3, "LIS": 5} def euronext_place2mep(place): if euronext_place.has_key(place): return euronext_place[place] else:
else: sticker = ticker # check if we need to translate to something different ! if yahoo_map_tickers.has_key(sticker): return yahoo_map_tickers[sticker] return sticker infile = itrade_csv.read( None, os.path.join(itrade_config.dirSysData, 'yahoo_tickers.txt')) if infile: # scan each line to read each quote for eachLine in infile: item = itrade_csv.parse(eachLine, 2) if item: yahoo_map_tickers[item[0]] = item[1].strip().upper() # ============================================================================ # yahooUrl # # some marketplaces seems to use various URL from Yahoo website :-( # ============================================================================ def yahooUrl(market, live): if live: if market in ['TORONTO VENTURE', 'TORONTO EXCHANGE']: url = "http://download.finance.yahoo.com/d/quotes.csv" else:
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