From deb8924cc60f0d64575657399f4fe112ff1cfb31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 21 Jan 2018 15:17:48 +0100 Subject: Add compute value lambdas for currency conversion --- test.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'test.py') diff --git a/test.py b/test.py index fde3a06..a9baadf 100644 --- a/test.py +++ b/test.py @@ -22,6 +22,8 @@ class AmountTest(unittest.TestCase): with mock.patch.object(portfolio.Trade, 'get_ticker', new=ticker_mock): ticker_mock.return_value = { + "bid": D("0.2"), + "ask": D("0.4"), "average": D("0.3"), "foo": "bar", } @@ -32,6 +34,12 @@ class AmountTest(unittest.TestCase): self.assertEqual(amount, converted_amount.linked_to) self.assertEqual("bar", converted_amount.ticker["foo"]) + converted_amount = amount.in_currency("ETH", None, action="bid", compute_value="default") + self.assertEqual(D("2"), converted_amount.value) + + converted_amount = amount.in_currency("ETH", None, compute_value="ask") + self.assertEqual(D("4"), converted_amount.value) + def test__abs(self): amount = portfolio.Amount("SC", -120) self.assertEqual(120, abs(amount).value) @@ -295,11 +303,11 @@ class BalanceTest(unittest.TestCase): self.assertEqual(D("0.65"), amounts["BTC"].value) self.assertEqual(D("0.30"), amounts["ETH"].value) - amounts = portfolio.Balance.in_currency("BTC", market, action="bid") + amounts = portfolio.Balance.in_currency("BTC", market, compute_value="bid") self.assertEqual(D("0.65"), amounts["BTC"].value) self.assertEqual(D("0.27"), amounts["ETH"].value) - amounts = portfolio.Balance.in_currency("BTC", market, action="bid", type="used") + amounts = portfolio.Balance.in_currency("BTC", market, compute_value="bid", type="used") self.assertEqual(D("0.30"), amounts["BTC"].value) self.assertEqual(0, amounts["ETH"].value) @@ -344,10 +352,16 @@ class BalanceTest(unittest.TestCase): "XEM": 7500, "BTC": 2500, } - get_ticker.side_effect = [ - { "average": D("0.0001") }, - { "average": D("0.000001") } - ] + def _get_ticker(c1, c2, market): + 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") } + raise Exception("Should be called with {}, {}".format(c1, c2)) + get_ticker.side_effect = _get_ticker + market = mock.Mock() market.fetch_balance.return_value = { "USDT": { @@ -492,6 +506,10 @@ class TradeTest(unittest.TestCase): def test_follow_orders(self): pass + @unittest.skip("TODO") + def test_compute_value(self): + pass + @unittest.skip("TODO") def test__repr(self): pass -- cgit v1.2.3