aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-02-26 12:07:07 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-02-26 12:07:07 +0100
commitd24bb10c3cad1f144b76022481f46b4524873f4b (patch)
treeee08dfb7118ea9a5af311250b036c067b9277ef4
parent516a2517aa428596199e56cc105c7b0132064ade (diff)
downloadTrader-d24bb10c3cad1f144b76022481f46b4524873f4b.tar.gz
Trader-d24bb10c3cad1f144b76022481f46b4524873f4b.tar.zst
Trader-d24bb10c3cad1f144b76022481f46b4524873f4b.zip
Fix dust amount error
-rw-r--r--main.py1
-rw-r--r--market.py2
-rw-r--r--portfolio.py4
-rw-r--r--test.py16
4 files changed, 18 insertions, 5 deletions
diff --git a/main.py b/main.py
index 3cb7f4a..17cf58c 100644
--- a/main.py
+++ b/main.py
@@ -7,7 +7,6 @@ pg_config, report_path = helper.main_parse_config(args.config)
7 7
8for market_config, user_id in helper.main_fetch_markets(pg_config, args.user): 8for 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:
diff --git a/market.py b/market.py
index 931de09..0cb3e67 100644
--- a/market.py
+++ b/market.py
@@ -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
3from decimal import Decimal as D, ROUND_DOWN 3from decimal import Decimal as D, ROUND_DOWN
4from json import JSONDecodeError 4from json import JSONDecodeError
5from simplejson.errors import JSONDecodeError as SimpleJSONDecodeError 5from simplejson.errors import JSONDecodeError as SimpleJSONDecodeError
6from ccxt import ExchangeError, ExchangeNotAvailable 6from ccxt import ExchangeError, ExchangeNotAvailable, InvalidOrder
7import requests 7import 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()
diff --git a/test.py b/test.py
index 4ed0477..52d737d 100644
--- a/test.py
+++ b/test.py
@@ -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")
2085class MouvementTest(WebMockTestCase): 2097class MouvementTest(WebMockTestCase):