diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-01-22 01:06:13 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-01-22 01:06:13 +0100 |
commit | b83d489771c1c4f482a711cffc572f23a1599b4d (patch) | |
tree | 7290a3b5615721940bcb2bc13f2d93c0170ac255 | |
parent | 7ab23e291602b6ffd54622cffdc76ba0b4437a05 (diff) | |
download | Trader-b83d489771c1c4f482a711cffc572f23a1599b4d.tar.gz Trader-b83d489771c1c4f482a711cffc572f23a1599b4d.tar.zst Trader-b83d489771c1c4f482a711cffc572f23a1599b4d.zip |
Fix bid/ask to sell/buy in orders
-rw-r--r-- | portfolio.py | 4 | ||||
-rw-r--r-- | test.py | 25 |
2 files changed, 16 insertions, 13 deletions
diff --git a/portfolio.py b/portfolio.py index 20f83e4..00beab0 100644 --- a/portfolio.py +++ b/portfolio.py | |||
@@ -348,9 +348,9 @@ class Trade: | |||
348 | 348 | ||
349 | def order_action(self, inverted): | 349 | def order_action(self, inverted): |
350 | if self.value_from < self.value_to: | 350 | if self.value_from < self.value_to: |
351 | return "ask" if not inverted else "bid" | 351 | return "buy" if not inverted else "sell" |
352 | else: | 352 | else: |
353 | return "bid" if not inverted else "ask" | 353 | return "sell" if not inverted else "buy" |
354 | 354 | ||
355 | def prepare_order(self, compute_value="default"): | 355 | def prepare_order(self, compute_value="default"): |
356 | if self.action is None: | 356 | if self.action is None: |
@@ -665,11 +665,11 @@ class AcceptanceTest(unittest.TestCase): | |||
665 | def create_order(symbol, type, action, amount, price=None): | 665 | def create_order(symbol, type, action, amount, price=None): |
666 | self.assertEqual("limit", type) | 666 | self.assertEqual("limit", type) |
667 | if symbol == "ETH/BTC": | 667 | if symbol == "ETH/BTC": |
668 | self.assertEqual("bid", action) | 668 | self.assertEqual("sell", action) |
669 | self.assertEqual(2, 3*amount) | 669 | self.assertEqual(2, 3*amount) |
670 | self.assertEqual(D("0.14014"), price) | 670 | self.assertEqual(D("0.14014"), price) |
671 | elif symbol == "XVG/BTC": | 671 | elif symbol == "XVG/BTC": |
672 | self.assertEqual("bid", action) | 672 | self.assertEqual("sell", action) |
673 | self.assertEqual(1000, amount) | 673 | self.assertEqual(1000, amount) |
674 | self.assertEqual(D("0.00003003"), price) | 674 | self.assertEqual(D("0.00003003"), price) |
675 | else: | 675 | else: |
@@ -755,19 +755,22 @@ class AcceptanceTest(unittest.TestCase): | |||
755 | self.assertEqual("sell", trades["XVG"].action) | 755 | self.assertEqual("sell", trades["XVG"].action) |
756 | 756 | ||
757 | # Action 6 | 757 | # Action 6 |
758 | portfolio.Trade.prepare_orders(only="buy", compute_value=lambda x, y: x["ask"] * D("0.999")) | 758 | portfolio.Trade.prepare_orders(only="buy", compute_value=lambda x, y: x["ask"]) |
759 | |||
759 | 760 | ||
760 | all_orders = portfolio.Trade.all_orders(state="pending") | 761 | all_orders = portfolio.Trade.all_orders(state="pending") |
761 | self.assertEqual(3, len(all_orders)) | 762 | self.assertEqual(3, len(all_orders)) |
762 | self.assertEqual(portfolio.Amount("ETC", D("15.4")), all_orders[0].amount) | 763 | self.assertEqual(portfolio.Amount("ETC", D("38.5")/3), all_orders[0].amount) |
763 | self.assertEqual(D("0.002997"), all_orders[0].rate) | 764 | self.assertEqual(D("0.003"), all_orders[0].rate) |
764 | self.assertEqual("ask", all_orders[0].action) | 765 | self.assertEqual("buy", all_orders[0].action) |
765 | self.assertEqual(portfolio.Amount("BTD", D("9.7")), all_orders[1].amount) | 766 | |
766 | self.assertEqual(D("0.0011988"), all_orders[1].rate) | 767 | self.assertEqual(portfolio.Amount("BTD", D("24.25")/3), all_orders[1].amount) |
767 | self.assertEqual("ask", all_orders[1].action) | 768 | self.assertEqual(D("0.0012"), all_orders[1].rate) |
769 | self.assertEqual("buy", all_orders[1].action) | ||
770 | |||
768 | self.assertEqual(portfolio.Amount("BTC", D("0.0097")), all_orders[2].amount) | 771 | self.assertEqual(portfolio.Amount("BTC", D("0.0097")), all_orders[2].amount) |
769 | self.assertEqual(D("15984"), all_orders[2].rate) | 772 | self.assertEqual(D("16000"), all_orders[2].rate) |
770 | self.assertEqual("bid", all_orders[2].action) | 773 | self.assertEqual("sell", all_orders[2].action) |
771 | 774 | ||
772 | with mock.patch.object(portfolio.time, "sleep") as sleep: | 775 | with mock.patch.object(portfolio.time, "sleep") as sleep: |
773 | # Action 7 | 776 | # Action 7 |