Skip to content

Commit

Permalink
Fix bug with max_orders not being respected
Browse files Browse the repository at this point in the history
  • Loading branch information
hammertoe committed Mar 9, 2019
1 parent 49022a8 commit b00e54a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crypto_balancer/simple_balancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def permute_differences(self, differences_quote):
res.append((p, n))
return res

def balance(self, initial_portfolio, exchange, accuracy=1.0, max_orders=5):
def balance(self, initial_portfolio, exchange, max_orders=5):
rates = exchange.rates
quote_currency = initial_portfolio.quote_currency

Expand Down
32 changes: 30 additions & 2 deletions crypto_balancer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ def test_base_differences_start_xrp_xlm_usdt_rates3(self):

class test_SimpleBalancer(unittest.TestCase):

def execute(self, targets, current, rates, fee=0.001):
def execute(self, targets, current, rates, fee=0.001, max_orders=5):
exchange = DummyExchange(targets.keys(), current, rates, fee)
portfolio = Portfolio.make_portfolio(targets, exchange)

balancer = SimpleBalancer()
return balancer.balance(portfolio, exchange, max_orders=5)
return balancer.balance(portfolio, exchange, max_orders=max_orders)

def test_noop(self):

Expand Down Expand Up @@ -512,6 +512,34 @@ def test_real2a(self):
self.assertAlmostEqual(targets[cur],
(base_amounts[cur] / total_base) * 100)

def test_real2a_max_orders(self):

targets = {'XRP': 40,
'XLM': 20,
'BTC': 20,
'ETH': 10,
'USDT': 10, }
current = {'XRP': 3352,
'XLM': 0,
'BTC': 0,
'ETH': 0,
'USDT': 243, }
rates = {'XRP/USDT': 0.32076,
'XLM/USDT': 0.09084,
'XLM/XRP': 0.283366,
'XRP/BTC': 0.00008102,
'XRP/ETH': 0.00217366,
'BTC/USDT': 3968.13,
'ETH/USDT': 147.81,
}

res = self.execute(targets, current, rates, max_orders=3)
# Test the orders we get are correct
expected = [Order('ETH/USDT', 'BUY', 0.7521902983559976, 147.81),
Order('XLM/XRP', 'BUY', 2902.218229854689, 0.283366),
Order('XRP/BTC', 'SELL', 821.9151515151515, 8.102e-05), ]
self.assertEqual(res['orders'], expected)

def test_real2_nondirect(self):

targets = {'XRP': 40,
Expand Down

0 comments on commit b00e54a

Please # to comment.