From: Ismaƫl Bouya Date: Mon, 22 Jan 2018 00:06:13 +0000 (+0100) Subject: Fix bid/ask to sell/buy in orders X-Git-Tag: v0.1~31 X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git;a=commitdiff_plain;h=b83d489771c1c4f482a711cffc572f23a1599b4d Fix bid/ask to sell/buy in orders --- diff --git a/portfolio.py b/portfolio.py index 20f83e4..00beab0 100644 --- a/portfolio.py +++ b/portfolio.py @@ -348,9 +348,9 @@ class Trade: def order_action(self, inverted): if self.value_from < self.value_to: - return "ask" if not inverted else "bid" + return "buy" if not inverted else "sell" else: - return "bid" if not inverted else "ask" + return "sell" if not inverted else "buy" def prepare_order(self, compute_value="default"): if self.action is None: diff --git a/test.py b/test.py index 2589896..1b8a109 100644 --- a/test.py +++ b/test.py @@ -665,11 +665,11 @@ class AcceptanceTest(unittest.TestCase): def create_order(symbol, type, action, amount, price=None): self.assertEqual("limit", type) if symbol == "ETH/BTC": - self.assertEqual("bid", action) + self.assertEqual("sell", action) self.assertEqual(2, 3*amount) self.assertEqual(D("0.14014"), price) elif symbol == "XVG/BTC": - self.assertEqual("bid", action) + self.assertEqual("sell", action) self.assertEqual(1000, amount) self.assertEqual(D("0.00003003"), price) else: @@ -755,19 +755,22 @@ class AcceptanceTest(unittest.TestCase): self.assertEqual("sell", trades["XVG"].action) # Action 6 - portfolio.Trade.prepare_orders(only="buy", compute_value=lambda x, y: x["ask"] * D("0.999")) + portfolio.Trade.prepare_orders(only="buy", compute_value=lambda x, y: x["ask"]) + all_orders = portfolio.Trade.all_orders(state="pending") self.assertEqual(3, len(all_orders)) - self.assertEqual(portfolio.Amount("ETC", D("15.4")), all_orders[0].amount) - self.assertEqual(D("0.002997"), all_orders[0].rate) - self.assertEqual("ask", all_orders[0].action) - self.assertEqual(portfolio.Amount("BTD", D("9.7")), all_orders[1].amount) - self.assertEqual(D("0.0011988"), all_orders[1].rate) - self.assertEqual("ask", all_orders[1].action) + self.assertEqual(portfolio.Amount("ETC", D("38.5")/3), all_orders[0].amount) + self.assertEqual(D("0.003"), all_orders[0].rate) + self.assertEqual("buy", all_orders[0].action) + + self.assertEqual(portfolio.Amount("BTD", D("24.25")/3), all_orders[1].amount) + self.assertEqual(D("0.0012"), all_orders[1].rate) + self.assertEqual("buy", all_orders[1].action) + self.assertEqual(portfolio.Amount("BTC", D("0.0097")), all_orders[2].amount) - self.assertEqual(D("15984"), all_orders[2].rate) - self.assertEqual("bid", all_orders[2].action) + self.assertEqual(D("16000"), all_orders[2].rate) + self.assertEqual("sell", all_orders[2].action) with mock.patch.object(portfolio.time, "sleep") as sleep: # Action 7