X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=portfolio.py;h=9b27e261d0bfa93ab511e2c692cfc10f3ecd61f8;hb=8a87fda40d24e3048809990f965c07d4a1e7559e;hp=c064249af992bcd46a9f5e41f47cd3c1c5fff724;hpb=1902674cbeaa4dc0cdc31e6f0f7a548b3fa7f38e;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git diff --git a/portfolio.py b/portfolio.py index c064249..9b27e26 100644 --- a/portfolio.py +++ b/portfolio.py @@ -261,12 +261,12 @@ class Trade: @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 = { @@ -585,11 +585,11 @@ class Order: 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: @@ -616,7 +616,7 @@ class Order: self.market.report.log_debug_action("Mark {} as cancelled".format(self)) self.status = "canceled" return - if self.open and self.id is not None: + if (self.status == "closed_dust_remaining" or self.open) and self.id is not None: try: self.market.ccxt.cancel_order(self.id) except OrderNotFound as e: # Closed inbetween