from bfxapi.rest.bfx_rest import BfxRest


class BfxWrapper(BfxRest):
    def __init__(self, api_key: str, api_secret: str):
        super().__init__(API_KEY=api_key, API_SECRET=api_secret)

    async def get_current_prices(self, symbol) -> (float, float, float):
        tickers = await self.get_public_ticker(symbol)

        bid_price = tickers[0]
        ask_price = tickers[2]
        ticker_price = tickers[6]

        return bid_price, ask_price, ticker_price

    async def get_usd_balance(self):
        balance = 0.0

        wallets = await self.get_wallets()

        for w in wallets:
            if w.currency == "USD":
                balance += w.balance
            else:
                current_price = await self.get_current_prices(f"t{w.currency}USD")
                balance += current_price * w.balance

        return balance
