- @mock.patch.object(portfolio.Portfolio, "repartition")
- @mock.patch.object(market.Market, "get_ticker")
- @mock.patch.object(market.TradeStore, "compute_trades")
- def test_prepare_trades_to_sell_all(self, compute_trades, get_ticker, repartition):
- 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") }
- 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.prepare_trades_to_sell_all()
-
- repartition.assert_not_called()
- 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("1.01"), call[0][1]["BTC"].value)
- m.report.log_stage.assert_called_once_with("prepare_trades_to_sell_all")
- m.report.log_balances.assert_called_once_with(tag="tag")