]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/blobdiff - portfolio.py
Fix infinite recursion during fetch
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git] / portfolio.py
index d8a546584afc4549be442e1593030ec82c5f0eef..9b27e261d0bfa93ab511e2c692cfc10f3ecd61f8 100644 (file)
@@ -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: