From 1b6768931337646d9b191087e7e0b8aa4c1c26b3 Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 19 Apr 2025 16:16:13 +0200 Subject: Add explicit partial buy test --- test_trade_queue.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test_trade_queue.py b/test_trade_queue.py index 5e0e434..72c1fda 100644 --- a/test_trade_queue.py +++ b/test_trade_queue.py @@ -233,6 +233,22 @@ class TestFIFOQueueMatchTrades(unittest.TestCase): # Sell trade amount self.assertEqual(matches[0][1].amount, Decimal(5)) + def test_partial_match_partial_buy_trade(self): + """Test if a single sell trade removes part of a buy trade.""" + self.fifo_queue.add_trade(Trade(Decimal(5), Decimal(50), "2025-04-19 10:00:00")) + self.fifo_queue.add_trade( + Trade(Decimal(-4), Decimal(-75), "2025-04-19 12:00:00") + ) + + matches = self.fifo_queue.match_trades() + + self.assertEqual(len(matches), 1) + # Buy trade amount + self.assertEqual(matches[0][0].amount, Decimal(4)) + # Sell trade amount + self.assertEqual(matches[0][1].amount, Decimal(4)) + self.assertEqual(self.fifo_queue.get_remaining_amount(), 1) + def test_error_single_buy_trade_invalid_order(self): """Test if a trade match fails if sell date is before buy date.""" self.fifo_queue.add_trade(Trade(Decimal(5), Decimal(50), "2025-04-19 10:00:00")) -- cgit v1.2.3