# 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)


import json
from django.conf import settings
from ratelimit import limits, sleep_and_retry
from requests import Session
from requests.exceptions import ConnectionError, Timeout, TooManyRedirects
from .Logger import Logger
    @limits(calls=27, period=60)
    def fetch(self, path, params=None):
        try:
            response = self.session.get(
                    '{}{}'.format(self.PRODUCTION_BASE_URL, path),
                    params=params)
            data = json.loads(response.text)
            return data
        except (ConnectionError, Timeout, TooManyRedirects) as e:
            self.logger.log(e)

    def getRates(self, fiat):
        market = {}

        parameters = {'start': '1', 'limit': '1000', 'convert': fiat}
        ticker = self.fetch(self.TICKER_PATH, params=parameters)

        for t in ticker['data']:
            name = t['name'].upper()
            symbol = t['symbol'].upper()
            price = t['quote'][fiat]['price']
            if price:
                market[name] = float(price)
                market[symbol] = float(price)

        return market

    def getCoinNames(self):
        parameters = {'start': '1', 'limit': '4710'}
        listings = self.fetch(self.LISTINGS_PATH, params=parameters)

# 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/Coinmarket.py
import json
from django.conf import settings
from ratelimit import limits, sleep_and_retry
from requests import Session
from requests.exceptions import ConnectionError, Timeout, TooManyRedirects
from .Logger import Logger

    @limits(calls=27, period=60)
    def fetch(self, path, params=None):
        try:
            response = self.session.get(
                    '{}{}'.format(self.PRODUCTION_BASE_URL, path),
                    params=params)
            data = json.loads(response.text)
            return data
        except (ConnectionError, Timeout, TooManyRedirects) as e:
            self.logger.log(e)

    def getRates(self, fiat):
        market = {}

        parameters = {'start': '1', 'limit': '1000', 'convert': fiat}
        ticker = self.fetch(self.TICKER_PATH, params=parameters)

        for t in ticker['data']:
            name = t['name'].upper()
            symbol = t['symbol'].upper()
            price = t['quote'][fiat]['price']
            if price:
                market[name] = float(price)
                market[symbol] = float(price)

        return market

    def getCoinNames(self):
        parameters = {'start': '1', 'limit': '4710'}
        listings = self.fetch(self.LISTINGS_PATH, params=parameters)

        coins = []