]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/commitdiff
Add method to print orders
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 22 Jan 2018 00:06:39 +0000 (01:06 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 22 Jan 2018 00:06:39 +0000 (01:06 +0100)
portfolio.py

index 00beab0ddd573474cc2f87fa44fd77e870e26018..1041df13a76ebad551646fa8e8209b822b89b26d 100644 (file)
@@ -407,6 +407,11 @@ class Trade:
         if verbose:
             print("All orders finished")
 
+    @classmethod
+    def update_all_orders_status(cls):
+        for order in cls.all_orders(state="open"):
+            order.get_status()
+
     def __repr__(self):
         return "Trade({} -> {} in {}, {})".format(
                 self.value_from,
@@ -414,8 +419,17 @@ class Trade:
                 self.currency,
                 self.action)
 
-class Order:
+    @classmethod
+    def print_all_with_order(cls):
+        for trade in cls.trades.values():
+            trade.print_with_order()
+
+    def print_with_order(self):
+        print(self)
+        for order in self.orders:
+            print("\t", order, sep="")
 
+class Order:
     def __init__(self, action, amount, rate, base_currency, market):
         self.action = action
         self.amount = amount
@@ -463,15 +477,15 @@ class Order:
             self.status = result["status"]
         return self.status
 
+    def cancel(self):
+        self.market.cancel_order(self.result['id'])
+
 def print_orders(market, base_currency="BTC"):
     Balance.prepare_trades(market, base_currency=base_currency, compute_value="average")
     Trade.prepare_orders(compute_value="average")
     for currency, balance in Balance.known_balances.items():
         print(balance)
-    for currency, trade in Trade.trades.items():
-        print(trade)
-        for order in trade.orders:
-            print("\t", order, sep="")
+    portfolio.Trade.print_all_with_order()
 
 def make_orders(market, base_currency="BTC"):
     Balance.prepare_trades(market, base_currency=base_currency)