# Path: OnePy/builtin_module/backtest_forex/calculate_func.py
# def dollar_per_pips(ticker, cur_price):
#     """外汇专用"""
# 
#     if ticker[:3] == 'USD':
#         return 10/cur_price
#     elif ticker[-3:] == 'USD':
#         return 10
#     else:
#         raise Exception("Could only backtest in USD currency pairs.")
# 
# Path: OnePy/sys_module/models/base_log.py
# class TradeLogBase(OnePyEnvBase, abc.ABC):
# 
#     buy: float = None
#     sell: float = None
#     size: float = None
# 
#     entry_date: str = field(init=False)
#     exit_date: str = field(init=False)
# 
#     entry_price: float = field(init=False)
#     exit_price: float = field(init=False)
# 
#     entry_type: str = field(init=False)
#     exit_type: str = field(init=False)
# 
#     pl_points: float = field(init=False)
#     re_pnl: float = field(init=False)
# 
#     commission: float = field(init=False)
# 
#     @abc.abstractmethod
#     def generate(self):
#         raise NotImplementedError
# 
#     def _earn_short(self):
#         return -1 if self.buy.action_type == ActionType.Short else 1
# 
#     @staticmethod
#     def _get_order_type(order):
#         if isinstance(order.signal, SignalByTrigger):
#             return order.signal.order_type.value
#         else:
#             return order.order_type.value
# 
#     @abc.abstractmethod
#     def settle_left_trade(self):
#         raise NotImplementedError
# 
#     @property
#     def ticker(self):
#         return self.buy.ticker


from dataclasses import dataclass
from OnePy.builtin_module.backtest_forex.calculate_func import dollar_per_pips
from OnePy.sys_module.models.base_log import TradeLogBase
        self.exit_type = f'{sell_order_type} {self.sell.action_type.value}'
        self.pl_points = (self.sell.first_cur_price -
                          self.buy.first_cur_price)*self._earn_short()
        self.re_pnl = self.pl_points*self.size * \
            dollar_per_pips(self.ticker, self.exit_price)

        self.commission = (
            slippage[self.ticker]*self.size/1e5*dollar_per_pips(self.ticker, self.entry_price))

        if self.env.execute_on_close_or_next_open == 'open':
            self.exit_date = self.sell.signal.next_datetime
        elif self.env.execute_on_close_or_next_open == 'close':
            self.exit_date = self.sell.trading_date

        return self

    def settle_left_trade(self):
        cur_price = self.env.feeds[self.ticker].cur_price
        buy_order_type = self._get_order_type(self.buy)
        slippage = self.env.recorder.slippage

        self.entry_date = self.buy.trading_date
        self.entry_price = self.buy.first_cur_price
        self.entry_type = f'{buy_order_type} {self.buy.action_type.value}'
        self.exit_date = None
        self.exit_price = None
        self.exit_type = None
        self.pl_points = (
            cur_price - self.buy.first_cur_price)*self._earn_short()
        self.re_pnl = self.pl_points*self.size * \

# Path: OnePy/builtin_module/backtest_forex/calculate_func.py
# def dollar_per_pips(ticker, cur_price):
#     """外汇专用"""
# 
#     if ticker[:3] == 'USD':
#         return 10/cur_price
#     elif ticker[-3:] == 'USD':
#         return 10
#     else:
#         raise Exception("Could only backtest in USD currency pairs.")
# 
# Path: OnePy/sys_module/models/base_log.py
# class TradeLogBase(OnePyEnvBase, abc.ABC):
# 
#     buy: float = None
#     sell: float = None
#     size: float = None
# 
#     entry_date: str = field(init=False)
#     exit_date: str = field(init=False)
# 
#     entry_price: float = field(init=False)
#     exit_price: float = field(init=False)
# 
#     entry_type: str = field(init=False)
#     exit_type: str = field(init=False)
# 
#     pl_points: float = field(init=False)
#     re_pnl: float = field(init=False)
# 
#     commission: float = field(init=False)
# 
#     @abc.abstractmethod
#     def generate(self):
#         raise NotImplementedError
# 
#     def _earn_short(self):
#         return -1 if self.buy.action_type == ActionType.Short else 1
# 
#     @staticmethod
#     def _get_order_type(order):
#         if isinstance(order.signal, SignalByTrigger):
#             return order.signal.order_type.value
#         else:
#             return order.order_type.value
# 
#     @abc.abstractmethod
#     def settle_left_trade(self):
#         raise NotImplementedError
# 
#     @property
#     def ticker(self):
#         return self.buy.ticker


# Path: OnePy/builtin_module/backtest_forex/forex_log.py
from dataclasses import dataclass
from OnePy.builtin_module.backtest_forex.calculate_func import dollar_per_pips
from OnePy.sys_module.models.base_log import TradeLogBase

        self.exit_type = f'{sell_order_type} {self.sell.action_type.value}'
        self.pl_points = (self.sell.first_cur_price -
                          self.buy.first_cur_price)*self._earn_short()
        self.re_pnl = self.pl_points*self.size * \
            dollar_per_pips(self.ticker, self.exit_price)

        self.commission = (
            slippage[self.ticker]*self.size/1e5*dollar_per_pips(self.ticker, self.entry_price))

        if self.env.execute_on_close_or_next_open == 'open':
            self.exit_date = self.sell.signal.next_datetime
        elif self.env.execute_on_close_or_next_open == 'close':
            self.exit_date = self.sell.trading_date

        return self

    def settle_left_trade(self):
        cur_price = self.env.feeds[self.ticker].cur_price
        buy_order_type = self._get_order_type(self.buy)
        slippage = self.env.recorder.slippage

        self.entry_date = self.buy.trading_date
        self.entry_price = self.buy.first_cur_price
        self.entry_type = f'{buy_order_type} {self.buy.action_type.value}'
        self.exit_date = None
        self.exit_price = None
        self.exit_type = None
        self.pl_points = (
            cur_price - self.buy.first_cur_price)*self._earn_short()
        self.re_pnl = self.pl_points*self.size * \

            dollar_per_pips(self.ticker, cur_price)