aboutsummaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-01 19:08:56 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-03-01 19:08:56 +0100
commit7bd830a83b662874c145ea9548edfde79eadc68f (patch)
treeeb68f245ae4d6e66f6e55beffbd4b65def3d4c63 /test.py
parent065ee3422a6ee9d40136cfa6b272e951e15c2e50 (diff)
downloadTrader-7bd830a83b662874c145ea9548edfde79eadc68f.tar.gz
Trader-7bd830a83b662874c145ea9548edfde79eadc68f.tar.zst
Trader-7bd830a83b662874c145ea9548edfde79eadc68f.zip
Remove useless update_trades method
Add arguments to log_stage
Diffstat (limited to 'test.py')
-rw-r--r--test.py74
1 files changed, 20 insertions, 54 deletions
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):
781 self.assertEqual(D("0.01"), call[0][0]["XVG"].value) 781 self.assertEqual(D("0.01"), call[0][0]["XVG"].value)
782 self.assertEqual(D("0.2525"), call[0][1]["BTC"].value) 782 self.assertEqual(D("0.2525"), call[0][1]["BTC"].value)
783 self.assertEqual(D("0.7575"), call[0][1]["XEM"].value) 783 self.assertEqual(D("0.7575"), call[0][1]["XEM"].value)
784 m.report.log_stage.assert_called_once_with("prepare_trades") 784 m.report.log_stage.assert_called_once_with("prepare_trades",
785 m.report.log_balances.assert_called_once_with(tag="tag") 785 base_currency='BTC', compute_value='average',
786 786 liquidity='medium', only=None)
787 @mock.patch.object(portfolio.Portfolio, "repartition")
788 @mock.patch.object(market.Market, "get_ticker")
789 @mock.patch.object(market.TradeStore, "compute_trades")
790 def test_update_trades(self, compute_trades, get_ticker, repartition):
791 repartition.return_value = {
792 "XEM": (D("0.75"), "long"),
793 "BTC": (D("0.25"), "long"),
794 }
795 def _get_ticker(c1, c2):
796 if c1 == "USDT" and c2 == "BTC":
797 return { "average": D("0.0001") }
798 if c1 == "XVG" and c2 == "BTC":
799 return { "average": D("0.000001") }
800 if c1 == "XEM" and c2 == "BTC":
801 return { "average": D("0.001") }
802 self.fail("Should be called with {}, {}".format(c1, c2))
803 get_ticker.side_effect = _get_ticker
804
805 with mock.patch("market.ReportStore"):
806 m = market.Market(self.ccxt)
807 self.ccxt.fetch_all_balances.return_value = {
808 "USDT": {
809 "exchange_free": D("10000.0"),
810 "exchange_used": D("0.0"),
811 "exchange_total": D("10000.0"),
812 "total": D("10000.0")
813 },
814 "XVG": {
815 "exchange_free": D("10000.0"),
816 "exchange_used": D("0.0"),
817 "exchange_total": D("10000.0"),
818 "total": D("10000.0")
819 },
820 }
821
822 m.balances.fetch_balances(tag="tag")
823
824 m.update_trades()
825 compute_trades.assert_called()
826
827 call = compute_trades.call_args
828 self.assertEqual(1, call[0][0]["USDT"].value)
829 self.assertEqual(D("0.01"), call[0][0]["XVG"].value)
830 self.assertEqual(D("0.2525"), call[0][1]["BTC"].value)
831 self.assertEqual(D("0.7575"), call[0][1]["XEM"].value)
832 m.report.log_stage.assert_called_once_with("update_trades")
833 m.report.log_balances.assert_called_once_with(tag="tag") 787 m.report.log_balances.assert_called_once_with(tag="tag")
834 788
835 @mock.patch.object(portfolio.Portfolio, "repartition") 789 @mock.patch.object(portfolio.Portfolio, "repartition")
@@ -2356,12 +2310,24 @@ class ReportStoreTest(WebMockTestCase):
2356 @mock.patch.object(market.ReportStore, "add_log") 2310 @mock.patch.object(market.ReportStore, "add_log")
2357 def test_log_stage(self, add_log, print_log): 2311 def test_log_stage(self, add_log, print_log):
2358 report_store = market.ReportStore(self.m) 2312 report_store = market.ReportStore(self.m)
2359 report_store.log_stage("foo") 2313 c = lambda x: x
2314 report_store.log_stage("foo", bar="baz", c=c, d=portfolio.Amount("BTC", 1))
2360 print_log.assert_has_calls([ 2315 print_log.assert_has_calls([
2361 mock.call("-----------"), 2316 mock.call("-----------"),
2362 mock.call("[Stage] foo"), 2317 mock.call("[Stage] foo bar=baz, c=c = lambda x: x, d={'currency': 'BTC', 'value': Decimal('1')}"),
2363 ]) 2318 ])
2364 add_log.assert_called_once_with({'type': 'stage', 'stage': 'foo'}) 2319 add_log.assert_called_once_with({
2320 'type': 'stage',
2321 'stage': 'foo',
2322 'args': {
2323 'bar': 'baz',
2324 'c': 'c = lambda x: x',
2325 'd': {
2326 'currency': 'BTC',
2327 'value': D('1')
2328 }
2329 }
2330 })
2365 2331
2366 @mock.patch.object(market.ReportStore, "print_log") 2332 @mock.patch.object(market.ReportStore, "print_log")
2367 @mock.patch.object(market.ReportStore, "add_log") 2333 @mock.patch.object(market.ReportStore, "add_log")
@@ -3089,7 +3055,7 @@ class HelperTest(WebMockTestCase):
3089 mock.call(tag="process_sell_needed__2_buy_begin"), 3055 mock.call(tag="process_sell_needed__2_buy_begin"),
3090 mock.call(tag="process_sell_needed__2_buy_end"), 3056 mock.call(tag="process_sell_needed__2_buy_end"),
3091 ]) 3057 ])
3092 self.m.update_trades.assert_called_with(base_currency="BTC", 3058 self.m.prepare_trades.assert_called_with(base_currency="BTC",
3093 liquidity="medium", only="acquire") 3059 liquidity="medium", only="acquire")
3094 self.m.trades.prepare_orders.assert_called_with(compute_value="average", 3060 self.m.trades.prepare_orders.assert_called_with(compute_value="average",
3095 only="acquire") 3061 only="acquire")
@@ -3346,7 +3312,7 @@ class AcceptanceTest(WebMockTestCase):
3346 3312
3347 with mock.patch.object(portfolio.Portfolio, "repartition", return_value=repartition): 3313 with mock.patch.object(portfolio.Portfolio, "repartition", return_value=repartition):
3348 # Action 5 3314 # Action 5
3349 helper.update_trades(market, only="acquire", compute_value="average") 3315 helper.prepare_trades(market, only="acquire", compute_value="average")
3350 3316
3351 balances = portfolio.BalanceStore.all 3317 balances = portfolio.BalanceStore.all
3352 self.assertEqual(portfolio.Amount("ETH", 1 / D("3")), balances["ETH"].total) 3318 self.assertEqual(portfolio.Amount("ETH", 1 / D("3")), balances["ETH"].total)