# Path: zaifbot/exchange/currency_pairs.py
# class CurrencyPair:
#     _lock = Lock()
#     _instances = {}
# 
#     def __new__(cls, name):
#         with cls._lock:
#             name = str(name)
#             if cls._instances.get(name, None) is None:
#                 cls._instances[name] = super().__new__(cls)
#         return cls._instances[name]
# 
#     def __init__(self, name):
#         self._name = str(name)
#         self._info = _ZaifCurrencyPairsInfo()[self._name]
# 
#     def __str__(self):
#         return self._name
# 
#     @property
#     def name(self):
#         return self._name
# 
#     @property
#     def info(self):
#         return self._info
# 
#     @property
#     def is_token(self):
#         return self._info['is_token']
# 
# 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={}):


from threading import Thread, Event, Lock
from zaifapi.impl import ZaifPublicStreamApi
from zaifbot.exchange.currency_pairs import CurrencyPair
from zaifbot.logger import bot_logger
    _error_events = {}
    _instance = None

    def __new__(cls):
        with cls._lock:
            if cls._instance is None:
                cls._instance = super().__new__(cls)
        return cls._instance

    def execute(self, currency_pair):
        if isinstance(currency_pair, CurrencyPair):
            if currency_pair.is_token:
                raise ValueError('token is not supported by stream api')

        currency_pair = str(currency_pair)
        if self._sockets.get(currency_pair, None):
            return self._sockets[currency_pair].last_receive
        self._run_new_socket(currency_pair)

        return self._sockets[currency_pair].last_receive

    def stop(self, currency_pair):
        if self._stop_events.get(currency_pair, None):
            self._sockets[currency_pair].stop()
        else:
            pass

    def _run_new_socket(self, currency_pair):
        if self._sockets.get(currency_pair, None):
            return

# Path: zaifbot/exchange/currency_pairs.py
# class CurrencyPair:
#     _lock = Lock()
#     _instances = {}
# 
#     def __new__(cls, name):
#         with cls._lock:
#             name = str(name)
#             if cls._instances.get(name, None) is None:
#                 cls._instances[name] = super().__new__(cls)
#         return cls._instances[name]
# 
#     def __init__(self, name):
#         self._name = str(name)
#         self._info = _ZaifCurrencyPairsInfo()[self._name]
# 
#     def __str__(self):
#         return self._name
# 
#     @property
#     def name(self):
#         return self._name
# 
#     @property
#     def info(self):
#         return self._info
# 
#     @property
#     def is_token(self):
#         return self._info['is_token']
# 
# 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/exchange/api/websocket.py
from threading import Thread, Event, Lock
from zaifapi.impl import ZaifPublicStreamApi
from zaifbot.exchange.currency_pairs import CurrencyPair
from zaifbot.logger import bot_logger

    _error_events = {}
    _instance = None

    def __new__(cls):
        with cls._lock:
            if cls._instance is None:
                cls._instance = super().__new__(cls)
        return cls._instance

    def execute(self, currency_pair):
        if isinstance(currency_pair, CurrencyPair):
            if currency_pair.is_token:
                raise ValueError('token is not supported by stream api')

        currency_pair = str(currency_pair)
        if self._sockets.get(currency_pair, None):
            return self._sockets[currency_pair].last_receive
        self._run_new_socket(currency_pair)

        return self._sockets[currency_pair].last_receive

    def stop(self, currency_pair):
        if self._stop_events.get(currency_pair, None):
            self._sockets[currency_pair].stop()
        else:
            pass

    def _run_new_socket(self, currency_pair):
        if self._sockets.get(currency_pair, None):
            return

        bot_logger.info('creating new socket for {}'.format(currency_pair))