Exemplo n.º 1
0
def save_quote(db, quote):
    """Saves quote to database"""
    expiration = database.encode_date(quote.expiration)
    date = database.encode_date(quote.date)
    time = database.encode_time(quote.time)
    db.execute('UPDATE futures SET time=?, close=? WHERE symbol=? ' \
               'AND expiration=? AND date=?;',
               [time, quote.close, quote.symbol, expiration, date])
    if db.rowcount == 0:
        db.execute('INSERT INTO futures VALUES (?, ?, ?, ?, ?);',
                   [quote.symbol, expiration, date, time, quote.close])
Exemplo n.º 2
0
def save_quote(db, quote):
    """Saves quote to database"""
    expiration = database.encode_date(quote.expiration)
    date = database.encode_date(quote.date)
    time = database.encode_time(quote.time)
    db.execute('UPDATE options SET time=?, bid=?, ask=?, stock=?, ' \
               'iv_bid=?, iv_ask=? ' \
               'WHERE symbol=? AND type=? AND expiration=? ' \
               'AND strike=? AND date=?;', [time, quote.bid, quote.ask,
                quote.stock, quote.iv_bid, quote.iv_ask, quote.symbol,
                quote.type, expiration, quote.strike, date])
    if db.rowcount == 0:
        db.execute('INSERT INTO options VALUES ' \
                   '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);',
                   [quote.symbol, quote.type, expiration, quote.strike,
                    date, time, quote.bid, quote.ask, quote.stock,
                    quote.iv_bid, quote.iv_ask])
Exemplo n.º 3
0
 def test_time_none(self):
     self.assertIsNone(database.encode_time(None))
     self.assertIsNone(database.decode_time(None))
Exemplo n.º 4
0
 def test_time(self):
     time = datetime.time(18, 55)
     self.assertEqual(database.decode_time(database.encode_time(time)), time)