Merge pull request #4391 from squat0001/develop

Add dust level to balance command in telegram
This commit is contained in:
Matthias 2021-02-28 10:36:44 +01:00 committed by GitHub
commit 54ccbd9370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 5 deletions

View File

@ -97,6 +97,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| `telegram.enabled` | Enable the usage of Telegram. <br> **Datatype:** Boolean | `telegram.enabled` | Enable the usage of Telegram. <br> **Datatype:** Boolean
| `telegram.token` | Your Telegram bot token. Only required if `telegram.enabled` is `true`. <br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String | `telegram.token` | Your Telegram bot token. Only required if `telegram.enabled` is `true`. <br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
| `telegram.chat_id` | Your personal Telegram account id. Only required if `telegram.enabled` is `true`. <br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String | `telegram.chat_id` | Your personal Telegram account id. Only required if `telegram.enabled` is `true`. <br>**Keep it in secret, do not disclose publicly.** <br> **Datatype:** String
| `telegram.balance_dust_level` | Dust-level (in stake currency) - currencies with a balance below this will not be shown by `/balance`. <br> **Datatype:** float
| `webhook.enabled` | Enable usage of Webhook notifications <br> **Datatype:** Boolean | `webhook.enabled` | Enable usage of Webhook notifications <br> **Datatype:** Boolean
| `webhook.url` | URL for the webhook. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String | `webhook.url` | URL for the webhook. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String
| `webhook.webhookbuy` | Payload to send on buy. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String | `webhook.webhookbuy` | Payload to send on buy. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details. <br> **Datatype:** String

View File

@ -83,10 +83,13 @@ Example configuration showing the different settings:
"sell": "on", "sell": "on",
"buy_cancel": "silent", "buy_cancel": "silent",
"sell_cancel": "on" "sell_cancel": "on"
} },
"balance_dust_level": 0.01
}, },
``` ```
`balance_dust_level` will define what the `/balance` command takes as "dust" - Currencies with a balance below this will be shown.
## Create a custom keyboard (command shortcut buttons) ## Create a custom keyboard (command shortcut buttons)
Telegram allows us to create a custom keyboard with buttons for commands. Telegram allows us to create a custom keyboard with buttons for commands.

View File

@ -54,6 +54,11 @@ DECIMALS_PER_COIN = {
'ETH': 5, 'ETH': 5,
} }
DUST_PER_COIN = {
'BTC': 0.0001,
'ETH': 0.01
}
# Soure files with destination directories within user-directory # Soure files with destination directories within user-directory
USER_DATA_FILES = { USER_DATA_FILES = {
@ -230,6 +235,7 @@ CONF_SCHEMA = {
'enabled': {'type': 'boolean'}, 'enabled': {'type': 'boolean'},
'token': {'type': 'string'}, 'token': {'type': 'string'},
'chat_id': {'type': 'string'}, 'chat_id': {'type': 'string'},
'balance_dust_level': {'type': 'number', 'minimum': 0.0},
'notification_settings': { 'notification_settings': {
'type': 'object', 'type': 'object',
'properties': { 'properties': {
@ -243,7 +249,7 @@ CONF_SCHEMA = {
} }
} }
}, },
'required': ['enabled', 'token', 'chat_id'] 'required': ['enabled', 'token', 'chat_id'],
}, },
'webhook': { 'webhook': {
'type': 'object', 'type': 'object',

View File

@ -17,6 +17,7 @@ from telegram.ext import CallbackContext, CommandHandler, Updater
from telegram.utils.helpers import escape_markdown from telegram.utils.helpers import escape_markdown
from freqtrade.__init__ import __version__ from freqtrade.__init__ import __version__
from freqtrade.constants import DUST_PER_COIN
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
from freqtrade.misc import round_coin_value from freqtrade.misc import round_coin_value
from freqtrade.rpc import RPC, RPCException, RPCHandler, RPCMessageType from freqtrade.rpc import RPC, RPCException, RPCHandler, RPCMessageType
@ -487,6 +488,10 @@ class Telegram(RPCHandler):
result = self._rpc._rpc_balance(self._config['stake_currency'], result = self._rpc._rpc_balance(self._config['stake_currency'],
self._config.get('fiat_display_currency', '')) self._config.get('fiat_display_currency', ''))
balance_dust_level = self._config['telegram'].get('balance_dust_level', 0.0)
if not balance_dust_level:
balance_dust_level = DUST_PER_COIN.get(self._config['stake_currency'], 1.0)
output = '' output = ''
if self._config['dry_run']: if self._config['dry_run']:
output += ( output += (
@ -496,7 +501,7 @@ class Telegram(RPCHandler):
f"`{self._config['dry_run_wallet']}` {self._config['stake_currency']}.\n" f"`{self._config['dry_run_wallet']}` {self._config['stake_currency']}.\n"
) )
for curr in result['currencies']: for curr in result['currencies']:
if curr['est_stake'] > 0.0001: if curr['est_stake'] > balance_dust_level:
curr_output = ( curr_output = (
f"*{curr['currency']}:*\n" f"*{curr['currency']}:*\n"
f"\t`Available: {curr['free']:.8f}`\n" f"\t`Available: {curr['free']:.8f}`\n"
@ -505,7 +510,8 @@ class Telegram(RPCHandler):
f"\t`Est. {curr['stake']}: " f"\t`Est. {curr['stake']}: "
f"{round_coin_value(curr['est_stake'], curr['stake'], False)}`\n") f"{round_coin_value(curr['est_stake'], curr['stake'], False)}`\n")
else: else:
curr_output = f"*{curr['currency']}:* not showing <1$ amount \n" curr_output = (f"*{curr['currency']}:* not showing <{balance_dust_level} "
f"{curr['stake']} amount \n")
# Handle overflowing messsage length # Handle overflowing messsage length
if len(output + curr_output) >= MAX_TELEGRAM_MESSAGE_LENGTH: if len(output + curr_output) >= MAX_TELEGRAM_MESSAGE_LENGTH:

View File

@ -520,7 +520,7 @@ def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance, tick
assert 'Balance:' in result assert 'Balance:' in result
assert 'Est. BTC:' in result assert 'Est. BTC:' in result
assert 'BTC: 12.00000000' in result assert 'BTC: 12.00000000' in result
assert '*XRP:* not showing <1$ amount' in result assert '*XRP:* not showing <0.0001 BTC amount' in result
def test_balance_handle_empty_response(default_conf, update, mocker) -> None: def test_balance_handle_empty_response(default_conf, update, mocker) -> None: