# Path: cryptofolio/api/Config.py
# class Config:
#     BINANCE="Binance"
#     BITTREX="Bittrex"
#     COINBASE="Coinbase"
#     POLONIEX="Poloniex"
#     COINBASEPRO="CoinbasePro"
#     KRAKEN="Kraken"
#     KUCOIN="Kucoin"
# 
#     BALANCE_ZERO=0.00000001
# 
# Path: cryptofolio/api/Logger.py
# class Logger:
#     def __init__(self, root):
#         self.logger = logging.getLogger(root)
#         self.logger.setLevel(logging.DEBUG)
#         ch = logging.StreamHandler()
#         ch.setLevel(logging.DEBUG)
#         formatter = logging.Formatter(
#             '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#         ch.setFormatter(formatter)
#         self.logger.addHandler(ch)
# 
#     def log(self, message):
#         self.logger.debug(message)
# 
# Path: cryptofolio/api/ExchangeException.py
# class ExchangeException(Exception):
#     def __init__(self, exchange, message):
#         super(ExchangeException, self).__init__(message)
#         self.message = "%s: %s" % (exchange, message)


from binance.client import Client
from .Config import Config
from .Logger import Logger
from .ExchangeException import ExchangeException



class Binance:
    def __init__(self, key, secret):
        self.logger = Logger(__name__)

        try:
            self.client = Client(key, secret)
        except Exception as e:
            self.logger.log(e)
            raise ExchangeException(self.__class__.__name__, e)

    def getBalances(self):
        try:
            result = self.client.get_account()
            balances = {}

            for currency in result['balances']:
                name = currency['asset'].upper()
                value = float(currency['free'])

                if value > Config.BALANCE_ZERO:
                    balances[name] = value

            return balances
        except Exception as e:
            self.logger.log(e)

# Path: cryptofolio/api/Config.py
# class Config:
#     BINANCE="Binance"
#     BITTREX="Bittrex"
#     COINBASE="Coinbase"
#     POLONIEX="Poloniex"
#     COINBASEPRO="CoinbasePro"
#     KRAKEN="Kraken"
#     KUCOIN="Kucoin"
# 
#     BALANCE_ZERO=0.00000001
# 
# Path: cryptofolio/api/Logger.py
# class Logger:
#     def __init__(self, root):
#         self.logger = logging.getLogger(root)
#         self.logger.setLevel(logging.DEBUG)
#         ch = logging.StreamHandler()
#         ch.setLevel(logging.DEBUG)
#         formatter = logging.Formatter(
#             '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#         ch.setFormatter(formatter)
#         self.logger.addHandler(ch)
# 
#     def log(self, message):
#         self.logger.debug(message)
# 
# Path: cryptofolio/api/ExchangeException.py
# class ExchangeException(Exception):
#     def __init__(self, exchange, message):
#         super(ExchangeException, self).__init__(message)
#         self.message = "%s: %s" % (exchange, message)


# Path: cryptofolio/api/Binance.py
from binance.client import Client
from .Config import Config
from .Logger import Logger
from .ExchangeException import ExchangeException




class Binance:
    def __init__(self, key, secret):
        self.logger = Logger(__name__)

        try:
            self.client = Client(key, secret)
        except Exception as e:
            self.logger.log(e)
            raise ExchangeException(self.__class__.__name__, e)

    def getBalances(self):
        try:
            result = self.client.get_account()
            balances = {}

            for currency in result['balances']:
                name = currency['asset'].upper()
                value = float(currency['free'])

                if value > Config.BALANCE_ZERO:
                    balances[name] = value

            return balances
        except Exception as e:
            self.logger.log(e)

            raise ExchangeException(self.__class__.__name__, e)