From dd78c62c3d60f28e139bbb78e89a96008828d552 Mon Sep 17 00:00:00 2001 From: Samuel Husso Date: Sat, 28 Oct 2017 08:44:49 +0300 Subject: [PATCH] added new command to return balance across all currencies --- freqtrade/exchange/__init__.py | 2 ++ freqtrade/exchange/bittrex.py | 6 ++++++ freqtrade/rpc/telegram.py | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 77a2d4b84..f255647b7 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -84,6 +84,8 @@ def get_balance(currency: str) -> float: return EXCHANGE.get_balance(currency) +def get_balances(): + return EXCHANGE.get_balances() def get_ticker(pair: str) -> dict: return EXCHANGE.get_ticker(pair) diff --git a/freqtrade/exchange/bittrex.py b/freqtrade/exchange/bittrex.py index cb85aaf87..0b70e7a3b 100644 --- a/freqtrade/exchange/bittrex.py +++ b/freqtrade/exchange/bittrex.py @@ -54,6 +54,12 @@ class Bittrex(Exchange): raise RuntimeError('{}: {}'.format(self.name.upper(), data['message'])) return float(data['result']['Balance'] or 0.0) + def get_balances(self): + data = _API.get_balances() + if not data['success']: + raise RuntimeError('{}: {}'.format(self.name.upper(), data['message'])) + return data['result'] + def get_ticker(self, pair: str) -> dict: data = _API.get_ticker(pair.replace('_', '-')) if not data['success']: diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 84c86f816..9ea81c0b7 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -41,6 +41,7 @@ def init(config: dict) -> None: handles = [ CommandHandler('status', _status), CommandHandler('profit', _profit), + CommandHandler('balance', _balance), CommandHandler('start', _start), CommandHandler('stop', _stop), CommandHandler('forcesell', _forcesell), @@ -201,6 +202,26 @@ def _profit(bot: Bot, update: Update) -> None: ) send_msg(markdown_msg, bot=bot) +@authorized_only +def _balance(bot: Bot, update: Update) -> None: + """ + Hander for /balance + Returns current account balance per crypto + """ + filter = {'Currency', 'CryptoAddress'} + output = "" + + balances = exchange.get_balances() + + for c in balances: + # output[c['Currency']] = {k: c[k] for k in c.keys() & {*set(c) - set(filter)}} + output += """*Currency*: {Currency} +*Available*: {Available} +*Balance*: {Balance} +*Pending*: {Pending} + +""".format(**c) + send_msg(output) @authorized_only def _start(bot: Bot, update: Update) -> None: