- 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")