aboutsummaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-04 12:59:57 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-04 12:59:57 +0100
commit17598517c544a3dda8b9f773dfeb669c886ea92b (patch)
treeeb02553743f2aa2cdd64e2b1cdd02d3c02d4a6cd /test.py
parent9db7d156833cd384baa64b6148b5c646bfcc41f8 (diff)
downloadTrader-17598517c544a3dda8b9f773dfeb669c886ea92b.tar.gz
Trader-17598517c544a3dda8b9f773dfeb669c886ea92b.tar.zst
Trader-17598517c544a3dda8b9f773dfeb669c886ea92b.zip
Add close trades action
Diffstat (limited to 'test.py')
-rw-r--r--test.py56
1 files changed, 50 insertions, 6 deletions
diff --git a/test.py b/test.py
index 7409212..78de76e 100644
--- a/test.py
+++ b/test.py
@@ -991,9 +991,9 @@ class TradeStoreTest(WebMockTestCase):
991 trade_mock2.prepare_order.return_value = 2 991 trade_mock2.prepare_order.return_value = 2
992 trade_mock3.prepare_order.return_value = 3 992 trade_mock3.prepare_order.return_value = 3
993 993
994 trade_mock1.is_fullfiled = False 994 trade_mock1.pending = True
995 trade_mock2.is_fullfiled = False 995 trade_mock2.pending = True
996 trade_mock3.is_fullfiled = True 996 trade_mock3.pending = False
997 997
998 trade_store.all.append(trade_mock1) 998 trade_store.all.append(trade_mock1)
999 trade_store.all.append(trade_mock2) 999 trade_store.all.append(trade_mock2)
@@ -1100,13 +1100,30 @@ class TradeStoreTest(WebMockTestCase):
1100 order_mock2.get_status.assert_called() 1100 order_mock2.get_status.assert_called()
1101 order_mock3.get_status.assert_called() 1101 order_mock3.get_status.assert_called()
1102 1102
1103 def test_close_trades(self):
1104 trade_mock1 = mock.Mock()
1105 trade_mock2 = mock.Mock()
1106 trade_mock3 = mock.Mock()
1107
1108 trade_store = market.TradeStore(self.m)
1109
1110 trade_store.all.append(trade_mock1)
1111 trade_store.all.append(trade_mock2)
1112 trade_store.all.append(trade_mock3)
1113
1114 trade_store.close_trades()
1115
1116 trade_mock1.close.assert_called_once_with()
1117 trade_mock2.close.assert_called_once_with()
1118 trade_mock3.close.assert_called_once_with()
1119
1103 def test_pending(self): 1120 def test_pending(self):
1104 trade_mock1 = mock.Mock() 1121 trade_mock1 = mock.Mock()
1105 trade_mock1.is_fullfiled = False 1122 trade_mock1.pending = True
1106 trade_mock2 = mock.Mock() 1123 trade_mock2 = mock.Mock()
1107 trade_mock2.is_fullfiled = False 1124 trade_mock2.pending = True
1108 trade_mock3 = mock.Mock() 1125 trade_mock3 = mock.Mock()
1109 trade_mock3.is_fullfiled = True 1126 trade_mock3.pending = False
1110 1127
1111 trade_store = market.TradeStore(self.m) 1128 trade_store = market.TradeStore(self.m)
1112 1129
@@ -1739,6 +1756,33 @@ class TradeTest(WebMockTestCase):
1739 self.assertEqual("\t\tMouvement 1", str(calls[3][1][0])) 1756 self.assertEqual("\t\tMouvement 1", str(calls[3][1][0]))
1740 self.assertEqual("\t\tMouvement 2", str(calls[4][1][0])) 1757 self.assertEqual("\t\tMouvement 2", str(calls[4][1][0]))
1741 1758
1759 def test_close(self):
1760 value_from = portfolio.Amount("BTC", "0.5")
1761 value_from.linked_to = portfolio.Amount("ETH", "10.0")
1762 value_to = portfolio.Amount("BTC", "1.0")
1763 trade = portfolio.Trade(value_from, value_to, "ETH", self.m)
1764
1765 trade.close()
1766
1767 self.assertEqual(True, trade.closed)
1768
1769 def test_pending(self):
1770 value_from = portfolio.Amount("BTC", "0.5")
1771 value_from.linked_to = portfolio.Amount("ETH", "10.0")
1772 value_to = portfolio.Amount("BTC", "1.0")
1773 trade = portfolio.Trade(value_from, value_to, "ETH", self.m)
1774
1775 trade.closed = True
1776 self.assertEqual(False, trade.pending)
1777
1778 trade.closed = False
1779 self.assertEqual(True, trade.pending)
1780
1781 order1 = mock.Mock()
1782 order1.filled_amount.return_value = portfolio.Amount("BTC", "0.5")
1783 trade.orders.append(order1)
1784 self.assertEqual(False, trade.pending)
1785
1742 def test__repr(self): 1786 def test__repr(self):
1743 value_from = portfolio.Amount("BTC", "0.5") 1787 value_from = portfolio.Amount("BTC", "0.5")
1744 value_from.linked_to = portfolio.Amount("ETH", "10.0") 1788 value_from.linked_to = portfolio.Amount("ETH", "10.0")