Example #1
0
def get_futures():
    date = get_db_date()
    quotes = futures.query_historical("VX", date)
    vix_quote = stocks.query_historical(["VIX"], date).get("VIX", 10)
    if vix_quote is None:
        return jsonify()

    data1 = [
        {
            "x": dates.business_dates_diff(date, quote.expiration),
            "y": quote.close,
            "name": quote.expiration.strftime("%b'%y"),
            "suffix": "%+.2f, %+.0f %%, " % (quote.close - vix_quote.close, (quote.close / vix_quote.close - 1) * 100),
        }
        for quote in quotes
    ]

    if len(data1) > 0:
        first_point = data1[0]
        first_point.update({"marker": {"enabled": "false"}})
        data2 = [{"x": 0, "y": vix_quote.close, "name": "VIX"}, first_point]
    else:
        data2 = []

    return jsonify({"part1": data1, "part2": data2})
Example #2
0
 def _check_database_quotes(self, symbol, total, check_date, total_date):
     with database.connect_db(TEST_DB_NAME) as db:
         db.execute('SELECT COUNT(*) FROM futures WHERE symbol=?;', [symbol])
         self.assertEqual(db.fetchall(), [(total,)])
     if total > 0:
         database_quotes = futures.query_historical(
             symbol, check_date, TEST_DB_NAME)
         self.assertEqual(len(database_quotes), total_date)
         self._check_quotes(database_quotes, symbol, check_date)
Example #3
0
 def test_query_historical_vx(self):
     test_date = date(2015, 12, 4)
     futures.fetch_historical('VX', TEST_DB_NAME)
     quotes = futures.query_historical('VX', test_date, TEST_DB_NAME)
     self._check_quotes(quotes, 'VX', test_date)