diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-02-26 12:07:07 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-02-26 12:07:07 +0100 |
commit | d24bb10c3cad1f144b76022481f46b4524873f4b (patch) | |
tree | ee08dfb7118ea9a5af311250b036c067b9277ef4 | |
parent | 516a2517aa428596199e56cc105c7b0132064ade (diff) | |
download | Trader-d24bb10c3cad1f144b76022481f46b4524873f4b.tar.gz Trader-d24bb10c3cad1f144b76022481f46b4524873f4b.tar.zst Trader-d24bb10c3cad1f144b76022481f46b4524873f4b.zip |
Fix dust amount error
-rw-r--r-- | main.py | 1 | ||||
-rw-r--r-- | market.py | 2 | ||||
-rw-r--r-- | portfolio.py | 4 | ||||
-rw-r--r-- | test.py | 16 |
4 files changed, 18 insertions, 5 deletions
@@ -7,7 +7,6 @@ pg_config, report_path = helper.main_parse_config(args.config) | |||
7 | 7 | ||
8 | for market_config, user_id in helper.main_fetch_markets(pg_config, args.user): | 8 | for market_config, user_id in helper.main_fetch_markets(pg_config, args.user): |
9 | try: | 9 | try: |
10 | market_config["apiKey"] = market_config.pop("key") | ||
11 | user_market = market.Market.from_config(market_config, debug=args.debug) | 10 | user_market = market.Market.from_config(market_config, debug=args.debug) |
12 | helper.main_process_market(user_market, args.action, before=args.before, after=args.after) | 11 | helper.main_process_market(user_market, args.action, before=args.before, after=args.after) |
13 | except Exception as e: | 12 | except Exception as e: |
@@ -20,6 +20,8 @@ class Market: | |||
20 | 20 | ||
21 | @classmethod | 21 | @classmethod |
22 | def from_config(cls, config, debug=False): | 22 | def from_config(cls, config, debug=False): |
23 | config["apiKey"] = config.pop("key") | ||
24 | |||
23 | ccxt_instance = ccxt.poloniexE(config) | 25 | ccxt_instance = ccxt.poloniexE(config) |
24 | 26 | ||
25 | # For requests logging | 27 | # For requests logging |
diff --git a/portfolio.py b/portfolio.py index 43a39c4..0797de0 100644 --- a/portfolio.py +++ b/portfolio.py | |||
@@ -3,7 +3,7 @@ from datetime import datetime, timedelta | |||
3 | from decimal import Decimal as D, ROUND_DOWN | 3 | from decimal import Decimal as D, ROUND_DOWN |
4 | from json import JSONDecodeError | 4 | from json import JSONDecodeError |
5 | from simplejson.errors import JSONDecodeError as SimpleJSONDecodeError | 5 | from simplejson.errors import JSONDecodeError as SimpleJSONDecodeError |
6 | from ccxt import ExchangeError, ExchangeNotAvailable | 6 | from ccxt import ExchangeError, ExchangeNotAvailable, InvalidOrder |
7 | import requests | 7 | import requests |
8 | 8 | ||
9 | # FIXME: correctly handle web call timeouts | 9 | # FIXME: correctly handle web call timeouts |
@@ -532,7 +532,7 @@ class Order: | |||
532 | else: | 532 | else: |
533 | try: | 533 | try: |
534 | self.results.append(self.market.ccxt.create_order(symbol, 'limit', self.action, amount, price=self.rate, account=self.account)) | 534 | self.results.append(self.market.ccxt.create_order(symbol, 'limit', self.action, amount, price=self.rate, account=self.account)) |
535 | except ExchangeNotAvailable: | 535 | except (ExchangeNotAvailable, InvalidOrder): |
536 | # Impossible to honor the order (dust amount) | 536 | # Impossible to honor the order (dust amount) |
537 | self.status = "closed" | 537 | self.status = "closed" |
538 | self.mark_finished_order() | 538 | self.mark_finished_order() |
@@ -571,7 +571,7 @@ class MarketTest(WebMockTestCase): | |||
571 | ccxt.poloniexE.return_value = self.ccxt | 571 | ccxt.poloniexE.return_value = self.ccxt |
572 | self.ccxt.session.request.return_value = "response" | 572 | self.ccxt.session.request.return_value = "response" |
573 | 573 | ||
574 | m = market.Market.from_config("config") | 574 | m = market.Market.from_config({"key": "key", "secred": "secret"}) |
575 | 575 | ||
576 | self.assertEqual(self.ccxt, m.ccxt) | 576 | self.assertEqual(self.ccxt, m.ccxt) |
577 | 577 | ||
@@ -580,7 +580,7 @@ class MarketTest(WebMockTestCase): | |||
580 | m.report.log_http_request.assert_called_with('GET', 'URL', 'data', | 580 | m.report.log_http_request.assert_called_with('GET', 'URL', 'data', |
581 | 'headers', 'response') | 581 | 'headers', 'response') |
582 | 582 | ||
583 | m = market.Market.from_config("config", debug=True) | 583 | m = market.Market.from_config({"key": "key", "secred": "secret"}, debug=True) |
584 | self.assertEqual(True, m.debug) | 584 | self.assertEqual(True, m.debug) |
585 | 585 | ||
586 | def test_get_ticker(self): | 586 | def test_get_ticker(self): |
@@ -2080,6 +2080,18 @@ class OrderTest(WebMockTestCase): | |||
2080 | self.assertEqual("closed", order.status) | 2080 | self.assertEqual("closed", order.status) |
2081 | mark_finished_order.assert_called_once() | 2081 | mark_finished_order.assert_called_once() |
2082 | 2082 | ||
2083 | self.m.ccxt.create_order.reset_mock() | ||
2084 | with self.subTest(dust_amount_exception=True),\ | ||
2085 | mock.patch.object(portfolio.Order, "mark_finished_order") as mark_finished_order: | ||
2086 | order = portfolio.Order("buy", portfolio.Amount("ETH", 0.001), | ||
2087 | D("0.1"), "BTC", "long", self.m, "trade") | ||
2088 | self.m.ccxt.create_order.side_effect = portfolio.InvalidOrder | ||
2089 | order.run() | ||
2090 | self.m.ccxt.create_order.assert_called_once() | ||
2091 | self.assertEqual(0, len(order.results)) | ||
2092 | self.assertEqual("closed", order.status) | ||
2093 | mark_finished_order.assert_called_once() | ||
2094 | |||
2083 | 2095 | ||
2084 | @unittest.skipUnless("unit" in limits, "Unit skipped") | 2096 | @unittest.skipUnless("unit" in limits, "Unit skipped") |
2085 | class MouvementTest(WebMockTestCase): | 2097 | class MouvementTest(WebMockTestCase): |