]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/blobdiff - tests/test_market.py
Fix available balance when buying
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git] / tests / test_market.py
index c89025be021383625a810a5eb8e33efb82bed6dd..07188aca1d7c7344d315d0501f1740fe0ed4511b 100644 (file)
@@ -186,14 +186,17 @@ class MarketTest(WebMockTestCase):
                     return { "average": D("0.000001") }
                 if c1 == "ETH" and c2 == "BTC":
                     return { "average": D("0.1") }
+                if c1 == "FOO" and c2 == "BTC":
+                    return { "average": D("0.1") }
                 self.fail("Should not be called with {}, {}".format(c1, c2))
             get_ticker.side_effect = _get_ticker
 
             repartition.return_value = {
-                    "DOGE": (D("0.25"), "short"),
-                    "BTC": (D("0.25"), "long"),
-                    "ETH": (D("0.25"), "long"),
-                    "XMR": (D("0.25"), "long"),
+                    "DOGE": (D("0.20"), "short"),
+                    "BTC": (D("0.20"), "long"),
+                    "ETH": (D("0.20"), "long"),
+                    "XMR": (D("0.20"), "long"),
+                    "FOO": (D("0.20"), "long"),
                     }
             m = market.Market(self.ccxt, self.market_args())
             self.ccxt.fetch_all_balances.return_value = {
@@ -210,12 +213,12 @@ class MarketTest(WebMockTestCase):
                         "total": D("5.0")
                         },
                     "BTC": {
-                        "exchange_free": D("0.075"),
+                        "exchange_free": D("0.065"),
                         "exchange_used": D("0.02"),
-                        "exchange_total": D("0.095"),
-                        "margin_available": D("0.025"),
+                        "exchange_total": D("0.085"),
+                        "margin_available": D("0.035"),
                         "margin_in_position": D("0.01"),
-                        "margin_total": D("0.035"),
+                        "margin_total": D("0.045"),
                         "total": D("0.13")
                         },
                     "ETH": {
@@ -224,6 +227,12 @@ class MarketTest(WebMockTestCase):
                         "exchange_total": D("1.0"),
                         "total": D("1.0")
                         },
+                    "FOO": {
+                        "exchange_free": D("0.1"),
+                        "exchange_used": D("0.0"),
+                        "exchange_total": D("0.1"),
+                        "total": D("0.1"),
+                        },
                     }
 
             m.balances.fetch_balances(tag="tag")
@@ -236,12 +245,13 @@ class MarketTest(WebMockTestCase):
 
             self.assertEqual(portfolio.Amount("BTC", "-0.025"),
                     new_repartition["DOGE"] - values_in_base["DOGE"])
-            self.assertEqual(portfolio.Amount("BTC", "0.025"),
-                    new_repartition["ETH"] - values_in_base["ETH"])
             self.assertEqual(0,
-                    new_repartition["ZRC"] - values_in_base["ZRC"])
+                    new_repartition["ETH"] - values_in_base["ETH"])
+            self.assertIsNone(new_repartition.get("ZRC"))
             self.assertEqual(portfolio.Amount("BTC", "0.025"),
                     new_repartition["XMR"])
+            self.assertEqual(portfolio.Amount("BTC", "0.015"),
+                    new_repartition["FOO"] - values_in_base["FOO"])
 
         compute_trades.reset_mock()
         with self.subTest(available_balance_only=True, balance=0),\