aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--market.py3
-rw-r--r--portfolio.py14
-rw-r--r--tests/test_market.py2
-rw-r--r--tests/test_portfolio.py26
4 files changed, 24 insertions, 21 deletions
diff --git a/market.py b/market.py
index 7996a58..3b6543a 100644
--- a/market.py
+++ b/market.py
@@ -96,7 +96,8 @@ class Market:
96 elif after: 96 elif after:
97 self.processor.process(action, steps="after") 97 self.processor.process(action, steps="after")
98 except Exception as e: 98 except Exception as e:
99 self.report.log_error("market_process", exception=e) 99 import traceback
100 self.report.log_error("market_process", exception=e, message=traceback.format_exc())
100 finally: 101 finally:
101 self.store_report() 102 self.store_report()
102 103
diff --git a/portfolio.py b/portfolio.py
index d8a5465..9b27e26 100644
--- a/portfolio.py
+++ b/portfolio.py
@@ -261,12 +261,12 @@ class Trade:
261 261
262 @property 262 @property
263 def is_fullfiled(self): 263 def is_fullfiled(self):
264 return abs(self.filled_amount(in_base_currency=(not self.inverted))) >= abs(self.delta) 264 return abs(self.filled_amount(in_base_currency=(not self.inverted), refetch=True)) >= abs(self.delta)
265 265
266 def filled_amount(self, in_base_currency=False): 266 def filled_amount(self, in_base_currency=False, refetch=False):
267 filled_amount = 0 267 filled_amount = 0
268 for order in self.orders: 268 for order in self.orders:
269 filled_amount += order.filled_amount(in_base_currency=in_base_currency) 269 filled_amount += order.filled_amount(in_base_currency=in_base_currency, refetch=refetch)
270 return filled_amount 270 return filled_amount
271 271
272 tick_actions = { 272 tick_actions = {
@@ -585,11 +585,11 @@ class Order:
585 if self.market.ccxt.is_dust_trade(self.remaining_amount().value, self.rate): 585 if self.market.ccxt.is_dust_trade(self.remaining_amount().value, self.rate):
586 self.status = "closed_dust_remaining" 586 self.status = "closed_dust_remaining"
587 587
588 def remaining_amount(self): 588 def remaining_amount(self, refetch=False):
589 return self.amount - self.filled_amount() 589 return self.amount - self.filled_amount(refetch=refetch)
590 590
591 def filled_amount(self, in_base_currency=False): 591 def filled_amount(self, in_base_currency=False, refetch=False):
592 if self.status == "open": 592 if refetch and self.status == "open":
593 self.fetch() 593 self.fetch()
594 filled_amount = 0 594 filled_amount = 0
595 for mouvement in self.mouvements: 595 for mouvement in self.mouvements:
diff --git a/tests/test_market.py b/tests/test_market.py
index 37c009b..0211638 100644
--- a/tests/test_market.py
+++ b/tests/test_market.py
@@ -890,7 +890,7 @@ class MarketTest(WebMockTestCase):
890 process.side_effect = Exception("bouh") 890 process.side_effect = Exception("bouh")
891 891
892 m.process(["some_action"], before=True) 892 m.process(["some_action"], before=True)
893 log_error.assert_called_with("market_process", exception=mock.ANY) 893 log_error.assert_called_with("market_process", exception=mock.ANY, message=mock.ANY)
894 store_report.assert_called_once() 894 store_report.assert_called_once()
895 895
896 896
diff --git a/tests/test_portfolio.py b/tests/test_portfolio.py
index 969f5d4..6ca3327 100644
--- a/tests/test_portfolio.py
+++ b/tests/test_portfolio.py
@@ -142,9 +142,9 @@ class TradeTest(WebMockTestCase):
142 142
143 self.assertTrue(trade.is_fullfiled) 143 self.assertTrue(trade.is_fullfiled)
144 144
145 order1.filled_amount.assert_called_with(in_base_currency=True) 145 order1.filled_amount.assert_called_with(in_base_currency=True, refetch=True)
146 order2.filled_amount.assert_called_with(in_base_currency=True) 146 order2.filled_amount.assert_called_with(in_base_currency=True, refetch=True)
147 order3.filled_amount.assert_called_with(in_base_currency=True) 147 order3.filled_amount.assert_called_with(in_base_currency=True, refetch=True)
148 148
149 with self.subTest(inverted=True): 149 with self.subTest(inverted=True):
150 value_from = portfolio.Amount("BTC", "0.5") 150 value_from = portfolio.Amount("BTC", "0.5")
@@ -169,9 +169,9 @@ class TradeTest(WebMockTestCase):
169 169
170 self.assertTrue(trade.is_fullfiled) 170 self.assertTrue(trade.is_fullfiled)
171 171
172 order1.filled_amount.assert_called_with(in_base_currency=False) 172 order1.filled_amount.assert_called_with(in_base_currency=False, refetch=True)
173 order2.filled_amount.assert_called_with(in_base_currency=False) 173 order2.filled_amount.assert_called_with(in_base_currency=False, refetch=True)
174 order3.filled_amount.assert_called_with(in_base_currency=False) 174 order3.filled_amount.assert_called_with(in_base_currency=False, refetch=True)
175 175
176 176
177 def test_filled_amount(self): 177 def test_filled_amount(self):
@@ -189,16 +189,16 @@ class TradeTest(WebMockTestCase):
189 trade.orders.append(order2) 189 trade.orders.append(order2)
190 190
191 self.assertEqual(portfolio.Amount("ETH", "0.31"), trade.filled_amount()) 191 self.assertEqual(portfolio.Amount("ETH", "0.31"), trade.filled_amount())
192 order1.filled_amount.assert_called_with(in_base_currency=False) 192 order1.filled_amount.assert_called_with(in_base_currency=False, refetch=False)
193 order2.filled_amount.assert_called_with(in_base_currency=False) 193 order2.filled_amount.assert_called_with(in_base_currency=False, refetch=False)
194 194
195 self.assertEqual(portfolio.Amount("ETH", "0.31"), trade.filled_amount(in_base_currency=False)) 195 self.assertEqual(portfolio.Amount("ETH", "0.31"), trade.filled_amount(in_base_currency=False))
196 order1.filled_amount.assert_called_with(in_base_currency=False) 196 order1.filled_amount.assert_called_with(in_base_currency=False, refetch=False)
197 order2.filled_amount.assert_called_with(in_base_currency=False) 197 order2.filled_amount.assert_called_with(in_base_currency=False, refetch=False)
198 198
199 self.assertEqual(portfolio.Amount("ETH", "0.31"), trade.filled_amount(in_base_currency=True)) 199 self.assertEqual(portfolio.Amount("ETH", "0.31"), trade.filled_amount(in_base_currency=True))
200 order1.filled_amount.assert_called_with(in_base_currency=True) 200 order1.filled_amount.assert_called_with(in_base_currency=True, refetch=False)
201 order2.filled_amount.assert_called_with(in_base_currency=True) 201 order2.filled_amount.assert_called_with(in_base_currency=True, refetch=False)
202 202
203 @mock.patch.object(portfolio.Computation, "compute_value") 203 @mock.patch.object(portfolio.Computation, "compute_value")
204 @mock.patch.object(portfolio.Trade, "filled_amount") 204 @mock.patch.object(portfolio.Trade, "filled_amount")
@@ -863,6 +863,8 @@ class OrderTest(WebMockTestCase):
863 fetch.assert_not_called() 863 fetch.assert_not_called()
864 order.status = "open" 864 order.status = "open"
865 self.assertEqual(portfolio.Amount("ETH", 5), order.filled_amount(in_base_currency=False)) 865 self.assertEqual(portfolio.Amount("ETH", 5), order.filled_amount(in_base_currency=False))
866 fetch.assert_not_called()
867 self.assertEqual(portfolio.Amount("ETH", 5), order.filled_amount(in_base_currency=False, refetch=True))
866 fetch.assert_called_once() 868 fetch.assert_called_once()
867 self.assertEqual(portfolio.Amount("BTC", "0.7"), order.filled_amount(in_base_currency=True)) 869 self.assertEqual(portfolio.Amount("BTC", "0.7"), order.filled_amount(in_base_currency=True))
868 870