diff options
author | uvok | 2025-04-19 16:16:13 +0200 |
---|---|---|
committer | uvok | 2025-04-19 16:16:13 +0200 |
commit | 1b6768931337646d9b191087e7e0b8aa4c1c26b3 (patch) | |
tree | f4dec21fed63950e1eea49788e529abf990d5bc6 | |
parent | e502987d3aba7b96c137344596bebf2cdc3f7b18 (diff) |
Add explicit partial buy test
-rw-r--r-- | test_trade_queue.py | 16 |
1 files changed, 16 insertions, 0 deletions
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")) |