Esempio n. 1
0
    def test_buy_fit_sellers(self):
        m = Market()
        c = m.companies[0]
        m.trade_queue[c][OrderType.SELL][90].append(Order(c, 90, 5, OrderType.SELL))
        m.trade_queue[c][OrderType.SELL][80].append(Order(c, 80, 25, OrderType.SELL))

        m.buy(c, 100, 30)

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

        m.buy(c, 100, 1)

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

        m.buy(c, 100, 30)

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