# 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/exchange/api/http.py
# class BotPublicApi(ZaifPublicApi):
# 
#     @_with_retry
#     def last_price(self, currency_pair):
#         return super().last_price(str(currency_pair))
# 
#     @_with_retry
#     def ticker(self, currency_pair):
#         return super().ticker(currency_pair)
# 
#     @_with_retry
#     def trades(self, currency_pair):
#         return super().trades(currency_pair)
# 
#     @_with_retry
#     def depth(self, currency_pair):
#         return super().depth(currency_pair)
# 
#     @_with_retry
#     def currency_pairs(self, currency_pair):
#         return super().currency_pairs(currency_pair)
# 
#     @_with_retry
#     def currencies(self, currency):
#         return super().currencies(currency)
# 
# Path: zaifbot/exchange/api/websocket.py
# class BotStreamApi:
#     _lock = Lock()
#     _sockets = {}
#     _stop_events = {}
#     _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))
#         stop_event = Event()
#         error_event = Event()
#         new_socket = _StreamThread(currency_pair, stop_event, error_event)
#         new_socket.start()
#         self._sockets[currency_pair] = new_socket
#         self._stop_events[currency_pair] = stop_event
#         self._error_events[currency_pair] = error_event


from zaifbot.exchange.currency_pairs import CurrencyPair
from zaifbot.exchange.api.http import BotPublicApi
from zaifbot.exchange.api.websocket import BotStreamApi


def get_latest_price(currency_pair):
    currency_pair = CurrencyPair(currency_pair)

    if currency_pair.is_token:
        public_api = BotPublicApi()
        return public_api.last_price(currency_pair)['last_price']
    else:

# 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/exchange/api/http.py
# class BotPublicApi(ZaifPublicApi):
# 
#     @_with_retry
#     def last_price(self, currency_pair):
#         return super().last_price(str(currency_pair))
# 
#     @_with_retry
#     def ticker(self, currency_pair):
#         return super().ticker(currency_pair)
# 
#     @_with_retry
#     def trades(self, currency_pair):
#         return super().trades(currency_pair)
# 
#     @_with_retry
#     def depth(self, currency_pair):
#         return super().depth(currency_pair)
# 
#     @_with_retry
#     def currency_pairs(self, currency_pair):
#         return super().currency_pairs(currency_pair)
# 
#     @_with_retry
#     def currencies(self, currency):
#         return super().currencies(currency)
# 
# Path: zaifbot/exchange/api/websocket.py
# class BotStreamApi:
#     _lock = Lock()
#     _sockets = {}
#     _stop_events = {}
#     _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))
#         stop_event = Event()
#         error_event = Event()
#         new_socket = _StreamThread(currency_pair, stop_event, error_event)
#         new_socket.start()
#         self._sockets[currency_pair] = new_socket
#         self._stop_events[currency_pair] = stop_event
#         self._error_events[currency_pair] = error_event


# Path: zaifbot/exchange/latest_price.py
from zaifbot.exchange.currency_pairs import CurrencyPair
from zaifbot.exchange.api.http import BotPublicApi
from zaifbot.exchange.api.websocket import BotStreamApi



def get_latest_price(currency_pair):
    currency_pair = CurrencyPair(currency_pair)

    if currency_pair.is_token:
        public_api = BotPublicApi()
        return public_api.last_price(currency_pair)['last_price']
    else:

        stream_api = BotStreamApi()