From 4859bf18a3ea9fc12be27c34665bdfc3f97fa3e3 Mon Sep 17 00:00:00 2001 From: gcarq Date: Sat, 20 May 2017 21:30:42 +0200 Subject: [PATCH] s/trade_thresholds/minimal_roi/ --- README.md | 9 ++++----- config.json.example | 8 +++----- main.py | 2 +- rpc/telegram.py | 13 ++++++++----- utils.py | 12 +++++------- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index c8b2ce3dc..5a5432fe8 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,11 @@ Persistence is achieved through sqlite. * /cancel: cancels open order for given trade (currently disabled) ##### Config -`trade_thresholds` is a JSON object where the key is a duration -in minutes and the value is the minimum profit threshold in -percent whether the bot should sell. See the example below: - +`minimal_roi` is a JSON object where the key is a duration +in minutes and the value is the minimum ROI in percent. +See the example below: ``` -"trade_thresholds": { +"minimal_roi": { "2880": 0.005, # Sell after 48 hours if there is at least 0.5% profit "1440": 0.01, # Sell after 24 hours if there is at least 1% profit "720": 0.02, # Sell after 12 hours if there is at least 2% profit diff --git a/config.json.example b/config.json.example index 3e0903df4..671535bea 100644 --- a/config.json.example +++ b/config.json.example @@ -3,12 +3,10 @@ "stake_currency": "BTC", "stake_amount": 0.05, "dry_run": false, - "trade_thresholds": { + "minimal_roi": { "2880": 0.005, - "1440": 0.01, - "720": 0.03, - "360": 0.05, - "0": 0.10 + "720": 0.01, + "0": 0.02 }, "poloniex": { "enabled": false, diff --git a/main.py b/main.py index 140c16138..57a847317 100755 --- a/main.py +++ b/main.py @@ -151,7 +151,7 @@ def handle_trade(trade): currency = trade.pair.split('_')[1] balance = api_wrapper.get_balance(currency) - for duration, threshold in sorted(conf['trade_thresholds'].items()): + for duration, threshold in sorted(conf['minimal_roi'].items()): duration, threshold = float(duration), float(threshold) # Check if time matches and current rate is above threshold time_diff = (datetime.utcnow() - trade.open_date).total_seconds() / 60 diff --git a/rpc/telegram.py b/rpc/telegram.py index dd8b31038..9b17da532 100644 --- a/rpc/telegram.py +++ b/rpc/telegram.py @@ -237,11 +237,14 @@ class TelegramHandler(object): :return: None """ if conf['telegram'].get('enabled', False): - bot = bot or TelegramHandler.get_updater(conf).bot try: - bot.send_message(conf['telegram']['chat_id'], msg, parse_mode=parse_mode) - except NetworkError as e: - logger.warning('Got Telegram NetworkError: {}! trying one more time'.format(e.message)) - bot.send_message(conf['telegram']['chat_id'], msg, parse_mode=parse_mode) + bot = bot or TelegramHandler.get_updater(conf).bot + try: + bot.send_message(conf['telegram']['chat_id'], msg, parse_mode=parse_mode) + except NetworkError as e: + # Sometimes the telegram server resets the current connection, + # if this is the case we send the message again. + logger.warning('Got Telegram NetworkError: {}! trying one more time'.format(e.message)) + bot.send_message(conf['telegram']['chat_id'], msg, parse_mode=parse_mode) except Exception: logger.exception('Exception occurred within Telegram API') diff --git a/utils.py b/utils.py index 85b112339..35246b3fd 100644 --- a/utils.py +++ b/utils.py @@ -36,16 +36,14 @@ def validate_conf(conf): raise ValueError('stake_amount must be a float') if not isinstance(conf.get('dry_run'), bool): raise ValueError('dry_run must be a boolean') - if not isinstance(conf.get('trade_thresholds'), dict): - raise ValueError('trade_thresholds must be a dict') - if not isinstance(conf.get('trade_thresholds'), dict): - raise ValueError('trade_thresholds must be a dict') + if not isinstance(conf.get('minimal_roi'), dict): + raise ValueError('minimal_roi must be a dict') - for i, (minutes, threshold) in enumerate(conf.get('trade_thresholds').items()): + for i, (minutes, threshold) in enumerate(conf.get('minimal_roi').items()): if not isinstance(minutes, str): - raise ValueError('trade_thresholds[{}].key must be a string'.format(i)) + raise ValueError('minimal_roi[{}].key must be a string'.format(i)) if not isinstance(threshold, float): - raise ValueError('trade_thresholds[{}].value must be a float'.format(i)) + raise ValueError('minimal_roi[{}].value must be a float'.format(i)) if conf.get('telegram'): telegram = conf.get('telegram')