<commit_before>import random
import time

from zaifbot.dao.order_log import OrderLogsDao
from zaifapi.api_error import ZaifApiNonceError, ZaifApiError
from zaifapi.impl import ZaifTradeApi, ZaifPublicApi
from zaifbot.bot_common.logger import logger
from zaifbot.utils import get_keys

_RETRY_COUNT = 5
_WAIT_SECOND = 5

__all__ = ['BotPublicApi', 'BotTradeApi']


# TODO:　リトライ実装見直したい。Exceptionでリトライするのは微妙だと思われる。
def _with_retry(func):
    def _wrapper(self, *args, **kwargs):
        for i in range(_RETRY_COUNT):
            try:
                return func(self, *args, **kwargs)
            except ZaifApiError as e:
                logger.error(e, exc_info=True)
                if i >= _RETRY_COUNT - 1:
                    raise e
            except ZaifApiNonceError as e:
                logger.error(e, exc_info=True)
                a = random.uniform(0.5, 1.0)
                time.sleep(a)
                if i >= _RETRY_COUNT - 1:
                    raise e
                continue
            except Exception as e:
                logger.error(e, exc_info=True)
                time.sleep(_WAIT_SECOND)
                if i >= _RETRY_COUNT - 1:
                    raise e
                continue
    return _wrapper


class BotTradeApi(ZaifTradeApi):
    def __init__(self, key=None, secret=None):
        if key is None and secret is None:
            key, secret = get_keys()
        elif type(key) is not type(secret):
            raise KeyError('only key or secret is set')

        super().__init__(key, secret)

    @_with_retry
    def active_orders(self, **kwargs):
        return super().active_orders(**kwargs)

    @_with_retry
    def cancel_order(self, **kwargs):
        return super().cancel_order(**kwargs)

    @_with_retry
    def deposit_history(self, **kwargs):
        return super().deposit_history(**kwargs)

    @_with_retry
    def get_id_info(self):
        return super().get_id_info()<commit_msg>remote exception<commit_after>import random
import time

from zaifbot.dao.order_log import OrderLogsDao
from zaifapi.api_error import ZaifApiNonceError, ZaifApiError
from zaifapi.impl import ZaifTradeApi, ZaifPublicApi
from zaifbot.bot_common.logger import logger
from zaifbot.utils import get_keys

_RETRY_COUNT = 5
_WAIT_SECOND = 5

__all__ = ['BotPublicApi', 'BotTradeApi']


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:
                    logger.error(e, exc_info=True)
                    raise e
                continue
    return _wrapper


class BotTradeApi(ZaifTradeApi):
    def __init__(self, key=None, secret=None):
        if key is None and secret is None:
            key, secret = get_keys()
        elif type(key) is not type(secret):
            raise KeyError('only key or secret is set')

        super().__init__(key, secret)

    @_with_retry
    def active_orders(self, **kwargs):
        return super().active_orders(**kwargs)

    @_with_retry
    def cancel_order(self, **kwargs):
        return super().cancel_order(**kwargs)

    @_with_retry
    def deposit_history(self, **kwargs):
        return super().deposit_history(**kwargs)

    @_with_retry
    def get_id_info(self):
        return super().get_id_info()
{'fraction_non_alphanumeric': 0.09174311926605505, 'fraction_numerical': 0.0045871559633027525, 'mean_word_length': 2.282220131702728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2936094', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1081, 'n_words': 271}