X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=test.py;h=7ec8ba76fa28e2c74b1fb9dbf8209824c348ec80;hb=7bd830a83b662874c145ea9548edfde79eadc68f;hp=235f6189008ae7bf67cbf5c17600c153d14db618;hpb=065ee3422a6ee9d40136cfa6b272e951e15c2e50;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git diff --git a/test.py b/test.py index 235f618..7ec8ba7 100644 --- a/test.py +++ b/test.py @@ -781,55 +781,9 @@ class MarketTest(WebMockTestCase): self.assertEqual(D("0.01"), call[0][0]["XVG"].value) self.assertEqual(D("0.2525"), call[0][1]["BTC"].value) self.assertEqual(D("0.7575"), call[0][1]["XEM"].value) - m.report.log_stage.assert_called_once_with("prepare_trades") - m.report.log_balances.assert_called_once_with(tag="tag") - - @mock.patch.object(portfolio.Portfolio, "repartition") - @mock.patch.object(market.Market, "get_ticker") - @mock.patch.object(market.TradeStore, "compute_trades") - def test_update_trades(self, compute_trades, get_ticker, repartition): - repartition.return_value = { - "XEM": (D("0.75"), "long"), - "BTC": (D("0.25"), "long"), - } - def _get_ticker(c1, c2): - if c1 == "USDT" and c2 == "BTC": - return { "average": D("0.0001") } - if c1 == "XVG" and c2 == "BTC": - return { "average": D("0.000001") } - if c1 == "XEM" and c2 == "BTC": - return { "average": D("0.001") } - self.fail("Should be called with {}, {}".format(c1, c2)) - get_ticker.side_effect = _get_ticker - - with mock.patch("market.ReportStore"): - m = market.Market(self.ccxt) - self.ccxt.fetch_all_balances.return_value = { - "USDT": { - "exchange_free": D("10000.0"), - "exchange_used": D("0.0"), - "exchange_total": D("10000.0"), - "total": D("10000.0") - }, - "XVG": { - "exchange_free": D("10000.0"), - "exchange_used": D("0.0"), - "exchange_total": D("10000.0"), - "total": D("10000.0") - }, - } - - m.balances.fetch_balances(tag="tag") - - m.update_trades() - compute_trades.assert_called() - - call = compute_trades.call_args - self.assertEqual(1, call[0][0]["USDT"].value) - self.assertEqual(D("0.01"), call[0][0]["XVG"].value) - self.assertEqual(D("0.2525"), call[0][1]["BTC"].value) - self.assertEqual(D("0.7575"), call[0][1]["XEM"].value) - m.report.log_stage.assert_called_once_with("update_trades") + m.report.log_stage.assert_called_once_with("prepare_trades", + base_currency='BTC', compute_value='average', + liquidity='medium', only=None) m.report.log_balances.assert_called_once_with(tag="tag") @mock.patch.object(portfolio.Portfolio, "repartition") @@ -2356,12 +2310,24 @@ class ReportStoreTest(WebMockTestCase): @mock.patch.object(market.ReportStore, "add_log") def test_log_stage(self, add_log, print_log): report_store = market.ReportStore(self.m) - report_store.log_stage("foo") + c = lambda x: x + report_store.log_stage("foo", bar="baz", c=c, d=portfolio.Amount("BTC", 1)) print_log.assert_has_calls([ mock.call("-----------"), - mock.call("[Stage] foo"), + mock.call("[Stage] foo bar=baz, c=c = lambda x: x, d={'currency': 'BTC', 'value': Decimal('1')}"), ]) - add_log.assert_called_once_with({'type': 'stage', 'stage': 'foo'}) + add_log.assert_called_once_with({ + 'type': 'stage', + 'stage': 'foo', + 'args': { + 'bar': 'baz', + 'c': 'c = lambda x: x', + 'd': { + 'currency': 'BTC', + 'value': D('1') + } + } + }) @mock.patch.object(market.ReportStore, "print_log") @mock.patch.object(market.ReportStore, "add_log") @@ -3089,7 +3055,7 @@ class HelperTest(WebMockTestCase): mock.call(tag="process_sell_needed__2_buy_begin"), mock.call(tag="process_sell_needed__2_buy_end"), ]) - self.m.update_trades.assert_called_with(base_currency="BTC", + self.m.prepare_trades.assert_called_with(base_currency="BTC", liquidity="medium", only="acquire") self.m.trades.prepare_orders.assert_called_with(compute_value="average", only="acquire") @@ -3346,7 +3312,7 @@ class AcceptanceTest(WebMockTestCase): with mock.patch.object(portfolio.Portfolio, "repartition", return_value=repartition): # Action 5 - helper.update_trades(market, only="acquire", compute_value="average") + helper.prepare_trades(market, only="acquire", compute_value="average") balances = portfolio.BalanceStore.all self.assertEqual(portfolio.Amount("ETH", 1 / D("3")), balances["ETH"].total)