# Buggy code
def _query_blockchain_balances(
    self,
    blockchain: Optional[SupportedBlockchain],
    ignore_cache: bool,
) -> Dict[str, Any]:
    msg = ""
    status_code = HTTPStatus.OK
    result = None
    try:
        balances = self.rotkehlchen.chain_manager.query_balances(
            blockchain=blockchain,
            ignore_cache=ignore_cache,
        )
    except EthSyncError as e:
        msg = str(e)
        status_code = HTTPStatus.CONFLICT
    except RemoteError as e:
        msg = str(e)
        status_code = HTTPStatus.BAD_GATEWAY
    else:
        result = balances.serialize()
        # If only specific input blockchain was given ignore other results
        if blockchain == SupportedBlockchain.ETHEREUM:
            result["per_account"].pop("BTC", None)
            result["totals"].pop("BTC", None)
        elif blockchain == SupportedBlockchain.BITCOIN:
            per_account = {"BTC": result["per_account"]["BTC"]}
            totals = {"BTC": result["totals"]["BTC"]}
            result = {"per_account": per_account, "totals": totals}

    return {"result": result, "message": msg, "status_code": status_code}


# Traceback (KeyError)
06/04/2020 19:32:00 W. Europe Daylight Time -- ERROR:rotkehlchen.api.server:Exception on /api/1/balances/blockchains/btc [GET]
Traceback (most recent call last):
File "C:\Users\Gebruiker\Envs\rotkehlchen\lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\Gebruiker\Envs\rotkehlchen\lib\site-packages\flask\app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\Gebruiker\Envs\rotkehlchen\lib\site-packages\flask_restful\__init__.py", line 458, in wrapper
resp = resource(*args, **kwargs)
File "C:\Users\Gebruiker\Envs\rotkehlchen\lib\site-packages\flask\views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "C:\Users\Gebruiker\Envs\rotkehlchen\lib\site-packages\flask_restful\__init__.py", line 573, in dispatch_request
resp = meth(*args, **kwargs)
File "C:\Users\Gebruiker\Envs\rotkehlchen\lib\site-packages\webargs\core.py", line 366, in wrapper
return func(*args, **kwargs)
File "C:\Users\Gebruiker\Source\Repos\rotki\rotkehlchen\api\v1\resources.py", line 302, in get
ignore_cache=ignore_cache,
File "C:\Users\Gebruiker\Source\Repos\rotki\rotkehlchen\api\rest.py", line 101, in wrapper
return f(wrappingobj, *args, **kwargs)
File "C:\Users\Gebruiker\Source\Repos\rotki\rotkehlchen\api\rest.py", line 575, in query_blockchain_balances
ignore_cache=ignore_cache,
File "C:\Users\Gebruiker\Source\Repos\rotki\rotkehlchen\api\rest.py", line 553, in _query_blockchain_balances
per_account = {'BTC': result['per_account']['BTC']}
KeyError: 'BTC'
06/04/2020 19:32:00 W. Europe Daylight Time -- INFO:rotkehlchen.api.server.pywsgi:127.0.0.1 - - [2020-04-06 19:32:00] "GET /api/1/balances/blockchains/btc HTTP/1.1" 500 164 0.001981

# Fixed code
def _query_blockchain_balances(
    self,
    blockchain: Optional[SupportedBlockchain],
    ignore_cache: bool,
) -> Dict[str, Any]:
    msg = ""
    status_code = HTTPStatus.OK
    result = None
    try:
        balances = self.rotkehlchen.chain_manager.query_balances(
            blockchain=blockchain,
            ignore_cache=ignore_cache,
        )
    except EthSyncError as e:
        msg = str(e)
        status_code = HTTPStatus.CONFLICT
    except RemoteError as e:
        msg = str(e)
        status_code = HTTPStatus.BAD_GATEWAY
    else:
        result = balances.serialize()
        # If only specific input blockchain was given ignore other results
        if blockchain == SupportedBlockchain.ETHEREUM:
            result["per_account"].pop("BTC", None)
            result["totals"].pop("BTC", None)
        elif blockchain == SupportedBlockchain.BITCOIN:
            val = result["per_account"].get("BTC", None)
            per_account = {"BTC": val} if val else {}
            val = result["totals"].get("BTC", None)
            totals = {"BTC": val} if val else {}
            result = {"per_account": per_account, "totals": totals}

    return {"result": result, "message": msg, "status_code": status_code}