def test_aggregated_position_with_two_related_trades_from_three(self): trades = [] trades.append(self.mock_trade(id="order1", amount=100, price=10)) trades.append(self.mock_trade(id="order2", amount=200, price=15)) trades.append(self.mock_trade(id="order1", amount=300, price=20)) aggregated_buys, aggregated_sells = PerformanceMetrics.aggregate_position_order( trades, []) self.assertEqual(len(aggregated_buys), 2) trade = aggregated_buys[0] self.assertTrue(trade.order_id == "order1" and trade.amount == 400 and trade.price == 15) self.assertEqual(aggregated_buys[1], trades[1]) self.assertEqual(len(aggregated_sells), 0) trades = [] trades.append(self.mock_trade(id="order1", amount=100, price=10)) trades.append(self.mock_trade(id="order2", amount=200, price=15)) trades.append(self.mock_trade(id="order1", amount=300, price=20)) aggregated_buys, aggregated_sells = PerformanceMetrics.aggregate_position_order( [], trades) self.assertEqual(len(aggregated_buys), 0) self.assertEqual(len(aggregated_sells), 2) trade = aggregated_sells[0] self.assertTrue(trade.order_id == "order1" and trade.amount == 400 and trade.price == 15) self.assertEqual(aggregated_sells[1], trades[1])
def test_aggregated_position_for_unrelated_trades(self): trades = [] trades.append(self.mock_trade(id="order1", amount=100, price=10)) trades.append(self.mock_trade(id="order2", amount=200, price=15)) trades.append(self.mock_trade(id="order3", amount=300, price=20)) aggregated_buys, aggregated_sells = PerformanceMetrics.aggregate_position_order(trades, []) self.assertEqual(aggregated_buys, trades) self.assertEqual(len(aggregated_sells), 0) aggregated_buys, aggregated_sells = PerformanceMetrics.aggregate_position_order([], trades) self.assertEqual(len(aggregated_buys), 0) self.assertEqual(aggregated_sells, trades)
def test_aggregated_position_with_no_trades(self): aggregated_buys, aggregated_sells = PerformanceMetrics.aggregate_position_order( [], []) self.assertEqual(len(aggregated_buys), 0) self.assertEqual(len(aggregated_sells), 0)