X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=portfolio.py;h=bed43261d70d127c1e4aca08b5b3baf9e9bbdfef;hb=5f721612111af5c56b5757cb2f21da5f2fa388bf;hp=c064249af992bcd46a9f5e41f47cd3c1c5fff724;hpb=1902674cbeaa4dc0cdc31e6f0f7a548b3fa7f38e;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git diff --git a/portfolio.py b/portfolio.py index c064249..bed4326 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 = { @@ -582,14 +582,14 @@ class Order: self.mark_finished_order() def mark_dust_amount_remaining_order(self): - if self.market.ccxt.is_dust_trade(self.remaining_amount().value, self.rate): + if self.status == "open" and 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