added new command to return balance across all currencies
This commit is contained in:
parent
29de1645fe
commit
dd78c62c3d
@ -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)
|
||||
|
@ -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']:
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user