# Path: zaifbot/db/dao/trades.py
# class TradesDao(DaoBase):
#     def _get_model(self):
#         return Trades
# 
#     def history(self, from_datetime, to_datetime, filters=None):
#         with self._session() as s:
# 
#             q = s.query(self._Model)
# 
#             if from_datetime is not None:
#                 q = q.filter(self._Model.entry_datetime >= from_datetime)
# 
#             if to_datetime is not None:
#                 q = q.filter(self._Model.exit_datetime <= to_datetime)
# 
#             if filters is None:
#                 return q.all()
# 
#             if not isinstance(filters, dict):
#                 raise TypeError("params should be 'dict'")
# 
#             q = self._custom_filters(q, filters)
#             return q.all()
# 
# Path: zaifbot/exchange/action.py
# def Action(action):
#     def __init__(self, action):  # necessary
#     def __str__(self):
#     def __eq__(self, other):
#     def name(self):
#     def is_my_action(self):
#     def is_my_action(action):
#     def opposite_action():
#     def name(self):
#     def is_my_action(action):
#     def opposite_action():
#     def name(self):
# class _TradeAction(metaclass=ABCMeta):
# class _Buy(_TradeAction):
# class _Sell(_TradeAction):
# 
# 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/http.py
# class BotTradeApi(ZaifTradeApi):
#     def __init__(self, key=None, secret=None):
#         if key is None and secret is None:
#             key, secret = get_keys()
#         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()
# 
#     @_with_retry
#     def get_info(self):
#         return super().get_info()
# 
#     @_with_retry
#     def get_info2(self):
#         return super().get_info2()
# 
#     @_with_retry
#     def get_personal_info(self):
#         return super().get_personal_info()
# 
#     @_with_retry
#     def trade(self, **kwargs):
#         def __params_pre_processing(**kwa):
#             kwa['currency_pair'] = str(kwa['currency_pair'])
#             kwa['action'] = str(kwa['action'])
#             return kwa
#         kwargs = __params_pre_processing(**kwargs)
#         return super().trade(**kwargs)
# 
#     @_with_retry
#     def trade_history(self, **kwargs):
#         return super().trade_history(**kwargs)
# 
#     @_with_retry
#     def withdraw(self, **kwargs):
#         return super().withdraw(**kwargs)
# 
#     @_with_retry
#     def withdraw_history(self, **kwargs):
#         return super().withdraw_history(**kwargs)
# 
# Path: zaifbot/trade/tools.py
# def last_price(currency_pair, *, timestamp=None):
#     if timestamp is None:
#         return get_latest_price(currency_pair)
# 
#     candle_sticks = CandleSticks(currency_pair, '1m')
#     return candle_sticks.last_price(timestamp)
# 
# Path: zaifbot/exchange/tick.py
# class Tick:
#     def __init__(self, currency_pair):
#         self.size = Decimal(str(currency_pair.info['aux_unit_step']))
#         self._decimal_digits = currency_pair.info['aux_unit_point']
# 
#     def truncate_price(self, price):
#         price = Decimal(str(price))
# 
#         remainder = price % self.size
#         truncated_price = price - remainder
#         if self._decimal_digits == 0:
#             return int(truncated_price)
#         return float(truncated_price)


from datetime import datetime
from zaifbot.db.dao.trades import TradesDao
from zaifbot.exchange.action import Action, Buy, Sell
from zaifbot.exchange.currency_pairs import CurrencyPair
from zaifbot.logger import trade_logger
from zaifbot.exchange.api.http import BotTradeApi
from zaifbot.trade.tools import last_price
from zaifbot.exchange.tick import Tick


class Trade:
    def __init__(self):
        self.currency_pair = None
        self.entry_datetime = None
        self.entry_price = None
        self.amount = None
        self.action = None
        self.exit_price = None
        self.exit_datetime = None
        self.id_ = None
        self.closed = False
        self._trade_api = BotTradeApi()

