def get_history(): # TODO: stock history doesn't show ETH request_date = get_db_date() current_date = dates.get_current_timestamp().date() with database.connect_db() as db: db.row_factory = stocks.quote_factory symbols = ["VIX", "VXST", "VXV", "VXMT", "VVIX", "SPX", "XIV", "TLT"] query_dates = [database.encode_date(request_date - timedelta(days=30)), database.encode_date(request_date)] db.execute( "SELECT * FROM stocks WHERE stocks.symbol IN (%s) " "AND stocks.date BETWEEN ? and ? " "ORDER BY symbol, date;" % ",".join("?" * len(symbols)), symbols + query_dates, ) quotes = db.fetchall() data = {} for symbol, quotes in groupby(quotes, key=itemgetter(0)): quotes = list(quotes) if symbol in ["VIX", "VXST", "VXV", "VXMT", "VVIX"]: data[symbol] = [ { "y": quote.close, "name": quote.date.strftime("%d.%m.%Y"), "xlabel": _get_xlabel1(current_date, quote), "suffix": ("%+.2f" % (quote.close - prev_quote.close)), } for quote, prev_quote in izip(quotes[-10:], quotes[-11:-1]) ] else: data[symbol] = [ { "y": quote.close, "name": quote.date.strftime("%d.%m.%Y"), "xlabel": _get_xlabel2(current_date, quote, prev_quote), "suffix": "%+.2f %%" % ((quote.close / prev_quote.close - 1) * 100), } for quote, prev_quote in izip(quotes[-20:], quotes[-21:-1]) ] return jsonify(data)
def get_dates(): date = request.args.get("date", None, type=str) current_date = dates.get_current_timestamp().date() if date is not None: try: date = datetime.strptime(date, "%Y-%m-%d").date() date = min(date, current_date) except ValueError: date = current_date data = {"date": date.strftime("%d.%m.%Y")} for name, lst in EXPIRATIONS.items(): pos = bisect.bisect_left(lst, date) if pos != len(lst): days_left = dates.business_dates_diff(date, lst[pos]) if days_left == 0: data[name] = "<strong>today</strong>" elif days_left == 1: data[name] = "<strong>tomorrow</strong>" else: data[name] = "in <strong>%d</strong> days" % days_left else: data[name] = "" return jsonify(data)
def test_no_tz(self): self.assertIsNone(dates.get_current_timestamp().tzinfo)