def test_get_balances_prod(default_conf, mocker): balance_item = { 'Currency': '1ST', 'Balance': 10.0, 'Available': 10.0, 'Pending': 0.0, 'CryptoAddress': None } api_mock = MagicMock() api_mock.get_balances = MagicMock( return_value=[balance_item, balance_item, balance_item]) mocker.patch('freqtrade.exchange._API', api_mock) default_conf['dry_run'] = False mocker.patch.dict('freqtrade.exchange._CONF', default_conf) assert len(get_balances()) == 3 assert get_balances()[0]['Currency'] == '1ST' assert get_balances()[0]['Balance'] == 10.0 assert get_balances()[0]['Available'] == 10.0 assert get_balances()[0]['Pending'] == 0.0
def _balance(bot: Bot, update: Update) -> None: """ Handler for /balance Returns current account balance per crypto """ output = "" balances = exchange.get_balances() for currency in balances: if not currency['Balance'] and not currency['Available'] and not currency['Pending']: continue output += """*Currency*: {Currency} *Available*: {Available} *Balance*: {Balance} *Pending*: {Pending} """.format(**currency) send_msg(output)
def _balance(bot: Bot, update: Update) -> None: """ Handler for /balance Returns current account balance per crypto """ output = '' balances = [ c for c in exchange.get_balances() if c['Balance'] or c['Available'] or c['Pending'] ] if not balances: output = '`All balances are zero.`' for currency in balances: output += """*Currency*: {Currency} *Available*: {Available} *Balance*: {Balance} *Pending*: {Pending} """.format(**currency) send_msg(output)
def rpc_balance(self, fiat_display_currency: str) -> Tuple[bool, Any]: """ :return: current account balance per crypto """ balances = [ c for c in exchange.get_balances() if c['Balance'] or c['Available'] or c['Pending'] ] if not balances: return True, '`All balances are zero.`' output = [] total = 0.0 for currency in balances: coin = currency['Currency'] if coin == 'BTC': currency["Rate"] = 1.0 else: if coin == 'USDT': currency["Rate"] = 1.0 / exchange.get_ticker( 'USDT_BTC', False)['bid'] else: currency["Rate"] = exchange.get_ticker( 'BTC_' + coin, False)['bid'] currency['BTC'] = currency["Rate"] * currency["Balance"] total = total + currency['BTC'] output.append({ 'currency': currency['Currency'], 'available': currency['Available'], 'balance': currency['Balance'], 'pending': currency['Pending'], 'est_btc': currency['BTC'] }) fiat = self.freqtrade.fiat_converter symbol = fiat_display_currency value = fiat.convert_amount(total, 'BTC', symbol) return False, (output, total, symbol, value)
def test_get_balances_dry_run(default_conf, mocker): default_conf['dry_run'] = True mocker.patch.dict('freqtrade.exchange._CONF', default_conf) assert get_balances() == []