# Path: zaifbot/logger.py
# def _bot_console_handler():
# def _bot_file_handler(file=None):
# def _bot_logger():
# def _trade_logger():
# def add_logging_directions(webhook_url=None, email={}):
# 
# Path: zaifbot/config.py
# def get_keys():
#     if env.get('ZAIFBOT_KEY') and env.get('ZAIFBOT_SECRET'):
#         return env['ZAIFBOT_KEY'], env['ZAIFBOT_SECRET']
# 
#     home = os.path.expanduser('~')
#     config_file = os.path.join(home, '.zaifbot')
#     if os.path.isfile(config_file):
#         config = configparser.ConfigParser()
#         config.read(config_file)
#         return config['api_keys']['key'], config['api_keys']['secret']
# 
#     raise ZaifBotError('api keys are not set')


import random
import time
import requests
import json
import inspect
from zaifapi.api_error import ZaifApiNonceError, ZaifApiError
from zaifapi.impl import ZaifTradeApi, ZaifPublicApi
from zaifbot.logger import bot_logger
from zaifbot.config import get_keys



_RETRY_COUNT = 5
_WAIT_SECOND = 5


def _with_retry(func):
    def _wrapper(self, *args, **kwargs):
        for i in range(_RETRY_COUNT):
            try:
                return func(self, *args, **kwargs)
            except (ZaifApiError, ZaifApiNonceError) as e:
                a = random.uniform(0.1, 0.5)
                time.sleep(a)
                if i >= _RETRY_COUNT - 1:
                    bot_logger.exception(e)
                    raise e
                continue
    return _wrapper


__all__ = ['BotPublicApi', 'BotTradeApi']


class BotTradeApi(ZaifTradeApi):
    def __init__(self, key=None, secret=None):
        if key is None and secret is None:

# Path: zaifbot/logger.py
# def _bot_console_handler():
# def _bot_file_handler(file=None):
# def _bot_logger():
# def _trade_logger():
# def add_logging_directions(webhook_url=None, email={}):
# 
# Path: zaifbot/config.py
# def get_keys():
#     if env.get('ZAIFBOT_KEY') and env.get('ZAIFBOT_SECRET'):
#         return env['ZAIFBOT_KEY'], env['ZAIFBOT_SECRET']
# 
#     home = os.path.expanduser('~')
#     config_file = os.path.join(home, '.zaifbot')
#     if os.path.isfile(config_file):
#         config = configparser.ConfigParser()
#         config.read(config_file)
#         return config['api_keys']['key'], config['api_keys']['secret']
# 
#     raise ZaifBotError('api keys are not set')


# Path: zaifbot/exchange/api/http.py
import random
import time
import requests
import json
import inspect
from zaifapi.api_error import ZaifApiNonceError, ZaifApiError
from zaifapi.impl import ZaifTradeApi, ZaifPublicApi
from zaifbot.logger import bot_logger
from zaifbot.config import get_keys




_RETRY_COUNT = 5
_WAIT_SECOND = 5


def _with_retry(func):
    def _wrapper(self, *args, **kwargs):
        for i in range(_RETRY_COUNT):
            try:
                return func(self, *args, **kwargs)
            except (ZaifApiError, ZaifApiNonceError) as e:
                a = random.uniform(0.1, 0.5)
                time.sleep(a)
                if i >= _RETRY_COUNT - 1:
                    bot_logger.exception(e)
                    raise e
                continue
    return _wrapper


__all__ = ['BotPublicApi', 'BotTradeApi']


class BotTradeApi(ZaifTradeApi):
    def __init__(self, key=None, secret=None):
        if key is None and secret is None:

            key, secret = get_keys()