def after_ct_symbol(self): """输入symbol 之后 """ self.ct_symbname.SetLabel('') self.symbol = string.upper(self.ct_symbol.GetValue()) tmp = self.symbol if tmp.startswith('^') : tmp = tmp[1:] self.ct_symbol.SetValue(tmp) b_found = False self.stkid = '' self.stkname = '' for ii in self.namelist: if ii[2] == tmp: b_found = True self.stkid = ii[0] self.stkname = ii [1] break if not b_found: if len(self.namelist) ==0 : self.stkid = 'SH770001' else: lastid = self.namelist[-1][0] self.stkid = 'SH' + str(int(lastid[2:]) +1) if self.stkname == '' : try: self.stkname = ystockquote.get_name(self.symbol) except : pass self.ct_stkid.SetValue(self.stkid) self.ct_stkname.SetValue(self.stkname)
def befor_run(self): """check """ self.symbol = self.ct_symbol.GetValue() if self.cr_usaind.GetValue() and not self.symbol.startswith('^'): self.symbol = '^' + self.symbol try: symbolName = ystockquote.get_name(self.symbol) self.ct_symbname.SetLabel(symbolName) except : pass if not os.path.isdir(self.YahooTemp): try: os.mkdir(self.YahooTemp) except IOError : self.puts('can not make dir %s' % self.YahooTemp) return False self.stkid = self.ct_stkid.GetValue() self.stkname = self.ct_stkname.GetValue() if self.stkid == '' : wx.puts('please specify the stock id') return False if self.stkname == '': wx.puts('please specify the stock name') return True
def _main(): for s in ["NA.TO", "XBB.TO", "NOU.V", "AP-UN.TO", "BRK-A", "AAPL"]: print("=============================================") print("s: {}".format(s)) print("get_name: {}".format(ysq.get_name(s))) print("get_price: {}".format(ysq.get_price(s))) print("get_volume: {}".format(ysq.get_volume(s))) print("get_stock_exchange: {}".format(ysq.get_stock_exchange(s))) print("get_market_cap: {}".format(ysq.get_market_cap(s))) print("get_dividend_yield: {}".format(ysq.get_dividend_yield(s))) print("get_price_earnings_ratio: {}".format( ysq.get_price_earnings_ratio(s))) print("get_52_week_low: {}".format(ysq.get_52_week_low(s))) print("get_52_week_high: {}".format(ysq.get_52_week_high(s))) print("get_currency: {}".format(ysq.get_currency(s)))
def check_db(path): # Create data base: db = sdm.StockDBMgr('./stock_db/' + path, startdate, enddate) # db.update_all_symbols() inv = [] symbolList = db.get_all_symbols() print(len(symbolList)) print(symbolList) for s in symbolList: if False: print("symbol:{}, yield:{}, name:{}".format( s, sq.get_dividend_yield(s), sq.get_name(s))) if not db.validate_symbol_data(s): inv.append(s) continue # Only applies if recent download... if True: df = db.get_symbol_data(s) t = startdate if df is not None and len(df) > 0: # t = r[-1].date t = df.iloc[-1].name.date() else: inv.append(s) continue if (today - t) > datetime.timedelta(4): inv.append(s) print("%s: len = %d" % (s, len(df))) print("Invalid list:") for s in inv: print(s)
def add_stock(self, ticker, name=None, exchange=None, sector=None, industry=None): """ Add a stock to the stock database Add the stock to the symbols table and populate quotes table with all available historical quotes. If any of the optional parameters are left out, the corresponding information will be obtained from Yahoo! Finance. :param ticker: Stock ticker symbol :param name: (optional) Company/security name :param exchange: (optional) Exchange on which the security is traded :param sector: (optional) Company/security sector :param Industry (optional) Company/security industry """ ticker = ticker.lower() if name is None: name = quotes.get_name(ticker) if exchange is None: exchange = quotes.get_stock_exchange(ticker) if sector is None: sector = quotes.get_sector(ticker) if industry is None: industry = quotes.get_industry(ticker) stock = Symbol(ticker, name, exchange, sector, industry) session = self.db.Session() if self.check_stock_exists(ticker,session): print "Stock %s already exists!" % (ticker.upper()) else: print "Adding %s to database" % (ticker.upper()) session.add(stock) q = self._download_quotes(ticker, date(1900,01,01), date.today()) for quote in q: quote.Features = Indicator(quote.Id) session.add_all(q) session.commit() session.close() self.update_quotes(ticker)
def update_quotes(request): securities = Security.objects.all().exclude(symbol='CASH') for s in securities: symbol = s.symbol if s.name is None: name = ystockquote.get_name(symbol) s.name = name # -- get quote as float multiply by 100 to get cents, convert to int. price = int( float(ystockquote.get_price(symbol)) * 100 ) if price > 10000: continue s.last_price = price s.save() # update last price in held. try: hs = PortfolioHolding.objects.get(securities=s) hs.last_price = price hs.save() except: pass return HttpResponseRedirect(request.META['HTTP_REFERER'])
def test_ysq_get_name(s): assert len(ysq.get_name(s)) > 5