]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/blobdiff - tests/test_store.py
Add USDT rate to balances
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git] / tests / test_store.py
index ee7e06349c4816263728b5c0d0504bb397e5018e..d7620a01fa204b3805e757ad232d3c300df78ada 100644 (file)
@@ -380,7 +380,7 @@ class BalanceStoreTest(WebMockTestCase):
             balance_store.fetch_balances(tag="foo")
             self.assertEqual(0, balance_store.all["ETC"].total)
             self.assertListEqual(["USDT", "XVG", "XMR", "ETC"], list(balance_store.currencies()))
-            self.m.report.log_balances.assert_called_with(tag="foo")
+            self.m.report.log_balances.assert_called_with(tag="foo", checkpoint=None)
 
         with self.subTest(log_tickers=True),\
                 mock.patch.object(balance_store, "in_currency") as in_currency:
@@ -388,11 +388,10 @@ class BalanceStoreTest(WebMockTestCase):
             balance_store.fetch_balances(log_tickers=True, ticker_currency="FOO",
                     ticker_compute_value="compute", ticker_type="type")
             self.m.report.log_balances.assert_called_with(compute_value='compute',
-                    tag=None, ticker_currency='FOO', tickers='tickers',
+                    tag=None, checkpoint=None, ticker_currency='FOO', tickers='tickers',
                     type='type')
 
         balance_store = market.BalanceStore(self.m)
-
         with self.subTest(add_portfolio=True),\
                 mock.patch.object(market.Portfolio, "repartition") as repartition:
             repartition.return_value = {
@@ -402,6 +401,37 @@ class BalanceStoreTest(WebMockTestCase):
             balance_store.fetch_balances(add_portfolio=True)
             self.assertListEqual(["USDT", "XVG", "XMR", "DOGE"], list(balance_store.currencies()))
 
+        self.m.ccxt.fetch_all_balances.return_value = {
+                "ETC": {
+                    "exchange_free": 0,
+                    "exchange_used": 0,
+                    "exchange_total": 0,
+                    "margin_total": 0,
+                    },
+                "XVG": {
+                    "exchange_free": 16,
+                    "exchange_used": 0,
+                    "exchange_total": 16,
+                    "margin_total": 0,
+                    },
+                "XMR": {
+                    "exchange_free": 0,
+                    "exchange_used": 0,
+                    "exchange_total": 0,
+                    "margin_total": D("-1.0"),
+                    "margin_free": 0,
+                    },
+                }
+
+        balance_store = market.BalanceStore(self.m)
+        with self.subTest(add_usdt=True),\
+                mock.patch.object(market.Portfolio, "repartition") as repartition:
+            repartition.return_value = {
+                    "DOGE": D("0.5"),
+                    "ETH": D("0.5"),
+                    }
+            balance_store.fetch_balances(add_usdt=True)
+            self.assertListEqual(["XVG", "XMR", "USDT"], list(balance_store.currencies()))
 
     @mock.patch.object(market.Portfolio, "repartition")
     def test_dispatch_assets(self, repartition):
@@ -425,7 +455,7 @@ class BalanceStoreTest(WebMockTestCase):
         self.assertEqual(D("2.6"), amounts["BTC"].value)
         self.assertEqual(D("7.5"), amounts["XEM"].value)
         self.assertEqual(D("-1.0"), amounts["DASH"].value)
-        self.m.report.log_balances.assert_called_with(tag=None)
+        self.m.report.log_balances.assert_called_with(tag=None, checkpoint=None)
         self.m.report.log_dispatch.assert_called_once_with(portfolio.Amount("BTC",
             "11.1"), amounts, "medium", repartition_hash)
 
@@ -617,12 +647,14 @@ class ReportStoreTest(WebMockTestCase):
                 ])
             add_log.assert_called_once_with({
                 'type': 'balance',
+                'checkpoint': None,
                 'balances': 'json',
                 'tag': 'tag'
                 })
             add_redis_status.assert_called_once_with({
                 'type': 'balance',
                 'balances': 'json',
+                'checkpoint': None,
                 'tag': 'tag'
                 })
         add_log.reset_mock()
@@ -639,6 +671,7 @@ class ReportStoreTest(WebMockTestCase):
                     type="total")
             add_log.assert_called_once_with({
                 'type': 'balance',
+                'checkpoint': None,
                 'balances': 'json',
                 'tag': 'tag',
                 'tickers': {
@@ -658,6 +691,7 @@ class ReportStoreTest(WebMockTestCase):
                 })
             add_redis_status.assert_called_once_with({
                 'type': 'balance',
+                'checkpoint': None,
                 'balances': 'json',
                 'tag': 'tag',
                 'tickers': {