]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/commitdiff
Fix bid/ask to sell/buy in orders
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 22 Jan 2018 00:06:13 +0000 (01:06 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 22 Jan 2018 00:06:13 +0000 (01:06 +0100)
portfolio.py
test.py

index 20f83e444894320d30bcd97c41fabbd286abeca5..00beab0ddd573474cc2f87fa44fd77e870e26018 100644 (file)
@@ -348,9 +348,9 @@ class Trade:
 
     def order_action(self, inverted):
         if self.value_from < self.value_to:
-            return "ask" if not inverted else "bid"
+            return "buy" if not inverted else "sell"
         else:
-            return "bid" if not inverted else "ask"
+            return "sell" if not inverted else "buy"
 
     def prepare_order(self, compute_value="default"):
         if self.action is None:
diff --git a/test.py b/test.py
index 25898961aa2f3729a6c205ce7a32ec764cbe784f..1b8a109ce64d6286541c88a86b86ccc0d288638d 100644 (file)
--- a/test.py
+++ b/test.py
@@ -665,11 +665,11 @@ class AcceptanceTest(unittest.TestCase):
         def create_order(symbol, type, action, amount, price=None):
             self.assertEqual("limit", type)
             if symbol == "ETH/BTC":
-                self.assertEqual("bid", action)
+                self.assertEqual("sell", action)
                 self.assertEqual(2, 3*amount)
                 self.assertEqual(D("0.14014"), price)
             elif symbol == "XVG/BTC":
-                self.assertEqual("bid", action)
+                self.assertEqual("sell", action)
                 self.assertEqual(1000, amount)
                 self.assertEqual(D("0.00003003"), price)
             else:
@@ -755,19 +755,22 @@ class AcceptanceTest(unittest.TestCase):
         self.assertEqual("sell", trades["XVG"].action)
 
         # Action 6
-        portfolio.Trade.prepare_orders(only="buy", compute_value=lambda x, y: x["ask"] * D("0.999"))
+        portfolio.Trade.prepare_orders(only="buy", compute_value=lambda x, y: x["ask"])
+
 
         all_orders = portfolio.Trade.all_orders(state="pending")
         self.assertEqual(3, len(all_orders))
-        self.assertEqual(portfolio.Amount("ETC", D("15.4")), all_orders[0].amount)
-        self.assertEqual(D("0.002997"), all_orders[0].rate)
-        self.assertEqual("ask", all_orders[0].action)
-        self.assertEqual(portfolio.Amount("BTD", D("9.7")), all_orders[1].amount)
-        self.assertEqual(D("0.0011988"), all_orders[1].rate)
-        self.assertEqual("ask", all_orders[1].action)
+        self.assertEqual(portfolio.Amount("ETC", D("38.5")/3), all_orders[0].amount)
+        self.assertEqual(D("0.003"), all_orders[0].rate)
+        self.assertEqual("buy", all_orders[0].action)
+
+        self.assertEqual(portfolio.Amount("BTD", D("24.25")/3), all_orders[1].amount)
+        self.assertEqual(D("0.0012"), all_orders[1].rate)
+        self.assertEqual("buy", all_orders[1].action)
+
         self.assertEqual(portfolio.Amount("BTC", D("0.0097")), all_orders[2].amount)
-        self.assertEqual(D("15984"), all_orders[2].rate)
-        self.assertEqual("bid", all_orders[2].action)
+        self.assertEqual(D("16000"), all_orders[2].rate)
+        self.assertEqual("sell", all_orders[2].action)
 
         with mock.patch.object(portfolio.time, "sleep") as sleep:
             # Action 7