From 5f9994c9ed1d7749412bf8201932f44e4e4b4c69 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 5 Jun 2020 20:24:21 +0200 Subject: [PATCH 1/4] Reduce verbosity of sell-rate fetching --- freqtrade/freqtradebot.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index a74b0a5a1..5104e4f95 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -702,11 +702,10 @@ class FreqtradeBot: self.dataprovider.ohlcv(trade.pair, self.strategy.ticker_interval)) if config_ask_strategy.get('use_order_book', False): - # logger.debug('Order book %s',orderBook) order_book_min = config_ask_strategy.get('order_book_min', 1) order_book_max = config_ask_strategy.get('order_book_max', 1) - logger.info(f'Using order book between {order_book_min} and {order_book_max} ' - f'for selling {trade.pair}...') + logger.debug(f'Using order book between {order_book_min} and {order_book_max} ' + f'for selling {trade.pair}...') order_book = self._order_book_gen(trade.pair, f"{config_ask_strategy['price_side']}s", order_book_min=order_book_min, From 8c32d691c7ee4cee9ff860748b3ebee2c1187388 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 5 Jun 2020 20:31:40 +0200 Subject: [PATCH 2/4] Add information about bid and ask strategy to /showconfig --- freqtrade/rpc/rpc.py | 2 ++ freqtrade/rpc/telegram.py | 4 +++- tests/rpc/test_rpc_apiserver.py | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 91b35e9ad..a5005f35e 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -105,6 +105,8 @@ class RPC: 'exchange': config['exchange']['name'], 'strategy': config['strategy'], 'forcebuy_enabled': config.get('forcebuy_enable', False), + 'ask_strategy': config.get('ask_strategy', {}), + 'bid_strategy': config.get('bid_strategy', {}), 'state': str(self._freqtrade.state) } return val diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 8fa973d73..09a99ad85 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -636,13 +636,15 @@ class Telegram(RPC): else: sl_info = f"*Stoploss:* `{val['stoploss']}`\n" - + import json self._send_msg( f"*Mode:* `{'Dry-run' if val['dry_run'] else 'Live'}`\n" f"*Exchange:* `{val['exchange']}`\n" f"*Stake per trade:* `{val['stake_amount']} {val['stake_currency']}`\n" f"*Max open Trades:* `{val['max_open_trades']}`\n" f"*Minimum ROI:* `{val['minimal_roi']}`\n" + f"*Ask strategy:* ```\n{val['ask_strategy']}```\n" + f"*Bid strategy:* ```\n{json.dumps(val['bid_strategy'])}```\n" f"{sl_info}" f"*Ticker Interval:* `{val['ticker_interval']}`\n" f"*Strategy:* `{val['strategy']}`\n" diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index cacf49f62..6a850ecc5 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -325,6 +325,8 @@ def test_api_show_config(botclient, mocker): assert rc.json['ticker_interval'] == '5m' assert rc.json['state'] == 'running' assert not rc.json['trailing_stop'] + assert 'bid_strategy' in rc.json + assert 'ask_strategy' in rc.json def test_api_daily(botclient, mocker, ticker, fee, markets): From 3bd38171f80c7b420d259f573861a7fed8a6d031 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 6 Jun 2020 17:19:44 +0200 Subject: [PATCH 3/4] DOn't use json.dumps - it's not necessary --- freqtrade/rpc/telegram.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 09a99ad85..2ea697ed4 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -636,7 +636,7 @@ class Telegram(RPC): else: sl_info = f"*Stoploss:* `{val['stoploss']}`\n" - import json + self._send_msg( f"*Mode:* `{'Dry-run' if val['dry_run'] else 'Live'}`\n" f"*Exchange:* `{val['exchange']}`\n" @@ -644,7 +644,7 @@ class Telegram(RPC): f"*Max open Trades:* `{val['max_open_trades']}`\n" f"*Minimum ROI:* `{val['minimal_roi']}`\n" f"*Ask strategy:* ```\n{val['ask_strategy']}```\n" - f"*Bid strategy:* ```\n{json.dumps(val['bid_strategy'])}```\n" + f"*Bid strategy:* ```\n{val['bid_strategy']}```\n" f"{sl_info}" f"*Ticker Interval:* `{val['ticker_interval']}`\n" f"*Strategy:* `{val['strategy']}`\n" From 8d8cf5a2fde3ea20f66991b1eb978e84d514e9d4 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 6 Jun 2020 17:28:00 +0200 Subject: [PATCH 4/4] Improve code formatting of telegram --- freqtrade/rpc/telegram.py | 72 +++++++++++++++++----------------- tests/rpc/test_rpc_telegram.py | 41 +++++++++---------- 2 files changed, 55 insertions(+), 58 deletions(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 965318f64..894955eb5 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -144,8 +144,8 @@ class Telegram(RPC): message += ")`" elif msg['type'] == RPCMessageType.BUY_CANCEL_NOTIFICATION: - message = "\N{WARNING SIGN} *{exchange}:* " \ - "Cancelling Open Buy Order for {pair}".format(**msg) + message = ("\N{WARNING SIGN} *{exchange}:* " + "Cancelling Open Buy Order for {pair}".format(**msg)) elif msg['type'] == RPCMessageType.SELL_NOTIFICATION: msg['amount'] = round(msg['amount'], 8) @@ -388,11 +388,11 @@ class Telegram(RPC): ) for currency in result['currencies']: if currency['est_stake'] > 0.0001: - curr_output = "*{currency}:*\n" \ - "\t`Available: {free: .8f}`\n" \ - "\t`Balance: {balance: .8f}`\n" \ - "\t`Pending: {used: .8f}`\n" \ - "\t`Est. {stake}: {est_stake: .8f}`\n".format(**currency) + curr_output = ("*{currency}:*\n" + "\t`Available: {free: .8f}`\n" + "\t`Balance: {balance: .8f}`\n" + "\t`Pending: {used: .8f}`\n" + "\t`Est. {stake}: {est_stake: .8f}`\n").format(**currency) else: curr_output = "*{currency}:* not showing <1$ amount \n".format(**currency) @@ -403,9 +403,9 @@ class Telegram(RPC): else: output += curr_output - output += "\n*Estimated Value*:\n" \ - "\t`{stake}: {total: .8f}`\n" \ - "\t`{symbol}: {value: .2f}`\n".format(**result) + output += ("\n*Estimated Value*:\n" + "\t`{stake}: {total: .8f}`\n" + "\t`{symbol}: {value: .2f}`\n").format(**result) self._send_msg(output) except RPCException as e: self._send_msg(str(e)) @@ -598,32 +598,32 @@ class Telegram(RPC): :param update: message update :return: None """ - forcebuy_text = "*/forcebuy []:* `Instantly buys the given pair. " \ - "Optionally takes a rate at which to buy.` \n" - message = "*/start:* `Starts the trader`\n" \ - "*/stop:* `Stops the trader`\n" \ - "*/status [table]:* `Lists all open trades`\n" \ - " *table :* `will display trades in a table`\n" \ - " `pending buy orders are marked with an asterisk (*)`\n" \ - " `pending sell orders are marked with a double asterisk (**)`\n" \ - "*/profit:* `Lists cumulative profit from all finished trades`\n" \ - "*/forcesell |all:* `Instantly sells the given trade or all trades, " \ - "regardless of profit`\n" \ - f"{forcebuy_text if self._config.get('forcebuy_enable', False) else ''}" \ - "*/performance:* `Show performance of each finished trade grouped by pair`\n" \ - "*/daily :* `Shows profit or loss per day, over the last n days`\n" \ - "*/count:* `Show number of trades running compared to allowed number of trades`" \ - "\n" \ - "*/balance:* `Show account balance per currency`\n" \ - "*/stopbuy:* `Stops buying, but handles open trades gracefully` \n" \ - "*/reload_conf:* `Reload configuration file` \n" \ - "*/show_config:* `Show running configuration` \n" \ - "*/whitelist:* `Show current whitelist` \n" \ - "*/blacklist [pair]:* `Show current blacklist, or adds one or more pairs " \ - "to the blacklist.` \n" \ - "*/edge:* `Shows validated pairs by Edge if it is enabled` \n" \ - "*/help:* `This help message`\n" \ - "*/version:* `Show version`" + forcebuy_text = ("*/forcebuy []:* `Instantly buys the given pair. " + "Optionally takes a rate at which to buy.` \n") + message = ("*/start:* `Starts the trader`\n" + "*/stop:* `Stops the trader`\n" + "*/status [table]:* `Lists all open trades`\n" + " *table :* `will display trades in a table`\n" + " `pending buy orders are marked with an asterisk (*)`\n" + " `pending sell orders are marked with a double asterisk (**)`\n" + "*/profit:* `Lists cumulative profit from all finished trades`\n" + "*/forcesell |all:* `Instantly sells the given trade or all trades, " + "regardless of profit`\n" + f"{forcebuy_text if self._config.get('forcebuy_enable', False) else ''}" + "*/performance:* `Show performance of each finished trade grouped by pair`\n" + "*/daily :* `Shows profit or loss per day, over the last n days`\n" + "*/count:* `Show number of trades running compared to allowed number of trades`" + "\n" + "*/balance:* `Show account balance per currency`\n" + "*/stopbuy:* `Stops buying, but handles open trades gracefully` \n" + "*/reload_conf:* `Reload configuration file` \n" + "*/show_config:* `Show running configuration` \n" + "*/whitelist:* `Show current whitelist` \n" + "*/blacklist [pair]:* `Show current blacklist, or adds one or more pairs " + "to the blacklist.` \n" + "*/edge:* `Shows validated pairs by Edge if it is enabled` \n" + "*/help:* `This help message`\n" + "*/version:* `Show version`") self._send_msg(message) diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 21b9df81c..b18106ee5 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -71,10 +71,10 @@ def test_init(default_conf, mocker, caplog) -> None: assert start_polling.dispatcher.add_handler.call_count > 0 assert start_polling.start_polling.call_count == 1 - message_str = "rpc.telegram is listening for following commands: [['status'], ['profit'], " \ - "['balance'], ['start'], ['stop'], ['forcesell'], ['forcebuy'], " \ - "['performance'], ['daily'], ['count'], ['reload_conf'], ['show_config'], " \ - "['stopbuy'], ['whitelist'], ['blacklist'], ['edge'], ['help'], ['version']]" + message_str = ("rpc.telegram is listening for following commands: [['status'], ['profit'], " + "['balance'], ['start'], ['stop'], ['forcesell'], ['forcebuy'], " + "['performance'], ['daily'], ['count'], ['reload_conf'], ['show_config'], " + "['stopbuy'], ['whitelist'], ['blacklist'], ['edge'], ['help'], ['version']]") assert log_has(message_str, caplog) @@ -1016,9 +1016,8 @@ def test_count_handle(default_conf, update, ticker, fee, mocker) -> None: msg_mock.reset_mock() telegram._count(update=update, context=MagicMock()) - msg = '
  current    max    total stake\n---------  -----  -------------\n' \
-          '        1      {}          {}
'\ - .format( + msg = ('
  current    max    total stake\n---------  -----  -------------\n'
