Esempio n. 1
0
    def test_sell_fit_buyers(self):
        m = Market()
        c = m.companies[0]
        m.trade_queue[c][OrderType.BUY][110].append(Order(c, 110, 5, OrderType.BUY))
        m.trade_queue[c][OrderType.BUY][120].append(Order(c, 120, 25, OrderType.BUY))

        m.sell(c, 100, 30)

        self.assertEqual(len(m.trade_queue[c][OrderType.SELL][100]), 0)
        self.assertEqual(len(m.trade_queue[c][OrderType.BUY][110]), 0)
        self.assertEqual(len(m.trade_queue[c][OrderType.BUY][120]), 0)
Esempio n. 2
0
    def test_sell_but_queued(self):
        m = Market()
        c = m.companies[0]

        m.sell(c, 100, 1)

        self.assertEqual(len(m.trade_queue[c][OrderType.SELL][100]), 1)

        order = m.trade_queue[c][OrderType.SELL][100][0]
        self.assertEqual(order.price, 100)
        self.assertEqual(order.amount, 1)
Esempio n. 3
0
    def test_sell_when_less_buyers(self):
        m = Market()
        c = m.companies[0]
        m.trade_queue[c][OrderType.BUY][110].append(Order(c, 110, 5, OrderType.BUY))

        m.sell(c, 100, 30)

        self.assertEqual(len(m.trade_queue[c][OrderType.BUY][110]), 0)
        self.assertEqual(len(m.trade_queue[c][OrderType.SELL][100]), 1)

        order = m.trade_queue[c][OrderType.SELL][100][0]
        self.assertEqual(order.price, 100)
        self.assertEqual(order.amount, 25)