# Path: zaifbot/exchange/candle_sticks.py
# class CandleSticks:
#     MAX_COUNT = 1500
# 
#     def __init__(self, currency_pair, period):
#         self._currency_pair = CurrencyPair(currency_pair)
#         self._period = Period(period)
#         self._dao = CandleSticksDao(self._currency_pair, self._period)
# 
#     def request_data(self, count=100, to_epoch_time=None):
#         count = min(count, self.MAX_COUNT)
#         to_epoch_time = int_epoch_time(to_epoch_time)
#         end_time_rounded = self._period.truncate_sec(to_epoch_time)
#         start_time = self._period.calc_start(count, end_time_rounded)
# 
#         return self._dao.get_by_duration(count, start_time, end_time_rounded)
# 
#     def last_price(self, timestamp):
#         return self.request_data(count=1, to_epoch_time=timestamp)[0]['close']
# 
# Path: zaifbot/exchange/latest_price.py
# 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()
#         return stream_api.execute(currency_pair)['last_price']['price']


from zaifbot.exchange.candle_sticks import CandleSticks
from zaifbot.exchange.latest_price import get_latest_price


def last_price(currency_pair, *, timestamp=None):
    if timestamp is None:
        return get_latest_price(currency_pair)


# Path: zaifbot/exchange/candle_sticks.py
# class CandleSticks:
#     MAX_COUNT = 1500
# 
#     def __init__(self, currency_pair, period):
#         self._currency_pair = CurrencyPair(currency_pair)
#         self._period = Period(period)
#         self._dao = CandleSticksDao(self._currency_pair, self._period)
# 
#     def request_data(self, count=100, to_epoch_time=None):
#         count = min(count, self.MAX_COUNT)
#         to_epoch_time = int_epoch_time(to_epoch_time)
#         end_time_rounded = self._period.truncate_sec(to_epoch_time)
#         start_time = self._period.calc_start(count, end_time_rounded)
# 
#         return self._dao.get_by_duration(count, start_time, end_time_rounded)
# 
#     def last_price(self, timestamp):
#         return self.request_data(count=1, to_epoch_time=timestamp)[0]['close']
# 
# Path: zaifbot/exchange/latest_price.py
# 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()
#         return stream_api.execute(currency_pair)['last_price']['price']


# Path: zaifbot/trade/tools.py
from zaifbot.exchange.candle_sticks import CandleSticks
from zaifbot.exchange.latest_price import get_latest_price



def last_price(currency_pair, *, timestamp=None):
    if timestamp is None:
        return get_latest_price(currency_pair)


    candle_sticks = CandleSticks(currency_pair, '1m')