aboutsummaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'test.py')
-rw-r--r--test.py30
1 files changed, 24 insertions, 6 deletions
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):
22 22
23 with mock.patch.object(portfolio.Trade, 'get_ticker', new=ticker_mock): 23 with mock.patch.object(portfolio.Trade, 'get_ticker', new=ticker_mock):
24 ticker_mock.return_value = { 24 ticker_mock.return_value = {
25 "bid": D("0.2"),
26 "ask": D("0.4"),
25 "average": D("0.3"), 27 "average": D("0.3"),
26 "foo": "bar", 28 "foo": "bar",
27 } 29 }
@@ -32,6 +34,12 @@ class AmountTest(unittest.TestCase):
32 self.assertEqual(amount, converted_amount.linked_to) 34 self.assertEqual(amount, converted_amount.linked_to)
33 self.assertEqual("bar", converted_amount.ticker["foo"]) 35 self.assertEqual("bar", converted_amount.ticker["foo"])
34 36
37 converted_amount = amount.in_currency("ETH", None, action="bid", compute_value="default")
38 self.assertEqual(D("2"), converted_amount.value)
39
40 converted_amount = amount.in_currency("ETH", None, compute_value="ask")
41 self.assertEqual(D("4"), converted_amount.value)
42
35 def test__abs(self): 43 def test__abs(self):
36 amount = portfolio.Amount("SC", -120) 44 amount = portfolio.Amount("SC", -120)
37 self.assertEqual(120, abs(amount).value) 45 self.assertEqual(120, abs(amount).value)
@@ -295,11 +303,11 @@ class BalanceTest(unittest.TestCase):
295 self.assertEqual(D("0.65"), amounts["BTC"].value) 303 self.assertEqual(D("0.65"), amounts["BTC"].value)
296 self.assertEqual(D("0.30"), amounts["ETH"].value) 304 self.assertEqual(D("0.30"), amounts["ETH"].value)
297 305
298 amounts = portfolio.Balance.in_currency("BTC", market, action="bid") 306 amounts = portfolio.Balance.in_currency("BTC", market, compute_value="bid")
299 self.assertEqual(D("0.65"), amounts["BTC"].value) 307 self.assertEqual(D("0.65"), amounts["BTC"].value)
300 self.assertEqual(D("0.27"), amounts["ETH"].value) 308 self.assertEqual(D("0.27"), amounts["ETH"].value)
301 309
302 amounts = portfolio.Balance.in_currency("BTC", market, action="bid", type="used") 310 amounts = portfolio.Balance.in_currency("BTC", market, compute_value="bid", type="used")
303 self.assertEqual(D("0.30"), amounts["BTC"].value) 311 self.assertEqual(D("0.30"), amounts["BTC"].value)
304 self.assertEqual(0, amounts["ETH"].value) 312 self.assertEqual(0, amounts["ETH"].value)
305 313
@@ -344,10 +352,16 @@ class BalanceTest(unittest.TestCase):
344 "XEM": 7500, 352 "XEM": 7500,
345 "BTC": 2500, 353 "BTC": 2500,
346 } 354 }
347 get_ticker.side_effect = [ 355 def _get_ticker(c1, c2, market):
348 { "average": D("0.0001") }, 356 if c1 == "USDT" and c2 == "BTC":
349 { "average": D("0.000001") } 357 return { "average": D("0.0001") }
350 ] 358 if c1 == "XVG" and c2 == "BTC":
359 return { "average": D("0.000001") }
360 if c1 == "XEM" and c2 == "BTC":
361 return { "average": D("0.001") }
362 raise Exception("Should be called with {}, {}".format(c1, c2))
363 get_ticker.side_effect = _get_ticker
364
351 market = mock.Mock() 365 market = mock.Mock()
352 market.fetch_balance.return_value = { 366 market.fetch_balance.return_value = {
353 "USDT": { 367 "USDT": {
@@ -493,6 +507,10 @@ class TradeTest(unittest.TestCase):
493 pass 507 pass
494 508
495 @unittest.skip("TODO") 509 @unittest.skip("TODO")
510 def test_compute_value(self):
511 pass
512
513 @unittest.skip("TODO")
496 def test__repr(self): 514 def test__repr(self):
497 pass 515 pass
498 516