+           '        1      {}          {}
').format( default_conf['max_open_trades'], default_conf['stake_amount'] ) @@ -1441,12 +1440,11 @@ def test_send_msg_buy_notification_no_fiat(default_conf, mocker) -> None: 'amount': 1333.3333333333335, 'open_date': arrow.utcnow().shift(hours=-1) }) - assert msg_mock.call_args[0][0] \ - == '\N{LARGE BLUE CIRCLE} *Bittrex:* Buying ETH/BTC\n' \ - '*Amount:* `1333.33333333`\n' \ - '*Open Rate:* `0.00001099`\n' \ - '*Current Rate:* `0.00001099`\n' \ - '*Total:* `(0.001000 BTC)`' + assert msg_mock.call_args[0][0] == ('\N{LARGE BLUE CIRCLE} *Bittrex:* Buying ETH/BTC\n' + '*Amount:* `1333.33333333`\n' + '*Open Rate:* `0.00001099`\n' + '*Current Rate:* `0.00001099`\n' + '*Total:* `(0.001000 BTC)`') def test_send_msg_sell_notification_no_fiat(default_conf, mocker) -> None: @@ -1477,15 +1475,14 @@ def test_send_msg_sell_notification_no_fiat(default_conf, mocker) -> None: 'open_date': arrow.utcnow().shift(hours=-2, minutes=-35, seconds=-3), 'close_date': arrow.utcnow(), }) - assert msg_mock.call_args[0][0] \ - == '\N{WARNING SIGN} *Binance:* Selling KEY/ETH\n' \ - '*Amount:* `1333.33333333`\n' \ - '*Open Rate:* `0.00007500`\n' \ - '*Current Rate:* `0.00003201`\n' \ - '*Close Rate:* `0.00003201`\n' \ - '*Sell Reason:* `stop_loss`\n' \ - '*Duration:* `2:35:03 (155.1 min)`\n' \ - '*Profit:* `-57.41%`' + assert msg_mock.call_args[0][0] == ('\N{WARNING SIGN} *Binance:* Selling KEY/ETH\n' + '*Amount:* `1333.33333333`\n' + '*Open Rate:* `0.00007500`\n' + '*Current Rate:* `0.00003201`\n' + '*Close Rate:* `0.00003201`\n' + '*Sell Reason:* `stop_loss`\n' + '*Duration:* `2:35:03 (155.1 min)`\n' + '*Profit:* `-57.41%`') @pytest.mark.parametrize('msg,expected', [