@property
def is_fullfiled(self):
- return abs(self.filled_amount(in_base_currency=(not self.inverted))) >= abs(self.delta)
+ return abs(self.filled_amount(in_base_currency=(not self.inverted), refetch=True)) >= abs(self.delta)
- def filled_amount(self, in_base_currency=False):
+ def filled_amount(self, in_base_currency=False, refetch=False):
filled_amount = 0
for order in self.orders:
- filled_amount += order.filled_amount(in_base_currency=in_base_currency)
+ filled_amount += order.filled_amount(in_base_currency=in_base_currency, refetch=refetch)
return filled_amount
tick_actions = {
if self.market.ccxt.is_dust_trade(self.remaining_amount().value, self.rate):
self.status = "closed_dust_remaining"
- def remaining_amount(self):
- return self.amount - self.filled_amount()
+ def remaining_amount(self, refetch=False):
+ return self.amount - self.filled_amount(refetch=refetch)
- def filled_amount(self, in_base_currency=False):
- if self.status == "open":
+ def filled_amount(self, in_base_currency=False, refetch=False):
+ if refetch and self.status == "open":
self.fetch()
filled_amount = 0
for mouvement in self.mouvements:
self.assertTrue(trade.is_fullfiled)
- order1.filled_amount.assert_called_with(in_base_currency=True)
- order2.filled_amount.assert_called_with(in_base_currency=True)
- order3.filled_amount.assert_called_with(in_base_currency=True)
+ order1.filled_amount.assert_called_with(in_base_currency=True, refetch=True)
+ order2.filled_amount.assert_called_with(in_base_currency=True, refetch=True)
+ order3.filled_amount.assert_called_with(in_base_currency=True, refetch=True)
with self.subTest(inverted=True):
value_from = portfolio.Amount("BTC", "0.5")
self.assertTrue(trade.is_fullfiled)
- order1.filled_amount.assert_called_with(in_base_currency=False)
- order2.filled_amount.assert_called_with(in_base_currency=False)
- order3.filled_amount.assert_called_with(in_base_currency=False)
+ order1.filled_amount.assert_called_with(in_base_currency=False, refetch=True)
+ order2.filled_amount.assert_called_with(in_base_currency=False, refetch=True)
+ order3.filled_amount.assert_called_with(in_base_currency=False, refetch=True)
def test_filled_amount(self):
trade.orders.append(order2)
self.assertEqual(portfolio.Amount("ETH", "0.31"), trade.filled_amount())
- order1.filled_amount.assert_called_with(in_base_currency=False)
- order2.filled_amount.assert_called_with(in_base_currency=False)
+ order1.filled_amount.assert_called_with(in_base_currency=False, refetch=False)
+ order2.filled_amount.assert_called_with(in_base_currency=False, refetch=False)
self.assertEqual(portfolio.Amount("ETH", "0.31"), trade.filled_amount(in_base_currency=False))
- order1.filled_amount.assert_called_with(in_base_currency=False)
- order2.filled_amount.assert_called_with(in_base_currency=False)
+ order1.filled_amount.assert_called_with(in_base_currency=False, refetch=False)
+ order2.filled_amount.assert_called_with(in_base_currency=False, refetch=False)
self.assertEqual(portfolio.Amount("ETH", "0.31"), trade.filled_amount(in_base_currency=True))
- order1.filled_amount.assert_called_with(in_base_currency=True)
- order2.filled_amount.assert_called_with(in_base_currency=True)
+ order1.filled_amount.assert_called_with(in_base_currency=True, refetch=False)
+ order2.filled_amount.assert_called_with(in_base_currency=True, refetch=False)
@mock.patch.object(portfolio.Computation, "compute_value")
@mock.patch.object(portfolio.Trade, "filled_amount")
fetch.assert_not_called()
order.status = "open"
self.assertEqual(portfolio.Amount("ETH", 5), order.filled_amount(in_base_currency=False))
+ fetch.assert_not_called()
+ self.assertEqual(portfolio.Amount("ETH", 5), order.filled_amount(in_base_currency=False, refetch=True))
fetch.assert_called_once()
self.assertEqual(portfolio.Amount("BTC", "0.7"), order.filled_amount(in_base_currency=True))