Exemplo n.º 1
0
    def test_find_latest(self):
        d = DataStore()
        now = datetime.utcnow()
        new_entry = Trade(symbol="TEST",
                          quantity=100,
                          price=100.0,
                          trade_type=BUY,
                          timestamp=now)
        old_entry = Trade(symbol="TEST",
                          quantity=100,
                          price=1.0,
                          trade_type=BUY,
                          timestamp=now - timedelta(minutes=10))

        d.append(new_entry)
        d.append(old_entry)

        entries = d.find(symbol="TEST", timestamp=now - timedelta(minutes=5))
        expected = [
            Trade(symbol="TEST",
                  quantity=100,
                  price=100.0,
                  trade_type=BUY,
                  timestamp=now)
        ]

        self.assertEquals(entries, expected)
Exemplo n.º 2
0
    def test_all_share_index(self):
        now = datetime.utcnow()
        entry = Trade(symbol="common",
                      quantity=1,
                      price=100.0,
                      trade_type=BUY,
                      timestamp=now)
        self.model.record(entry)
        entry = Trade(symbol="preferred",
                      quantity=1,
                      price=4.0,
                      trade_type=BUY,
                      timestamp=now)
        self.model.record(entry)

        all_share_index = self.model.all_share_index()
        self.assertEqual(all_share_index, 20.0)
Exemplo n.º 3
0
 def test_record_fails_for_non_exisant_stock(self):
     with self.assertRaises(NoSuchStockException):
         entry = Trade(symbol="fake stock",
                       quantity=100,
                       price=100.0,
                       trade_type=SELL,
                       timestamp=datetime.utcnow())
         self.model.record(entry)
Exemplo n.º 4
0
 def test_record_sell_trade(self):
     new_entry = Trade(symbol="common",
                       quantity=100,
                       price=100.0,
                       trade_type=SELL,
                       timestamp=datetime.utcnow())
     self.model.record(new_entry)
     self.assertEqual(self.model.count, 1)
Exemplo n.º 5
0
 def test_insert_entry(self):
     d = DataStore()
     new_entry = Trade(symbol="TEST",
                       quantity=100,
                       price=100.0,
                       trade_type=BUY,
                       timestamp=datetime.utcnow())
     d.append(new_entry)
     self.assertEqual(d.count, 1)
Exemplo n.º 6
0
    def test_volume_weighted_price(self):
        now = datetime.utcnow()
        for t in range(1, 5):
            entry = Trade(symbol="common",
                          quantity=100,
                          price=100.0,
                          trade_type=BUY,
                          timestamp=now - timedelta(minutes=t))
            self.model.record(entry)

        very_old_entry = Trade(symbol="common",
                               quantity=100,
                               price=200.0,
                               trade_type=BUY,
                               timestamp=now - timedelta(minutes=6))
        self.model.record(very_old_entry)

        volume_weighted_price = self.model.volume_weighted_price(
            symbol="common")
        self.assertEqual(volume_weighted_price, 100.0)
Exemplo n.º 7
0
    def test_find_trade(self):
        d = DataStore()
        new_entry = Trade(symbol="TEST",
                          quantity=100,
                          price=100.0,
                          trade_type=BUY,
                          timestamp=datetime.utcnow())
        d.append(new_entry)

        entry = d.find(symbol="TEST")
        self.assertNotEquals(entry, [])
Exemplo n.º 8
0
    def test_default_model(self):
        now = datetime.utcnow()
        for symbol in ['TEA', 'POP', 'ALE', 'GIN', 'JOE']:
            entry = Trade(symbol=symbol,
                          quantity=1,
                          price=2.0,
                          trade_type=BUY,
                          timestamp=now)
            default_model.record(entry)

        all_share_index = default_model.all_share_index()
        self.assertEqual(all_share_index, 2.0)