# Path: zaifbot/db/dao/trades.py
# class TradesDao(DaoBase):
#     def _get_model(self):
#         return Trades
# 
#     def history(self, from_datetime, to_datetime, filters=None):
#         with self._session() as s:
# 
#             q = s.query(self._Model)
# 
#             if from_datetime is not None:
#                 q = q.filter(self._Model.entry_datetime >= from_datetime)
# 
#             if to_datetime is not None:
#                 q = q.filter(self._Model.exit_datetime <= to_datetime)
# 
#             if filters is None:
#                 return q.all()
# 
#             if not isinstance(filters, dict):
#                 raise TypeError("params should be 'dict'")
# 
#             q = self._custom_filters(q, filters)
#             return q.all()
# 
# Path: zaifbot/exchange/action.py
# def Action(action):
#     def __init__(self, action):  # necessary
#     def __str__(self):
#     def __eq__(self, other):
#     def name(self):
#     def is_my_action(self):
#     def is_my_action(action):
#     def opposite_action():
#     def name(self):
#     def is_my_action(action):
#     def opposite_action():
#     def name(self):
# class _TradeAction(metaclass=ABCMeta):
# class _Buy(_TradeAction):
# class _Sell(_TradeAction):
# 
# 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/http.py
# class BotTradeApi(ZaifTradeApi):
#     def __init__(self, key=None, secret=None):
#         if key is None and secret is None:
#             key, secret = get_keys()
#         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()
# 
#     @_with_retry
#     def get_info(self):
#         return super().get_info()
# 
#     @_with_retry
#     def get_info2(self):
#         return super().get_info2()
# 
#     @_with_retry
#     def get_personal_info(self):
#         return super().get_personal_info()
# 
#     @_with_retry
#     def trade(self, **kwargs):
#         def __params_pre_processing(**kwa):
#             kwa['currency_pair'] = str(kwa['currency_pair'])
#             kwa['action'] = str(kwa['action'])
#             return kwa
#         kwargs = __params_pre_processing(**kwargs)
#         return super().trade(**kwargs)
# 
#     @_with_retry
#     def trade_history(self, **kwargs):
#         return super().trade_history(**kwargs)
# 
#     @_with_retry
#     def withdraw(self, **kwargs):
#         return super().withdraw(**kwargs)
# 
#     @_with_retry
#     def withdraw_history(self, **kwargs):
#         return super().withdraw_history(**kwargs)
# 
# Path: zaifbot/trade/tools.py
# def last_price(currency_pair, *, timestamp=None):
#     if timestamp is None:
#         return get_latest_price(currency_pair)
# 
#     candle_sticks = CandleSticks(currency_pair, '1m')
#     return candle_sticks.last_price(timestamp)
# 
# Path: zaifbot/exchange/tick.py
# class Tick:
#     def __init__(self, currency_pair):
#         self.size = Decimal(str(currency_pair.info['aux_unit_step']))
#         self._decimal_digits = currency_pair.info['aux_unit_point']
# 
#     def truncate_price(self, price):
#         price = Decimal(str(price))
# 
#         remainder = price % self.size
#         truncated_price = price - remainder
#         if self._decimal_digits == 0:
#             return int(truncated_price)
#         return float(truncated_price)


# Path: zaifbot/trade/trade.py
from datetime import datetime
from zaifbot.db.dao.trades import TradesDao
from zaifbot.exchange.action import Action, Buy, Sell
from zaifbot.exchange.currency_pairs import CurrencyPair
from zaifbot.logger import trade_logger
from zaifbot.exchange.api.http import BotTradeApi
from zaifbot.trade.tools import last_price
from zaifbot.exchange.tick import Tick



class Trade:
    def __init__(self):
        self.currency_pair = None
        self.entry_datetime = None
        self.entry_price = None
        self.amount = None
        self.action = None
        self.exit_price = None
        self.exit_datetime = None
        self.id_ = None
        self.closed = False
        self._trade_api = BotTradeApi()

        self._dao = TradesDao()