def test_position_order_returns_nothing_when_no_open_and_no_close_orders( self): trade_for_open = [ self.mock_trade(id=f"order{i}", amount=100, price=10, position="INVALID") for i in range(3) ] trades_for_close = [ self.mock_trade(id=f"order{i}", amount=100, price=10, position="INVALID") for i in range(2) ] self.assertIsNone( PerformanceMetrics.position_order(trade_for_open, trades_for_close)) trade_for_open[1].position = "OPEN" self.assertIsNone( PerformanceMetrics.position_order(trade_for_open, trades_for_close)) trade_for_open[1].position = "INVALID" trades_for_close[-1].position = "CLOSE" self.assertIsNone( PerformanceMetrics.position_order(trade_for_open, trades_for_close))
def test_position_order_returns_open_and_close_pair(self): trades_for_open = [self.mock_trade(id=f"order{i}", amount=100, price=10, position="INVALID") for i in range(3)] trades_for_close = [self.mock_trade(id=f"order{i}", amount=100, price=10, position="INVALID") for i in range(2)] trades_for_open[1].position = "OPEN" trades_for_close[-1].position = "CLOSE" selected_open, selected_close = PerformanceMetrics.position_order(trades_for_open.copy(), trades_for_close.copy()) self.assertEqual(selected_open, trades_for_open[1]) self.assertEqual(selected_close, trades_for_close[-1])